DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
VolReader.h
1 
17 #pragma once
18 
31 #if defined(VolReader_RECURSES)
32 #error Recursive header files inclusion detected in VolReader.h
33 #else // defined(VolReader_RECURSES)
34 
35 #define VolReader_RECURSES
36 
37 #if !defined VolReader_h
38 
39 #define VolReader_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <string>
45 #include <cstdio>
46 #include "DGtal/base/Common.h"
47 #include <boost/static_assert.hpp>
48 #include "DGtal/helpers/StdDefs.h"
49 
51 
52 namespace DGtal
53 {
54 
56  // template class VolReader
87  template <typename TImageContainer>
88  struct VolReader
89  {
90  // ----------------------- Standard services ------------------------------
91 
92  typedef TImageContainer ImageContainer;
93 
94  BOOST_STATIC_ASSERT(ImageContainer::Domain::dimension == 3);
95 
96 
104  static ImageContainer importVol(const std::string & filename) throw(DGtal::IOException);
105 
106 
107 
108  private:
109 
110  typedef unsigned char voxel;
111  // This class help us to associate a field type and his value.
112  // An object is a pair (type, value). You can copy and assign
113  // such objects.
114  /* In recent C++, we should use a std::map, but we prefer (badly) code it
115  by hand for compatibility with old compilers.
116  At this time, there is a limit of 30 fields in header :-} */
117  struct HeaderField {
119  HeaderField( const char *t, const char *v ) :
120  type( strdup(t) ), value( strdup(v) ) {}
122  free( type );
123  free( value );
124  }
126  HeaderField( const HeaderField &h ) :
127  type( strdup(h.type) ), value( strdup(h.value) ) {};
129  HeaderField() : type(NULL), value(NULL) {};
132  free( type );
133  free( value );
134  if (h.type != NULL) {
135  type = strdup( h.type );
136  value = strdup( h.value );
137  }
138  return *this;
139  }
141  char *type;
143  char *value;
144  };
145 
146 
148  static const char *getHeaderValue( const char *type, const HeaderField * header );
149 
151  static int getHeaderValueAsInt( const char *type, int *dest , const HeaderField * header);
152 
153 
155  static const int MAX_HEADERNUMLINES = 64;
156 
157 
159  static int getHeaderField( const char *type, const HeaderField * header ) ;
160 
162  static const char *requiredHeaders[];
163 
164  }; // end of class VolReader
165 
166 
167 } // namespace DGtal
168 
169 
171 // Includes inline functions.
172 #include "DGtal/io/readers/VolReader.ih"
173 
174 // //
176 
177 #endif // !defined VolReader_h
178 
179 #undef VolReader_RECURSES
180 #endif // else defined(VolReader_RECURSES)