DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testPNMReader.cpp
1 
30 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/io/boards/Board2D.h"
35 #include "DGtal/io/readers/PNMReader.h"
36 #include "DGtal/images/ImageSelector.h"
37 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
38 #include "ConfigTest.h"
39 
41 
42 using namespace std;
43 using namespace DGtal;
44 
46 // Functions for testing class PNMReader.
48 
52 bool testPNMReader()
53 {
54  unsigned int nbok = 0;
55  unsigned int nb = 0;
56  trace.beginBlock ( "Testing pgm reader ..." );
57  nbok += true ? 1 : 0;
58  nb++;
59  std::string filename = testPath + "samples/circleR10.pgm";
60 
61  trace.info() << "Loading filename: "<< filename<<std::endl;
62 
64  Image image = PNMReader<Image>::importPGM( filename );
65 
66  Z2i::DigitalSet set2d (image.domain());
67  SetFromImage<Z2i::DigitalSet>::append<Image>(set2d, image, 0, 255);
68 
69  Board2D board;
70  board << image.domain() << set2d; // display domain and set
71 
72  board.saveEPS( "testPNMReader.eps");
73  trace.info() << "(" << nbok << "/" << nb << ") "
74  << "true == true" << std::endl;
75  trace.endBlock();
76  return nbok == nb;
77 }
82 bool testPNM3DReader()
83 {
84  unsigned int nbok = 0;
85  unsigned int nb = 0;
86  trace.beginBlock ( "Testing pgm3D reader ..." );
87  nbok += true ? 1 : 0;
88  nb++;
89  std::string filename = testPath + "samples/simple.pgm3d";
90 
91  trace.info() << "Loading filename: "<< filename<<std::endl;
92 
94  Image image = PNMReader<Image>::importPGM3D( filename );
95 
96  trace.info() << "Image 3D = "<<image<<std::endl;
97 
98  trace.info() << "(" << nbok << "/" << nb << ") "
99  << "true == true" << std::endl;
100  trace.endBlock();
101  return nbok == nb;
102 }
103 
105 // Standard services - public :
106 
107 int main( int argc, char** argv )
108 {
109  trace.beginBlock ( "Testing class PNMReader" );
110  trace.info() << "Args:";
111  for ( int i = 0; i < argc; ++i )
112  trace.info() << " " << argv[ i ];
113  trace.info() << endl;
114 
115  bool res = testPNMReader() && testPNM3DReader(); // && ... other tests
116  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
117  trace.endBlock();
118  return res ? 0 : 1;
119 }
120 // //