DGtal  0.9.3
testLocalEstimatorFromFunctorAdapter.cpp
Go to the documentation of this file.
1 
30 #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/ExactPredicateLpSeparableMetric.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 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 TPoint3>
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 
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;
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");
134  typedef DGtal::functors::ConstValue< double > ConvFunctor;
135  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric,
136  Functor, ConvFunctor> Reporter;
137 
138  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric,
139  Functor, DGtal::functors::GaussianKernel> ReporterGaussian;
140 
141  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
142  Functor estimator(embedder, 1);
143 
144  ConvFunctor convFunc(1.0);
145  Reporter reporter;//(surface,l2Metric,estimator,convFunc);
146  reporter.attach(surface);
147  reporter.setParams(l2Metric,estimator,convFunc, 5);
148 
149  //We just test the init for Gaussian
150  DGtal::functors::GaussianKernel gaussKernelFunc(1.0);
151  ReporterGaussian reporterGaussian;
152  reporterGaussian.attach(surface);
153  reporterGaussian.setParams(l2Metric,estimator,gaussKernelFunc, 5.0);
154  reporterGaussian.init(1, surface.begin(), surface.end());
155 
156  reporter.init(1.0, surface.begin(), surface.end());
157  Functor::Quantity val = reporter.eval( surface.begin() );
158  trace.info() << "Value with radius 5= "<<val << std::endl;
159  nbok += ((fabs((double)val - 124.0)) < 40) ? 1 : 0;
160  nb++;
161 
162  reporter.setParams(l2Metric,estimator,convFunc, 20.0);
163  reporter.init(1, surface.begin(), surface.end());
164  Functor::Quantity val2 = reporter.eval( surface.begin() );
165  trace.info() << "Value with radius 20= "<<val2 << std::endl;
166 
167  nbok += ((fabs((double)val2 - 398.0)) < 120) ? 1 : 0;
168  nb++;
169 
170  trace.endBlock();
171  trace.endBlock();
172 
173  nbok += true ? 1 : 0;
174  nb++;
175  trace.info() << "(" << nbok << "/" << nb << ") "
176  << "true == true" << std::endl;
177 
178  return nbok == nb;
179 }
180 
181 
183 {
184  typedef Z3i::KSpace::Surfel Surfel;
185  typedef CanonicSCellEmbedder<Z3i::KSpace> Embedder;
186  trace.beginBlock("Checking concepts");
189 
190 #ifdef WITH_CGAL
195 #endif
196 
197  trace.endBlock();
198  return true;
199 }
200 
202 // Standard services - public :
203 
204 int main( int argc, char** argv )
205 {
206  trace.beginBlock ( "Testing class LocalEstimatorFromFunctorAdapter" );
207  trace.info() << "Args:";
208  for ( int i = 0; i < argc; ++i )
209  trace.info() << " " << argv[ i ];
210  trace.info() << endl;
211 
212  bool res = testConcepts() && testLocalEstimatorFromFunctorAdapter(); // && ... other tests
213  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
214  trace.endBlock();
215  return res ? 0 : 1;
216 }
217 // //
void beginBlock(const std::string &keyword="")
Aim: defines a functor on double numbers which corresponds to a Gaussian convolution kernel...
Aim: Define a simple functor that returns a constant value (0 by default).
InHalfPlaneBySimple3x3Matrix< Point, double > Functor
Aim: Estimates normal vector by convolution of elementary normal vector to adjacent surfel...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
Aim: Estimates normal vector using CGAL linear least squares plane fitting.
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
STL namespace.
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
int main(int argc, char **argv)
Aim: implements separable l_p metrics with exact predicates.
Aim: Estimates normal vector using CGAL Jet Fitting and Monge Form.
std::ostream & emphase()
Aim: Estimates Mean curvature using CGAL Jet Fitting and Monge Form.
Aim: this concept describes functors on digtal surface surfel which can be used to define local estim...
bool testLocalEstimatorFromFunctorAdapter()
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
std::ostream & info()
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
Aim: Estimates Gaussian curvature using CGAL Jet Fitting and Monge Form.
Aim: this class adapts any local functor on digital surface element to define a local estimator...
KSpace K