DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testSphericalAccumulator.cpp
Go to the documentation of this file.
1
16
29
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
44
bool
testSphericalAccumulator
()
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;
77
typedef
SphericalAccumulator<Vector>::Size
Size
;
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: "
;
92
SphericalAccumulator<Vector>::ConstIterator
itwith2;
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
121
bool
testSphericalMore
()
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
160
bool
testSphericalMoreIntegerDir
()
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
187
typedef
SphericalAccumulator<Vector>::Size
Size
;
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
213
bool
res =
testSphericalAccumulator
() &&
testSphericalMore
()
214
&&
testSphericalMoreIntegerDir
();
215
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
216
trace
.
endBlock
();
217
return
res ? 0 : 1;
218
}
219
// //
DGtal::Vector
DGtal::SphericalAccumulator
Aim: implements an accumulator (as histograms for 1D scalars) adapted to spherical point samples.
Definition
SphericalAccumulator.h:103
DGtal::SphericalAccumulator::ConstIterator
std::vector< Quantity >::const_iterator ConstIterator
Type to iterate on bin values.
Definition
SphericalAccumulator.h:117
DGtal::SphericalAccumulator::begin
ConstIterator begin() const
Definition
SphericalAccumulator.h:308
DGtal::SphericalAccumulator::clear
void clear()
DGtal::SphericalAccumulator::maxCountBin
void maxCountBin(Size &posPhi, Size &posTheta) const
DGtal::SphericalAccumulator::count
Quantity count(const Size &posPhi, const Size &posTheta) const
DGtal::SphericalAccumulator::binCoordinates
void binCoordinates(const Vector &aDir, Size &posPhi, Size &posTheta) const
DGtal::SphericalAccumulator::end
ConstIterator end() const
Definition
SphericalAccumulator.h:316
DGtal::SphericalAccumulator::Size
size_t Size
Type to represent bin indexes.
Definition
SphericalAccumulator.h:114
DGtal::SphericalAccumulator::representativeDirection
Vector representativeDirection(const Size &posPhi, const Size &posTheta) const
DGtal::SphericalAccumulator::samples
Quantity samples() const
DGtal::SphericalAccumulator::addDirection
void addDirection(const Vector &aDir)
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
DGtal::Z3i::RealVector
Space::RealVector RealVector
Definition
StdDefs.h:171
DGtal::Z3i::Vector
Space::Vector Vector
Definition
StdDefs.h:169
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
Size
HalfEdgeDataStructure::Size Size
Definition
testHalfEdgeDataStructure.cpp:50
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testSphericalMore
bool testSphericalMore()
Definition
testSphericalAccumulator.cpp:121
testSphericalMoreIntegerDir
bool testSphericalMoreIntegerDir()
Definition
testSphericalAccumulator.cpp:160
testSphericalAccumulator
bool testSphericalAccumulator()
Definition
testSphericalAccumulator.cpp:44
tests
geometry
tools
testSphericalAccumulator.cpp
Generated on
for DGtal by
1.18.0