DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
LongvolReader.h
1
16
17
#pragma once
18
30
31
#if defined(LongvolReader_RECURSES)
32
#error Recursive header files inclusion detected in LongvolReader.h
33
#else
// defined(LongvolReader_RECURSES)
35
#define LongvolReader_RECURSES
36
37
#if !defined LongvolReader_h
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 >
>
91
struct
LongvolReader
92
{
93
// ----------------------- Standard services ------------------------------
94
95
typedef
TImageContainer
ImageContainer
;
96
typedef
typename
TImageContainer::Value
Value
;
97
typedef
TFunctor
Functor
;
98
99
BOOST_CONCEPT_ASSERT
((
concepts::CUnaryFunctor<TFunctor, DGtal::uint64_t, Value >
)) ;
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) ) {}
153
~HeaderField
() {
154
free(
type
);
155
free(
value
);
156
}
157
158
HeaderField
(
const
HeaderField
&h ) :
159
type
( strdup(h.
type
) ),
value
( strdup(h.
value
) ) {};
160
161
HeaderField
() :
type
(NULL),
value
(NULL) {};
163
const
HeaderField
&
operator =
(
const
HeaderField
&h) {
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
}
172
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::ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > >::Value
std::unordered_set< Z2i::Point > Value
Definition
ImageContainerBySTLVector.h:153
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::LongvolReader::HeaderField
Definition
LongvolReader.h:149
DGtal::LongvolReader::HeaderField::HeaderField
HeaderField()
Default constructor.
Definition
LongvolReader.h:161
DGtal::LongvolReader::HeaderField::type
char * type
Type of field (e.g. Voxel-Size).
Definition
LongvolReader.h:173
DGtal::LongvolReader::HeaderField::value
char * value
Value of field (e.g. 2).
Definition
LongvolReader.h:175
DGtal::LongvolReader::HeaderField::HeaderField
HeaderField(const HeaderField &h)
Copy constructor.
Definition
LongvolReader.h:158
DGtal::LongvolReader::HeaderField::HeaderField
HeaderField(const char *t, const char *v)
Constructor. The string are copied.
Definition
LongvolReader.h:151
DGtal::LongvolReader::HeaderField::operator=
const HeaderField & operator=(const HeaderField &h)
Assignment operator.
Definition
LongvolReader.h:163
DGtal::LongvolReader::HeaderField::~HeaderField
~HeaderField()
Definition
LongvolReader.h:153
DGtal::LongvolReader
Aim: implements methods to read a "Longvol" file format (with DGtal::uint64_t value type).
Definition
LongvolReader.h:92
DGtal::LongvolReader::read_word
static std::stringstream & read_word(std::stringstream &fin, Word &aValue)
Definition
LongvolReader.h:131
DGtal::LongvolReader::requiredHeaders
static const char * requiredHeaders[]
Global list of required fields in a .longvol file.
Definition
LongvolReader.h:189
DGtal::LongvolReader::Value
TImageContainer::Value Value
Definition
LongvolReader.h:96
DGtal::LongvolReader::Functor
TFunctor Functor
Definition
LongvolReader.h:97
DGtal::LongvolReader::importLongvol
static ImageContainer importLongvol(const std::string &filename, const Functor &aFunctor=Functor())
DGtal::LongvolReader::getHeaderValueAsInt
static int getHeaderValueAsInt(const char *type, int *dest, const HeaderField *header)
Returns non-zero if failure.
DGtal::LongvolReader::ImageContainer
TImageContainer ImageContainer
Definition
LongvolReader.h:95
DGtal::LongvolReader::BOOST_STATIC_ASSERT
BOOST_STATIC_ASSERT(ImageContainer::Domain::dimension==3)
DGtal::LongvolReader::getHeaderValue
static const char * getHeaderValue(const char *type, const HeaderField *header)
Returns NULL if this field is not found.
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::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CUnaryFunctor< TFunctor, DGtal::uint64_t, Value >))
DGtal::LongvolReader::voxel
unsigned char voxel
Definition
LongvolReader.h:140
DGtal::concepts::CUnaryFunctor
Aim: Defines a unary functor, which associates arguments to results.
Definition
CUnaryFunctor.h:90
DGtal::functors::Cast
Aim: Define a simple functor using the static cast operator.
Definition
BasicFunctors.h:394
TImageContainer
ImageContainerBySTLVector< HyperRectDomain< Z2i::Space >, std::unordered_set< Z2i::Point > > TImageContainer
Definition
testVoronoiMapComplete.cpp:48
src
DGtal
io
readers
LongvolReader.h
Generated on
for DGtal by
1.18.0