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/COBANaivePlaneComputer.h"
47template <
typename Integer>
51 return ( r % (after_last - first) ) + first;
57template <
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( axis, diameter, 1, 1 );
82 unsigned int nbok = 0;
83 unsigned int nbchanges = 0;
85 while ( nb != nbpoints )
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 );
115template <
typename NaivePlaneComputer>
117checkPlanes(
unsigned int nbplanes,
int diameter,
unsigned int nbpoints,
123 unsigned int nbok = 0;
124 for (
unsigned int nbp = 0; nbp < nbplanes; ++nbp )
130 if ( ( a != 0 ) || ( b != 0 ) || ( c != 0 ) )
135 std::cerr <<
"[ERROR] for plane " << a <<
" * x + "
136 << b <<
" * y + " << c <<
" * z = " << d << std::endl;
148int 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 COBANaivePlaneComputer. 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;
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)
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
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.
bool checkPlane(Integer a, Integer b, Integer c, Integer d, int diameter, unsigned int nbpoints, Statistic< double > &stats)
Integer getRandomInteger(const Integer &first, const Integer &after_last)
bool checkPlanes(unsigned int nbplanes, int diameter, unsigned int nbpoints, Statistic< double > &stats)