DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testSphereFitting.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/base/BasicFunctors.h"
35
#include "DGtal/graph/GraphVisitorRange.h"
36
#include "DGtal/io/boards/Board2D.h"
37
#include "DGtal/io/Color.h"
38
#include "DGtal/io/colormaps/GradientColorMap.h"
39
40
#include "DGtal/shapes/Shapes.h"
41
#include "DGtal/shapes/implicit/ImplicitBall.h"
42
#include "DGtal/shapes/GaussDigitizer.h"
43
44
#include "DGtal/topology/CanonicSCellEmbedder.h"
45
#include "DGtal/graph/DistanceBreadthFirstVisitor.h"
46
#include "DGtal/geometry/volumes/distance/LpMetric.h"
47
#include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
48
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/BasicEstimatorFromSurfelsFunctors.h"
49
#include "DGtal/topology/LightImplicitDigitalSurface.h"
50
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/SphereFittingEstimator.h"
51
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/ElementaryConvolutionNormalVectorEstimator.h"
52
#include "DGtal/geometry/surfaces/estimation/EstimatorCache.h"
54
55
using namespace
std
;
56
using namespace
DGtal
;
57
59
// Functions for testing class LocalEstimatorFromFunctorAdapter.
61
62
67
bool
testFitting
()
68
{
69
unsigned
int
nbok = 0;
70
unsigned
int
nb = 0;
71
trace
.
beginBlock
(
"Testing init ..."
);
72
73
using namespace
Z3i
;
74
75
trace
.
beginBlock
(
"Creating Surface"
);
76
Point
p1( -20, -20, -20 );
77
Point
p2( 20, 20, 20 );
78
79
ImplicitBall<Z3i::Space>
shape(
RealPoint
(6.0,0,0), 4);
80
typedef
GaussDigitizer<Z3i::Space, ImplicitBall<Z3i::Space>
> Gauss;
81
Gauss gauss;
82
gauss.
attach
(shape);
83
gauss.init(p1, p2, 1);
84
85
typedef
LightImplicitDigitalSurface<KSpace, Gauss >
SurfaceContainer;
86
typedef
DigitalSurface<SurfaceContainer>
Surface
;
87
typedef
Surface::Surfel
Surfel
;
88
89
90
KSpace
K
;
91
nbok +=
K
.
init
( p1, p2,
true
) ? 1 : 0;
92
nb++;
93
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
94
<<
"K.init() is ok"
<< std::endl;
95
Surfel
bel =
Surfaces<KSpace>::findABel
(
K
, gauss, 10000 );
96
SurfaceContainer* surfaceContainer =
new
SurfaceContainer
97
(
K
, gauss,
SurfelAdjacency<KSpace::dimension>
(
true
), bel );
98
Surface
surface
( surfaceContainer );
// acquired
99
CanonicSCellEmbedder<KSpace>
embedder(
surface
.container().space());
100
trace
.
endBlock
();
101
102
trace
.
beginBlock
(
"Normal vector field computation"
);
103
typedef
functors::ElementaryConvolutionNormalVectorEstimator<Surfel, CanonicSCellEmbedder<KSpace>
> FunctorNormal;
104
typedef
LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>
,
105
FunctorNormal,
106
DGtal::functors::GaussianKernel
> ReporterNormal;
107
typedef
EstimatorCache<ReporterNormal>
NormalCache;
108
109
//estimator
110
DGtal::functors::GaussianKernel
gaussKernelFunc(5.0);
111
FunctorNormal functorNormal(embedder, 1.0);
112
ReporterNormal reporterNormal;
113
reporterNormal.attach(
surface
);
114
LpMetric<Z3i::Space>
l2(2.0);
115
reporterNormal.setParams(l2, functorNormal, gaussKernelFunc, 5.0);
116
117
//caching normal field
118
NormalCache normalCache(reporterNormal);
119
normalCache.init( 1,
surface
.begin(),
surface
.end());
120
trace
.
info
() <<
"Normal vector field cached... "
<< normalCache << std::endl;
121
trace
.
endBlock
();
122
123
trace
.
beginBlock
(
"Creating sphere fitting adapter from normal vector field"
);
124
typedef
functors::SphereFittingEstimator<Surfel, CanonicSCellEmbedder<KSpace>
, NormalCache>
Functor
;
125
typedef
functors::ConstValue< double >
ConvFunctor;
126
typedef
LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>
,
Functor
, ConvFunctor> Reporter;
127
128
Functor
fitter(embedder,1.0, 5.0, normalCache);
129
ConvFunctor convFunc(1.0);
130
Reporter reporter;
131
reporter.attach(
surface
);
132
reporter.setParams(l2, fitter , convFunc, 15.0);
133
134
reporter.init(1,
surface
.begin(),
surface
.end());
135
for
(
Surface::ConstIterator
it =
surface
.begin(), ite=
surface
.end(); it!=ite; ++it)
136
{
137
Functor::Quantity val = reporter.eval( it );
138
trace
.
info
() <<
"Fitting = "
<<val.center <<
" rad="
<<val.radius<<std::endl;
139
}
140
trace
.
endBlock
();
141
142
143
trace
.
endBlock
();
144
145
nbok +=
true
? 1 : 0;
146
nb++;
147
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
148
<<
"true == true"
<< std::endl;
149
150
return
nbok == nb;
151
}
152
154
// Standard services - public :
155
156
int
main
(
int
argc,
char
** argv )
157
{
158
trace
.
beginBlock
(
"Testing class SphereFitting"
);
159
trace
.
info
() <<
"Args:"
;
160
for
(
int
i = 0; i < argc; ++i )
161
trace
.
info
() <<
" "
<< argv[ i ];
162
trace
.
info
() << endl;
163
164
bool
res =
testFitting
();
// && ... other tests
165
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
166
trace
.
endBlock
();
167
return
res ? 0 : 1;
168
}
169
// //
DGtal::DigitalSurface
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Definition
DigitalSurface.h:140
DGtal::DigitalSurface< ExplicitSurfaceContainer >::Surfel
DigitalSurfaceContainer::Surfel Surfel
Definition
DigitalSurface.h:162
DGtal::DigitalSurface< ExplicitSurfaceContainer >::ConstIterator
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
Definition
DigitalSurface.h:163
DGtal::EstimatorCache
Aim: this class adapts any local surface estimator to cache the estimated values in a associative con...
Definition
EstimatorCache.h:78
DGtal::GaussDigitizer
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Definition
GaussDigitizer.h:80
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
DGtal::ImplicitBall
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD....
Definition
ImplicitBall.h:65
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::LightImplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Definition
LightImplicitDigitalSurface.h:116
DGtal::LocalEstimatorFromSurfelFunctorAdapter
Aim: this class adapts any local functor on digital surface element to define a local estimator....
Definition
LocalEstimatorFromSurfelFunctorAdapter.h:104
DGtal::LpMetric
Aim: implements l_p metrics.
Definition
LpMetric.h:75
DGtal::Point
DGtal::Surfaces::findABel
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
DGtal::SurfelAdjacency
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Definition
SurfelAdjacency.h:66
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::functors::ConstValue
Aim: Define a simple functor that returns a constant value (0 by default).
Definition
BasicFunctors.h:311
DGtal::functors::ElementaryConvolutionNormalVectorEstimator
Aim: Estimates normal vector by convolution of elementary normal vector to adjacent surfel.
Definition
ElementaryConvolutionNormalVectorEstimator.h:76
DGtal::functors::SphereFittingEstimator
Aim: Use Ponca library to perform a local sphere fitting.
Definition
SphereFittingEstimator.h:89
surface
CountedPtr< SH3::DigitalSurface > surface
Definition
dgtalCalculus-geodesic.cpp:66
Surface
SH3::DigitalSurface Surface
Definition
exampleMaximalSegmentSliceEstimation.cpp:45
DGtal::Z3i
Z3i this namespace gathers the standard of types for 3D imagery.
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.
DGtal::CanonicSCellEmbedder
Aim: A trivial embedder for signed cell, which corresponds to the canonic injection of cell centroids...
Definition
CanonicSCellEmbedder.h:66
DGtal::functors::GaussianKernel
Aim: defines a functor on double numbers which corresponds to a Gaussian convolution kernel....
Definition
BasicFunctors.h:947
Functor
Definition
testFunctorHolder.cpp:45
Surfel
KSpace::SCell Surfel
Definition
testArithmeticalDSSComputerOnSurfels.cpp:50
KSpace
Z3i::KSpace KSpace
Definition
testArithmeticalDSSComputerOnSurfels.cpp:48
K
KSpace K
Definition
testCubicalComplex.cpp:62
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testFitting
bool testFitting()
Definition
testSphereFitting.cpp:67
RealPoint
PointVector< 3, double > RealPoint
Definition
testTriangulatedSurface.cpp:51
tests
geometry
surfaces
testSphereFitting.cpp
Generated on
for DGtal by
1.18.0