DGtal  1.2.0
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 
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";
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 
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
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 
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
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 // //
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
Definition: Common.h:154
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:90
Aim: Export a 3D Image using the Vol formats.
Definition: VolWriter.h:69
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
Image image(domain)
ImageContainerBySTLVector< Domain, Value > Image
int main(int argc, char **argv)
bool testConsistence()
bool testIOException()
bool testVolReader()