DGtal  1.5.beta
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)
35 #define VolReader_RECURSES
36 
37 #if !defined VolReader_h
39 #define VolReader_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <sstream>
45 #include <string>
46 #include <cstdio>
47 #include "DGtal/base/Common.h"
48 #include "DGtal/base/CUnaryFunctor.h"
50 
51 namespace DGtal
52 {
53 
55  // template class VolReader
87  template <typename TImageContainer,
88  typename TFunctor = functors::Cast< typename TImageContainer::Value > >
89  struct VolReader
90  {
91  // ----------------------- Standard services ------------------------------
92 
94  typedef typename TImageContainer::Value Value;
95  typedef TFunctor Functor;
96 
98 
99  BOOST_STATIC_ASSERT(ImageContainer::Domain::dimension == 3);
100 
101 
114  static ImageContainer importVol(const std::string & filename,
115  const Functor & aFunctor = Functor());
116 
117  private:
118 
119  typedef unsigned char voxel;
125  /* In recent C++, we should use a std::map, but we prefer (badly) code it
126  by hand for compatibility with old compilers.
127  At this time, there is a limit of 30 fields in header :-} */
128  struct HeaderField {
130  HeaderField( const char *t, const char *v ) :
131  type( strdup(t) ), value( strdup(v) ) {}
133  free( type );
134  free( value );
135  }
137  HeaderField( const HeaderField &h ) :
138  type( strdup(h.type) ), value( strdup(h.value) ) {};
140  HeaderField() : type(NULL), value(NULL) {};
143  free( type );
144  free( value );
145  if (h.type != NULL) {
146  type = strdup( h.type );
147  value = strdup( h.value );
148  }
149  return *this;
150  }
152  char *type;
154  char *value;
155  };
156 
157 
159  static const char *getHeaderValue( const char *type, const HeaderField * header );
160 
162  static int getHeaderValueAsInt( const char *type, int *dest , const HeaderField * header);
163 
165  static int getHeaderField( const char *type, const HeaderField * header ) ;
166 
168  static const char *requiredHeaders[];
169 
170  }; // end of class VolReader
171 
172 
173 } // namespace DGtal
174 
175 
177 // Includes inline functions.
178 #include "DGtal/io/readers/VolReader.ih"
179 
180 // //
182 
183 #endif // !defined VolReader_h
184 
185 #undef VolReader_RECURSES
186 #endif // else defined(VolReader_RECURSES)
DGtal is the top-level namespace which contains all DGtal functions and types.
HeaderField(const HeaderField &h)
Copy constructor.
Definition: VolReader.h:137
const HeaderField & operator=(const HeaderField &h)
Assignement operator.
Definition: VolReader.h:142
char * type
Type of field (e.g. Voxel-Size)
Definition: VolReader.h:152
HeaderField()
Default constructor.
Definition: VolReader.h:140
HeaderField(const char *t, const char *v)
Constructor. The string are copied.
Definition: VolReader.h:130
char * value
Value of field (e.g. 2)
Definition: VolReader.h:154
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
TFunctor Functor
Definition: VolReader.h:95
TImageContainer::Value Value
Definition: VolReader.h:94
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctor, unsigned char, Value >))
static int getHeaderValueAsInt(const char *type, int *dest, const HeaderField *header)
Returns non-zero if failure.
TImageContainer ImageContainer
Definition: VolReader.h:93
BOOST_STATIC_ASSERT(ImageContainer::Domain::dimension==3)
static const char * requiredHeaders[]
Global list of required fields in a .vol file.
Definition: VolReader.h:168
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
unsigned char voxel
Definition: VolReader.h:119
static const char * getHeaderValue(const char *type, const HeaderField *header)
Returns NULL if this field is not found.
static int getHeaderField(const char *type, const HeaderField *header)
Internal method which returns the index of a field or -1 if not found.
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:90
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer