DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testPNMRawWriter.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "DGtal/kernel/SpaceND.h"
34
#include "DGtal/kernel/domains/HyperRectDomain.h"
35
#include "DGtal/images/ImageSelector.h"
36
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
37
#include "DGtal/io/colormaps/HueShadeColorMap.h"
38
#include "DGtal/io/colormaps/GradientColorMap.h"
39
#include "DGtal/io/colormaps/ColorBrightnessColorMap.h"
40
#include "DGtal/io/colormaps/RandomColorMap.h"
41
#include "DGtal/io/colormaps/BasicColorToScalarFunctors.h"
42
#include "DGtal/base/BasicFunctors.h"
43
44
#include "DGtal/io/writers/PGMWriter.h"
45
#include "DGtal/io/writers/PPMWriter.h"
46
#include "DGtal/io/readers/PGMReader.h"
47
#include "DGtal/io/writers/RawWriter.h"
48
#include "DGtal/io/boards/Board2D.h"
50
51
using namespace
DGtal
;
52
54
// Functions for testing class PNMWriter.
56
60
bool
testPNMWriter
()
61
{
62
63
trace
.
beginBlock
(
"Testing block ..."
);
64
65
typedef
SpaceND<2>
TSpace;
66
typedef
TSpace::Point
Point
;
67
typedef
HyperRectDomain<TSpace>
Domain
;
68
typedef
HueShadeColorMap<unsigned char>
Hue;
69
typedef
HueShadeColorMap<unsigned char,2>
HueTwice;
70
typedef
GrayscaleColorMap<unsigned char>
Gray;
71
// Gradient using the "Jet" preset.
72
typedef
GradientColorMap<unsigned char, CMAP_JET >
Jet;
73
// Gradient from black to red.
74
const
int
BlackColor = DGTAL_RGB2INT(0,0,0);
75
const
int
RedColor = DGTAL_RGB2INT(255,0,0);
76
typedef
GradientColorMap< unsigned char, CMAP_CUSTOM, BlackColor, RedColor >
RedShade1;
77
// Gradient from black to red, using a ColorBrightnessColorMap.
78
typedef
ColorBrightnessColorMap< unsigned char, RedColor >
RedShade2;
79
80
Point
a ( 1, 1);
81
Point
b ( 16, 16);
82
typedef
ImageSelector<Domain, unsigned char>::Type
Image
;
83
Image
image
(
Domain
(a,b));
84
for
(
unsigned
int
i=0 ; i < 256; i++)
85
image
[i] = i;
86
87
PPMWriter<Image,Hue>::exportPPM
(
"export-hue.ppm"
,
image
, Hue(0,255) );
88
PPMWriter<Image,HueTwice>::exportPPM
(
"export-hue-twice.ppm"
,
image
,HueTwice(0,255));
89
PGMWriter<Image>::exportPGM
(
"export-hue-twice.pgm"
,
image
);
90
PPMWriter<Image,Gray>::exportPPM
(
"export-gray.ppm"
,
image
, Gray(0,255));
91
PPMWriter<Image,Jet>::exportPPM
(
"export-jet.ppm"
,
image
,Jet(0,255));
92
PPMWriter<Image,RedShade1>::exportPPM
(
"export-red1.ppm"
,
image
,RedShade1(0,255));
93
PPMWriter<Image,RedShade2>::exportPPM
(
"export-red2.ppm"
,
image
,RedShade2(0,255));
94
95
//TestingFunctor
96
typedef
DGtal::functors::Composer< Jet, functors::RedChannel, unsigned char>
RedFunctor;
97
Jet jf( 0, 255 );
98
functors::RedChannel
rf;
99
RedFunctor redFunctor( jf, rf );
100
PGMWriter<Image, RedFunctor>::exportPGM
(
"export-jet-red.pgm"
,
image
, redFunctor);
101
102
//test Raw export
103
RawWriter<Image>::exportRaw8
(
"export-hue-twice.raw"
,
image
);
104
105
//test Image export with libboard
106
Board2D
board;
107
board.
setUnit
(
LibBoard::Board::UCentimeter
);
108
Display2DFactory::drawImage<HueTwice>
(board,
image
, (
unsigned
char
)0, (
unsigned
char
)255);
109
board.
saveSVG
(
"export-hue-twice.svg"
);
110
111
trace
.
endBlock
();
112
113
return
true
;
114
}
115
116
117
bool
testRWIssue254
()
118
{
119
trace
.
beginBlock
(
"Testing R/W on PPM Writer (issue 254) ..."
);
120
121
typedef
SpaceND<2>
TSpace;
122
typedef
TSpace::Point
Point
;
123
typedef
HyperRectDomain<TSpace>
Domain
;
124
125
Point
a ( 0, 0);
126
Point
b ( 15, 15);
127
typedef
ImageSelector<Domain, unsigned char>::Type
Image
;
128
Domain
domain
(a,b);
129
Image
image
(
domain
);
130
for
(
unsigned
int
i=0 ; i < 256; i++)
131
image
[i] = i;
132
133
PGMWriter<Image>::exportPGM
(
"export-gray-first.pgm"
,
image
);
134
135
Image
imageRead =
PGMReader<Image>::importPGM
(
"export-gray-first.pgm"
);
136
137
PGMWriter<Image>::exportPGM
(
"export-gray-second.pgm"
,imageRead);
138
139
trace
.
info
() <<
image
<<std::endl;
140
trace
.
info
() << imageRead<<std::endl;
141
142
143
bool
ok =
true
;
144
for
(
Image::Domain::ConstIterator
it =
image
.
domain
().
begin
(),
145
itend =
image
.
domain
().
end
();
146
it != itend;
147
++it)
148
ok = (
image
(*it) == imageRead(*it));
149
150
trace
.
endBlock
();
151
return
ok;
152
}
153
155
// Standard services - public :
156
157
int
main
(
int
argc,
char
** argv )
158
{
159
trace
.
beginBlock
(
"Testing class PNMWriter"
);
160
trace
.
info
() <<
"Args:"
;
161
for
(
int
i = 0; i < argc; ++i )
162
trace
.
info
() <<
" "
<< argv[ i ];
163
trace
.
info
() << std::endl;
164
165
bool
res =
testPNMWriter
() &&
testRWIssue254
();
// && ... other tests
166
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << std::endl;
167
trace
.
endBlock
();
168
return
res ? 0 : 1;
169
}
170
171
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::ColorBrightnessColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition
ColorBrightnessColorMap.h:90
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition
GradientColorMap.h:120
DGtal::GrayscaleColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Definition
GrayscaleColorMap.h:94
DGtal::HueShadeColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition
HueShadeColorMap.h:91
DGtal::HyperRectDomain
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
Definition
HyperRectDomain.h:100
DGtal::HyperRectDomain< Space >::Domain
HyperRectDomain< Space > Domain
Definition
HyperRectDomain.h:112
DGtal::HyperRectDomain::begin
const ConstIterator & begin() const
Definition
HyperRectDomain.h:176
DGtal::HyperRectDomain::end
const ConstIterator & end() const
Definition
HyperRectDomain.h:201
DGtal::ImageContainerBySTLVector< Domain, Value >::ConstIterator
std::vector< Value >::const_iterator ConstIterator
Definition
ImageContainerBySTLVector.h:265
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::SpaceND
Definition
SpaceND.h:96
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()
DGtal::Domain
DGtal::functors::Composer
Aim: Define a new Functor from the composition of two other functors.
Definition
BasicFunctors.h:418
LibBoard::Board::UCentimeter
@ UCentimeter
Definition
Board.h:43
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1011
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition
Board.cpp:239
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
DGtal::Display2DFactory::drawImage
static void drawImage(DGtal::Board2D &board, const Image &i, const typename Image::Value &minV, const typename Image::Value &maxV)
DGtal::ImageSelector::Type
ImageContainerBySTLVector< Domain, Value > Type
Definition
ImageSelector.h:84
DGtal::PGMReader::importPGM
static ImageContainer importPGM(const std::string &aFilename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
DGtal::PGMWriter::exportPGM
static bool exportPGM(const std::string &filename, const Image &aImage, const Functor &aFunctor=Functor(), bool saveASCII=false, bool topbotomOrder=true)
DGtal::PPMWriter::exportPPM
static bool exportPPM(const std::string &filename, const Image &aImage, const Functor &aFunctor=Functor(), bool topbottomOrder=true)
DGtal::RawWriter::exportRaw8
static bool exportRaw8(const std::string &filename, const Image &anImage, const Functor &aFunctor=Functor())
DGtal::functors::RedChannel
Definition
BasicColorToScalarFunctors.h:58
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testPNMWriter
bool testPNMWriter()
Definition
testPNMRawWriter.cpp:60
testRWIssue254
bool testRWIssue254()
Definition
testPNMRawWriter.cpp:117
domain
Domain domain
Definition
testProjection.cpp:88
image
Image image(domain)
tests
io
writers
testPNMRawWriter.cpp
Generated on
for DGtal by
1.18.0