DGtal  0.9.2
testGenericWriter.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/images/ImageContainerBySTLVector.h"
34 #include "DGtal/io/readers/GenericReader.h"
35 #include "DGtal/io/writers/GenericWriter.h"
36 #include "DGtal/helpers/StdDefs.h"
37 #include "ConfigTest.h"
38 
40 
41 using namespace std;
42 using namespace DGtal;
43 
45 // Functions for testing class GenericWriter.
47 
51 bool testGenericWriter()
52 {
53  unsigned int nbok = 0;
54  unsigned int nb = 0;
59 
60  Image3D32bits an32bitsImage3D (DGtal::Z3i::Domain(DGtal::Z3i::Point(0,0,0), DGtal::Z3i::Point(4,4,4)));
61  for(unsigned int i =0; i< 5; i++){
62  for(unsigned int j =0; j< 5; j++){
63  for(unsigned int k =0; k< 5; k++){
64  an32bitsImage3D.setValue(DGtal::Z3i::Point(k,j,i), 250000*i*j*k);
65  }
66  }
67  }
68  Image2D32bits an32bitsImage2D (DGtal::Z2i::Domain(DGtal::Z2i::Point(0,0), DGtal::Z2i::Point(4,4)));
69  for(unsigned int i =0; i< 5; i++){
70  for(unsigned int j =0; j< 5; j++){
71  an32bitsImage2D.setValue(DGtal::Z2i::Point(j,i), 250000*i*j*4);
72  }
73  }
74 
75  trace.beginBlock ( "Testing block ..." );
76  std::string filenameImage1 = testPath + "samples/cat10.pgm3d";
77  trace.info() << "Reading 3D image ... ";
78  Image3D anImportedImage1 = DGtal::GenericReader<Image3D>::import(filenameImage1);
79  trace.info() <<"[done]" << std::endl;
80  trace.info() << "Testing writing PGM3D ... ";
81  bool ok1 = anImportedImage1>> "testGenericWriter.pgm3d";
82  trace.info() <<"[done]" << std::endl;
83 
84  bool okh5 = true;
85  bool okh5bis = true;
86 #ifdef WITH_HDF5
87  trace.info() << "Testing writing HDF5 3D ... ";
88  okh5 = anImportedImage1 >> "testGenericWriter.h5";
89  trace.info() <<"[done]" << std::endl;
90  trace.info() << "Testing writing HDF5 3D (bis) ... ";
91  okh5bis = DGtal::GenericWriter<Image3D>::exportFile("testGenericWriter_bis.h5", anImportedImage1, "/UInt8Array3D");
92  trace.info() <<"[done]" << std::endl;
93 #endif
94 
95  trace.info() << "Testing writing vol ... ";
96  bool ok2 = anImportedImage1 >> "testGenericWriter.vol";
97  trace.info() <<"[done]" << std::endl;
98  trace.info() << "Testing writing raw ... ";
99  bool ok3 = anImportedImage1 >>"testGenericWriter.raw";
100  trace.info() <<"[done]" << std::endl;
101  trace.info() << "Testing writing raw (bis) ... ";
102  bool ok3bis = DGtal::GenericWriter<Image3D>::exportFile( "testGenericWriter.raw", anImportedImage1);
103  trace.info() <<"[done]" << std::endl;
104 
105  std::string filenameImage2 = testPath + "samples/contourS.pgm";
106 
107  trace.info() << "Reading 2D image ... ";
108  Image2D anImportedImage2 = DGtal::GenericReader<Image2D>::import(filenameImage2);
109  trace.info() <<"[done]" << std::endl;
110  trace.info() << "Testing writing pgm ... ";
111  bool ok4 = anImportedImage2 >> "testGenericWriter.pgm";
112  trace.info() <<"[done]" << std::endl;
113  trace.info() << "Testing writing raw ... ";
114  bool ok5 = anImportedImage2 >> "testGenericWriter.raw";
115  trace.info() <<"[done]" << std::endl;
116  bool ok6 = DGtal::GenericWriter<Image3D32bits>::exportFile( "testGenericWriter32bits3D.raw", an32bitsImage3D);
117  trace.info() <<"[done]" << std::endl;
118  bool ok7 = DGtal::GenericWriter<Image2D32bits>::exportFile( "testGenericWriter32bits2D.raw", an32bitsImage2D);
119  trace.info() <<"[done]" << std::endl;
120 
121 
122 
123  nbok += ok1 && okh5 && okh5bis && ok2 && ok3 && ok3bis && ok4 & ok5 & ok6 & ok7 ? 1 : 0;
124  nb++;
125  trace.info() << "(" << nbok << "/" << nb << ") "
126  << "true == true" << std::endl;
127  trace.endBlock();
128 
129  return nbok == nb;
130 }
131 
133 // Standard services - public :
134 
135 int main( int argc, char** argv )
136 {
137  trace.beginBlock ( "Testing class GenericWriter" );
138  trace.info() << "Args:";
139  for ( int i = 0; i < argc; ++i )
140  trace.info() << " " << argv[ i ];
141  trace.info() << endl;
142 
143  bool res = testGenericWriter(); // && ... other tests
144  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
145  trace.endBlock();
146  return res ? 0 : 1;
147 }
148 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
STL namespace.
double endBlock()
static TContainer import(const std::string &filename, std::vector< unsigned int > dimSpace=std::vector< unsigned int >())
std::ostream & emphase()
DGtal is the top-level namespace which contains all DGtal functions and types.
static bool exportFile(const std::string &filename, const TContainer &anImage, const TFunctor &aFunctor=TFunctor())
std::ostream & info()