DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testPNMReader.cpp
Go to the documentation of this file.
1
16
29
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
53
bool
testPNMReader
()
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
60
typedef
ImageSelector < Z2i::Domain, unsigned int>::Type
Image
;
61
Image
image
=
PGMReader<Image>::importPGM
( filename );
62
63
Z2i::DigitalSet
set2d (
image
.
domain
());
64
SetFromImage<Z2i::DigitalSet>::append<Image>
(set2d,
image
, 0, 255);
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
77
typedef
ImageSelector < Z2i::Domain, unsigned int>::Type
Image
;
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
}
91
95
bool
testPNM3DReader
()
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
102
typedef
ImageSelector < Z3i::Domain, unsigned int>::Type
Image
;
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
111
bool
testPNM3DASCIIReader
()
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
118
typedef
ImageSelector < Z3i::Domain, unsigned int>::Type
Image
;
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
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::Image
Aim: implements association between points lying in a digital domain and values.
Definition
Image.h:70
DGtal::Image::domain
const Domain & domain() const
Definition
Image.h:192
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:804
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition
StdDefs.h:100
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::ImageSelector::Type
ImageContainerBySTLVector< Domain, Value > Type
Definition
ImageSelector.h:84
DGtal::PGMReader::importPGM3D
static ImageContainer importPGM3D(const std::string &aFilename, const Functor &aFunctor=Functor())
DGtal::PGMReader::importPGM
static ImageContainer importPGM(const std::string &aFilename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
DGtal::PPMReader::importPPM
static ImageContainer importPPM(const std::string &aFilename, const Functor &aFunctor=functors::ColorRGBEncoder< Value >(), bool topbotomOrder=true)
DGtal::SetFromImage::append
static void append(Set &aSet, const ForegroundPredicate &isForeground, typename Image::Domain::ConstIterator itBegin, typename Image::Domain::ConstIterator itEnd)
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testPNMReader
bool testPNMReader()
Definition
testPNMReader.cpp:53
testPNM3DASCIIReader
bool testPNM3DASCIIReader()
Definition
testPNMReader.cpp:111
testPNM3DReader
bool testPNM3DReader()
Definition
testPNMReader.cpp:95
image
Image image(domain)
tests
io
readers
testPNMReader.cpp
Generated on
for DGtal by
1.18.0