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));
80 accumulator.binCoordinates( Vector(1,1,1).getNormalized(), i,j);
81 trace.
info() <<
"Got coordinates ("<<i<<
","<<j<<
")"<<std::endl;
82 trace.
info() <<
"Count(i,j) = "<< accumulator.count(i,j) <<std::endl;
83 nbok += (accumulator.count(i,j) == 2) ? 1 : 0;
85 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
86 <<
"bin with 2dirs" << std::endl;
89 trace.
info() <<
"Representative(i,j) = "<< accumulator.representativeDirection(i,j) <<std::endl;
103 trace.
info() <<
"Representative(it) = "<< accumulator.representativeDirection(itwith2) <<std::endl;
104 nbok += (accumulator.representativeDirection(i,j) == accumulator.representativeDirection(itwith2)) ? 1 : 0;
106 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
107 <<
"representative directions identical" << std::endl;
110 accumulator.binCoordinates(itwith2, ii,jj);
111 trace.
info() <<
"Coordinate from (it) = ("<<ii<<
","<<jj<<
")"<<std::endl;
112 nbok += (( i == ii) && (j==jj)) ? 1 : 0;
114 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
115 <<
"coordinates ok" << std::endl;
122 bool testSphericalMore()
124 unsigned int nbok = 0;
127 trace.
beginBlock (
"Testing Spherical Accumulator with more points ..." );
138 accumulator.addDirection( Vector(0,1,0));
139 accumulator.addDirection( Vector(1,-0.01,0));
140 accumulator.addDirection( Vector(1,0.01,-0.01));
141 accumulator.addDirection( Vector(1,-0.01,0.01));
144 accumulator.addDirection( Vector(1,0.01,0.01));
145 accumulator.addDirection( Vector(1,-.01,-0.01));
161 bool testSphericalMoreIntegerDir()
163 unsigned int nbok = 0;
166 trace.
beginBlock (
"Testing Spherical Accumulator with more Integer points ..." );
174 accumulator.addDirection( Vector(0,1,0));
175 accumulator.addDirection( Vector(100,-1,0));
176 accumulator.addDirection( Vector(100,1,-1));
177 accumulator.addDirection( Vector(100,-1,1));
178 accumulator.addDirection( Vector(1,1,1));
190 accumulator.maxCountBin(i,j);
191 trace.
info() <<
"Max bin= ("<<i<<
","<<j<<
")"<<std::endl;
192 trace.
info() <<
"Max representative= "<<accumulator.representativeDirection(i,j)<<std::endl;
193 nbok += ( accumulator.representativeDirection(i,j) == Vector(300,-1,0 )) ? 1 : 0;
195 trace.
info() <<
"(" << nbok <<
"/" << nb <<
") "
196 <<
"Representative ok" << std::endl;
206 int main(
int argc,
char** argv )
210 for (
int i = 0; i < argc; ++i )
214 bool res = testSphericalAccumulator() && testSphericalMore()
215 && testSphericalMoreIntegerDir();
216 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;