DGtal  0.9.3
Functions
testIntegralInvariantCovarianceEstimator.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/implicit/ImplicitBall.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/topology/LightImplicitDigitalSurface.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/graph/DepthFirstVisitor.h"
#include "DGtal/graph/GraphVisitorRange.h"
#include "DGtal/geometry/surfaces/estimation/IIGeometricFunctors.h"
#include "DGtal/geometry/surfaces/estimation/IntegralInvariantCovarianceEstimator.h"
Include dependency graph for testIntegralInvariantCovarianceEstimator.cpp:

Go to the source code of this file.

Functions

bool testGaussianCurvature3d (double h, double delta)
 
bool testPrincipalCurvatures3d (double h)
 
int main (int, char **)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Jérémy Levallois (jerem.nosp@m.y.le.nosp@m.vallo.nosp@m.is@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), INSA-Lyon, France LAboratoire de MAthématiques - LAMA (CNRS, UMR 5127), Université de Savoie, France
Date
2014/06/26

Functions for testing class IntegralInvariantCovarianceEstimator and IIGeometricFunctor.

This file is part of the DGtal library.

Definition in file testIntegralInvariantCovarianceEstimator.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

Definition at line 257 of file testIntegralInvariantCovarianceEstimator.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::emphase(), DGtal::Trace::endBlock(), testGaussianCurvature3d(), testPrincipalCurvatures3d(), and DGtal::trace.

258 {
259  trace.beginBlock ( "Testing class IntegralInvariantCovarianceEstimator and 3d functors" );
260  bool res = testGaussianCurvature3d( 0.6, 0.007 ) && testPrincipalCurvatures3d( 0.6 );
261  trace.emphase() << ( res ? "Passed." : "Error." ) << std::endl;
262  trace.endBlock();
263  return res ? 0 : 1;
264 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
double endBlock()
std::ostream & emphase()
bool testGaussianCurvature3d(double h, double delta)
bool testPrincipalCurvatures3d(double h)

◆ testGaussianCurvature3d()

bool testGaussianCurvature3d ( double  h,
double  delta 
)

Definition at line 59 of file testIntegralInvariantCovarianceEstimator.cpp.

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getLowerBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getUpperBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), K, DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

60 {
66  typedef GraphVisitorRange< Visitor > VisitorRange;
67  typedef VisitorRange::ConstIterator VisitorConstIterator;
68 
69  typedef functors::IIGaussianCurvature3DFunctor<Z3i::Space> MyIICurvatureFunctor;
72 
73  double re = 5.0;
74  double radius = 5.0;
75  double realValue = 1.0/(radius * radius);
76 
77  trace.beginBlock( "Shape initialisation ..." );
78 
79  ImplicitShape ishape( Z3i::RealPoint( 0, 0, 0 ), radius );
80  DigitalShape dshape;
81  dshape.attach( ishape );
82  dshape.init( Z3i::RealPoint( -10.0, -10.0, -10.0 ), Z3i::RealPoint( 10.0, 10.0, 10.0 ), h );
83 
84  Z3i::KSpace K;
85  if ( !K.init( dshape.getLowerBound(), dshape.getUpperBound(), true ) )
86  {
87  trace.error() << "Problem with Khalimsky space" << std::endl;
88  return false;
89  }
90 
91  Z3i::KSpace::Surfel bel = Surfaces<Z3i::KSpace>::findABel( K, dshape, 10000 );
92  Boundary boundary( K, dshape, SurfelAdjacency<Z3i::KSpace::dimension>( true ), bel );
93  MyDigitalSurface surf ( boundary );
94 
95  trace.endBlock();
96 
97  trace.beginBlock( "Curvature estimator initialisation ...");
98 
99  VisitorRange range( new Visitor( surf, *surf.begin() ));
100  VisitorConstIterator ibegin = range.begin();
101  VisitorConstIterator iend = range.end();
102 
103  MyIICurvatureFunctor curvatureFunctor;
104  curvatureFunctor.init( h, re );
105 
106  MyIICurvatureEstimator curvatureEstimator( curvatureFunctor );
107  curvatureEstimator.attach( K, dshape );
108  curvatureEstimator.setParams( re/h );
109  curvatureEstimator.init( h, ibegin, iend );
110 
111  trace.endBlock();
112 
113  trace.beginBlock( "Curvature estimator evaluation ...");
114 
115  std::vector< Value > results;
116  std::back_insert_iterator< std::vector< Value > > resultsIt( results );
117  curvatureEstimator.eval( ibegin, iend, resultsIt );
118 
119  trace.endBlock();
120 
121  trace.beginBlock ( "Comparing results of integral invariant 3D Gaussian curvature ..." );
122 
123  double mean = 0.0;
124  unsigned int rsize = results.size();
125 
126  if( rsize == 0 )
127  {
128  trace.error() << "ERROR: surface is empty" << std::endl;
129  trace.endBlock();
130  return false;
131  }
132 
133  for ( unsigned int i = 0; i < rsize; ++i )
134  {
135  mean += results[ i ];
136  }
137  mean /= rsize;
138 
139  if( mean != mean ) //NaN
140  {
141  trace.error() << "ERROR: result is NaN" << std::endl;
142  trace.endBlock();
143  return false;
144  }
145 
146  double v = std::abs ( realValue - mean );
147 
148  trace.warning() << "True value: " << realValue << std::endl;
149  trace.warning() << "Mean value: " << mean << std::endl;
150  trace.warning() << "Delta: " << delta << " |true - mean|: " << v << std::endl;
151 
152  if( v > delta )
153  {
154  trace.endBlock();
155  return false;
156  }
157  trace.endBlock();
158  return true;
159 }
void beginBlock(const std::string &keyword="")
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
MyDigitalSurface::ConstIterator ConstIterator
const Point & getLowerBound() const
Trace trace
Definition: Common.h:137
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
const Point & getUpperBound() const
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
BreadthFirstVisitor< MyDigitalSurface > Visitor
Aim: This class implement an Integral Invariant estimator which computes for each surfel the covarian...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
void attach(const EuclideanShape &shape)
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
bool init(const Point &lower, const Point &upper, bool isClosed)
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD...
Definition: ImplicitBall.h:64
Aim: Transforms a graph visitor into a single pass input range.
std::ostream & warning()
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
KSpace K
std::ostream & error()
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface
Aim: A functor Matrix -> Real that returns the Gaussian curvature by diagonalizing the given covarian...

◆ testPrincipalCurvatures3d()

bool testPrincipalCurvatures3d ( double  h)

Definition at line 161 of file testIntegralInvariantCovarianceEstimator.cpp.

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::DigitalSurface< TDigitalSurfaceContainer >::begin(), DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), DGtal::Trace::error(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getLowerBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getUpperBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), K, DGtal::trace, and DGtal::Trace::warning().

Referenced by main().

162 {
168  typedef GraphVisitorRange< Visitor > VisitorRange;
169  typedef VisitorRange::ConstIterator VisitorConstIterator;
170 
171  typedef functors::IIPrincipalCurvatures3DFunctor<Z3i::Space> MyIICurvatureFunctor;
174 
175  double re = 5.0;
176  double radius = 5.0;
177 
178  trace.beginBlock( "Shape initialisation ..." );
179 
180  ImplicitShape ishape( Z3i::RealPoint( 0, 0, 0 ), radius );
181  DigitalShape dshape;
182  dshape.attach( ishape );
183  dshape.init( Z3i::RealPoint( -10.0, -10.0, -10.0 ), Z3i::RealPoint( 10.0, 10.0, 10.0 ), h );
184 
185  Z3i::KSpace K;
186  if ( !K.init( dshape.getLowerBound(), dshape.getUpperBound(), true ) )
187  {
188  trace.error() << "Problem with Khalimsky space" << std::endl;
189  return false;
190  }
191 
192  Z3i::KSpace::Surfel bel = Surfaces<Z3i::KSpace>::findABel( K, dshape, 10000 );
193  Boundary boundary( K, dshape, SurfelAdjacency<Z3i::KSpace::dimension>( true ), bel );
194  MyDigitalSurface surf ( boundary );
195 
196  trace.endBlock();
197 
198  trace.beginBlock( "Curvature estimator initialisation ...");
199 
200  VisitorRange range( new Visitor( surf, *surf.begin() ));
201  VisitorConstIterator ibegin = range.begin();
202  VisitorConstIterator iend = range.end();
203 
204  MyIICurvatureFunctor curvatureFunctor;
205  curvatureFunctor.init( h, re );
206 
207  MyIICurvatureEstimator curvatureEstimator( curvatureFunctor );
208  curvatureEstimator.attach( K, dshape );
209  curvatureEstimator.setParams( re/h );
210  curvatureEstimator.init( h, ibegin, iend );
211 
212  trace.endBlock();
213 
214  trace.beginBlock( "Curvature estimator evaluation ...");
215 
216  std::vector< Value > results;
217  std::back_insert_iterator< std::vector< Value > > resultsIt( results );
218  curvatureEstimator.eval( ibegin, iend, resultsIt );
219 
220  trace.endBlock();
221 
222  trace.beginBlock ( "Comparing results of integral invariant 3D Gaussian curvature ..." );
223 
224  unsigned int error_order = 0;
225  unsigned int rsize = results.size();
226 
227  if( rsize == 0 )
228  {
229  trace.error() << "ERROR: surface is empty" << std::endl;
230  trace.endBlock();
231  return false;
232  }
233 
234  for ( unsigned int i = 0; i < rsize; ++i )
235  {
236  if( std::abs(results[i].first) < std::abs(results[i].second) )
237  {
238  ++error_order;
239  }
240  }
241 
242  trace.warning() << "Error order: " << error_order << std::endl;
243  trace.warning() << "If not equals to 0, something is wrong..." << std::endl;
244 
245  trace.endBlock();
246 
247  if( error_order != 0 )
248  {
249  return false;
250  }
251  return true;
252 }
void beginBlock(const std::string &keyword="")
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as the boundary of an impl...
MyDigitalSurface::ConstIterator ConstIterator
const Point & getLowerBound() const
Trace trace
Definition: Common.h:137
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
const Point & getUpperBound() const
Aim: This class is useful to perform a depth-first exploration of a graph given a starting point or s...
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
double endBlock()
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
BreadthFirstVisitor< MyDigitalSurface > Visitor
Aim: This class implement an Integral Invariant estimator which computes for each surfel the covarian...
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
void attach(const EuclideanShape &shape)
Aim: A functor Matrix -> std::pair<Real,Real> that returns the first and the second principal curvatu...
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
bool init(const Point &lower, const Point &upper, bool isClosed)
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Aim: model of CEuclideanOrientedShape concepts to create a shape from a polynomial.
Aim: model of CEuclideanOrientedShape and CEuclideanBoundedShape concepts to create a ball in nD...
Definition: ImplicitBall.h:64
Aim: Transforms a graph visitor into a single pass input range.
std::ostream & warning()
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
KSpace K
std::ostream & error()
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
DigitalSurface< MyDigitalSurfaceContainer > MyDigitalSurface