DGtal  0.9.2
testPNMReader.cpp
1 
30 #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/PPMReader.h"
36 #include "DGtal/io/readers/PGMReader.h"
37 #include "DGtal/images/ImageSelector.h"
38 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
39 #include "ConfigTest.h"
40 
42 
43 using namespace std;
44 using namespace DGtal;
45 
47 // Functions for testing class PNMReader.
49 
53 bool testPNMReader()
54 {
55  unsigned int nbok = 0;
56  unsigned int nb = 0;
57  trace.beginBlock ( "Testing pgm reader ..." );
58  nbok += true ? 1 : 0;
59  nb++;
60  std::string filename = testPath + "samples/circleR10.pgm";
61 
62  trace.info() << "Loading filename: "<< filename<<std::endl;
63 
65  Image image = PGMReader<Image>::importPGM( filename );
66 
67  Z2i::DigitalSet set2d (image.domain());
68  SetFromImage<Z2i::DigitalSet>::append<Image>(set2d, image, 0, 255);
69 
70  Board2D board;
71  board << image.domain() << set2d; // display domain and set
72 
73  board.saveEPS( "testPNMReaderPGM.eps");
74  trace.info() << "(" << nbok << "/" << nb << ") "
75  << "true == true" << std::endl;
76  trace.endBlock();
77 
78  trace.beginBlock ( "Testing ppm reader ..." );
79  nbok += true ? 1 : 0;
80  nb++;
81  std::string filenamePPM = testPath + "samples/color64.ppm";
82 
83  trace.info() << "Loading filename: "<< filenamePPM <<std::endl;
84 
86  Image imagePPM = PPMReader<Image>::importPPM( filenamePPM );
87 
88  Z2i::DigitalSet set2dPPM (imagePPM.domain());
89  SetFromImage<Z2i::DigitalSet>::append<Image>(set2dPPM, imagePPM, 0, 0xFFFFFEu);
90 
91  Board2D boardPPM;
92  boardPPM << imagePPM.domain() << set2dPPM; // display domain and set
93 
94  boardPPM.saveEPS( "testPNMReaderPPM.eps");
95  trace.info() << "(" << nbok << "/" << nb << ") "
96  << "true == true" << std::endl;
97  trace.endBlock();
98 
99  return nbok == nb;
100 }
105 bool testPNM3DReader()
106 {
107  unsigned int nbok = 0;
108  unsigned int nb = 0;
109  trace.beginBlock ( "Testing pgm3D reader ..." );
110  nbok += true ? 1 : 0;
111  nb++;
112  std::string filename = testPath + "samples/simple.pgm3d";
113 
114  trace.info() << "Loading filename: "<< filename<<std::endl;
115 
117  Image image = PGMReader<Image>::importPGM3D( filename );
118 
119  trace.info() << "Image 3D = "<<image<<std::endl;
120 
121  trace.info() << "(" << nbok << "/" << nb << ") "
122  << "true == true" << std::endl;
123  trace.endBlock();
124  return nbok == nb;
125 }
126 
127 bool testPNM3DASCIIReader()
128 {
129  unsigned int nbok = 0;
130  unsigned int nb = 0;
131  trace.beginBlock ( "Testing P2 pgm3D reader ..." );
132  nbok += true ? 1 : 0;
133  nb++;
134  std::string filename = testPath + "samples/ascii_ball.pgm3d";
135 
136  trace.info() << "Loading filename: "<< filename<<std::endl;
137 
139  Image image = PGMReader<Image>::importPGM3D( filename );
140 
141  trace.info() << "Image 3D = "<<image<<std::endl;
142 
143  trace.info() << "(" << nbok << "/" << nb << ") "
144  << "true == true" << std::endl;
145  trace.endBlock();
146  return nbok == nb;
147 }
148 
150 // Standard services - public :
151 
152 int main( int argc, char** argv )
153 {
154  trace.beginBlock ( "Testing class PNMReader" );
155  trace.info() << "Args:";
156  for ( int i = 0; i < argc; ++i )
157  trace.info() << " " << argv[ i ];
158  trace.info() << endl;
159 
160  bool res = testPNMReader() && testPNM3DReader() && testPNM3DASCIIReader(); // && ... other tests
161  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
162  trace.endBlock();
163  return res ? 0 : 1;
164 }
165 // //
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: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:96
STL namespace.
double endBlock()
std::ostream & emphase()
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PPMReader.h:98
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:63
std::ostream & info()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
const Domain & domain() const
Definition: Image.h:192
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70