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/arithmetic/IntegerComputer.h"
38 #include "DGtal/geometry/surfaces/ChordNaivePlaneComputer.h"
42 using namespace DGtal;
48 template <
typename Integer>
52 return ( r % (after_last - first) ) + first;
58 template <
typename Integer,
typename NaivePlaneComputer>
61 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, 1, 1 );
82 unsigned int nbok = 0;
83 while ( nb != nbpoints )
85 p[ 0 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
86 p[ 1 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
87 p[ 2 ] = getRandomInteger<PointInteger>( -diameter+1, diameter );
96 bool ok = plane.
extend( p );
97 ++nb; nbok += ok ? 1 : 0;
100 std::cerr <<
"[ERROR] p=" << p <<
" NOT IN plane=" << plane << std::endl;
107 template <
typename NaivePlaneComputer>
109 checkPlanes(
unsigned int nbplanes,
unsigned int diameter,
unsigned int nbpoints )
112 typedef typename NaivePlaneComputer::InternalScalar
Integer;
114 unsigned int nbok = 0;
115 for (
unsigned int nbp = 0; nbp < nbplanes; ++nbp )
121 if ( ( a != 0 ) || ( b != 0 ) || ( c != 0 ) )
123 ++nb; nbok += checkPlane<Integer, NaivePlaneComputer>( a, b, c, d, diameter, nbpoints ) ? 1 : 0;
126 std::cerr <<
"[ERROR] for plane " << a <<
" * x + "
127 << b <<
" * y + " << c <<
" * z = " << d << std::endl;
139 int main(
int argc,
char** argv )
142 unsigned int nbtries = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 100;
143 unsigned int nbpoints = ( argc > 2 ) ? atoi( argv[ 2 ] ) : 100;
144 unsigned int diameter = ( argc > 3 ) ? atoi( argv[ 3 ] ) : 100;
145 std::cout <<
"# Usage: " << argv[0] <<
" <nbtries> <nbpoints> <diameter>." << std::endl;
146 std::cout <<
"# Test class ChordNaivePlaneComputer. Points are randomly chosen in [-diameter,diameter]^3." << std::endl;
147 std::cout <<
"# Integer nbtries nbpoints diameter time/plane(ms)" << std::endl;
151 && checkPlanes<ChordNaivePlaneComputer<Space, Point, DGtal::int64_t> >( nbtries, diameter, nbpoints );
152 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
154 std::cout <<
"int64_t" <<
" " << nbtries
157 <<
" " << ( (double) t / (
double) nbtries )
void init(Dimension axis, InternalInteger diameter, InternalInteger widthNumerator=NumberTraits< InternalInteger >::ONE, InternalInteger widthDenominator=NumberTraits< InternalInteger >::ONE)
bool extend(const Point &p)
static Integer abs(IntegerParamType a)
Integer ceilDiv(IntegerParamType na, IntegerParamType nb) const
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)
bool checkPlane(Integer a, Integer b, Integer c, Integer d, int diameter, unsigned int nbpoints)
bool checkPlanes(unsigned int nbplanes, unsigned int diameter, unsigned int nbpoints)
Integer getRandomInteger(const Integer &first, const Integer &after_last)