DGtal  0.9.2
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 "DGtal/base/CUnaryFunctor.h"
49 
50 namespace DGtal
51 {
52 
54  // template class VolReader
86  template <typename TImageContainer,
87  typename TFunctor = functors::Cast< typename TImageContainer::Value > >
88  struct VolReader
89  {
90  // ----------------------- Standard services ------------------------------
91 
92  typedef TImageContainer ImageContainer;
93  typedef typename TImageContainer::Value Value;
94  typedef TFunctor Functor;
95 
97 
98  BOOST_STATIC_ASSERT(ImageContainer::Domain::dimension == 3);
99 
100 
113  static ImageContainer importVol(const std::string & filename,
114  const Functor & aFunctor = Functor()) throw(DGtal::IOException);
115 
116 
117 
118  private:
119 
120  typedef unsigned char voxel;
126  /* In recent C++, we should use a std::map, but we prefer (badly) code it
127  by hand for compatibility with old compilers.
128  At this time, there is a limit of 30 fields in header :-} */
129  struct HeaderField {
131  HeaderField( const char *t, const char *v ) :
132  type( strdup(t) ), value( strdup(v) ) {}
134  free( type );
135  free( value );
136  }
138  HeaderField( const HeaderField &h ) :
139  type( strdup(h.type) ), value( strdup(h.value) ) {};
141  HeaderField() : type(NULL), value(NULL) {};
143  const HeaderField &operator = (const HeaderField &h) {
144  free( type );
145  free( value );
146  if (h.type != NULL) {
147  type = strdup( h.type );
148  value = strdup( h.value );
149  }
150  return *this;
151  }
153  char *type;
155  char *value;
156  };
157 
158 
160  static const char *getHeaderValue( const char *type, const HeaderField * header );
161 
163  static int getHeaderValueAsInt( const char *type, int *dest , const HeaderField * header);
164 
166  static int getHeaderField( const char *type, const HeaderField * header ) ;
167 
169  static const char *requiredHeaders[];
170 
171  }; // end of class VolReader
172 
173 
174 } // namespace DGtal
175 
176 
178 // Includes inline functions.
179 #include "DGtal/io/readers/VolReader.ih"
180 
181 // //
183 
184 #endif // !defined VolReader_h
185 
186 #undef VolReader_RECURSES
187 #endif // else defined(VolReader_RECURSES)
TImageContainer::Value Value
Definition: VolReader.h:93
HeaderField(const char *t, const char *v)
Constructor. The string are copied.
Definition: VolReader.h:131
unsigned char voxel
Definition: VolReader.h:120
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.
BOOST_STATIC_ASSERT(ImageContainer::Domain::dimension==3)
HeaderField(const HeaderField &h)
Copy constructor.
Definition: VolReader.h:138
TImageContainer ImageContainer
Definition: VolReader.h:92
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:89
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
static const char * requiredHeaders[]
Global list of required fields in a .vol file.
Definition: VolReader.h:169
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctor, unsigned char, Value >))
DGtal is the top-level namespace which contains all DGtal functions and types.
char * type
Type of field (e.g. Voxel-Size)
Definition: VolReader.h:153
char * value
Value of field (e.g. 2)
Definition: VolReader.h:155
TFunctor Functor
Definition: VolReader.h:94
static int getHeaderValueAsInt(const char *type, int *dest, const HeaderField *header)
Returns non-zero if failure.
HeaderField()
Default constructor.
Definition: VolReader.h:141