DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
SphereFittingEstimator.h
1
16
17
#pragma once
18
33
34
#if defined(SphereFittingEstimator_RECURSES)
35
#error Recursive header files inclusion detected in SphereFittingEstimator.h
36
#else
// defined(SphereFittingEstimator_RECURSES)
38
#define SphereFittingEstimator_RECURSES
39
40
#if !defined SphereFittingEstimator_h
42
#define SphereFittingEstimator_h
43
45
// Inclusions
46
#include <iostream>
47
#include <DGtal/base/Common.h>
48
#include <DGtal/topology/SCellsFunctors.h>
49
50
#ifndef DGTAL_WITH_PONCA
51
#error You need to have activated Ponca (DGTAL_WITH_PONCA) to include this file.
52
#endif
53
54
//Ponca includes
55
#include <Ponca/Fitting>
56
#include <Eigen/Eigen>
57
#include <vector>
58
60
61
namespace
DGtal
62
{
63
namespace
functors
64
{
66
// template class SphereFittingEstimator
85
template
<
typename
TSurfel,
86
typename
TEmbedder,
87
typename
TNormalVectorEstimatorCache>
88
class
SphereFittingEstimator
89
{
90
public
:
91
92
93
class
PoncaPoint
94
{
95
public
:
96
enum
{
Dim
= 3};
97
typedef
double
Scalar
;
98
typedef
Eigen::Matrix<Scalar, Dim, 1>
VectorType
;
99
typedef
Eigen::Matrix<Scalar, Dim, Dim>
MatrixType
;
100
101
PONCA_MULTIARCH
inline
PoncaPoint
(
const
VectorType
& _pos = VectorType::Zero(),
102
const
VectorType
& _normal = VectorType::Zero())
103
:
m_pos
(_pos),
m_normal
(_normal) {}
104
105
PONCA_MULTIARCH
inline
const
VectorType
&
pos
()
const
{
return
m_pos
; }
106
PONCA_MULTIARCH
inline
const
VectorType
&
normal
()
const
{
return
m_normal
; }
107
108
PONCA_MULTIARCH
inline
VectorType
&
pos
() {
return
m_pos
; }
109
PONCA_MULTIARCH
inline
VectorType
&
normal
() {
return
m_normal
; }
110
111
private
:
112
VectorType
m_pos
,
m_normal
;
113
};
114
115
116
typedef
TSurfel
Surfel
;
117
typedef
TEmbedder
SCellEmbedder
;
118
typedef
typename
SCellEmbedder::RealPoint
RealPoint
;
119
120
typedef
TNormalVectorEstimatorCache
NormalVectorEstimatorCache
;
121
122
typedef
typename
PoncaPoint::Scalar
Scalar
;
123
typedef
typename
PoncaPoint::VectorType
VectorType
;
124
125
typedef
Ponca::DistWeightFunc<PoncaPoint, Ponca::SmoothWeightKernel<Scalar>>
WeightFunc
;
126
typedef
Ponca::Basket<PoncaPoint, WeightFunc, Ponca::OrientedSphereFit, Ponca::GLSParam>
Fit
;
127
129
struct
Quantity
130
{
131
RealPoint
center
;
132
double
radius
;
133
double
tau
;
134
double
kappa
;
135
RealPoint
eta
;
136
137
Quantity
(){}
138
Quantity
(
RealPoint
p,
double
rad,
double
_tau,
139
double
_kappa,
RealPoint
_eta):
center
(p),
radius
(rad),
140
tau
(_tau),
kappa
(_kappa),
141
eta
(_eta) {}
142
~Quantity
(){}
143
bool
operator==
(
Quantity
aq) {
return
(
center
==aq.
center
) && (
radius
==aq.
radius
);}
144
bool
operator<
(
Quantity
aq) {
return
(
center
<aq.
center
) && (
radius
<aq.
radius
);}
145
bool
operator!=
(
Quantity
aq) {
return
!(*
this
== aq);}
146
};
147
148
158
SphereFittingEstimator
(
ConstAlias<SCellEmbedder>
anEmbedder,
159
const
double
h,
160
const
double
radius,
161
ConstAlias<NormalVectorEstimatorCache>
anEstimator):
162
myEmbedder
(&anEmbedder),
myH
(h),
myRadius
(radius),
myNormalEsitmatorCache
(&anEstimator)
163
{
164
myFit
=
new
Fit
();
165
}
166
167
171
~SphereFittingEstimator
( )
172
{
173
delete
myFit
;
174
}
175
176
183
void
pushSurfel
(
const
Surfel
& aSurf,
184
const
double
aDistance)
185
{
186
BOOST_VERIFY(aDistance==aDistance);
187
188
RealPoint
p =
myEmbedder
->operator()(aSurf);
189
RealPoint
norm =
myNormalEsitmatorCache
->eval(aSurf);
190
VectorType
pp;
191
pp(0) = p[0]*
myH
;
192
pp(1) = p[1]*
myH
;
193
pp(2) = p[2]*
myH
;
194
VectorType
normal;
195
normal(0) = norm[0];
196
normal(1) = norm[1];
197
normal(2) = norm[2];
198
PoncaPoint
point(pp, normal);
199
if
(
myFirstPoint
)
200
{
201
myFirstPoint
=
false
;
202
myFit
->setWeightFunc({pp,
myRadius
});
203
myFit
->init();
204
}
205
else
206
myFit
->addNeighbor(point);
207
208
#ifdef DGTAL_DEV_VERBOSE
209
trace
.
info
() <<
"#"
;
210
#endif
211
}
212
218
Quantity
eval
()
219
{
220
myFit
->finalize();
221
222
#ifdef DGTAL_DEV_VERBOSE
223
trace
.
info
() <<std::endl;
224
225
//Test if the fitting ended without errors
226
if
(
myFit
->isStable())
227
{
228
std::cout <<
"Center: ["
<<
myFit
->center().transpose() <<
"] ; radius: "
<<
myFit
->radius() << std::endl;
229
230
std::cout <<
"Pratt normalization"
231
<< (
myFit
->applyPrattNorm() ?
" is now done."
:
" has already been applied."
) << std::endl;
232
233
234
std::cout <<
"Fitted Sphere: "
<< std::endl
235
<<
"\t Tau : "
<<
myFit
->tau() << std::endl
236
<<
"\t Eta : "
<<
myFit
->eta().transpose() << std::endl
237
<<
"\t Kappa: "
<<
myFit
->kappa() << std::endl;
238
239
}
240
else
241
{
242
std::cout <<
"Ooops... not stable result"
<<std::endl;
243
}
244
#endif
245
Quantity
res;
246
res.
center
=
RealPoint
((
myFit
->center())(0),
247
(
myFit
->center())(1),
248
(
myFit
->center())(2));
249
res.
radius
=
myFit
->radius();
250
res.
tau
=
myFit
->tau();
251
res.
kappa
=
myFit
->kappa();
252
res.
eta
=
RealPoint
((
myFit
->eta())(0),
253
(
myFit
->eta())(1),
254
(
myFit
->eta())(2));
255
return
res;
256
}
257
258
263
void
reset
()
264
{
265
delete
myFit
;
266
myFit
=
new
Fit
();
267
myFirstPoint
=
true
;
268
}
269
270
271
private
:
272
274
const
SCellEmbedder
*
myEmbedder
;
275
277
Fit
*
myFit
;
278
280
double
myH
;
281
283
double
myRadius
;
284
286
bool
myFirstPoint
;
287
289
const
NormalVectorEstimatorCache
*
myNormalEsitmatorCache
;
290
291
};
// end of class SphereFittingEstimator
292
}
293
}
// namespace DGtal
294
295
296
// //
298
299
#endif
// !defined SphereFittingEstimator_h
300
301
#undef SphereFittingEstimator_RECURSES
302
#endif
// else defined(SphereFittingEstimator_RECURSES)
DGtal::ConstAlias
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition
ConstAlias.h:187
DGtal::Trace::info
std::ostream & info()
DGtal::functors::SphereFittingEstimator::PoncaPoint
Definition
SphereFittingEstimator.h:94
DGtal::functors::SphereFittingEstimator::PoncaPoint::normal
PONCA_MULTIARCH const VectorType & normal() const
Definition
SphereFittingEstimator.h:106
DGtal::functors::SphereFittingEstimator::PoncaPoint::normal
PONCA_MULTIARCH VectorType & normal()
Definition
SphereFittingEstimator.h:109
DGtal::functors::SphereFittingEstimator::PoncaPoint::Dim
@ Dim
Definition
SphereFittingEstimator.h:96
DGtal::functors::SphereFittingEstimator::PoncaPoint::m_normal
VectorType m_normal
Definition
SphereFittingEstimator.h:112
DGtal::functors::SphereFittingEstimator::PoncaPoint::pos
PONCA_MULTIARCH VectorType & pos()
Definition
SphereFittingEstimator.h:108
DGtal::functors::SphereFittingEstimator::PoncaPoint::Scalar
double Scalar
Definition
SphereFittingEstimator.h:97
DGtal::functors::SphereFittingEstimator::PoncaPoint::pos
PONCA_MULTIARCH const VectorType & pos() const
Definition
SphereFittingEstimator.h:105
DGtal::functors::SphereFittingEstimator::PoncaPoint::m_pos
VectorType m_pos
Definition
SphereFittingEstimator.h:112
DGtal::functors::SphereFittingEstimator::PoncaPoint::VectorType
Eigen::Matrix< Scalar, Dim, 1 > VectorType
Definition
SphereFittingEstimator.h:98
DGtal::functors::SphereFittingEstimator::PoncaPoint::PoncaPoint
PONCA_MULTIARCH PoncaPoint(const VectorType &_pos=VectorType::Zero(), const VectorType &_normal=VectorType::Zero())
Definition
SphereFittingEstimator.h:101
DGtal::functors::SphereFittingEstimator::PoncaPoint::MatrixType
Eigen::Matrix< Scalar, Dim, Dim > MatrixType
Definition
SphereFittingEstimator.h:99
DGtal::functors::SphereFittingEstimator::WeightFunc
Ponca::DistWeightFunc< PoncaPoint, Ponca::SmoothWeightKernel< Scalar > > WeightFunc
Definition
SphereFittingEstimator.h:125
DGtal::functors::SphereFittingEstimator::myNormalEsitmatorCache
const NormalVectorEstimatorCache * myNormalEsitmatorCache
NormalVectorCache.
Definition
SphereFittingEstimator.h:289
DGtal::functors::SphereFittingEstimator::Fit
Ponca::Basket< PoncaPoint, WeightFunc, Ponca::OrientedSphereFit, Ponca::GLSParam > Fit
Definition
SphereFittingEstimator.h:126
DGtal::functors::SphereFittingEstimator::myFirstPoint
bool myFirstPoint
Boolean for initial point.
Definition
SphereFittingEstimator.h:286
DGtal::functors::SphereFittingEstimator::eval
Quantity eval()
Definition
SphereFittingEstimator.h:218
DGtal::functors::SphereFittingEstimator::myFit
Fit * myFit
Fitting object.
Definition
SphereFittingEstimator.h:277
DGtal::functors::SphereFittingEstimator::myEmbedder
const SCellEmbedder * myEmbedder
Alias of the geometrical embedder.
Definition
SphereFittingEstimator.h:274
DGtal::functors::SphereFittingEstimator::Surfel
TSurfel Surfel
Definition
SphereFittingEstimator.h:116
DGtal::functors::SphereFittingEstimator::myRadius
double myRadius
Radius.
Definition
SphereFittingEstimator.h:283
DGtal::functors::SphereFittingEstimator::reset
void reset()
Definition
SphereFittingEstimator.h:263
DGtal::functors::SphereFittingEstimator::Scalar
PoncaPoint::Scalar Scalar
Definition
SphereFittingEstimator.h:122
DGtal::functors::SphereFittingEstimator::RealPoint
SCellEmbedder::RealPoint RealPoint
Definition
SphereFittingEstimator.h:118
DGtal::functors::SphereFittingEstimator::SphereFittingEstimator
SphereFittingEstimator(ConstAlias< SCellEmbedder > anEmbedder, const double h, const double radius, ConstAlias< NormalVectorEstimatorCache > anEstimator)
Definition
SphereFittingEstimator.h:158
DGtal::functors::SphereFittingEstimator::NormalVectorEstimatorCache
TNormalVectorEstimatorCache NormalVectorEstimatorCache
Definition
SphereFittingEstimator.h:120
DGtal::functors::SphereFittingEstimator::~SphereFittingEstimator
~SphereFittingEstimator()
Definition
SphereFittingEstimator.h:171
DGtal::functors::SphereFittingEstimator::pushSurfel
void pushSurfel(const Surfel &aSurf, const double aDistance)
Definition
SphereFittingEstimator.h:183
DGtal::functors::SphereFittingEstimator::myH
double myH
Grid step.
Definition
SphereFittingEstimator.h:280
DGtal::functors::SphereFittingEstimator::VectorType
PoncaPoint::VectorType VectorType
Definition
SphereFittingEstimator.h:123
DGtal::functors::SphereFittingEstimator::SCellEmbedder
TEmbedder SCellEmbedder
Definition
SphereFittingEstimator.h:117
DGtal::functors
functors namespace gathers all DGtal functors.
Definition
BasicBoolFunctors.h:49
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
DGtal::functors::SphereFittingEstimator::Quantity
Quantity type: a 3-sphere (model of CQuantity).
Definition
SphereFittingEstimator.h:130
DGtal::functors::SphereFittingEstimator::Quantity::radius
double radius
Definition
SphereFittingEstimator.h:132
DGtal::functors::SphereFittingEstimator::Quantity::~Quantity
~Quantity()
Definition
SphereFittingEstimator.h:142
DGtal::functors::SphereFittingEstimator::Quantity::Quantity
Quantity()
Definition
SphereFittingEstimator.h:137
DGtal::functors::SphereFittingEstimator::Quantity::kappa
double kappa
Definition
SphereFittingEstimator.h:134
DGtal::functors::SphereFittingEstimator::Quantity::operator<
bool operator<(Quantity aq)
Definition
SphereFittingEstimator.h:144
DGtal::functors::SphereFittingEstimator::Quantity::operator!=
bool operator!=(Quantity aq)
Definition
SphereFittingEstimator.h:145
DGtal::functors::SphereFittingEstimator::Quantity::Quantity
Quantity(RealPoint p, double rad, double _tau, double _kappa, RealPoint _eta)
Definition
SphereFittingEstimator.h:138
DGtal::functors::SphereFittingEstimator::Quantity::eta
RealPoint eta
Definition
SphereFittingEstimator.h:135
DGtal::functors::SphereFittingEstimator::Quantity::tau
double tau
Definition
SphereFittingEstimator.h:133
DGtal::functors::SphereFittingEstimator::Quantity::operator==
bool operator==(Quantity aq)
Definition
SphereFittingEstimator.h:143
DGtal::functors::SphereFittingEstimator::Quantity::center
RealPoint center
Definition
SphereFittingEstimator.h:131
src
DGtal
geometry
surfaces
estimation
estimationFunctors
SphereFittingEstimator.h
Generated on
for DGtal by
1.18.0