DGtal  1.4.2
testPNMReader.cpp
Go to the documentation of this file.
1 
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/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 
54 {
55  trace.beginBlock ( "Testing pgm reader ..." );
56  std::string filename = testPath + "samples/circleR10.pgm";
57 
58  trace.info() << "Loading filename: "<< filename<<std::endl;
59 
61  Image image = PGMReader<Image>::importPGM( filename );
62 
63  Z2i::DigitalSet set2d (image.domain());
65 
66  Board2D board;
67  board << image.domain() << set2d; // display domain and set
68 
69  board.saveEPS( "testPNMReaderPGM.eps");
70  trace.endBlock();
71 
72  trace.beginBlock ( "Testing ppm reader ..." );
73  std::string filenamePPM = testPath + "samples/color64.ppm";
74 
75  trace.info() << "Loading filename: "<< filenamePPM <<std::endl;
76 
78  Image imagePPM = PPMReader<Image>::importPPM( filenamePPM );
79 
80  Z2i::DigitalSet set2dPPM (imagePPM.domain());
81  SetFromImage<Z2i::DigitalSet>::append<Image>(set2dPPM, imagePPM, 0, 0xFFFFFEu);
82 
83  Board2D boardPPM;
84  boardPPM << imagePPM.domain() << set2dPPM; // display domain and set
85 
86  boardPPM.saveEPS( "testPNMReaderPPM.eps");
87  trace.endBlock();
88 
89  return true;
90 }
96 {
97  trace.beginBlock ( "Testing pgm3D reader ..." );
98  std::string filename = testPath + "samples/simple.pgm3d";
99 
100  trace.info() << "Loading filename: "<< filename<<std::endl;
101 
103  Image image = PGMReader<Image>::importPGM3D( filename );
104 
105  trace.info() << "Image 3D = "<<image<<std::endl;
106 
107  trace.endBlock();
108  return true;
109 }
110 
112 {
113  trace.beginBlock ( "Testing P2 pgm3D reader ..." );
114  std::string filename = testPath + "samples/ascii_ball.pgm3d";
115 
116  trace.info() << "Loading filename: "<< filename<<std::endl;
117 
119  Image image = PGMReader<Image>::importPGM3D( filename );
120 
121  trace.info() << "Image 3D = "<<image<<std::endl;
122 
123  trace.endBlock();
124  return true;
125 }
126 
128 // Standard services - public :
129 
130 int main( int argc, char** argv )
131 {
132  trace.beginBlock ( "Testing class PNMReader" );
133  trace.info() << "Args:";
134  for ( int i = 0; i < argc; ++i )
135  trace.info() << " " << argv[ i ];
136  trace.info() << endl;
137 
138  bool res = testPNMReader() && testPNM3DReader() && testPNM3DASCIIReader(); // && ... other tests
139  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
140  trace.endBlock();
141  return res ? 0 : 1;
142 }
143 // //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:70
const Domain & domain() const
Definition: Image.h:192
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:98
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PPMReader.h:99
Aim: Define utilities to convert a digital set into an image.
Definition: SetFromImage.h:64
bool testPNMReader()
bool testPNM3DASCIIReader()
bool testPNM3DReader()
int main(int argc, char **argv)
ImageContainerBySTLVector< Domain, Value > Image