DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LongvolReader.h
1 
17 #pragma once
18 
31 #if defined(LongvolReader_RECURSES)
32 #error Recursive header files inclusion detected in LongvolReader.h
33 #else // defined(LongvolReader_RECURSES)
34 
35 #define LongvolReader_RECURSES
36 
37 #if !defined LongvolReader_h
38 
39 #define LongvolReader_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 LongvolReader
86  template <typename TImageContainer>
88  {
89  // ----------------------- Standard services ------------------------------
90 
91  typedef TImageContainer ImageContainer;
92 
93  BOOST_STATIC_ASSERT(ImageContainer::Domain::dimension == 3);
94 
95 
103  static ImageContainer importLongvol(const std::string & filename) throw(DGtal::IOException);
104 
105 
106 
107  private:
108 
117  template <typename Word>
118  static
119  FILE* read_word( FILE* fin, Word& aValue )
120  {
121  aValue = 0;
122  for (unsigned size = 0; size < sizeof( Word ); ++size)
123  aValue |= getc(fin) << (8 * size);
124  return fin;
125  }
126 
127  typedef unsigned char voxel;
128  // This class help us to associate a field type and his value.
129  // An object is a pair (type, value). You can copy and assign
130  // such objects.
131  /* In recent C++, we should use a std::map, but we prefer (badly) code it
132  by hand for compatibility with old compilers.
133  At this time, there is a limit of 30 fields in header :-} */
134  struct HeaderField {
136  HeaderField( const char *t, const char *v ) :
137  type( strdup(t) ), value( strdup(v) ) {}
139  free( type );
140  free( value );
141  }
143  HeaderField( const HeaderField &h ) :
144  type( strdup(h.type) ), value( strdup(h.value) ) {};
146  HeaderField() : type(NULL), value(NULL) {};
149  free( type );
150  free( value );
151  if (h.type != NULL) {
152  type = strdup( h.type );
153  value = strdup( h.value );
154  }
155  return *this;
156  }
158  char *type;
160  char *value;
161  };
162 
163 
165  static const char *getHeaderValue( const char *type, const HeaderField * header );
166 
168  static int getHeaderValueAsInt( const char *type, int *dest , const HeaderField * header);
169 
170 
172  static const int MAX_HEADERNUMLINES = 64;
173 
174 
176  static int getHeaderField( const char *type, const HeaderField * header ) ;
177 
179  static const char *requiredHeaders[];
180 
181  }; // end of class LongvolReader
182 
183 
184 } // namespace DGtal
185 
186 
188 // Includes inline functions.
189 #include "DGtal/io/readers/LongvolReader.ih"
190 
191 // //
193 
194 #endif // !defined LongvolReader_h
195 
196 #undef LongvolReader_RECURSES
197 #endif // else defined(LongvolReader_RECURSES)