DGtal  0.9.3
Functions
testPNMReader.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/io/boards/Board2D.h"
#include "DGtal/io/readers/PPMReader.h"
#include "DGtal/io/readers/PGMReader.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/images/imagesSetsUtils/SetFromImage.h"
#include "ConfigTest.h"
Include dependency graph for testPNMReader.cpp:

Go to the source code of this file.

Functions

bool testPNMReader ()
 
bool testPNM3DReader ()
 
bool testPNM3DASCIIReader ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Bertrand Kerautret (kerau.nosp@m.tre@.nosp@m.loria.nosp@m..fr ) LORIA (CNRS, UMR 7503), University of Nancy, France
Date
2011/04/29

Functions for testing class PNMReader.

This file is part of the DGtal library.

Definition in file testPNMReader.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 152 of file testPNMReader.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testPNM3DASCIIReader(), testPNM3DReader(), testPNMReader(), and DGtal::trace.

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
std::ostream & emphase()
std::ostream & info()
bool testPNM3DReader()
bool testPNM3DASCIIReader()
bool testPNMReader()

◆ testPNM3DASCIIReader()

bool testPNM3DASCIIReader ( )

Definition at line 127 of file testPNMReader.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:96
double endBlock()
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image

◆ testPNM3DReader()

bool testPNM3DReader ( )

Example of a test. To be completed.

Definition at line 105 of file testPNMReader.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:96
double endBlock()
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image

◆ testPNMReader()

bool testPNMReader ( )

Example of a test. To be completed.

Definition at line 53 of file testPNMReader.cpp.

References DGtal::Trace::beginBlock(), DGtal::Image< TImageContainer >::domain(), DGtal::Trace::endBlock(), image(), DGtal::Trace::info(), LibBoard::Board::saveEPS(), and DGtal::trace.

Referenced by main().

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 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:96
double endBlock()
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PPMReader.h:98
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()
ImageContainerBySTLVector< Domain, Value > Image
const Domain & domain() const
Definition: Image.h:192
Image image(domain)
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70