DGtal  0.9.2
testVolReader.cpp
1 
30 #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
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  nbok += true ? 1 : 0;
77  nb++;
78 
79  unsigned int nbval=0;
80  for(Image::ConstIterator it=image.begin(), itend=image.end();
81  it != itend; ++it)
82  if ( (*it) != 0)
83  nbval++;
84 
85  trace.info() << "Number of points with (val!=0) = "<<nbval<<endl;
86 
87  nbok += ( nbval == 8043) ? 1 : 0;
88  nb++;
89 
90  VolWriter<Image>::exportVol("catenoid-export.vol",image);
91 
92  nbok += ( true ) ? 1 : 0;
93  nb++;
94 
95  trace.info() << "(" << nbok << "/" << nb << ") "
96  << "true == true" << std::endl;
97  trace.endBlock();
98 
99  return nbok == nb;
100 }
101 
102 
103 bool testIOException()
104 {
105  unsigned int nbok = 0;
106  unsigned int nb = 0;
107 
108  trace.beginBlock ( "Testing VolReader ..." );
109 
110  typedef SpaceND<3> Space4Type;
111  typedef HyperRectDomain<Space4Type> TDomain;
112 
113  //Default image selector = STLVector
115 
116 
117  std::string filename = testPath + "samples/null.vol";
118  try
119  {
120  Image image = VolReader<Image>::importVol( filename );
121  }
122  catch(exception& e)
123  {
124  trace.info() << "Exception catched. Message : "<< e.what()<<endl;
125  }
126 
127 
128 
129  nbok += ( true ) ? 1 : 0;
130  nb++;
131 
132  trace.info() << "(" << nbok << "/" << nb << ") "
133  << "true == true" << std::endl;
134  trace.endBlock();
135 
136  return nbok == nb;
137 }
138 
139 bool testConsistence()
140 {
141  trace.beginBlock ( "Testing VolWriter ..." );
142 
143  typedef SpaceND<3> Space4Type;
144  typedef HyperRectDomain<Space4Type> TDomain;
145  typedef TDomain::Point Point;
146 
147  //Default image selector = STLVector
149  TDomain domain(Point(-17,-14,-13), Point(5,7,11));
150  Image image(domain);
151  trace.info() << image.domain() <<endl;
152 
153  VolWriter<Image>::exportVol("testConsistence.vol",image);
154 
155  trace.endBlock();
156 
157  trace.beginBlock ( "Testing VolReader ..." );
158 
159  Image image2 = VolReader<Image>::importVol( "testConsistence.vol" );
160 
161  trace.info() << image2.domain() <<endl;
162  trace.endBlock();
163 
164  if( image.domain().lowerBound() != image2.domain().lowerBound()
165  || image.domain().upperBound() != image2.domain().upperBound() )
166  {
167  return false;
168  }
169  return true;
170 }
171 
173 // Standard services - public :
174 
175 int main( int argc, char** argv )
176 {
177  int aaaaa = 21/2;
178  std::cout << aaaaa << std::endl;
179 
180  trace.beginBlock ( "Testing class VolReader" );
181  trace.info() << "Args:";
182  for ( int i = 0; i < argc; ++i )
183  trace.info() << " " << argv[ i ];
184  trace.info() << endl;
185 
186  bool res = testVolReader() && testIOException() && testConsistence(); // && ... other tests
187  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
188  trace.endBlock();
189  return res ? 0 : 1;
190 
191 }
192 // //
void beginBlock(const std::string &keyword="")
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:130
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Export a 3D Image using the Vol formats.
Definition: VolWriter.h:68
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
STL namespace.
double endBlock()
std::ostream & emphase()
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:88
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
const Domain & domain() const
Definition: Image.h:192