33 #include "DGtal/base/Common.h"
34 #include "DGtal/helpers/StdDefs.h"
35 #include "DGtal/kernel/CPointPredicate.h"
36 #include "DGtal/geometry/surfaces/CAdditivePrimitiveComputer.h"
37 #include "DGtal/geometry/surfaces/COBANaivePlaneComputer.h"
38 #include "DGtal/geometry/surfaces/COBAGenericNaivePlaneComputer.h"
42 using namespace DGtal;
49 template <
typename Integer>
53 return ( r % (after_last - first) ) + first;
59 template <
typename Integer,
typename NaivePlaneComputer>
62 int diameter,
unsigned int nbtries )
65 typedef typename Point::Component PointInteger;
72 if ( ( absA >= absB ) && ( absA >= absC ) )
74 else if ( ( absB >= absA ) && ( absB >= absC ) )
80 plane.
init( axis, diameter, 1, 1 );
83 unsigned int nbok = 0;
84 while ( nb != nbtries )
86 p[ 0 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
87 p[ 1 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
88 p[ 2 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
98 bool ok = plane.
extend( p );
99 ++nb; nbok += ok_ext ? 1 : 0;
100 ++nb; nbok += ok ? 1 : 0;
103 std::cerr <<
"[ERROR] p=" << p <<
" NOT IN plane=" << plane << std::endl;
108 std::cerr <<
"[ERROR] p=" << p <<
" was NOT extendable IN plane=" << plane << std::endl;
116 while ( nb != (nbtries * 11 ) / 10 )
118 p[ 0 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
119 p[ 1 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
120 p[ 2 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
129 PointInteger tmp = getRandomInteger<PointInteger>( 2, 5 )
130 * (2*getRandomInteger<PointInteger>( 0, 2 ) - 1 );
133 bool ok = ! plane.
extend( p );
134 ++nb; nbok += ok ? 1 : 0;
135 ++nb; nbok += ok_ext ? 1 : 0;
138 std::cerr <<
"[ERROR] p=" << p <<
" IN plane=" << plane << std::endl;
143 std::cerr <<
"[ERROR] p=" << p <<
" was extendable IN plane=" << plane << std::endl;
156 template <
typename Integer,
typename GenericNaivePlaneComputer>
159 int diameter,
unsigned int nbtries )
162 typedef typename Point::Component PointInteger;
169 if ( ( absA >= absB ) && ( absA >= absC ) )
171 else if ( ( absB >= absA ) && ( absB >= absC ) )
176 GenericNaivePlaneComputer plane;
177 plane.init( diameter, 1, 1 );
180 unsigned int nbok = 0;
181 while ( nb != nbtries )
183 p[ 0 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
184 p[ 1 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
185 p[ 2 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
194 bool ok_ext = plane.isExtendable( p );
195 bool ok = plane.extend( p );
196 ++nb; nbok += ok_ext ? 1 : 0;
197 ++nb; nbok += ok ? 1 : 0;
200 std::cerr <<
"[ERROR] p=" << p <<
" NOT IN plane=" << plane << std::endl;
205 std::cerr <<
"[ERROR] p=" << p <<
" was NOT extendable IN plane=" << plane << std::endl;
213 while ( nb != (nbtries * 11 ) / 10 )
215 p[ 0 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
216 p[ 1 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
217 p[ 2 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
226 PointInteger tmp = getRandomInteger<PointInteger>( 2, 5 )
227 * (2*getRandomInteger<PointInteger>( 0, 2 ) - 1 );
229 bool ok_ext = ! plane.isExtendable( p );
230 bool ok = ! plane.extend( p );
231 ++nb; nbok += ok ? 1 : 0;
232 ++nb; nbok += ok_ext ? 1 : 0;
235 std::cerr <<
"[ERROR] p=" << p <<
" IN plane=" << plane << std::endl;
240 std::cerr <<
"[ERROR] p=" << p <<
" was extendable IN plane=" << plane << std::endl;
246 std::cerr <<
"plane = " << plane << std::endl;
251 template <
typename Integer,
typename NaivePlaneComputer>
253 checkPlanes(
unsigned int nbplanes,
int diameter,
unsigned int nbtries )
258 unsigned int nbok = 0;
259 for (
unsigned int nbp = 0; nbp < nbplanes; ++nbp )
265 if ( ( a != 0 ) || ( b != 0 ) || ( c != 0 ) )
267 ++nb; nbok += checkPlane<Integer, NaivePlaneComputer>( a, b, c, d, diameter, nbtries ) ? 1 : 0;
270 std::cerr <<
"[ERROR] for plane " << a <<
" * x + "
271 << b <<
" * y + " << c <<
" * z = " << d << std::endl;
285 unsigned int nbok = 0;
298 trace.
beginBlock (
"Testing block: COBANaivePlaneComputer instantiation." );
300 Point pt0( 0, 0, 0 );
301 plane.
init( 2, 100, 3, 2 );
302 bool pt0_inside = plane.
extend( pt0 );
303 FATAL_ERROR(pt0_inside);
305 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") Plane=" << plane
308 bool pt1_inside = plane.
extend( pt1 );
309 ++nb; nbok += pt1_inside ==
true ? 1 : 0;
310 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt1
311 <<
" Plane=" << plane << std::endl;
313 bool pt2_inside = plane.
extend( pt2 );
314 ++nb; nbok += pt2_inside ==
true ? 1 : 0;
315 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt2
316 <<
" Plane=" << plane << std::endl;
319 bool pt3_inside = plane.
extend( pt3 );
320 ++nb; nbok += pt3_inside ==
false ? 1 : 0;
321 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt3
322 <<
" Plane=" << plane << std::endl;
325 bool pt4_inside = plane.
extend( pt4 );
326 ++nb; nbok += pt4_inside ==
false ? 1 : 0;
327 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt4
328 <<
" Plane=" << plane << std::endl;
330 Point pt5 = pt0 + pt1 + pt2 +
Point( 0, 0, 2 );
331 bool pt5_inside = plane.
extend( pt5 );
332 ++nb; nbok += pt5_inside ==
true ? 1 : 0;
333 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt5
334 <<
" Plane=" << plane << std::endl;
337 plane2.
init( 2, 100, 1, 1 );
341 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
342 <<
" Plane2=" << plane2 << std::endl;
344 ++nb; nbok += checkPlane<Integer,NaivePlaneComputer>( 11, 5, 19, 20, 100, 100 ) ? 1 : 0;
346 <<
") checkPlane<Integer,NaivePlaneComputer>( 11, 5, 19, 20, 100, 100 )"
349 ++nb; nbok += checkGenericPlane<Integer,GenericNaivePlaneComputer>( 11, 5, 19, 20, 100, 100 ) ? 1 : 0;
351 <<
") checkGenericPlane<Integer,GenericNaivePlaneComputer>( 11, 5, 19, 20, 100, 100 )"
353 ++nb; nbok += checkGenericPlane<Integer,GenericNaivePlaneComputer>( 17, 33, 7, 10, 100, 100 ) ? 1 : 0;
355 <<
") checkGenericPlane<Integer,GenericNaivePlaneComputer>( 17, 33, 7, 10, 100, 100 )"
357 ++nb; nbok += checkPlane<Integer,NaivePlaneComputer>( 15, 8, 13, 15, 100, 100 ) ? 1 : 0;
359 <<
") checkPlane<Integer,NaivePlaneComputer>( 15, 8, 13, 15, 100, 100 )"
361 ++nb; nbok += checkGenericPlane<Integer,GenericNaivePlaneComputer>( 15, 8, 13, 15, 100, 100 ) ? 1 : 0;
363 <<
") checkGenericPlane<Integer,GenericNaivePlaneComputer>( 15, 8, 13, 15, 100, 100 )"
369 template <
typename NaivePlaneComputer>
372 unsigned int nbplanes,
373 unsigned int nbpoints )
375 unsigned int nbok = 0;
378 stringstream ss (stringstream::out);
379 ss <<
"Testing block: Diameter is " << diameter <<
". Check " << nbplanes <<
" planes with " << nbpoints <<
" points each.";
381 ++nb; nbok += checkPlanes<Integer,NaivePlaneComputer>( nbplanes, diameter, nbpoints ) ? 1 : 0;
383 <<
") checkPlanes<Integer,NaivePlaneComputer>()"
392 template <
typename NaivePlaneComputer>
397 unsigned int middle = (min+
max)/2;
398 bool ok = checkManyPlanes<NaivePlaneComputer>( middle, 2, 2000 );
399 if ( ok ) min = middle+1;
405 template <
typename GenericNaivePlaneComputer>
408 unsigned int nbplanes,
409 unsigned int nbpoints )
411 unsigned int nbok = 0;
415 typedef typename Point::Coordinate PointInteger;
419 for (
unsigned int j = 0; j < nbplanes; ++j )
425 GenericNaivePlaneComputer plane;
427 if ( ( a >= b ) && ( a >= c ) ) axis = 0;
428 else if ( ( b >= a ) && ( b >= c ) ) axis = 1;
430 plane.init( diameter, 1, 1 );
432 std::vector<Point> pts;
433 for (
unsigned int i = 0; i < nbpoints; ++i )
436 p[ 0 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
437 p[ 1 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
438 p[ 2 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
449 ++nb; nbok += plane.isExtendable( pts.begin(), pts.end() );
451 <<
") plane.isExtendable( pts.begin(), pts.end() )"
453 Point & any0 = pts[ getRandomInteger<int>( 0, pts.size() ) ];
454 pts.push_back( any0 +
Point(1,0,0) );
455 Point & any1 = pts[ getRandomInteger<int>( 0, pts.size() ) ];
456 pts.push_back( any1 +
Point(0,1,0) );
457 Point & any2 = pts[ getRandomInteger<int>( 0, pts.size() ) ];
458 pts.push_back( any2 +
Point(0,0,1) );
459 bool check = ! plane.isExtendable( pts.begin(), pts.end() );
460 ++nb; nbok += check ? 1 : 0;
462 <<
") ! plane.isExtendable( pts.begin(), pts.end() )"
465 trace.
warning() << plane <<
" last=" << pts.back() << std::endl
466 <<
"a=" << a <<
" b=" << b <<
" c=" << c <<
" d=" << d << std::endl;
467 ++nb; nbok += plane.extend( pts.begin(), pts.end() - 3 );
469 <<
") plane.extend( pts.begin(), pts.end() - 3)"
471 ++nb; nbok += ! plane.extend( pts.end() - 3, pts.end() );
473 <<
") ! plane.extend( pts.end() - 3, pts.end() )"
491 && checkManyPlanes<COBANaivePlaneComputer<Z3, DGtal::int32_t> >( 20, 100, 200 )
493 && checkManyPlanes<COBANaivePlaneComputer<Z3, DGtal::BigInteger> >( 10000, 10, 200 )
496 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
Aim: A class that recognizes pieces of digital planes of given axis width. When the width is 1,...
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
InternalInteger InternalInteger
bool isExtendable(const Point &p) const
bool extend(const Point &p)
static Integer abs(IntegerParamType a)
Integer ceilDiv(IntegerParamType na, IntegerParamType nb) const
void beginBlock(const std::string &keyword="")
Point::Coordinate Integer
COBANaivePlaneComputer< Z3, InternalInteger > NaivePlaneComputer
DGtal::int64_t InternalInteger
Aim: Gathers several functions useful for concept checks.
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Aim: The traits class for all models of Cinteger.
Aim: Defines the concept describing an object that computes some primitive from input points given gr...
Aim: Defines a predicate on a point.
Go to http://www.sgi.com/tech/stl/ForwardContainer.html.
unsigned int maxDiameter(unsigned int min, unsigned int max)
bool checkPlane(Integer a, Integer b, Integer c, Integer d, int diameter, unsigned int nbtries)
bool checkPlanes(unsigned int nbplanes, int diameter, unsigned int nbtries)
bool checkGenericPlane(Integer a, Integer b, Integer c, Integer d, int diameter, unsigned int nbtries)
Integer getRandomInteger(const Integer &first, const Integer &after_last)
bool checkExtendWithManyPoints(unsigned int diameter, unsigned int nbplanes, unsigned int nbpoints)
bool testCOBANaivePlaneComputer()
bool checkManyPlanes(unsigned int diameter, unsigned int nbplanes, unsigned int nbpoints)