DGtal  0.9.2
testMagickReader.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 
34 #include "DGtal/kernel/SpaceND.h"
35 #include "DGtal/kernel/domains/HyperRectDomain.h"
36 #include "DGtal/images/ImageSelector.h"
37 #include "DGtal/io/colormaps/HueShadeColorMap.h"
38 #include "DGtal/io/colormaps/GrayscaleColorMap.h"
39 #include "DGtal/io/colormaps/GradientColorMap.h"
40 #include "DGtal/io/colormaps/ColorBrightnessColorMap.h"
41 
42 #include "DGtal/io/readers/MagickReader.h"
43 #include "DGtal/io/boards/Board2D.h"
44 #include "ConfigTest.h"
45 
46 
48 
49 using namespace std;
50 using namespace DGtal;
51 
53 // Functions for testing class MagickReader.
56 
60 bool testMagickReader()
61 {
62  unsigned int nbok = 0;
63  unsigned int nb = 0;
64 
65  trace.beginBlock ( "Testing MagickReader ..." );
66 
67  typedef SpaceND<2> Space2;
68  typedef HyperRectDomain<Space2> TDomain;
69 
70  //Default image selector = STLVector
72 
73  std::string filename = testPath + "samples/color64.png";
74 
75  trace.info()<<"Importing: "<<filename<<endl;
76 
77  MagickReader<Image> reader;
78  Image img = reader.importImage( filename );
79 
80  nbok += img.isValid() ? 1 : 0;
81  nb++;
82  trace.info() << "(" << nbok << "/" << nb << ") "
83  << "img.isValid() == true"
84  << std::endl;
85 
86  nbok += img.extent() == Image::Vector( 64, 64 ) ? 1 : 0;
87  nb++;
88  trace.info() << "(" << nbok << "/" << nb << ") "
89  << "img.extent() = " << img.extent()
90  << "( == {64,64} )"
91  << std::endl;
92 
93  Board2D board;
94  typedef HueShadeColorMap<unsigned char,2> HueTwice;
95 
96 
98 
99  Display2DFactory::drawImage<HueTwice>(board, img, (unsigned char)0, (unsigned char)255);
100  board.saveSVG("testMagick-export.svg");
101 
102  trace.endBlock();
103 
104  return nbok == nb;
105 }
106 
108 // Standard services - public :
109 
110 int main( int argc, char** argv )
111 {
112  trace.beginBlock ( "Testing class MagickReader" );
113  trace.info() << "Args:";
114  for ( int i = 0; i < argc; ++i )
115  trace.info() << " " << argv[ i ];
116  trace.info() << endl;
117 
118  bool res = testMagickReader(); // && ... other tests
119  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
120  trace.endBlock();
121  return res ? 0 : 1;
122 }
123 // //
void beginBlock(const std::string &keyword="")
Aim: implements association bewteen points lying in a digital domain and values.
Definition: Image.h:69
Trace trace
Definition: Common.h:130
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 'CDomain'.
STL namespace.
double endBlock()
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
std::ostream & emphase()
Aim: implements methods to read a 2D image using the ImageMagick library.
Definition: MagickReader.h:65
static ImageContainer importImage(const std::string &filename, const Functor &aFunctor=Functor(), bool topbotomOrder=true)
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
void setUnit(Unit unit)
Definition: Board.cpp:240
bool isValid() const
Definition: Image.h:266
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70