DGtal  1.3.beta
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 <sstream>
45 #include <string>
46 #include <cstdio>
47 #include "DGtal/base/Common.h"
48 #include <boost/static_assert.hpp>
49 #include "DGtal/helpers/StdDefs.h"
50 #include "DGtal/base/CUnaryFunctor.h"
51 
53 
54 namespace DGtal
55 {
56 
58  // template class LongvolReader
89  template <typename TImageContainer,
90  typename TFunctor= functors::Cast< typename TImageContainer::Value > >
92  {
93  // ----------------------- Standard services ------------------------------
94 
96  typedef typename TImageContainer::Value Value;
97  typedef TFunctor Functor;
98 
100  BOOST_STATIC_ASSERT(ImageContainer::Domain::dimension == 3);
101 
102 
114  static ImageContainer importLongvol(const std::string & filename,
115  const Functor & aFunctor = Functor());
116 
117 
118 
119  private:
120 
129  template <typename Word>
130  static
131  std::stringstream& read_word( std::stringstream & fin, Word& aValue )
132  {
133  char* raw = reinterpret_cast<char*>(&aValue);
134  for (std::size_t i = 0; i < sizeof(Word); ++i)
135  raw[i] = fin.get();
136  return fin;
137  }
138 
139 
140  typedef unsigned char voxel;
145  /* In recent C++, we should use a std::map, but we prefer (badly) code it
146  * by hand for compatibility with old compilers.
147  * At this time, there is a limit of 30 fields in header :-}
148  */
149  struct HeaderField {
151  HeaderField( const char *t, const char *v ) :
152  type( strdup(t) ), value( strdup(v) ) {}
154  free( type );
155  free( value );
156  }
158  HeaderField( const HeaderField &h ) :
159  type( strdup(h.type) ), value( strdup(h.value) ) {};
161  HeaderField() : type(NULL), value(NULL) {};
164  free( type );
165  free( value );
166  if (h.type != NULL) {
167  type = strdup( h.type );
168  value = strdup( h.value );
169  }
170  return *this;
171  }
173  char *type;
175  char *value;
176  };
177 
178 
180  static const char *getHeaderValue( const char *type, const HeaderField * header );
181 
183  static int getHeaderValueAsInt( const char *type, int *dest , const HeaderField * header);
184 
186  static int getHeaderField( const char *type, const HeaderField * header ) ;
187 
189  static const char *requiredHeaders[];
190 
191  }; // end of class LongvolReader
192 
193 
194 } // namespace DGtal
195 
196 
198 // Includes inline functions.
199 #include "DGtal/io/readers/LongvolReader.ih"
200 
201 // //
203 
204 #endif // !defined LongvolReader_h
205 
206 #undef LongvolReader_RECURSES
207 #endif // else defined(LongvolReader_RECURSES)
DGtal::LongvolReader::HeaderField
Definition: LongvolReader.h:149
DGtal::LongvolReader::HeaderField::type
char * type
Type of field (e.g. Voxel-Size)
Definition: LongvolReader.h:173
DGtal::ImageContainerBySTLVector::Value
TValue Value
Definition: ImageContainerBySTLVector.h:153
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::LongvolReader
Aim: implements methods to read a "Longvol" file format (with DGtal::uint64_t value type).
Definition: LongvolReader.h:91
DGtal::LongvolReader::HeaderField::operator=
const HeaderField & operator=(const HeaderField &h)
Assignement operator.
Definition: LongvolReader.h:163
DGtal::LongvolReader::getHeaderValueAsInt
static int getHeaderValueAsInt(const char *type, int *dest, const HeaderField *header)
Returns non-zero if failure.
DGtal::LongvolReader::read_word
static std::stringstream & read_word(std::stringstream &fin, Word &aValue)
Definition: LongvolReader.h:131
DGtal::LongvolReader::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT(ImageContainer::Domain::dimension==3)
DGtal::LongvolReader::Functor
TFunctor Functor
Definition: LongvolReader.h:97
DGtal::LongvolReader::ImageContainer
TImageContainer ImageContainer
Definition: LongvolReader.h:95
DGtal::LongvolReader::Value
TImageContainer::Value Value
Definition: LongvolReader.h:96
DGtal::LongvolReader::getHeaderField
static int getHeaderField(const char *type, const HeaderField *header)
Internal method which returns the index of a field or -1 if not found.
DGtal::LongvolReader::HeaderField::value
char * value
Value of field (e.g. 2)
Definition: LongvolReader.h:175
DGtal::LongvolReader::HeaderField::HeaderField
HeaderField()
Default constructor.
Definition: LongvolReader.h:161
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::LongvolReader::HeaderField::HeaderField
HeaderField(const HeaderField &h)
Copy constructor.
Definition: LongvolReader.h:158
DGtal::LongvolReader::HeaderField::~HeaderField
~HeaderField()
Definition: LongvolReader.h:153
DGtal::LongvolReader::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctor, DGtal::uint64_t, Value >))
DGtal::LongvolReader::HeaderField::HeaderField
HeaderField(const char *t, const char *v)
Constructor. The string are copied.
Definition: LongvolReader.h:151
DGtal::LongvolReader::importLongvol
static ImageContainer importLongvol(const std::string &filename, const Functor &aFunctor=Functor())
DGtal::LongvolReader::voxel
unsigned char voxel
Definition: LongvolReader.h:140
TImageContainer
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer
Definition: testVoronoiMapComplete.cpp:49
DGtal::LongvolReader::requiredHeaders
static const char * requiredHeaders[]
Global list of required fields in a .longvol file.
Definition: LongvolReader.h:189
DGtal::LongvolReader::getHeaderValue
static const char * getHeaderValue(const char *type, const HeaderField *header)
Returns NULL if this field is not found.
DGtal::concepts::CUnaryFunctor
Aim: Defines a unary functor, which associates arguments to results.
Definition: CUnaryFunctor.h:89