DGtal  0.9.3
Functions
testPNMRawWriter.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/images/ImageSelector.h"
#include "DGtal/io/colormaps/GrayscaleColorMap.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/colormaps/ColorBrightnessColorMap.h"
#include "DGtal/io/colormaps/RandomColorMap.h"
#include "DGtal/io/colormaps/BasicColorToScalarFunctors.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/io/writers/PGMWriter.h"
#include "DGtal/io/writers/PPMWriter.h"
#include "DGtal/io/readers/PGMReader.h"
#include "DGtal/io/writers/RawWriter.h"
#include "DGtal/io/boards/Board2D.h"
Include dependency graph for testPNMRawWriter.cpp:

Go to the source code of this file.

Functions

bool testPNMWriter ()
 
bool testRWIssue254 ()
 
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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2010/07/22

Functions for testing class PNMWriter.

This file is part of the DGtal library.

Definition in file testPNMRawWriter.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 156 of file testPNMRawWriter.cpp.

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

157 {
158  trace.beginBlock ( "Testing class PNMWriter" );
159  trace.info() << "Args:";
160  for ( int i = 0; i < argc; ++i )
161  trace.info() << " " << argv[ i ];
162  trace.info() << std::endl;
163 
164  bool res = testPNMWriter() && testRWIssue254(); // && ... other tests
165  trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
166  trace.endBlock();
167  return res ? 0 : 1;
168 }
void beginBlock(const std::string &keyword="")
bool testRWIssue254()
Trace trace
Definition: Common.h:137
double endBlock()
std::ostream & emphase()
std::ostream & info()
bool testPNMWriter()

◆ testPNMWriter()

bool testPNMWriter ( )

Example of a test. To be completed.

Definition at line 60 of file testPNMRawWriter.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::PGMWriter< TImage, TFunctor >::exportPGM(), DGtal::PPMWriter< TImage, TFunctor >::exportPPM(), DGtal::RawWriter< TImage, TFunctor >::exportRaw8(), image(), LibBoard::Board::setUnit(), DGtal::trace, and LibBoard::Board::UCentimeter.

Referenced by main().

61 {
62 
63  trace.beginBlock ( "Testing block ..." );
64 
65  typedef SpaceND<2> TSpace;
66  typedef TSpace::Point Point;
69  typedef HueShadeColorMap<unsigned char,2> HueTwice;
71  // Gradient using the "Jet" preset.
73  // Gradient from black to red.
74  const int BlackColor = DGTAL_RGB2INT(0,0,0);
75  const int RedColor = DGTAL_RGB2INT(255,0,0);
77  // Gradient from black to red, using a ColorBrightnessColorMap.
79 
80  Point a ( 1, 1);
81  Point b ( 16, 16);
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
97  RedFunctor redFunctor( Jet(0,255), functors::RedChannel() ) ;
98  PGMWriter<Image, RedFunctor>::exportPGM("export-jet-red.pgm",image, redFunctor);
99 
100 
101  //test Raw export
102  RawWriter<Image>::exportRaw8("export-hue-twice.raw",image);
103 
104  //test Image export with libboard
105  Board2D board;
107  Display2DFactory::drawImage<HueTwice>(board, image, (unsigned char)0, (unsigned char)255);
108  board.saveSVG("export-hue-twice.svg");
109 
110  trace.endBlock();
111 
112  return true;
113 }
void beginBlock(const std::string &keyword="")
HyperRectDomain< Space > Domain
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: Automatically defines an adequate image type according to the hints given by the user...
Definition: ImageSelector.h:66
Trace trace
Definition: Common.h:137
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: Export a 2D and a 3D Image using the Netpbm PPM formats (ASCII mode).
Definition: PPMWriter.h:72
Aim: This class template may be used to (linearly) convert scalar values in a given range into gray l...
Aim: Raw binary export of an Image.
Definition: RawWriter.h:98
Aim: Define a new Functor from the composition of two other functors.
MyPointD Point
Definition: testClone2.cpp:383
ImageContainerBySTLVector< Domain, Value > Image
Aim: Export a 2D and a 3D Image using the Netpbm PGM formats (ASCII mode).
Definition: PGMWriter.h:88
void setUnit(Unit unit)
Definition: Board.cpp:240
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

◆ testRWIssue254()

bool testRWIssue254 ( )

Definition at line 116 of file testPNMRawWriter.cpp.

References DGtal::Trace::beginBlock(), domain(), DGtal::Image< TImageContainer >::domain(), DGtal::Trace::endBlock(), DGtal::PGMWriter< TImage, TFunctor >::exportPGM(), image(), DGtal::PGMReader< TImageContainer, TFunctor >::importPGM(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

117 {
118  trace.beginBlock ( "Testing R/W on PPM Writer (issue 254) ..." );
119 
120  typedef SpaceND<2> TSpace;
121  typedef TSpace::Point Point;
123 
124  Point a ( 0, 0);
125  Point b ( 15, 15);
127  Domain domain(a,b);
128  Image image(domain);
129  for(unsigned int i=0 ; i < 256; i++)
130  image[i] = i;
131 
132  PGMWriter<Image>::exportPGM("export-gray-first.pgm",image);
133 
134  Image imageRead = PGMReader<Image>::importPGM("export-gray-first.pgm");
135 
136  PGMWriter<Image>::exportPGM("export-gray-second.pgm",imageRead);
137 
138  trace.info() << image<<std::endl;
139  trace.info() << imageRead<<std::endl;
140 
141 
142  bool ok = true;
143  for(Image::Domain::ConstIterator it = image.domain().begin(),
144  itend = image.domain().end();
145  it != itend;
146  ++it)
147  ok = (image(*it) == imageRead(*it));
148 
149  trace.endBlock();
150  return ok;
151 }
void beginBlock(const std::string &keyword="")
HyperRectDomain< Space > Domain
Aim: Automatically defines an adequate image type according to the hints given by the user...
Definition: ImageSelector.h:66
const Domain domain(Point(1, 2), Point(6, 5))
Trace trace
Definition: Common.h:137
Aim: Import a 2D or 3D using the Netpbm formats (ASCII mode).
Definition: PGMReader.h:96
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
double endBlock()
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
ImageContainerBySTLVector< Domain, Value > Image
Aim: Export a 2D and a 3D Image using the Netpbm PGM formats (ASCII mode).
Definition: PGMWriter.h:88
Image image(domain)