32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/geometry/tools/SphericalAccumulator.h"
38 using namespace DGtal;
44 bool testSphericalAccumulator()
46 unsigned int nbok = 0;
57 accumulator.addDirection( Vector(1,1,1));
58 accumulator.addDirection( Vector(1.1,1.1,1.1));
59 nbok += (accumulator.samples() == 2) ? 1 : 0;
61 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
62 <<
"insert dirs" << std::endl;
68 nbok += (accumulator.samples() == 0) ? 1 : 0;
70 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
71 <<
"clear" << std::endl;
74 accumulator.addDirection( Vector(1,1,1));
75 accumulator.addDirection( Vector(1.1,1.1,1.1));
79 accumulator.binCoordinates( Vector(1,1,1).getNormalized(), i,j);
80 trace.
info() <<
"Got coordinates ("<<i<<
","<<j<<
")"<<std::endl;
81 trace.
info() <<
"Count(i,j) = "<< accumulator.count(i,j) <<std::endl;
82 nbok += (accumulator.count(i,j) == 2) ? 1 : 0;
84 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
85 <<
"bin with 2dirs" << std::endl;
88 trace.
info() <<
"Representative(i,j) = "<< accumulator.representativeDirection(i,j) <<std::endl;
102 trace.
info() <<
"Representative(it) = "<< accumulator.representativeDirection(itwith2) <<std::endl;
103 nbok += (accumulator.representativeDirection(i,j) == accumulator.representativeDirection(itwith2)) ? 1 : 0;
105 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
106 <<
"representative directions identical" << std::endl;
109 accumulator.binCoordinates(itwith2, ii,jj);
110 trace.
info() <<
"Coordinate from (it) = ("<<ii<<
","<<jj<<
")"<<std::endl;
111 nbok += (( i == ii) && (j==jj)) ? 1 : 0;
113 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
114 <<
"coordinates ok" << std::endl;
121 bool testSphericalMore()
123 unsigned int nbok = 0;
126 trace.
beginBlock (
"Testing Spherical Accumulator with more points ..." );
137 accumulator.addDirection( Vector(0,1,0));
138 accumulator.addDirection( Vector(1,-0.01,0));
139 accumulator.addDirection( Vector(1,0.01,-0.01));
140 accumulator.addDirection( Vector(1,-0.01,0.01));
143 accumulator.addDirection( Vector(1,0.01,0.01));
144 accumulator.addDirection( Vector(1,-.01,-0.01));
160 bool testSphericalMoreIntegerDir()
162 unsigned int nbok = 0;
165 trace.
beginBlock (
"Testing Spherical Accumulator with more Integer points ..." );
173 accumulator.addDirection( Vector(0,1,0));
174 accumulator.addDirection( Vector(100,-1,0));
175 accumulator.addDirection( Vector(100,1,-1));
176 accumulator.addDirection( Vector(100,-1,1));
177 accumulator.addDirection( Vector(1,1,1));
189 accumulator.maxCountBin(i,j);
190 trace.
info() <<
"Max bin= ("<<i<<
","<<j<<
")"<<std::endl;
191 trace.
info() <<
"Max representative= "<<accumulator.representativeDirection(i,j)<<std::endl;
192 nbok += ( accumulator.representativeDirection(i,j) == Vector(300,-1,0 )) ? 1 : 0;
194 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
195 <<
"Representative ok" << std::endl;
205 int main(
int argc,
char** argv )
209 for (
int i = 0; i < argc; ++i )
213 bool res = testSphericalAccumulator() && testSphericalMore()
214 && testSphericalMoreIntegerDir();
215 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
void beginBlock(const std::string &keyword="")
std::vector< Quantity >::const_iterator ConstIterator
Type to iterate on bin values.
Aim: Implements basic operations that will be used in Point and Vector classes.
DGtal is the top-level namespace which contains all DGtal functions and types.
Aim: implements an accumulator (as histograms for 1D scalars) adapted to spherical point samples...
DGtal::uint32_t Size
Type to represent bin indexes.