DGtal
2.1.0
Loading...
Searching...
No Matches
testVolReader.cpp
Go to the documentation of this file.
1
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/kernel/SpaceND.h"
34
#include "DGtal/kernel/domains/HyperRectDomain.h"
35
#include "DGtal/images/ImageSelector.h"
36
#include "DGtal/io/readers/VolReader.h"
37
#include "DGtal/io/colormaps/HueShadeColorMap.h"
38
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
39
#include "DGtal/io/colormaps/GradientColorMap.h"
40
#include "DGtal/io/colormaps/ColorBrightnessColorMap.h"
41
#include "DGtal/io/writers/VolWriter.h"
42
43
#include "ConfigTest.h"
44
46
47
using namespace
std
;
48
using namespace
DGtal
;
49
51
// Functions for testing class VolReader.
53
57
bool
testVolReader
()
58
{
59
unsigned
int
nbok = 0;
60
unsigned
int
nb = 0;
61
62
trace
.
beginBlock
(
"Testing VolReader ..."
);
63
64
typedef
SpaceND<3>
Space4Type;
65
typedef
HyperRectDomain<Space4Type>
TDomain;
66
67
//Default image selector = STLVector
68
typedef
ImageSelector<TDomain, unsigned char>::Type
Image
;
69
70
71
std::string filename = testPath +
"samples/cat10.vol"
;
72
Image
image
=
VolReader<Image>::importVol
( filename );
73
74
trace
.
info
() <<
image
<<endl;
75
76
unsigned
int
nbval=0;
77
for
(
Image::ConstIterator
it=
image
.begin(), itend=
image
.end();
78
it != itend; ++it)
79
if
( (*it) != 0)
80
nbval++;
81
82
trace
.
info
() <<
"Number of points with (val!=0) = "
<<nbval<<endl;
83
84
nbok += ( nbval == 8043) ? 1 : 0;
85
nb++;
86
87
VolWriter<Image>::exportVol
(
"catenoid-export.vol"
,
image
);
88
89
nbok += ( true ) ? 1 : 0;
90
nb++;
91
92
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
93
<<
"true == true"
<< std::endl;
94
trace
.
endBlock
();
95
96
return
nbok == nb;
97
}
98
99
104
bool
testIOException
()
105
{
106
unsigned
int
nbok = 0;
107
unsigned
int
nb = 0;
108
109
trace
.
beginBlock
(
"Testing VolReader ..."
);
110
111
typedef
SpaceND<3>
Space4Type;
112
typedef
HyperRectDomain<Space4Type>
TDomain;
113
114
//Default image selector = STLVector
115
typedef
ImageSelector<TDomain, unsigned char>::Type
Image
;
116
117
118
std::string filename = testPath +
"samples/null.vol"
;
119
try
120
{
121
Image
image
=
VolReader<Image>::importVol
( filename );
122
}
123
catch
(exception& e)
124
{
125
trace
.
info
() <<
"Exception catched. Message : "
<< e.what()<<endl;
126
}
127
128
129
130
nbok += ( true ) ? 1 : 0;
131
nb++;
132
133
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
134
<<
"true == true"
<< std::endl;
135
trace
.
endBlock
();
136
137
return
nbok == nb;
138
}
139
140
bool
testConsistence
()
141
{
142
trace
.
beginBlock
(
"Testing VolWriter ..."
);
143
144
typedef
SpaceND<3>
Space4Type;
145
typedef
HyperRectDomain<Space4Type>
TDomain;
146
typedef
TDomain::Point
Point
;
147
148
//Default image selector = STLVector
149
typedef
ImageSelector<TDomain, unsigned char>::Type
Image
;
150
TDomain
domain
(
Point
(-17,-14,-13),
Point
(5,7,11));
151
Image
image
(
domain
);
152
trace
.
info
() <<
image
.
domain
() <<endl;
153
154
VolWriter<Image>::exportVol
(
"testConsistence.vol"
,
image
);
155
156
trace
.
endBlock
();
157
158
trace
.
beginBlock
(
"Testing VolReader ..."
);
159
160
Image
image2 =
VolReader<Image>::importVol
(
"testConsistence.vol"
);
161
162
trace
.
info
() << image2.
domain
() <<endl;
163
trace
.
endBlock
();
164
165
if
(
image
.
domain
().lowerBound() != image2.
domain
().lowerBound()
166
||
image
.
domain
().upperBound() != image2.
domain
().upperBound() )
167
{
168
return
false
;
169
}
170
return
true
;
171
}
172
174
// Standard services - public :
175
176
int
main
(
int
argc,
char
** argv )
177
{
178
int
aaaaa = 21/2;
179
std::cout << aaaaa << std::endl;
180
181
trace
.
beginBlock
(
"Testing class VolReader"
);
182
trace
.
info
() <<
"Args:"
;
183
for
(
int
i = 0; i < argc; ++i )
184
trace
.
info
() <<
" "
<< argv[ i ];
185
trace
.
info
() << endl;
186
187
bool
res =
testVolReader
() &&
testIOException
() &&
testConsistence
();
// && ... other tests
188
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
189
trace
.
endBlock
();
190
return
res ? 0 : 1;
191
192
}
193
// //
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition
HyperRectDomain.h:100
DGtal::ImageContainerBySTLVector
Definition
ImageContainerBySTLVector.h:127
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition
ImageContainerBySTLVector.h:265
DGtal::Image
Aim: implements association bewteen points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Image::domain
const Domain & domain() const
Definition
Image.h:192
DGtal::SpaceND
Definition
SpaceND.h:96
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::VolReader::importVol
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
DGtal::VolWriter::exportVol
static bool exportVol(const std::string &filename, const Image &aImage, const bool compressed=true, const Functor &aFunctor=Functor())
main
int main()
Definition
testBits.cpp:56
Point
MyPointD Point
Definition
testClone2.cpp:381
domain
Domain domain
Definition
testProjection.cpp:88
image
Image image(domain)
testConsistence
bool testConsistence()
Definition
testVolReader.cpp:140
testIOException
bool testIOException()
Tests the VolReader's behavior when attempting to read a non-existent or invalid ....
Definition
testVolReader.cpp:104
testVolReader
bool testVolReader()
Definition
testVolReader.cpp:57
tests
io
readers
testVolReader.cpp
Generated on Tue Aug 26 2025 14:28:23 for DGtal by
1.9.8