DGtal  1.5.beta
testSphericalAccumulator.cpp
Go to the documentation of this file.
1 
31 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/geometry/tools/SphericalAccumulator.h"
36 
37 using namespace std;
38 using namespace DGtal;
39 
41 // Functions for testing class SphericalAccumulator.
43 
45 {
46  unsigned int nbok = 0;
47  unsigned int nb = 0;
48 
49  trace.beginBlock ( "Testing Spherical Accumulator ..." );
50 
51  typedef Z3i::RealVector Vector;
52 
53  SphericalAccumulator<Vector> accumulator(10);
54  trace.info()<< accumulator << std::endl;
55 
56  //testing insert
57  accumulator.addDirection( Vector(1,1,1));
58  accumulator.addDirection( Vector(1.1,1.1,1.1));
59  nbok += (accumulator.samples() == 2) ? 1 : 0;
60  nb++;
61  trace.info() << "(" << nbok << "/" << nb << ") "
62  << "insert dirs" << std::endl;
63  trace.info()<< accumulator << std::endl;
64 
65  //testing clear
66  accumulator.clear();
67  trace.info()<< accumulator << std::endl;
68  nbok += (accumulator.samples() == 0) ? 1 : 0;
69  nb++;
70  trace.info() << "(" << nbok << "/" << nb << ") "
71  << "clear" << std::endl;
72 
73  //testing bin
74  accumulator.addDirection( Vector(1,1,1));
75  accumulator.addDirection( Vector(1.1,1.1,1.1));
76  trace.info()<< accumulator << std::endl;
78  Size i,j;
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;
83  nb++;
84  trace.info() << "(" << nbok << "/" << nb << ") "
85  << "bin with 2dirs" << std::endl;
86  trace.info()<< accumulator << std::endl;
87 
88  trace.info() << "Representative(i,j) = "<< accumulator.representativeDirection(i,j) <<std::endl;
89 
90  //testing ConstIterator
91  trace.info() << "Bin values: ";
93  for(SphericalAccumulator<Vector>::ConstIterator it=accumulator.begin(), itend=accumulator.end();
94  it != itend;
95  ++it)
96  {
97  trace.info() << *it<<" ";
98  if ( (*it) == 2)
99  itwith2=it;
100  }
101  trace.info() << std::endl;
102  trace.info() << "Representative(it) = "<< accumulator.representativeDirection(itwith2) <<std::endl;
103  nbok += (accumulator.representativeDirection(i,j) == accumulator.representativeDirection(itwith2)) ? 1 : 0;
104  nb++;
105  trace.info() << "(" << nbok << "/" << nb << ") "
106  << "representative directions identical" << std::endl;
107 
108  Size ii,jj;
109  accumulator.binCoordinates(itwith2, ii,jj);
110  trace.info() << "Coordinate from (it) = ("<<ii<<","<<jj<<")"<<std::endl;
111  nbok += (( i == ii) && (j==jj)) ? 1 : 0;
112  nb++;
113  trace.info() << "(" << nbok << "/" << nb << ") "
114  << "coordinates ok" << std::endl;
115 
116  trace.endBlock();
117 
118  return nbok == nb;
119 }
120 
122 {
123  unsigned int nbok = 0;
124  unsigned int nb = 0;
125 
126  trace.beginBlock ( "Testing Spherical Accumulator with more points ..." );
127 
129  typedef Z3i::RealVector Vector;
130  SphericalAccumulator<Vector> accumulator(6);
132 
133 
134  trace.info()<< accumulator << std::endl;
136  //Insert some directions
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));
142 
143  accumulator.addDirection( Vector(1,0.01,0.01));
144  accumulator.addDirection( Vector(1,-.01,-0.01));
145 
146  trace.info() << "Bin values: ";
147  for(SphericalAccumulator<Vector>::ConstIterator it=accumulator.begin(), itend=accumulator.end();
148  it != itend;
149  ++it)
150  trace.info() << *it<<" ";
151  trace.info() << std::endl;
152  trace.info() << accumulator<<std::endl;
153 
154 
155  trace.endBlock();
156 
157  return nbok == nb;
158 }
159 
161 {
162  unsigned int nbok = 0;
163  unsigned int nb = 0;
164 
165  trace.beginBlock ( "Testing Spherical Accumulator with more Integer points ..." );
166 
167  typedef Z3i::Vector Vector;
168  SphericalAccumulator<Vector> accumulator(5);
169 
170 
171  trace.info()<< accumulator << std::endl;
172  //Insert some directions
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));
178 
179  trace.info() << "Bin values: ";
180  for(SphericalAccumulator<Vector>::ConstIterator it=accumulator.begin(), itend=accumulator.end();
181  it != itend;
182  ++it)
183  trace.info() << *it<<" ";
184  trace.info() << std::endl;
185  trace.info() << accumulator<<std::endl;
186 
188  Size i,j;
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;
193  nb++;
194  trace.info() << "(" << nbok << "/" << nb << ") "
195  << "Representative ok" << std::endl;
196 
197  trace.endBlock();
198 
199  return nbok == nb;
200 }
201 
203 // Standard services - public :
204 
205 int main( int argc, char** argv )
206 {
207  trace.beginBlock ( "Testing class SphericalAccumulator" );
208  trace.info() << "Args:";
209  for ( int i = 0; i < argc; ++i )
210  trace.info() << " " << argv[ i ];
211  trace.info() << endl;
212 
215  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
216  trace.endBlock();
217  return res ? 0 : 1;
218 }
219 // //
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:593
Aim: implements an accumulator (as histograms for 1D scalars) adapted to spherical point samples.
std::vector< Quantity >::const_iterator ConstIterator
Type to iterate on bin values.
void maxCountBin(Size &posPhi, Size &posTheta) const
Quantity count(const Size &posPhi, const Size &posTheta) const
void binCoordinates(const Vector &aDir, Size &posPhi, Size &posTheta) const
size_t Size
Type to represent bin indexes.
Vector representativeDirection(const Size &posPhi, const Size &posTheta) const
Quantity samples() const
void addDirection(const Vector &aDir)
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
DigitalPlane::Point Vector
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
HalfEdgeDataStructure::Size Size
bool testSphericalMore()
int main(int argc, char **argv)
bool testSphericalMoreIntegerDir()
bool testSphericalAccumulator()