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