DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VolWriter.ih
1 
30 
31 #include <cstdlib>
32 #include <fstream>
33 #include "DGtal/io/Color.h"
35 
37 // IMPLEMENTATION of inline methods.
39 
40 
41 namespace DGtal {
42  template<typename I,typename F>
43  bool
44  VolWriter<I,F>::exportVol(const std::string & filename, const I & aImage,
45  const Functor & aFunctor) throw(DGtal::IOException)
46  {
47  DGtal::IOException dgtalio;
48 
49  ofstream out;
50  typename I::Domain::Vector ext = aImage.extent();
51  typename I::Domain domain = aImage.domain();
52  typename I::Value val;
53 
54  try
55  {
56  out.open(filename.c_str());
57 
58  //Vol format
59  out << "X: "<< ext[0]<<endl;
60  out << "Y: "<< ext[1]<<endl;
61  out << "Z: "<< ext[2]<<endl;
62  out << "Voxel-Size: 1"<<endl;
63  out << "Alpha-Color: 0"<<endl;
64  out << "Voxel-Endian: 0"<<endl;
65  out << "Int-Endian: 0123"<<endl;
66  out << "Version: 2"<<endl;
67  out << "."<<endl;
68 
69  //We scan the domain instead of the image because we cannot
70  //trust the image container Iterator
71  for(typename I::Domain::ConstIterator it = domain.begin(), itend=domain.end();
72  it!=itend;
73  ++it)
74  {
75  val = aImage( (*it) );
76  out.put(aFunctor(val));
77  }
78 
79  out.close();
80 
81  }
82  catch( ... )
83  {
84  std::cout << "Vol writer IO error on export " << filename << endl;
85  throw dgtalio;
86  }
87  return true;
88  }
89 
90 }//namespace