DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
testSphericalAccumulator.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/geometry/tools/SphericalAccumulator.h"

Go to the source code of this file.

Functions

bool testSphericalAccumulator ()
 
bool testSphericalMore ()
 
bool testSphericalMoreIntegerDir ()
 
int main (int argc, char **argv)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/09/18

Functions for testing class SphericalAccumulator.

This file is part of the DGtal library.

Definition in file testSphericalAccumulator.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 205 of file testSphericalAccumulator.cpp.

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}
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Trace trace
Definition: Common.h:154
bool testSphericalMore()
bool testSphericalMoreIntegerDir()
bool testSphericalAccumulator()

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Trace::info(), testSphericalAccumulator(), testSphericalMore(), testSphericalMoreIntegerDir(), and DGtal::trace.

◆ testSphericalAccumulator()

bool testSphericalAccumulator ( )

Definition at line 44 of file testSphericalAccumulator.cpp.

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}
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.
size_t Size
Type to represent bin indexes.
FreemanChain< int >::Vector Vector
HalfEdgeDataStructure::Size Size

References DGtal::SphericalAccumulator< TVector >::addDirection(), DGtal::SphericalAccumulator< TVector >::begin(), DGtal::Trace::beginBlock(), DGtal::SphericalAccumulator< TVector >::binCoordinates(), DGtal::SphericalAccumulator< TVector >::clear(), DGtal::SphericalAccumulator< TVector >::count(), DGtal::SphericalAccumulator< TVector >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::SphericalAccumulator< TVector >::representativeDirection(), DGtal::SphericalAccumulator< TVector >::samples(), and DGtal::trace.

Referenced by main().

◆ testSphericalMore()

bool testSphericalMore ( )

[SphericalAccum-init]

[SphericalAccum-init]

[SphericalAccum-add]

[SphericalAccum-add]

Definition at line 121 of file testSphericalAccumulator.cpp.

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}

References DGtal::SphericalAccumulator< TVector >::addDirection(), DGtal::SphericalAccumulator< TVector >::begin(), DGtal::Trace::beginBlock(), DGtal::SphericalAccumulator< TVector >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), and DGtal::trace.

Referenced by main().

◆ testSphericalMoreIntegerDir()

bool testSphericalMoreIntegerDir ( )

Definition at line 160 of file testSphericalAccumulator.cpp.

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}

References DGtal::SphericalAccumulator< TVector >::addDirection(), DGtal::SphericalAccumulator< TVector >::begin(), DGtal::Trace::beginBlock(), DGtal::SphericalAccumulator< TVector >::end(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::SphericalAccumulator< TVector >::maxCountBin(), DGtal::SphericalAccumulator< TVector >::representativeDirection(), and DGtal::trace.

Referenced by main().