34 #include "DGtal/base/Common.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/kernel/CPointPredicate.h"
37 #include "DGtal/geometry/surfaces/CAdditivePrimitiveComputer.h"
38 #include "DGtal/geometry/surfaces/COBAGenericStandardPlaneComputer.h"
42 using namespace DGtal;
50 template <
typename Integer>
51 Integer getRandomInteger(
const Integer & first,
const Integer & after_last )
54 return ( r % (after_last - first) ) + first;
57 template <
typename Domain>
58 std::vector<typename Domain::Point> pointsInStandardPlane
68 std::vector<Point> pts;
69 Integer mup = mu +
abs(a) +
abs(b) +
abs(c);
70 for ( ConstIterator it = domain.
begin(), itE = domain.
end();
74 Integer r = a * p[ 0 ] + b * p[ 1 ] + c * p[ 2 ];
75 if ( ( mu <= r ) && ( r < mup ) )
81 template <
typename PlaneComputer >
82 bool checkCOBAGenericStandardPlaneComputer
83 ( PlaneComputer & computer,
unsigned int nbplanes,
int diameter )
85 typedef typename PlaneComputer::Space
Space;
90 unsigned int nbok = 0;
91 Domain domain( Point( -diameter, -diameter, -diameter ),
92 Point( diameter, diameter, diameter ) );
94 for (
unsigned int p = 0; p < nbplanes; ++p )
97 a = getRandomInteger( -diameter, diameter+1 );
98 b = getRandomInteger( -diameter, diameter+1 );
99 c = getRandomInteger( -diameter, diameter+1 );
101 while ( ( a == 0 ) && ( b == 0 ) && ( c == 0 ) );
102 mu = getRandomInteger( -diameter, diameter );
103 std::vector<Point> pts = pointsInStandardPlane( domain, a, b, c, mu );
104 computer.init( 2*diameter, 1, 1 );
105 ++nb, nbok += computer.extend( pts.begin(), pts.end() ) ? 1 : 0;
106 trace.
info() <<
"Primitive=" << computer.primitive() << std::endl;
107 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") extend "
108 << pts.size() <<
" points of plane "
109 << mu <<
" <= " << a <<
"*x+" << b <<
"*y+" << c <<
"*z+"
110 <<
" < " << (mu+a+b+c) << std::endl;
111 computer.init( 2*diameter, 1, 1 );
112 std::random_shuffle( pts.begin(), pts.end() );
113 ++nb, nbok += computer.extend( pts.begin(), pts.end() ) ? 1 : 0;
114 trace.
info() <<
"Primitive=" << computer.primitive() << std::endl;
115 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") extend "
116 << pts.size() <<
" shuffled points of plane "
117 << mu <<
" <= " << a <<
"*x+" << b <<
"*y+" << c <<
"*z+"
118 <<
" < " << (mu+a+b+c) << std::endl;
124 int main(
int ,
char** )
132 plane.
init( 100, 1, 1 );
133 ok = plane.extend( Point(0,0,0) );
134 trace.
info() <<
"Point(0,0,0) is " << ( ok ?
"ok" :
"ko" ) << std::endl;
136 ok = plane.extend( Point(1,0,0) );
137 trace.
info() <<
"Point(1,0,0) is " << ( ok ?
"ok" :
"ko" ) << std::endl;
139 ok = plane.extend( Point(0,1,0) );
140 trace.
info() <<
"Point(0,1,0) is " << ( ok ?
"ok" :
"ko" ) << std::endl;
142 ok = plane.extend( Point(1,1,0) );
143 trace.
info() <<
"Point(1,1,0) is " << ( ok ?
"ok" :
"ko" ) << std::endl;
145 ok = plane.extend( Point(2,0,0) );
146 trace.
info() <<
"Point(2,0,0) is " << ( ok ?
"ok" :
"ko" ) << std::endl;
148 ok = plane.extend( Point(0,2,0) );
149 trace.
info() <<
"Point(0,2,0) is " << ( ok ?
"ok" :
"ko" ) << std::endl;
151 ok = plane.extend( Point(0,2,0) );
152 trace.
info() <<
"Point(0,2,0) is " << ( ok ?
"ok" :
"ko" ) << std::endl;
154 ok = plane.extend( Point(1,1,1) );
155 trace.
info() <<
"Point(1,1,1) is " << ( ok ?
"ok" :
"ko" ) << std::endl;
157 checkCOBAGenericStandardPlaneComputer( plane, 5, 20 );
const ConstIterator & begin() const
const ConstIterator & end() const
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Aim: A class that recognizes pieces of digital planes of given axis width. When the diagonal width is...
void init(InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
TInteger Integer
Arithmetic ring induced by (+,-,*) and Integer numbers.
DGtal is the top-level namespace which contains all DGtal functions and types.