DGtal  0.9.3
testSimpleBoard.cpp
1 
17 /*licenses*
18  * @file testSimpleBoard.cpp
19  * @ingroup Tests
20  * @author David Coeurjolly (\c david.coeurjolly@liris.cnrs.fr )
21  * Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
22  *
23  * @date 2010/07/16
24  *
25  * Functions for testing class SimpleBoard.
26  *
27  * This file is part of the DGtal library.
28  */
29 
31 #include "DGtal/base/Common.h"
32 #include "DGtal/kernel/PointVector.h"
33 #include "DGtal/kernel/SpaceND.h"
34 #include "DGtal/kernel/domains/HyperRectDomain.h"
35 #include "DGtal/io/boards/Board2D.h"
36 #include "ConfigTest.h"
37 
39 
40 using namespace std;
41 using namespace DGtal;
42 using namespace LibBoard;
43 
45 // Functions for testing class SimpleBoard.
47 
51 bool testSimpleBoard()
52 {
53  unsigned int nbok = 0;
54  unsigned int nb = 2;
55 
56  trace.beginBlock ( "Testing class SimpleBoard" );
57 
58  Board2D board;
59 
60  board.setPenColorRGBi( 0, 0, 0);
61  board.drawRectangle( -1, 1, 2.0, 2.0 );
62  board.setPenColorRGBi( 0, 0, 255 );
63  board.fillCircle( 2, 2, 1 );
64 
65 
66 
67  board.saveSVG( "simpleboard.svg" );
68  board.saveFIG( "simpleboard.fig" );
69  board.saveEPS( "simpleboard.eps" );
70  board.saveTikZ( "simpleboard.tikz" );
71  nbok++;
72 
73  typedef PointVector<2,int> Point2D;
74  Point2D apoint, p2;
75  apoint[0] = 5;
76  p2[0] = 1;
77  apoint[1] = 8;
78  p2[1] = 1;
79 
80  board.setPenColorRGBi( 255, 0, 255 );
81  board << apoint;
82 
83  board.setPenColorRGBi( 255, 0, 0 );
84  Display2DFactory::draw(board, apoint, p2);
85 
86  board.scale(10);
87 
88  board.saveSVG( "pointsimpleboard.svg" );
89  board.saveFIG( "pointsimpleboard.fig" );
90  board.saveEPS( "pointsimpleboard.eps" );
91  board.saveTikZ( "pointsimpleboard.tikz" );
92  nbok++;
93  trace.endBlock();
94  return nbok == nb;
95 }
96 
97 bool testDomain()
98 {
99  typedef SpaceND<2> TSpace;
100  typedef TSpace::Point Point;
101  Point a ( 1, 1);
102  Point b ( 15, 15);
103 
104  trace.beginBlock ( "HyperRectDomain Iterator" );
105  HyperRectDomain<TSpace> myDomain ( a,b );
106 
107  Board2D board;
108 
109  board << SetMode( myDomain.className(), "Grid" ) << myDomain;
110  board.scale(10);
111  board.saveSVG( "domain-grid.svg" );
112  board.saveTikZ( "domain-grid.tikz" );
113 
114  Board2D b2;
115  b2 << SetMode( myDomain.className(), "Paving" ) << myDomain;
116  b2.scale(10);
117  b2.saveSVG( "domain-paving.svg" );
118  b2.saveTikZ( "domain-paving.tikz" );
119  trace.endBlock();
120 
122  //An assert should be raised
123  //Display2DFactory::draw(b2, pl);
124 
125  return true;
126 }
127 
128 
129 bool testImage()
130 {
131  unsigned int nbok = 0;
132  unsigned int nb = 1;
133  trace.beginBlock ( "Testing Display Image with Board " );
134  Board2D board;
135 
136  std::string filenameImage1 = testPath + "samples/contourS.png";
137  board.drawImage(filenameImage1, 0, 85, 185, 85);
138  board.saveFIG("boardTestDisplayImage.fig");
139  board.saveSVG("boardTestDisplayImage.svg");
140  board.saveTikZ("boardTestDisplayImage.tikz" );
141 #ifdef WITH_CAIRO
142  board.saveCairo("boardTestDisplayImageCAIRO.eps", Board2D::CairoEPS );
143  board.saveCairo("boardTestDisplayImageCAIRO.pdf", Board2D::CairoPDF );
144  board.saveCairo("boardTestDisplayImageCAIRO.png", Board2D::CairoPNG );
145 #endif
146  nbok++;
147  trace.endBlock();
148  return nbok == nb;
149 }
150 
151 
153 // Standard services - public :
154 
155 int main( int argc, char** argv )
156 {
157  trace.beginBlock ( "Testing class SimpleBoard" );
158  trace.info() << "Args:";
159  for ( int i = 0; i < argc; ++i )
160  trace.info() << " " << argv[ i ];
161  trace.info() << endl;
162 
163  bool res = testSimpleBoard() && testDomain() && testImage(); // && ... other tests
164  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
165  trace.endBlock();
166  return res ? 0 : 1;
167 }
168 // //
void beginBlock(const std::string &keyword="")
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
Shape & scale(double sx, double sy)
Definition: Board.cpp:184
Aim: Parallelepidec region of a digital space, model of a &#39;CDomain&#39;.
void drawImage(std::string filename, double x, double y, double width, double height, int depthValue=-1, double alpha=1.0)
Definition: Board.cpp:428
STL namespace.
double endBlock()
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1139
void fillCircle(double x, double y, double radius, int depthValue=-1)
Definition: Board.cpp:471
std::ostream & emphase()
void drawRectangle(double x, double y, double width, double height, int depthValue=-1)
Definition: Board.cpp:417
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
int main(int argc, char **argv)
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
Modifier class in a Board2D stream. Useful to choose your own mode for a given class. Realizes the concept CDrawableWithBoard2D.
Definition: Board2D.h:247
bool testImage(const Image &aImage)
Definition: testImage.cpp:57
Board & setPenColorRGBi(unsigned char red, unsigned char green, unsigned char blue, unsigned char alpha=255)
Definition: Board.cpp:278
void saveTikZ(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1219
void saveFIG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0, bool includeFIGHeader=true) const
Definition: Board.cpp:907
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70