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 )
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;
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 )
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;
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 ) )
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;
299 trace.
beginBlock (
"Testing block: COBANaivePlaneComputer instantiation." );
301 Point pt0( 0, 0, 0 );
302 plane.
init( 2, 100, 3, 2 );
303 bool pt0_inside = plane.
extend( pt0 );
304 FATAL_ERROR(pt0_inside);
306 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") Plane=" << plane
309 bool pt1_inside = plane.
extend( pt1 );
310 ++nb; nbok += pt1_inside ==
true ? 1 : 0;
311 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt1
312 <<
" Plane=" << plane << std::endl;
314 bool pt2_inside = plane.
extend( pt2 );
315 ++nb; nbok += pt2_inside ==
true ? 1 : 0;
316 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt2
317 <<
" Plane=" << plane << std::endl;
320 bool pt3_inside = plane.
extend( pt3 );
321 ++nb; nbok += pt3_inside ==
false ? 1 : 0;
322 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt3
323 <<
" Plane=" << plane << std::endl;
326 bool pt4_inside = plane.
extend( pt4 );
327 ++nb; nbok += pt4_inside ==
false ? 1 : 0;
328 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt4
329 <<
" Plane=" << plane << std::endl;
331 Point pt5 = pt0 + pt1 + pt2 +
Point( 0, 0, 2 );
332 bool pt5_inside = plane.
extend( pt5 );
333 ++nb; nbok += pt5_inside ==
true ? 1 : 0;
334 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") add " << pt5
335 <<
" Plane=" << plane << std::endl;
338 plane2.
init( 2, 100, 1, 1 );
342 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
343 <<
" Plane2=" << plane2 << std::endl;
345 ++nb; nbok += checkPlane<Integer,NaivePlaneComputer>( 11, 5, 19, 20, 100, 100 ) ? 1 : 0;
347 <<
") checkPlane<Integer,NaivePlaneComputer>( 11, 5, 19, 20, 100, 100 )"
350 ++nb; nbok += checkGenericPlane<Integer,GenericNaivePlaneComputer>( 11, 5, 19, 20, 100, 100 ) ? 1 : 0;
352 <<
") checkGenericPlane<Integer,GenericNaivePlaneComputer>( 11, 5, 19, 20, 100, 100 )"
354 ++nb; nbok += checkGenericPlane<Integer,GenericNaivePlaneComputer>( 17, 33, 7, 10, 100, 100 ) ? 1 : 0;
356 <<
") checkGenericPlane<Integer,GenericNaivePlaneComputer>( 17, 33, 7, 10, 100, 100 )"
358 ++nb; nbok += checkPlane<Integer,NaivePlaneComputer>( 15, 8, 13, 15, 100, 100 ) ? 1 : 0;
360 <<
") checkPlane<Integer,NaivePlaneComputer>( 15, 8, 13, 15, 100, 100 )"
362 ++nb; nbok += checkGenericPlane<Integer,GenericNaivePlaneComputer>( 15, 8, 13, 15, 100, 100 ) ? 1 : 0;
364 <<
") checkGenericPlane<Integer,GenericNaivePlaneComputer>( 15, 8, 13, 15, 100, 100 )"
370template <
typename NaivePlaneComputer>
373 unsigned int nbplanes,
374 unsigned int nbpoints )
376 unsigned int nbok = 0;
379 stringstream ss (stringstream::out);
380 ss <<
"Testing block: Diameter is " << diameter <<
". Check " << nbplanes <<
" planes with " << nbpoints <<
" points each.";
382 ++nb; nbok += checkPlanes<Integer,NaivePlaneComputer>( nbplanes, diameter, nbpoints ) ? 1 : 0;
384 <<
") checkPlanes<Integer,NaivePlaneComputer>()"
393template <
typename NaivePlaneComputer>
398 unsigned int middle = (min+
max)/2;
399 bool ok = checkManyPlanes<NaivePlaneComputer>( middle, 2, 2000 );
400 if ( ok ) min = middle+1;
406template <
typename GenericNaivePlaneComputer>
409 unsigned int nbplanes,
410 unsigned int nbpoints )
412 unsigned int nbok = 0;
414 typedef typename GenericNaivePlaneComputer::InternalInteger
Integer;
415 typedef typename GenericNaivePlaneComputer::Point
Point;
416 typedef typename Point::Coordinate PointInteger;
420 for (
unsigned int j = 0; j < nbplanes; ++j )
426 GenericNaivePlaneComputer plane;
428 if ( ( a >= b ) && ( a >= c ) ) axis = 0;
429 else if ( ( b >= a ) && ( b >= c ) ) axis = 1;
431 plane.init( diameter, 1, 1 );
433 std::vector<Point> pts;
434 for (
unsigned int i = 0; i < nbpoints; ++i )
437 p[ 0 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
438 p[ 1 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
439 p[ 2 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
450 ++nb; nbok += plane.isExtendable( pts.begin(), pts.end() );
452 <<
") plane.isExtendable( pts.begin(), pts.end() )"
454 Point & any0 = pts[ getRandomInteger<int>( 0, pts.size() ) ];
455 pts.push_back( any0 +
Point(1,0,0) );
456 Point & any1 = pts[ getRandomInteger<int>( 0, pts.size() ) ];
457 pts.push_back( any1 +
Point(0,1,0) );
458 Point & any2 = pts[ getRandomInteger<int>( 0, pts.size() ) ];
459 pts.push_back( any2 +
Point(0,0,1) );
460 bool check = ! plane.isExtendable( pts.begin(), pts.end() );
461 ++nb; nbok += check ? 1 : 0;
463 <<
") ! plane.isExtendable( pts.begin(), pts.end() )"
466 trace.
warning() << plane <<
" last=" << pts.back() << std::endl
467 <<
"a=" << a <<
" b=" << b <<
" c=" << c <<
" d=" << d << std::endl;
468 ++nb; nbok += plane.extend( pts.begin(), pts.end() - 3 );
470 <<
") plane.extend( pts.begin(), pts.end() - 3)"
472 ++nb; nbok += ! plane.extend( pts.end() - 3, pts.end() );
474 <<
") ! plane.extend( pts.end() - 3, pts.end() )"
492 && checkManyPlanes<COBANaivePlaneComputer<Z3, DGtal::int32_t> >( 20, 100, 200 )
494 && checkManyPlanes<COBANaivePlaneComputer<Z3, DGtal::BigInteger> >( 10000, 10, 200 )
497 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
mpz_class BigInteger
Multi-precision integer with GMP implementation.
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)