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
47using namespace std;
48using namespace DGtal;
49
51// Functions for testing class VolReader.
53
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
69
70
71 std::string filename = testPath + "samples/cat10.vol";
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;
95
96 return nbok == nb;
97}
98
99
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
116
117
118 std::string filename = testPath + "samples/null.vol";
119 try
120 {
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
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
150 TDomain domain(Point(-17,-14,-13), Point(5,7,11));
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
176int 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// //
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Aim: implements association bewteen points lying in a digital domain and values.
Definition Image.h:70
const Domain & domain() const
Definition Image.h:192
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
static bool exportVol(const std::string &filename, const Image &aImage, const bool compressed=true, const Functor &aFunctor=Functor())
int main()
Definition testBits.cpp:56
MyPointD Point
Domain domain
Image image(domain)
bool testConsistence()
bool testIOException()
Tests the VolReader's behavior when attempting to read a non-existent or invalid ....
bool testVolReader()