DGtal  0.9.2
testMonge.cpp
1 
30 #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 #include "DGtal/shapes/Shapes.h"
40 #include "DGtal/topology/CanonicSCellEmbedder.h"
41 #include "DGtal/graph/DistanceBreadthFirstVisitor.h"
42 #include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
43 #include "DGtal/geometry/surfaces/estimation/LocalEstimatorFromSurfelFunctorAdapter.h"
44 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/BasicEstimatorFromSurfelsFunctors.h"
45 #include "DGtal/topology/LightImplicitDigitalSurface.h"
46 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingPrincipalCurvaturesEstimator.h"
47 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingGaussianCurvatureEstimator.h"
48 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingMeanCurvatureEstimator.h"
49 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/MongeJetFittingNormalVectorEstimator.h"
50 #include "DGtal/geometry/surfaces/estimation/estimationFunctors/LinearLeastSquareFittingNormalVectorEstimator.h"
52 
53 using namespace std;
54 using namespace DGtal;
55 
57 // Functions for testing class LocalEstimatorFromFunctorAdapter.
59 
60 template <typename TPoint3>
61 struct ImplicitDigitalEllipse3 {
62  typedef TPoint3 Point;
63  inline
64  ImplicitDigitalEllipse3( double a, double b, double c )
65  : myA( a ), myB( b ), myC( c )
66  {}
67  inline
68  bool operator()( const TPoint3 & p ) const
69  {
70  double x = ( (double) p[ 0 ] / myA );
71  double y = ( (double) p[ 1 ] / myB );
72  double z = ( (double) p[ 2 ] / myC );
73  return ( x*x + y*y + z*z ) <= 1.0;
74  }
75  double myA, myB, myC;
76 };
77 
78 
83 bool testLocalEstimatorFromFunctorAdapter()
84 {
85  unsigned int nbok = 0;
86  unsigned int nb = 0;
87  trace.beginBlock ( "Testing init ..." );
88 
89  using namespace Z3i;
90  typedef ImplicitDigitalEllipse3<Point> ImplicitDigitalEllipse;
92  typedef DigitalSurface<SurfaceContainer> Surface;
93  //typedef Surface::SurfelConstIterator ConstIterator;
94  //typedef Surface::Tracker Tracker;
95  typedef Surface::Surfel Surfel;
96 
97 
98  trace.beginBlock("Creating Surface");
99  Point p1( -10, -10, -10 );
100  Point p2( 10, 10, 10 );
101  KSpace K;
102  nbok += K.init( p1, p2, true ) ? 1 : 0;
103  nb++;
104  trace.info() << "(" << nbok << "/" << nb << ") "
105  << "K.init() is ok" << std::endl;
106  ImplicitDigitalEllipse ellipse( 6.0, 4.5, 3.4 );
107  Surfel bel = Surfaces<KSpace>::findABel( K, ellipse, 10000 );
108  SurfaceContainer* surfaceContainer = new SurfaceContainer
109  ( K, ellipse, SurfelAdjacency<KSpace::dimension>( true ), bel );
110  Surface surface( surfaceContainer ); // acquired
111  trace.endBlock();
112 
113  trace.beginBlock("Creating adapters");
119 
120  typedef functors::ConstValue< double > ConvFunctor;
126 
127  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
128  FunctorGaussian estimatorK(embedder,1);
129  FunctorPrincipalCurvatures estimatork1k2(embedder,1);
130  FunctorMean estimatorH(embedder, 1);
131  FunctorNormal estimatorN(embedder,1);
132  FunctorNormalLeast estimatorL(embedder,1);
133 
134  ConvFunctor convFunc(1.0);
135  ReporterK reporterK;
136  Reporterk1k2 reporterk1k2;
137  ReporterH reporterH;
138  ReporterNormal reporterN;
139  ReporterNormalLeast reporterL;
140 
141  reporterK.attach(surface);
142  reporterk1k2.attach(surface);
143  reporterH.attach(surface);
144  reporterN.attach(surface);
145  reporterL.attach(surface);
146 
147  reporterK.init(1, surface.begin(), surface.end());
148  reporterk1k2.init(1, surface.begin(), surface.end());
149  reporterH.init(1, surface.begin(), surface.end());
150  reporterN.init(1, surface.begin(), surface.end());
151  reporterL.init(1, surface.begin(), surface.end());
152 
153  reporterK.setParams(l2Metric, estimatorK, convFunc, 5.0);
154  reporterk1k2.setParams(l2Metric, estimatork1k2, convFunc, 5.0);
155  reporterH.setParams(l2Metric, estimatorH, convFunc, 5.0);
156  reporterN.setParams(l2Metric, estimatorN, convFunc, 5.0);
157  reporterL.setParams(l2Metric, estimatorL, convFunc, 5.0);
158 
159  FunctorGaussian::Quantity valK = reporterK.eval( surface.begin());
160  FunctorPrincipalCurvatures::Quantity valk1k2 = reporterk1k2.eval( surface.begin());
161  FunctorMean::Quantity valH = reporterH.eval( surface.begin());
162  FunctorNormal::Quantity valN = reporterN.eval( surface.begin());
163  FunctorNormalLeast::Quantity valL = reporterL.eval( surface.begin());
164 
165 
166  trace.info() << "Gaussian = "<<valK <<std::endl;
167  trace.info() << "k1 = " << valk1k2.first << " , k2 = " << valk1k2.second <<std::endl;
168  trace.info() << "Mean = "<<valH<< std::endl;
169  trace.info() << "Normal Vector (from Monge form) = "<<valN<< std::endl;
170  trace.info() << "Normal Vector (linear least square) = "<<valL<< std::endl;
171 
172  trace.endBlock();
173  trace.endBlock();
174 
175  nbok += true ? 1 : 0;
176  nb++;
177  trace.info() << "(" << nbok << "/" << nb << ") "
178  << "true == true" << std::endl;
179 
180  return nbok == nb;
181 }
182 
184 // Standard services - public :
185 
186 int main( int argc, char** argv )
187 {
188  trace.beginBlock ( "Testing class LocalEstimatorFromFunctorAdapter" );
189  trace.info() << "Args:";
190  for ( int i = 0; i < argc; ++i )
191  trace.info() << " " << argv[ i ];
192  trace.info() << endl;
193 
194  bool res = testLocalEstimatorFromFunctorAdapter(); // && ... other tests
195  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
196  trace.endBlock();
197  return res ? 0 : 1;
198 }
199 // //
void beginBlock(const std::string &keyword="")
Aim: Define a simple functor that returns a constant value (0 by default).
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.
double endBlock()
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.
std::ostream & emphase()
Aim: Estimates Mean curvature using CGAL Jet Fitting and Monge Form.
Aim: Estimates Gaussian 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...