DGtal
1.4.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
100
bool
testIOException
()
101
{
102
unsigned
int
nbok = 0;
103
unsigned
int
nb = 0;
104
105
trace
.
beginBlock
(
"Testing VolReader ..."
);
106
107
typedef
SpaceND<3>
Space4Type;
108
typedef
HyperRectDomain<Space4Type>
TDomain;
109
110
//Default image selector = STLVector
111
typedef
ImageSelector<TDomain, unsigned char>::Type
Image
;
112
113
114
std::string filename = testPath +
"samples/null.vol"
;
115
try
116
{
117
Image
image =
VolReader<Image>::importVol
( filename );
118
}
119
catch
(exception& e)
120
{
121
trace
.
info
() <<
"Exception catched. Message : "
<< e.what()<<endl;
122
}
123
124
125
126
nbok += ( true ) ? 1 : 0;
127
nb++;
128
129
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
130
<<
"true == true"
<< std::endl;
131
trace
.
endBlock
();
132
133
return
nbok == nb;
134
}
135
136
bool
testConsistence
()
137
{
138
trace
.
beginBlock
(
"Testing VolWriter ..."
);
139
140
typedef
SpaceND<3>
Space4Type;
141
typedef
HyperRectDomain<Space4Type>
TDomain;
142
typedef
TDomain::Point
Point
;
143
144
//Default image selector = STLVector
145
typedef
ImageSelector<TDomain, unsigned char>::Type
Image
;
146
TDomain
domain
(
Point
(-17,-14,-13),
Point
(5,7,11));
147
Image
image(
domain
);
148
trace
.
info
() << image.domain() <<endl;
149
150
VolWriter<Image>::exportVol
(
"testConsistence.vol"
,image);
151
152
trace
.
endBlock
();
153
154
trace
.
beginBlock
(
"Testing VolReader ..."
);
155
156
Image
image2 =
VolReader<Image>::importVol
(
"testConsistence.vol"
);
157
158
trace
.
info
() << image2.
domain
() <<endl;
159
trace
.
endBlock
();
160
161
if
( image.domain().lowerBound() != image2.
domain
().lowerBound()
162
|| image.domain().upperBound() != image2.
domain
().upperBound() )
163
{
164
return
false
;
165
}
166
return
true
;
167
}
168
170
// Standard services - public :
171
172
int
main
(
int
argc,
char
** argv )
173
{
174
int
aaaaa = 21/2;
175
std::cout << aaaaa << std::endl;
176
177
trace
.
beginBlock
(
"Testing class VolReader"
);
178
trace
.
info
() <<
"Args:"
;
179
for
(
int
i = 0; i < argc; ++i )
180
trace
.
info
() <<
" "
<< argv[ i ];
181
trace
.
info
() << endl;
182
183
bool
res =
testVolReader
() &&
testIOException
() &&
testConsistence
();
// && ... other tests
184
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
185
trace
.
endBlock
();
186
return
res ? 0 : 1;
187
188
}
189
// //
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
Definition
Common.h:153
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:383
domain
Domain domain
Definition
testProjection.cpp:88
Image
ImageContainerBySTLVector< Domain, Value > Image
Definition
testSimpleRandomAccessRangeFromPoint.cpp:45
testConsistence
bool testConsistence()
Definition
testVolReader.cpp:136
testIOException
bool testIOException()
Definition
testVolReader.cpp:100
testVolReader
bool testVolReader()
Definition
testVolReader.cpp:57
tests
io
readers
testVolReader.cpp
Generated on Mon Jun 10 2024 17:36:12 for DGtal by
1.11.0