DGtal  0.9.2
exampleEstimatorFromSurfelFunctors.cpp
1 
28 #include <iostream>
30 #include "DGtal/base/Common.h"
31 
32 // Shape constructors
33 #include "DGtal/io/readers/VolReader.h"
34 #include "DGtal/images/ImageSelector.h"
35 #include "DGtal/images/imagesSetsUtils/SetFromImage.h"
36 #include "DGtal/images/SimpleThresholdForegroundPredicate.h"
37 #include "DGtal/topology/SurfelAdjacency.h"
38 #include "DGtal/topology/helpers/Surfaces.h"
39 #include "DGtal/topology/LightImplicitDigitalSurface.h"
40 #include "DGtal/images/ImageHelper.h"
41 #include "DGtal/topology/DigitalSurface.h"
42 #include "DGtal/graph/DepthFirstVisitor.h"
43 #include "DGtal/graph/GraphVisitorRange.h"
44 #include "DGtal/shapes/Shapes.h"
45 
46 #include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
47 #ifdef WITH_CGAL
48 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingGaussianCurvatureEstimator.h"
49 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingMeanCurvatureEstimator.h"
50 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingNormalVectorEstimator.h"
51 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/LinearLeastSquareFittingNormalVectorEstimator.h"
52 #endif
53 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/ElementaryConvolutionNormalVectorEstimator.h"
54 #include "DGtal/base/BasicFunctors.h"
56 
57 using namespace std;
58 using namespace DGtal;
59 
61 
62 template <typename TPoint3>
63 struct ImplicitDigitalEllipse3 {
64  typedef TPoint3 Point;
65  inline
66  ImplicitDigitalEllipse3( double a, double b, double c )
67  : myA( a ), myB( b ), myC( c )
68  {}
69  inline
70  bool operator()( const TPoint3 & p ) const
71  {
72  double x = ( (double) p[ 0 ] / myA );
73  double y = ( (double) p[ 1 ] / myB );
74  double z = ( (double) p[ 2 ] / myC );
75  return ( x*x + y*y + z*z ) <= 1.0;
76  }
77  double myA, myB, myC;
78 };
79 
80 
81 int main( )
82 {
84  using namespace Z3i;
85  typedef ImplicitDigitalEllipse3<Point> ImplicitDigitalEllipse;
87  typedef DigitalSurface< SurfaceContainer > Surface;
88  typedef SurfaceContainer::Surfel Surfel;
89 
90  Point p1( -10, -10, -10 );
91  Point p2( 10, 10, 10 );
92  KSpace K;
93  K.init( p1, p2, true );
94  ImplicitDigitalEllipse ellipse( 6.0, 4.5, 3.4 );
95  Surfel bel = Surfaces<KSpace>::findABel( K, ellipse, 10000 );
96  SurfaceContainer* surfaceContainer = new SurfaceContainer
97  ( K, ellipse, SurfelAdjacency<KSpace::dimension>( true ), bel );
98  Surface surface( surfaceContainer ); // acquired
100 
101 
103 #ifdef WITH_CGAL
108 
109  //constant convolution functor
110  typedef functors::ConstValue<double> ConstFunctor;
111 
116 #endif
117 
121  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, Z3i::L2Metric,
122  FunctorNormalElem, DGtal::functors::GaussianKernel> ReporterNormalElem;
124 
125 
127  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
128 #ifdef WITH_CGAL
129  FunctorGaussian estimatorK(embedder,1.0);
131  FunctorMean estimatorH(embedder, 1.0);
132  FunctorNormal estimatorN(embedder,1.0);
133  FunctorNormalLeast estimatorL(embedder,1.0);
134 
135  ConstFunctor constFunctor(1.0);
136 
137  ReporterK reporterK;
138  ReporterH reporterH;
139  ReporterNormal reporterN;
140  ReporterNormalLeast reporterL;
141 #endif
142 
143  FunctorNormalElem estimatorNormalElem(embedder,1.0);
145  DGtal::functors::GaussianKernel gaussian(2.0);
146  ReporterNormalElem reporterElem(surface, l2Metric,
147  estimatorNormalElem, gaussian);
149 
151 #ifdef WITH_CGAL
152  reporterK.attach(surface);
153  reporterH.attach(surface);
154  reporterN.attach(surface);
155  reporterL.attach(surface);
156 
157  reporterK.init(1, surface.begin(), surface.end());
158  reporterH.init(1, surface.begin(), surface.end());
159  reporterN.init(1, surface.begin(), surface.end());
160  reporterL.init(1, surface.begin(), surface.end());
161 
162  reporterK.setParams(l2Metric, estimatorK, constFunctor, 5.0);
163  reporterH.setParams(l2Metric, estimatorH, constFunctor, 5.0);
164  reporterN.setParams(l2Metric, estimatorN, constFunctor, 5.0);
165  reporterL.setParams(l2Metric, estimatorL, constFunctor, 5.0);
166 
167  FunctorGaussian::Quantity valK = reporterK.eval( surface.begin());
168  FunctorMean::Quantity valH = reporterH.eval( surface.begin());
169  FunctorNormal::Quantity valN = reporterN.eval( surface.begin());
170  FunctorNormalLeast::Quantity valL = reporterL.eval( surface.begin());
171 #endif
172 
173  reporterElem.attach(surface);
174  reporterElem.setParams(l2Metric,
175  estimatorNormalElem, gaussian, 5.0);
176  reporterElem.init(1.0, surface.begin(), surface.end());
177  FunctorNormalElem::Quantity valElem = reporterElem.eval( surface.begin());
178 
179 #ifdef WITH_CGAL
180  trace.info() << "Gaussian = "<<valK <<std::endl;
181  trace.info() << "Mean = "<<valH<< std::endl;
182  trace.info() << "Normal Vector (from Monge form) = "<<valN<< std::endl;
183  trace.info() << "Normal Vector (linear least square) = "<<valL<< std::endl;
184 #endif
185  trace.info() << "Normal Vector (Elementary conv) = "<<valElem<< std::endl;
187 
188  return 0;
189 }
190 // //
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).
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...
Trace trace
Definition: Common.h:130
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
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
STL namespace.
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: implements separable l_p metrics with exact predicates.
Aim: Estimates normal vector using CGAL Jet Fitting and Monge Form.
Aim: Estimates Mean curvature using CGAL Jet Fitting and Monge Form.
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & info()
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...