DGtal  1.5.beta
testDigitalShapesDecorator.cpp
Go to the documentation of this file.
1 
32 #include <iostream>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/shapes/GaussDigitizer.h"
36 
38 #include "DGtal/shapes/DigitalShapesDecorator.h"
39 
41 #include "DGtal/shapes/parametric/Ball2D.h"
42 
44 
45 using namespace std;
46 using namespace DGtal;
47 
49 // Functions for testing class DigitalShapesDecorator.
51 
56 {
57  unsigned int nbok = 0;
58  unsigned int nb = 0;
59 
60  trace.beginBlock ( "Testing Unary operation on digital shapes ..." );
61 
62  typedef Z2i::Space Space;
63  typedef Ball2D< Space > ShapeA;
64  typedef GaussDigitizer< Space, ShapeA > MyGaussDigitizerA;
65 
66  typedef Space::Point Point;
67 
68  double h = 0.5;
69 
70  ShapeA shapeA(-2.501, 0.0, 2.5013);
71  ShapeA shapeB(2, 0.0, 2.5013);
72  ShapeA shapeC(0.0, 0.0, 2.5);
73 
74  MyGaussDigitizerA digShapeA;
75  digShapeA.attach( shapeA );
76  digShapeA.init( shapeA.getLowerBound(), shapeA.getUpperBound(), h );
77 
78  MyGaussDigitizerA digShapeB;
79  digShapeB.attach( shapeB );
80  digShapeB.init( shapeB.getLowerBound(), shapeB.getUpperBound(), h );
81 
82  MyGaussDigitizerA digShapeC;
83  digShapeC.attach( shapeC );
84  digShapeC.init( shapeC.getLowerBound(), shapeC.getUpperBound(), h );
85 
86 
88  CSG s_union ( digShapeA );
89  s_union.plus( digShapeB );
90 
91  CSG s_intersec ( digShapeA );
92  s_intersec.plus( digShapeB );
93  s_intersec.intersection( digShapeC );
94 
95  CSG s_minus ( digShapeA );
96  s_minus.minus( digShapeC );
97 
98 
99  nbok += (( s_union.orientation( Point( -12, 0 )) == INSIDE )
100  || ( s_union.orientation( Point( -12, 0 )) == ON ))? 0 : 1;
101  nbok += (( s_union.orientation( Point( 0, 0 )) == INSIDE )
102  || ( s_union.orientation( Point( 0, 0 )) == ON ))? 1 : 0;
103  nbok += (( s_union.orientation( Point( 10, 0 )) == INSIDE )
104  || ( s_union.orientation( Point( 10, 0 )) == ON ))? 0 : 1;
105  nbok += (( s_union.orientation( Point( 9, 0 )) == INSIDE )
106  || ( s_union.orientation( Point( 9, 0 )) == ON ))? 1 : 0;
107  nbok += (( s_union.orientation( Point( -10, 0 )) == INSIDE )
108  || ( s_union.orientation( Point( -10, 0 )) == ON ))? 1 : 0;
109 
110 
111  nbok += (( s_intersec.orientation( Point( -6, 0 )) == INSIDE )
112  || ( s_intersec.orientation( Point( -6, 0 )) == ON ))? 0 : 1;
113  nbok += (( s_intersec.orientation( Point( 4, 0 )) == INSIDE )
114  || ( s_intersec.orientation( Point( 4, 0 )) == ON ))? 1 : 0;
115  nbok += (( s_intersec.orientation( Point( 6, 0 )) == INSIDE )
116  || ( s_intersec.orientation( Point( 6, 0 )) == ON ))? 0 : 1;
117  nbok += (( s_intersec.orientation( Point( 0, 5 )) == INSIDE )
118  || ( s_intersec.orientation( Point( 0, 5 )) == ON ))? 0 : 1;
119 
120 
121  nbok += (( s_minus.orientation( Point( -9, 0 )) == INSIDE )
122  || ( s_minus.orientation( Point( -9, 0 )) == ON ))? 1 : 0;
123  nbok += (( s_minus.orientation( Point( -2, 0 )) == INSIDE )
124  || ( s_minus.orientation( Point( -2, 0 )) == ON ))? 0 : 1;
125  nbok += (( s_minus.orientation( Point( 0, 2 )) == INSIDE )
126  || ( s_minus.orientation( Point( 0, 2 )) == ON ))? 0 : 1;
127  nbok += (( s_minus.orientation( Point( -8, 0 )) == INSIDE )
128  || ( s_minus.orientation( Point( -8, 0 )) == ON ))? 1 : 0;
129 
130  nb = 13;
131 
132 
133  trace.info() << "(" << nbok << "/" << nb << ") "
134  << "true == true" << std::endl;
135  trace.endBlock();
136  return nbok == nb;
137 }
138 
140 // Standard services - public :
141 
142 int main( int argc, char** argv )
143 {
144  trace.beginBlock ( "Testing class DigitalShapesDecorator" );
145  trace.info() << "Args:";
146  for ( int i = 0; i < argc; ++i )
147  trace.info() << " " << argv[ i ];
148  trace.info() << std::endl;
149 
150  bool res = testDigitalShapesDecorator(); // && ... other tests
151  trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
152  trace.endBlock();
153  return res ? 0 : 1;
154 }
155 // //
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition: Ball2D.h:61
Aim: Constructive Solid Geometry (CSG) between models of CDigitalBoundedShape and CDigitalOrientedSha...
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
@ INSIDE
Definition: Common.h:141
@ ON
Definition: Common.h:141
MyPointD Point
Definition: testClone2.cpp:383
int main(int argc, char **argv)
bool testDigitalShapesDecorator()