DGtal  0.9.2
testEuclideanShapesDecorator.cpp
1 
31 #include <iostream>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 
37 #include "DGtal/shapes/EuclideanShapesDecorator.h"
38 
40 #include "DGtal/shapes/implicit/ImplicitBall.h"
41 
43 
44 using namespace DGtal;
45 
47 // Functions for testing class EuclideanShapesDecorator.
49 
50 bool testEuclideanShapesDecorator()
51 {
52  unsigned int nbok = 0;
53  unsigned int nb = 0;
54 
55  trace.beginBlock ( "Testing Unary operation on euclidean shapes ..." );
56 
57  typedef ImplicitBall< Z2i::Space > ShapeA;
58  typedef ShapeA::RealPoint RealPoint;
59 
60  ShapeA shapeA(Z2i::RealPoint( -2.501, 0.0 ), 2.5013);
61  ShapeA shapeB(Z2i::RealPoint( 2, 0.0 ), 2.5013);
62  ShapeA shapeC(Z2i::RealPoint( 0.0, 0.0 ), 2.5);
63 
65  CSG s_union ( shapeA );
66  s_union.plus( shapeB );
67 
68  CSG s_intersec ( shapeA );
69  s_intersec.plus( shapeB );
70  s_intersec.intersection( shapeC );
71 
72  CSG s_minus ( shapeA );
73  s_minus.minus( shapeC );
74 
75 
76  nbok += (( s_union.orientation( RealPoint( -5.1, 0.0 )) == INSIDE )
77  || ( s_union.orientation( RealPoint( -5.1, 0.0 )) == ON ))? 0 : 1;
78  nbok += (( s_union.orientation( RealPoint( 0.0, 0.0 )) == INSIDE )
79  || ( s_union.orientation( RealPoint( 0.0, 0.0 )) == ON ))? 1 : 0;
80  nbok += (( s_union.orientation( RealPoint( 4.6, 0.0 )) == INSIDE )
81  || ( s_union.orientation( RealPoint( 4.6, 0.0 )) == ON ))? 0 : 1;
82  nbok += (( s_union.orientation( RealPoint( 4.5, 0.0 )) == INSIDE )
83  || ( s_union.orientation( RealPoint( 4.5, 0.0 )) == ON ))? 1 : 0;
84  nbok += (( s_union.orientation( RealPoint( -5.0, 0.0 )) == INSIDE )
85  || ( s_union.orientation( RealPoint( -5.0, 0.0 )) == ON ))? 1 : 0;
86 
87 
88  nbok += (( s_intersec.orientation( RealPoint( -2.6, 0.0 )) == INSIDE )
89  || ( s_intersec.orientation( RealPoint( -2.6, 0.0 )) == ON ))? 0 : 1;
90  nbok += (( s_intersec.orientation( RealPoint( 2.5, 0.0 )) == INSIDE )
91  || ( s_intersec.orientation( RealPoint( 2.5, 0.0 )) == ON ))? 1 : 0;
92  nbok += (( s_intersec.orientation( RealPoint( 2.6, 0.0 )) == INSIDE )
93  || ( s_intersec.orientation( RealPoint( 2.6, 0.0 )) == ON ))? 0 : 1;
94  nbok += (( s_intersec.orientation( RealPoint( 0.0, 2.5 )) == INSIDE )
95  || ( s_intersec.orientation( RealPoint( 0.0, 2.5 )) == ON ))? 0 : 1;
96 
97 
98  nbok += (( s_minus.orientation( RealPoint( -5.0, 0.0 )) == INSIDE )
99  || ( s_minus.orientation( RealPoint( -5.0, 0.0 )) == ON ))? 1 : 0;
100  nbok += (( s_minus.orientation( RealPoint( -1.0, 0.0 )) == INSIDE )
101  || ( s_minus.orientation( RealPoint( -1.0, 0.0 )) == ON ))? 0 : 1;
102  nbok += (( s_minus.orientation( RealPoint( 0.0, 2.0 )) == INSIDE )
103  || ( s_minus.orientation( RealPoint( 0.0, 2.0 )) == ON ))? 0 : 1;
104  nbok += (( s_minus.orientation( RealPoint( -2.6, 0.0 )) == INSIDE )
105  || ( s_minus.orientation( RealPoint( -2.6, 0.0 )) == ON ))? 1 : 0;
106 
107 
108  nb = 13;
109 
110 
111  trace.info() << "(" << nbok << "/" << nb << ") "
112  << "true == true" << std::endl;
113  trace.endBlock();
114  return nbok == nb;
115 }
116 
118 // Standard services - public :
119 
120 int main( int argc, char** argv )
121 {
122  trace.beginBlock ( "Testing class EuclideanShapesDecorator" );
123  trace.info() << "Args:";
124  for ( int i = 0; i < argc; ++i )
125  trace.info() << " " << argv[ i ];
126  trace.info() << std::endl;
127 
128  bool res = testEuclideanShapesDecorator(); // && ... other tests
129  trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
130  trace.endBlock();
131  return res ? 0 : 1;
132 }
133 // //
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:130
double endBlock()
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
Aim: Constructive Solid Geometry (CSG) between models of CEuclideanBoundedShape and CEuclideanOriente...
std::ostream & emphase()
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD...
Definition: ImplicitBall.h:64
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
Space::RealPoint RealPoint
Definition: StdDefs.h:97