33 #include "DGtal/base/Common.h"
34 #include "DGtal/math/Statistic.h"
35 #include "DGtal/helpers/StdDefs.h"
36 #include "DGtal/kernel/CPointPredicate.h"
37 #include "DGtal/geometry/surfaces/COBAGenericNaivePlaneComputer.h"
41 using namespace DGtal;
47 template <
typename Integer>
51 return ( r % (after_last - first) ) + first;
57 template <
typename Integer,
typename NaivePlaneComputer>
60 int diameter,
unsigned int nbpoints,
64 typedef typename Point::Component PointInteger;
71 if ( ( absA >= absB ) && ( absA >= absC ) )
73 else if ( ( absB >= absA ) && ( absB >= absC ) )
79 plane.
init( diameter, 1, 1 );
82 unsigned int nbok = 0;
83 unsigned int nbchanges = 0;
85 while ( nb != nbpoints )
87 p[ 0 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
88 p[ 1 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
89 p[ 2 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
98 bool ok = plane.
extend( p );
99 ++nb; nbok += ok ? 1 : 0;
102 std::cerr <<
"[ERROR] p=" << p <<
" NOT IN plane=" << plane << std::endl;
111 stats.
addValue( (
double) nbchanges );
115 template <
typename NaivePlaneComputer>
123 unsigned int nbok = 0;
124 for (
unsigned int nbp = 0; nbp < nbplanes; ++nbp )
130 if ( ( a != 0 ) || ( b != 0 ) || ( c != 0 ) )
132 ++nb; nbok += checkGenericPlane<Integer, NaivePlaneComputer>( a, b, c, d, diameter, nbpoints, stats ) ? 1 : 0;
135 std::cerr <<
"[ERROR] for plane " << a <<
" * x + "
136 << b <<
" * y + " << c <<
" * z = " << d << std::endl;
148 int main(
int argc,
char** argv )
152 unsigned int nbtries = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 100;
153 unsigned int nbpoints = ( argc > 2 ) ? atoi( argv[ 2 ] ) : 100;
154 unsigned int diameter = ( argc > 3 ) ? atoi( argv[ 3 ] ) : 100;
155 std::cout <<
"# Usage: " << argv[0] <<
" <nbtries> <nbpoints> <diameter>." << std::endl;
156 std::cout <<
"# Test class COBAGenericNaivePlaneComputer. Points are randomly chosen in [-diameter,diameter]^3." << std::endl;
157 std::cout <<
"# Integer nbtries nbpoints diameter time/plane(ms) E(comp) V(comp)" << std::endl;
162 && checkGenericPlanes<COBAGenericNaivePlaneComputer<Z3, DGtal::BigInteger> >( nbtries, diameter, nbpoints, stats );
163 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
166 std::cout <<
"BigInteger" <<
" " << stats.
samples()
169 <<
" " << ( (double) t / (
double) stats.
samples() )
170 <<
" " << stats.
mean()
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
InternalInteger InternalInteger
bool extend(const Point &p)
static Integer abs(IntegerParamType a)
Integer ceilDiv(IntegerParamType na, IntegerParamType nb) const
Aim: This class processes a set of sample values for one variable and can then compute different stat...
unsigned int samples() const
void addValue(Quantity v)
void beginBlock(const std::string &keyword="")
Point::Coordinate Integer
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.
int main(int argc, char **argv)
Integer getRandomInteger(const Integer &first, const Integer &after_last)
bool checkGenericPlanes(unsigned int nbplanes, int diameter, unsigned int nbpoints, Statistic< double > &stats)
bool checkGenericPlane(Integer a, Integer b, Integer c, Integer d, int diameter, unsigned int nbpoints, Statistic< double > &stats)