DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testLocalEstimatorFromFunctorAdapter.cpp
Go to the documentation of this file.
1
16
29
31
#include <iostream>
32
#include "DGtal/base/Common.h"
33
#include "ConfigTest.h"
34
#include "DGtal/helpers/StdDefs.h"
35
#include "DGtal/base/BasicFunctors.h"
36
#include "DGtal/graph/GraphVisitorRange.h"
37
#include "DGtal/io/boards/Board2D.h"
38
#include "DGtal/io/Color.h"
39
#include "DGtal/io/colormaps/GradientColorMap.h"
40
#include "DGtal/shapes/Shapes.h"
41
#include "DGtal/kernel/CanonicEmbedder.h"
42
#include "DGtal/topology/CanonicSCellEmbedder.h"
43
#include "DGtal/graph/DistanceBreadthFirstVisitor.h"
44
#include "DGtal/geometry/volumes/distance/LpMetric.h"
45
#include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
46
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/BasicEstimatorFromSurfelsFunctors.h"
47
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/CLocalEstimatorFromSurfelFunctor.h"
48
49
#include "DGtal/topology/LightImplicitDigitalSurface.h"
50
#include "DGtal/topology/DigitalSurface.h"
51
52
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/ElementaryConvolutionNormalVectorEstimator.h"
53
54
55
#ifdef DGTAL_WITH_CGAL
56
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingGaussianCurvatureEstimator.h"
57
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingMeanCurvatureEstimator.h"
58
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingNormalVectorEstimator.h"
59
#include "DGtal/geometry/surfaces/estimation/estimationFunctors/LinearLeastSquareFittingNormalVectorEstimator.h"
60
#endif
61
63
64
using namespace
std
;
65
using namespace
DGtal
;
66
68
// Functions for testing class LocalEstimatorFromFunctorAdapter.
70
71
72
73
template
<
typename
TPo
int
3>
74
struct
ImplicitDigitalEllipse3
{
75
typedef
TPoint3
Point
;
76
inline
77
ImplicitDigitalEllipse3
(
double
a,
double
b,
double
c )
78
:
myA
( a ),
myB
( b ),
myC
( c )
79
{}
80
inline
81
bool
operator()
(
const
TPoint3 & p )
const
82
{
83
double
x = ( (double) p[ 0 ] /
myA
);
84
double
y = ( (double) p[ 1 ] /
myB
);
85
double
z = ( (double) p[ 2 ] /
myC
);
86
return
( x*x + y*y + z*z ) <= 1.0;
87
}
88
double
myA
,
myB
,
myC
;
89
};
90
91
96
bool
testLocalEstimatorFromFunctorAdapter
()
97
{
98
unsigned
int
nbok = 0;
99
unsigned
int
nb = 0;
100
trace
.
beginBlock
(
"Testing init ..."
);
101
102
using namespace
Z3i
;
103
typedef
ImplicitDigitalEllipse3<Point>
ImplicitDigitalEllipse;
104
typedef
LightImplicitDigitalSurface<KSpace,ImplicitDigitalEllipse>
SurfaceContainer;
105
typedef
DigitalSurface< SurfaceContainer >
Surface
;
106
typedef
SurfaceContainer::SurfelConstIterator
ConstIterator
;
107
typedef
SurfaceContainer::Surfel
Surfel
;
108
109
110
trace
.
beginBlock
(
"Creating Surface"
);
111
Point
p1( -10, -10, -10 );
112
Point
p2( 10, 10, 10 );
113
KSpace
K
;
114
nbok +=
K
.
init
( p1, p2,
true
) ? 1 : 0;
115
nb++;
116
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
117
<<
"K.init() is ok"
<< std::endl;
118
ImplicitDigitalEllipse ellipse( 6.0, 4.5, 3.4 );
119
Surfel
bel =
Surfaces<KSpace>::findABel
(
K
, ellipse, 10000 );
120
SurfaceContainer* surfaceContainer =
new
SurfaceContainer
121
(
K
, ellipse,
SurfelAdjacency<KSpace::dimension>
(
true
), bel );
122
Surface
surface
( surfaceContainer );
// acquired
123
unsigned
int
nbsurfels = 0;
124
for
(
ConstIterator
it =
surface
.begin(), it_end =
surface
.end();
125
it != it_end; ++it )
126
{
127
++nbsurfels;
128
}
129
trace
.
info
() << nbsurfels <<
" surfels found."
<< std::endl;
130
trace
.
endBlock
();
131
132
trace
.
beginBlock
(
"Creating adapter"
);
133
typedef
DGtal::functors::DummyEstimatorFromSurfels<Surfel, CanonicSCellEmbedder<KSpace>
>
Functor
;
134
typedef
DGtal::functors::ConstValue< double >
ConvFunctor;
135
typedef
LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>
,
136
Functor
, ConvFunctor> Reporter;
137
138
typedef
LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>
,
139
Functor
,
DGtal::functors::GaussianKernel
> ReporterGaussian;
140
141
LpMetric<Z3i::Space>
l2(2.0);
142
CanonicSCellEmbedder<KSpace>
embedder(
surface
.container().space());
143
Functor
estimator(embedder, 1);
144
145
ConvFunctor convFunc(1.0);
146
Reporter reporter;
147
reporter.attach(
surface
);
148
reporter.setParams(l2,estimator,convFunc, 5);
149
150
//We just test the init for Gaussian
151
DGtal::functors::GaussianKernel
gaussKernelFunc(1.0);
152
ReporterGaussian reporterGaussian;
153
reporterGaussian.attach(
surface
);
154
reporterGaussian.setParams(l2,estimator,gaussKernelFunc, 5.0);
155
reporterGaussian.init(1,
surface
.begin(),
surface
.end());
156
157
reporter.init(1.0,
surface
.begin(),
surface
.end());
158
Functor::Quantity val = reporter.eval(
surface
.begin() );
159
trace
.
info
() <<
"Value with radius 5= "
<<val << std::endl;
160
nbok += ((fabs((
double
)val - 124.0)) < 40) ? 1 : 0;
161
nb++;
162
163
reporter.setParams(l2,estimator,convFunc, 20.0);
164
reporter.init(1,
surface
.begin(),
surface
.end());
165
Functor::Quantity val2 = reporter.eval(
surface
.begin() );
166
trace
.
info
() <<
"Value with radius 20= "
<<val2 << std::endl;
167
168
nbok += ((fabs((
double
)val2 - 398.0)) < 120) ? 1 : 0;
169
nb++;
170
171
trace
.
endBlock
();
172
trace
.
endBlock
();
173
174
trace
.
info
() <<
"("
<< nbok <<
"/"
<< nb <<
") "
175
<<
"true == true"
<< std::endl;
176
177
return
nbok == nb;
178
}
179
180
181
bool
testConcepts
()
182
{
183
typedef
Z3i::KSpace::Surfel
Surfel
;
184
typedef
CanonicSCellEmbedder<Z3i::KSpace>
Embedder;
185
trace
.
beginBlock
(
"Checking concepts"
);
186
BOOST_CONCEPT_ASSERT((
concepts::CLocalEstimatorFromSurfelFunctor
<
functors::DummyEstimatorFromSurfels<Surfel,Embedder >
>));
187
BOOST_CONCEPT_ASSERT((
concepts::CLocalEstimatorFromSurfelFunctor
<
functors::ElementaryConvolutionNormalVectorEstimator<Surfel,Embedder >
>));
188
189
#ifdef DGTAL_WITH_CGAL
190
BOOST_CONCEPT_ASSERT((
concepts::CLocalEstimatorFromSurfelFunctor
<
functors::MongeJetFittingNormalVectorEstimator<Surfel,Embedder >
>));
191
BOOST_CONCEPT_ASSERT((
concepts::CLocalEstimatorFromSurfelFunctor
<
functors::MongeJetFittingMeanCurvatureEstimator<Surfel,Embedder >
>));
192
BOOST_CONCEPT_ASSERT((
concepts::CLocalEstimatorFromSurfelFunctor
<
functors::MongeJetFittingGaussianCurvatureEstimator<Surfel,Embedder >
>));
193
BOOST_CONCEPT_ASSERT((
concepts::CLocalEstimatorFromSurfelFunctor
<
functors::LinearLeastSquareFittingNormalVectorEstimator<Surfel,Embedder >
>));
194
#endif
195
196
trace
.
endBlock
();
197
return
true
;
198
}
199
201
// Standard services - public :
202
203
int
main
(
int
argc,
char
** argv )
204
{
205
trace
.
beginBlock
(
"Testing class LocalEstimatorFromFunctorAdapter"
);
206
trace
.
info
() <<
"Args:"
;
207
for
(
int
i = 0; i < argc; ++i )
208
trace
.
info
() <<
" "
<< argv[ i ];
209
trace
.
info
() << endl;
210
211
bool
res =
testConcepts
() &&
testLocalEstimatorFromFunctorAdapter
();
// && ... other tests
212
trace
.
emphase
() << ( res ?
"Passed."
:
"Error."
) << endl;
213
trace
.
endBlock
();
214
return
res ? 0 : 1;
215
}
216
// //
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::ConstIterator
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::KhalimskySpaceND< 3, Integer >::Surfel
SCell Surfel
Definition
KhalimskySpaceND.h:420
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::LinearLeastSquareFittingNormalVectorEstimator
Aim: Estimates normal vector using CGAL linear least squares plane fitting.
Definition
LinearLeastSquareFittingNormalVectorEstimator.h:80
DGtal::functors::MongeJetFittingGaussianCurvatureEstimator
Aim: Estimates Gaussian curvature using CGAL Jet Fitting and Monge Form.
Definition
MongeJetFittingGaussianCurvatureEstimator.h:78
DGtal::functors::MongeJetFittingMeanCurvatureEstimator
Aim: Estimates Mean curvature using CGAL Jet Fitting and Monge Form.
Definition
MongeJetFittingMeanCurvatureEstimator.h:91
DGtal::functors::MongeJetFittingNormalVectorEstimator
Aim: Estimates normal vector using CGAL Jet Fitting and Monge Form.
Definition
MongeJetFittingNormalVectorEstimator.h:82
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::ImplicitDigitalEllipse3
Definition
testImplicitDigitalSurface-benchmark.cpp:82
DGtal::concepts::CLocalEstimatorFromSurfelFunctor
Aim: this concept describes functors on digtal surface surfel which can be used to define local estim...
Definition
CLocalEstimatorFromSurfelFunctor.h:106
DGtal::functors::DummyEstimatorFromSurfels
Definition
BasicEstimatorFromSurfelsFunctors.h:55
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
ImplicitDigitalEllipse3::myC
double myC
Definition
testLocalEstimatorFromFunctorAdapter.cpp:88
ImplicitDigitalEllipse3::Point
TPoint3 Point
Definition
testLocalEstimatorFromFunctorAdapter.cpp:75
ImplicitDigitalEllipse3::operator()
bool operator()(const TPoint3 &p) const
Definition
testLocalEstimatorFromFunctorAdapter.cpp:81
ImplicitDigitalEllipse3::ImplicitDigitalEllipse3
ImplicitDigitalEllipse3(double a, double b, double c)
Definition
testLocalEstimatorFromFunctorAdapter.cpp:77
ImplicitDigitalEllipse3::myA
double myA
Definition
testLocalEstimatorFromFunctorAdapter.cpp:88
ImplicitDigitalEllipse3::myB
double myB
Definition
testLocalEstimatorFromFunctorAdapter.cpp:88
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
testLocalEstimatorFromFunctorAdapter
bool testLocalEstimatorFromFunctorAdapter()
Definition
testLocalEstimatorFromFunctorAdapter.cpp:96
testConcepts
bool testConcepts()
Definition
testLocalEstimatorFromFunctorAdapter.cpp:181
tests
geometry
surfaces
testLocalEstimatorFromFunctorAdapter.cpp
Generated on
for DGtal by
1.18.0