DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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 
38 
39 using namespace std;
40 using namespace DGtal;
41 using namespace LibBoard;
42 
44 // Functions for testing class SimpleBoard.
46 
50 bool testSimpleBoard()
51 {
52  unsigned int nbok = 0;
53  unsigned int nb = 2;
54 
55  trace.beginBlock ( "Testing class SimpleBoard" );
56 
57  Board2D board;
58 
59  board.setPenColorRGBi( 0, 0, 0);
60  board.drawRectangle( -1, 1, 2.0, 2.0 );
61  board.setPenColorRGBi( 0, 0, 255 );
62  board.fillCircle( 2, 2, 1 );
63 
64 
65 
66  board.saveSVG( "simpleboard.svg" );
67  board.saveFIG( "simpleboard.fig" );
68  board.saveEPS( "simpleboard.eps" );
69  board.saveTikZ( "simpleboard.tikz" );
70  nbok++;
71 
72  typedef PointVector<2,int> Point2D;
73  Point2D apoint, p2;
74  apoint[0] = 5;
75  p2[0] = 1;
76  apoint[1] = 8;
77  p2[1] = 1;
78 
79  board.setPenColorRGBi( 255, 0, 255 );
80  board << apoint;
81 
82  board.setPenColorRGBi( 255, 0, 0 );
83  Display2DFactory::draw(board, apoint, p2);
84 
85  board.scale(10);
86 
87  board.saveSVG( "pointsimpleboard.svg" );
88  board.saveFIG( "pointsimpleboard.fig" );
89  board.saveEPS( "pointsimpleboard.eps" );
90  board.saveTikZ( "pointsimpleboard.tikz" );
91  nbok++;
92  trace.endBlock();
93  return nbok == nb;
94 }
95 
96 bool testDomain()
97 {
98  typedef SpaceND<2> TSpace;
99  typedef TSpace::Point Point;
100  Point a ( 1, 1);
101  Point b ( 15, 15);
102 
103  trace.beginBlock ( "HyperRectDomain Iterator" );
104  HyperRectDomain<TSpace> myDomain ( a,b );
105 
106  Board2D board;
107 
108  board << SetMode( myDomain.className(), "Grid" ) << myDomain;
109  board.scale(10);
110  board.saveSVG( "domain-grid.svg" );
111  board.saveTikZ( "domain-grid.tikz" );
112 
113  Board2D b2;
114  b2 << SetMode( myDomain.className(), "Paving" ) << myDomain;
115  b2.scale(10);
116  b2.saveSVG( "domain-paving.svg" );
117  b2.saveTikZ( "domain-paving.tikz" );
118 
119 
120  trace.endBlock();
121 
123  //An assert should be raised
124  //Display2DFactory::draw(b2, pl);
125 
126  return true;
127 }
128 
130 // Standard services - public :
131 
132 int main( int argc, char** argv )
133 {
134  trace.beginBlock ( "Testing class SimpleBoard" );
135  trace.info() << "Args:";
136  for ( int i = 0; i < argc; ++i )
137  trace.info() << " " << argv[ i ];
138  trace.info() << endl;
139 
140  bool res = testSimpleBoard() && testDomain(); // && ... other tests
141  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
142  trace.endBlock();
143  return res ? 0 : 1;
144 }
145 // //