DGtal  1.0.0
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 #include "DGtal/geometry/volumes/distance/LpMetric.h"
48 #ifdef WITH_CGAL
49 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingGaussianCurvatureEstimator.h"
50 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingMeanCurvatureEstimator.h"
51 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingNormalVectorEstimator.h"
52 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/LinearLeastSquareFittingNormalVectorEstimator.h"
53 #endif
54 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/ElementaryConvolutionNormalVectorEstimator.h"
55 #include "DGtal/base/BasicFunctors.h"
57 
58 using namespace std;
59 using namespace DGtal;
60 
62 
63 template <typename TPoint3>
64 struct ImplicitDigitalEllipse3 {
65  typedef TPoint3 Point;
66  inline
67  ImplicitDigitalEllipse3( double a, double b, double c )
68  : myA( a ), myB( b ), myC( c )
69  {}
70  inline
71  bool operator()( const TPoint3 & p ) const
72  {
73  double x = ( (double) p[ 0 ] / myA );
74  double y = ( (double) p[ 1 ] / myB );
75  double z = ( (double) p[ 2 ] / myC );
76  return ( x*x + y*y + z*z ) <= 1.0;
77  }
78  double myA, myB, myC;
79 };
80 
81 
82 int main( )
83 {
85  using namespace Z3i;
86  typedef ImplicitDigitalEllipse3<Point> ImplicitDigitalEllipse;
88  typedef DigitalSurface< SurfaceContainer > Surface;
89  typedef SurfaceContainer::Surfel Surfel;
90 
91  Point p1( -10, -10, -10 );
92  Point p2( 10, 10, 10 );
93  KSpace K;
94  K.init( p1, p2, true );
95  ImplicitDigitalEllipse ellipse( 6.0, 4.5, 3.4 );
96  Surfel bel = Surfaces<KSpace>::findABel( K, ellipse, 10000 );
97  SurfaceContainer* surfaceContainer = new SurfaceContainer
98  ( K, ellipse, SurfelAdjacency<KSpace::dimension>( true ), bel );
99  Surface surface( surfaceContainer ); // acquired
101 
102 
104 #ifdef WITH_CGAL
109 
110  //constant convolution functor
111  typedef functors::ConstValue<double> ConstFunctor;
112 
113  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>, FunctorGaussian, ConstFunctor> ReporterK;
114  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>, FunctorMean, ConstFunctor> ReporterH;
115  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>, FunctorNormal, ConstFunctor> ReporterNormal;
116  typedef LocalEstimatorFromSurfelFunctorAdapter<SurfaceContainer, LpMetric<Z3i::Space>, FunctorNormalLeast, ConstFunctor> ReporterNormalLeast;
117 #endif
118 
123  FunctorNormalElem, DGtal::functors::GaussianKernel> ReporterNormalElem;
125 
126 
128  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
129 #ifdef WITH_CGAL
130  FunctorGaussian estimatorK(embedder,1.0);
132  FunctorMean estimatorH(embedder, 1.0);
133  FunctorNormal estimatorN(embedder,1.0);
134  FunctorNormalLeast estimatorL(embedder,1.0);
135 
136  ConstFunctor constFunctor(1.0);
137 
138  ReporterK reporterK;
139  ReporterH reporterH;
140  ReporterNormal reporterN;
141  ReporterNormalLeast reporterL;
142 #endif
143 
144  LpMetric<Z3i::Space> l2(2.0);
145  FunctorNormalElem estimatorNormalElem(embedder,1.0);
147  DGtal::functors::GaussianKernel gaussian(2.0);
148  ReporterNormalElem reporterElem(surface, l2,
149  estimatorNormalElem, gaussian);
151 
153 #ifdef WITH_CGAL
154  reporterK.attach(surface);
155  reporterH.attach(surface);
156  reporterN.attach(surface);
157  reporterL.attach(surface);
158 
159  reporterK.init(1, surface.begin(), surface.end());
160  reporterH.init(1, surface.begin(), surface.end());
161  reporterN.init(1, surface.begin(), surface.end());
162  reporterL.init(1, surface.begin(), surface.end());
163 
164  reporterK.setParams(l2, estimatorK, constFunctor, 5.0);
165  reporterH.setParams(l2, estimatorH, constFunctor, 5.0);
166  reporterN.setParams(l2, estimatorN, constFunctor, 5.0);
167  reporterL.setParams(l2, estimatorL, constFunctor, 5.0);
168 
169  FunctorGaussian::Quantity valK = reporterK.eval( surface.begin());
170  FunctorMean::Quantity valH = reporterH.eval( surface.begin());
171  FunctorNormal::Quantity valN = reporterN.eval( surface.begin());
172  FunctorNormalLeast::Quantity valL = reporterL.eval( surface.begin());
173 #endif
174 
175  reporterElem.attach(surface);
176  reporterElem.setParams(l2,
177  estimatorNormalElem, gaussian, 5.0);
178  reporterElem.init(1.0, surface.begin(), surface.end());
179  FunctorNormalElem::Quantity valElem = reporterElem.eval( surface.begin());
180 
181 #ifdef WITH_CGAL
182  trace.info() << "Gaussian = "<<valK <<std::endl;
183  trace.info() << "Mean = "<<valH<< std::endl;
184  trace.info() << "Normal Vector (from Monge form) = "<<valN<< std::endl;
185  trace.info() << "Normal Vector (linear least square) = "<<valL<< std::endl;
186 #endif
187  trace.info() << "Normal Vector (Elementary conv) = "<<valElem<< std::endl;
189 
190  return 0;
191 }
192 // //
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:144
Aim: implements l_p metrics.
Definition: LpMetric.h:74
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
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: Estimates normal vector using CGAL Jet Fitting and Monge Form.
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: Estimates Mean curvature using CGAL Jet Fitting and Monge Form.
int main(int argc, char **argv)
DGtal is the top-level namespace which contains all DGtal functions and types.
MyPointD Point
Definition: testClone2.cpp:383
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....
KSpace K
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...