DGtal 1.4.0
Loading...
Searching...
No Matches
testInHalfPlane.cpp
Go to the documentation of this file.
1
31#include <iostream>
32#include "DGtal/base/Common.h"
33#include "DGtal/kernel/PointVector.h"
34
35#include "DGtal/geometry/tools/determinant/Simple2x2DetComputer.h"
36#include "DGtal/geometry/tools/determinant/AvnaimEtAl2x2DetSignComputer.h"
37
38#include "DGtal/geometry/tools/determinant/COrientationFunctor2.h"
39#include "DGtal/geometry/tools/determinant/InHalfPlaneBy2x2DetComputer.h"
40#include "DGtal/geometry/tools/determinant/InHalfPlaneBySimple3x3Matrix.h"
41
42#include "DGtal/geometry/tools/determinant/InGeneralizedDiskOfGivenRadius.h"
44
45using namespace std;
46using namespace DGtal;
47
49// Functions for testing class InHalfPlane.
51
56template<typename OrientationFunctor>
57bool testInHalfPlane(OrientationFunctor f)
58{
60
61 unsigned int nbok = 0;
62 unsigned int nb = 0;
63
64 trace.beginBlock ( "Testing block ..." );
65 trace.info() << f << endl;
66
67 typedef typename OrientationFunctor::Value Value;
68 typedef typename OrientationFunctor::Point Point;
69 Point a(0,0);
70 Point b(5,2);
71
72 //first quadrant
73 f.init(a, b);
74 if (f( Point(2,1) ) == NumberTraits<Value>::ONE)
75 nbok++; //a, b, (2,1) are CCW oriented
76 nb++;
77 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
78
79 if (f( Point(3,1) ) == -NumberTraits<Value>::ONE)
80 nbok++; //a, b, (3,1) are CW oriented
81 nb++;
82 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
83
84 if (f( Point(10,4) ) == NumberTraits<Value>::ZERO)
85 nbok++; //a, b, (10,4) belong to the same line
86 nb++;
87 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
88
90
91 return nbok == nb;
92}
93
98{
99 unsigned int nbok = 0;
100 unsigned int nb = 0;
101
105 BOOST_CONCEPT_ASSERT(( concepts::COrientationFunctor2<Functor> ));
106 typedef Functor::Value Value;
107
108 Value res;
109
110 trace.beginBlock ( "Infinite radius..." );
111
112 Functor f_inf; //infinite radius by default
113 trace.info() << f_inf << " " << f_inf.isValid() << endl;
114
115 f_inf.init( Point(0,0), Point(5,2) );
116 res = f_inf( Point(7,3) );
117 trace.info() << res << " > 0 " << std::endl;
118 if ( res > NumberTraits<Value>::ZERO )
119 nbok++;
120 nb++;
121 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
122
123 f_inf.init( Point(0,0), Point(5,2) );
124 res = f_inf( Point(8,3) );
125 trace.info() << res << " < 0 " << std::endl;
126 if ( res < NumberTraits<Value>::ZERO )
127 nbok++;
128 nb++;
129 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
130
131 f_inf.init( Point(0,0), Point(5,2) );
132 res = f_inf( Point(10,4) );
133 trace.info() << res << " == 0 " << std::endl;
134 if ( res == NumberTraits<Value>::ZERO )
135 nbok++;
136 nb++;
137 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
138
139 Functor f_inf2(false); //infinite radius too, but with another orientation
140 trace.info() << f_inf2 << " " << f_inf2.isValid() << endl;
141
142 f_inf2.init( Point(0,0), Point(5,2) );
143 res = f_inf2( Point(7,3) );
144 trace.info() << res << " < 0 " << std::endl;
145 if ( res < NumberTraits<Value>::ZERO )
146 nbok++;
147 nb++;
148 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
149
150 f_inf2.init( Point(0,0), Point(5,2) );
151 res = f_inf2( Point(8,3) );
152 trace.info() << res << " > 0 " << std::endl;
153 if ( res > NumberTraits<Value>::ZERO )
154 nbok++;
155 nb++;
156 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
157
158 f_inf2.init( Point(0,0), Point(5,2) );
159 res = f_inf2( Point(10,4) );
160 trace.info() << res << " == 0 " << std::endl;
161 if ( res == NumberTraits<Value>::ZERO )
162 nbok++;
163 nb++;
164 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
165
166 trace.endBlock();
167
168 trace.beginBlock ( "Finite radius..." );
169
170 Functor f5(true, 25, 1); //radius 5 with positive orientation
171 trace.info() << f5 << " " << f5.isValid() << endl;
172
173 f5.init( Point(5,0), Point(0,5) );
174 res = f5( Point(-4,1) );
175 trace.info() << res << " > 0 " << std::endl;
176 if ( res > NumberTraits<Value>::ZERO )
177 nbok++;
178 nb++;
179 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
180
181 res = f5( Point(-5,1) );
182 trace.info() << res << " < 0 " << std::endl;
183 if ( res < NumberTraits<Value>::ZERO )
184 nbok++;
185 nb++;
186 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
187
188 res = f5( Point(-3,4) );
189 trace.info() << res << " == 0 " << std::endl;
190 if ( res == NumberTraits<Value>::ZERO )
191 nbok++;
192 nb++;
193 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
194
195 res = f5( Point(-1,6) );
196 trace.info() << res << " < 0 " << std::endl;
197 if ( res < NumberTraits<Value>::ZERO )
198 nbok++;
199 nb++;
200 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
201
202 res = f5( Point(-1,7) );
203 trace.info() << res << " < 0 " << std::endl;
204 if ( res < NumberTraits<Value>::ZERO )
205 nbok++;
206 nb++;
207 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
208
209 Functor f52(false, 25, 1); //radius 5 with negative orientation
210 trace.info() << f52 << " " << f52.isValid() << endl;
211
212 f52.init( Point(-5,0), Point(0,5) );
213 res = f52( Point(4,1) );
214 trace.info() << res << " < 0 " << std::endl;
215 if ( res < NumberTraits<Value>::ZERO )
216 nbok++;
217 nb++;
218 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
219
220 res = f52( Point(3,1) );
221 trace.info() << res << " < 0 " << std::endl;
222 if ( res < NumberTraits<Value>::ZERO )
223 nbok++;
224 nb++;
225 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
226
227 res = f52( Point(5,1) );
228 trace.info() << res << " > 0 " << std::endl;
229 if ( res > NumberTraits<Value>::ZERO )
230 nbok++;
231 nb++;
232 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
233
234 res = f52( Point(3,4) );
235 trace.info() << res << " == 0 " << std::endl;
236 if ( res == NumberTraits<Value>::ZERO )
237 nbok++;
238 nb++;
239 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
240
241 res = f52( Point(4,3) );
242 trace.info() << res << " == 0 " << std::endl;
243 if ( res == NumberTraits<Value>::ZERO )
244 nbok++;
245 nb++;
246 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
247
248 res = f52( Point(1,6) );
249 trace.info() << res << " > 0 " << std::endl;
250 if ( res > NumberTraits<Value>::ZERO )
251 nbok++;
252 nb++;
253 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
254
255 res = f52( Point(1,7) );
256 trace.info() << res << " > 0 " << std::endl;
257 if ( res > NumberTraits<Value>::ZERO )
258 nbok++;
259 nb++;
260 trace.info() << "(" << nbok << "/" << nb << ") " << endl;
261
262 trace.endBlock();
263
264
265 return nbok == nb;
266}
268// Standard services - public :
269int main( int argc, char** argv )
270{
271 trace.beginBlock ( "Testing class InHalfPlane" );
272 trace.info() << "Args:";
273 for ( int i = 0; i < argc; ++i )
274 trace.info() << " " << argv[ i ];
275 trace.info() << endl;
276
278
279 bool res = true;
280
283 res = res && testInHalfPlane( Functor1() );
284
286 res = res && testInHalfPlane( Functor2() );
287
289
290 trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
291 trace.endBlock();
292 return res ? 0 : 1;
293}
294// //
Aim: Class that provides a way of computing the sign of the determinant of a 2x2 matrix from its four...
Aim: This class implements an orientation functor that provides a way to determine the position of ...
Aim: Class that implements an orientation functor, ie. it provides a way to compute the orientation o...
Aim: Class that implements an orientation functor, ie. it provides a way to compute the orientation o...
Aim: Implements basic operations that will be used in Point and Vector classes.
Aim: Small class useful to compute the determinant of a 2x2 matrix from its four coefficients,...
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
STL namespace.
Aim: The traits class for all models of Cinteger.
Aim: This concept is a refinement of COrientationFunctor, useful for simple algebraic curves that can...
int main()
Definition testBits.cpp:56
MyPointD Point
InHalfPlaneBySimple3x3Matrix< Point, double > Functor
bool testInGeneralizedDiskOfGivenRadius()
bool testInHalfPlane(OrientationFunctor f)