DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testVolReader.cpp
1 
30 
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  typedef TDomain::Point Point;
67 
68  //Default image selector = STLVector
70 
71 
72  std::string filename = testPath + "samples/cat10.vol";
73  Image image = VolReader<Image>::importVol( filename );
74 
75  trace.info() << image <<endl;
76 
77  nbok += true ? 1 : 0;
78  nb++;
79 
80  unsigned int nbval=0;
81  for(Image::ConstIterator it=image.begin(), itend=image.end();
82  it != itend; ++it)
83  if ( (*it) != 0)
84  nbval++;
85 
86  trace.info() << "Number of points with (val!=0) = "<<nbval<<endl;
87 
88  nbok += ( nbval == 8043) ? 1 : 0;
89  nb++;
90 
91  VolWriter<Image>::exportVol("catenoid-export.vol",image);
92 
93  nbok += ( true ) ? 1 : 0;
94  nb++;
95 
96  trace.info() << "(" << nbok << "/" << nb << ") "
97  << "true == true" << std::endl;
98  trace.endBlock();
99 
100  return nbok == nb;
101 }
102 
103 
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  typedef TDomain::Point Point;
114 
115  //Default image selector = STLVector
117 
118 
119  std::string filename = testPath + "samples/null.vol";
120  try
121  {
122  Image image = VolReader<Image>::importVol( filename );
123  }
124  catch(exception& e)
125  {
126  trace.info() << "Exception catched. Message : "<< e.what()<<endl;
127  }
128 
129 
130 
131  nbok += ( true ) ? 1 : 0;
132  nb++;
133 
134  trace.info() << "(" << nbok << "/" << nb << ") "
135  << "true == true" << std::endl;
136  trace.endBlock();
137 
138  return nbok == nb;
139 }
140 
142 // Standard services - public :
143 
144 int main( int argc, char** argv )
145 {
146  trace.beginBlock ( "Testing class VolReader" );
147  trace.info() << "Args:";
148  for ( int i = 0; i < argc; ++i )
149  trace.info() << " " << argv[ i ];
150  trace.info() << endl;
151 
152  bool res = testVolReader() && testIOException(); // && ... other tests
153  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
154  trace.endBlock();
155  return res ? 0 : 1;
156 }
157 // //