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"
49template <
typename Integer>
53 return ( r % (after_last - first) ) + first;
59template <
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 )
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 )
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;
156template <
typename Integer,
typename GenericNaivePlaneComputer>
159 int diameter,
unsigned int nbtries )
161 typedef typename GenericNaivePlaneComputer::Point
Point;
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 )
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 )
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;
251template <
typename Integer,
typename NaivePlaneComputer>
253checkPlanes(
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 ) )
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;
346 <<
") checkPlane<Integer,NaivePlaneComputer>( 11, 5, 19, 20, 100, 100 )"
351 <<
") checkGenericPlane<Integer,GenericNaivePlaneComputer>( 11, 5, 19, 20, 100, 100 )"
355 <<
") checkGenericPlane<Integer,GenericNaivePlaneComputer>( 17, 33, 7, 10, 100, 100 )"
359 <<
") checkPlane<Integer,NaivePlaneComputer>( 15, 8, 13, 15, 100, 100 )"
363 <<
") checkGenericPlane<Integer,GenericNaivePlaneComputer>( 15, 8, 13, 15, 100, 100 )"
369template <
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.";
383 <<
") checkPlanes<Integer,NaivePlaneComputer>()"
392template <
typename NaivePlaneComputer>
397 unsigned int middle = (min+
max)/2;
399 if ( ok ) min = middle+1;
405template <
typename GenericNaivePlaneComputer>
408 unsigned int nbplanes,
409 unsigned int nbpoints )
411 unsigned int nbok = 0;
413 typedef typename GenericNaivePlaneComputer::InternalInteger
Integer;
414 typedef typename GenericNaivePlaneComputer::Point
Point;
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 )
449 ++nb; nbok += plane.isExtendable( pts.begin(), pts.end() );
451 <<
") plane.isExtendable( pts.begin(), pts.end() )"
454 pts.push_back( any0 +
Point(1,0,0) );
456 pts.push_back( any1 +
Point(0,1,0) );
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() )"
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)
Aim: This class gathers several types and methods to make computation with integers.
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
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)