DGtal  1.4.2
testMonge.cpp
1 
31 #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/LpMetric.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 
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;
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;
121  typedef LpMetric<Space> L2Metric;
127 
128  CanonicSCellEmbedder<KSpace> embedder(surface.container().space());
129  FunctorGaussian estimatorK(embedder,1);
130  FunctorPrincipalCurvatures estimatork1k2(embedder,1);
131  FunctorMean estimatorH(embedder, 1);
132  FunctorNormal estimatorN(embedder,1);
133  FunctorNormalLeast estimatorL(embedder,1);
134 
135  ConvFunctor convFunc(1.0);
136  ReporterK reporterK;
137  Reporterk1k2 reporterk1k2;
138  ReporterH reporterH;
139  ReporterNormal reporterN;
140  ReporterNormalLeast reporterL;
141 
142  reporterK.attach(surface);
143  reporterk1k2.attach(surface);
144  reporterH.attach(surface);
145  reporterN.attach(surface);
146  reporterL.attach(surface);
147 
148  reporterK.init(1, surface.begin(), surface.end());
149  reporterk1k2.init(1, surface.begin(), surface.end());
150  reporterH.init(1, surface.begin(), surface.end());
151  reporterN.init(1, surface.begin(), surface.end());
152  reporterL.init(1, surface.begin(), surface.end());
153 
154  L2Metric l2(2.0);
155  reporterK.setParams(l2, estimatorK, convFunc, 5.0);
156  reporterk1k2.setParams(l2, estimatork1k2, convFunc, 5.0);
157  reporterH.setParams(l2, estimatorH, convFunc, 5.0);
158  reporterN.setParams(l2, estimatorN, convFunc, 5.0);
159  reporterL.setParams(l2, estimatorL, convFunc, 5.0);
160 
161  FunctorGaussian::Quantity valK = reporterK.eval( surface.begin());
162  FunctorPrincipalCurvatures::Quantity valk1k2 = reporterk1k2.eval( surface.begin());
163  FunctorMean::Quantity valH = reporterH.eval( surface.begin());
164  FunctorNormal::Quantity valN = reporterN.eval( surface.begin());
165  FunctorNormalLeast::Quantity valL = reporterL.eval( surface.begin());
166 
167 
168  trace.info() << "Gaussian = "<<valK <<std::endl;
169  trace.info() << "k1 = " << valk1k2.first << " , k2 = " << valk1k2.second <<std::endl;
170  trace.info() << "Mean = "<<valH<< std::endl;
171  trace.info() << "Normal Vector (from Monge form) = "<<valN<< std::endl;
172  trace.info() << "Normal Vector (linear least square) = "<<valL<< std::endl;
173 
174  trace.endBlock();
175  trace.endBlock();
176 
177  nbok += true ? 1 : 0;
178  nb++;
179  trace.info() << "(" << nbok << "/" << nb << ") "
180  << "true == true" << std::endl;
181 
182  return nbok == nb;
183 }
184 
186 // Standard services - public :
187 
188 int main( int argc, char** argv )
189 {
190  trace.beginBlock ( "Testing class LocalEstimatorFromFunctorAdapter" );
191  trace.info() << "Args:";
192  for ( int i = 0; i < argc; ++i )
193  trace.info() << " " << argv[ i ];
194  trace.info() << endl;
195 
196  bool res = testLocalEstimatorFromFunctorAdapter(); // && ... other tests
197  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
198  trace.endBlock();
199  return res ? 0 : 1;
200 }
201 // //
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
DigitalSurfaceContainer::Surfel Surfel
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
Aim: this class adapts any local functor on digital surface element to define a local estimator....
Aim: implements l_p metrics.
Definition: LpMetric.h:75
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:79
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
Aim: Define a simple functor that returns a constant value (0 by default).
Aim: Estimates normal vector using CGAL linear least squares plane fitting.
Aim: Estimates Gaussian curvature using CGAL Jet Fitting and Monge Form.
Aim: Estimates Mean curvature using CGAL Jet Fitting and Monge Form.
Aim: Estimates normal vector using CGAL Jet Fitting and Monge Form.
Aim: Estimates Gaussian curvature using CGAL Jet Fitting and Monge Form.
CountedPtr< SH3::DigitalSurface > surface
SH3::DigitalSurface Surface
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
int main(int argc, char **argv)
MyPointD Point
Definition: testClone2.cpp:383
KSpace K
bool testLocalEstimatorFromFunctorAdapter()