DGtal  0.9.3
Functions
testEstimatorComparator.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/shapes/ShapeFactory.h"
#include "DGtal/geometry/curves/estimation/TrueLocalEstimatorOnPoints.h"
#include "DGtal/geometry/curves/estimation/ParametricShapeCurvatureFunctor.h"
#include "DGtal/geometry/curves/estimation/ParametricShapeTangentFunctor.h"
#include "DGtal/geometry/curves/estimation/ParametricShapeArcLengthFunctor.h"
#include "DGtal/geometry/curves/estimation/MostCenteredMaximalSegmentEstimator.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/kernel/sets/DigitalSetSelector.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/topology/SurfelAdjacency.h"
#include "DGtal/topology/SurfelNeighborhood.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/geometry/curves/estimation/CompareLocalEstimators.h"
#include "ConfigTest.h"
Include dependency graph for testEstimatorComparator.cpp:

Go to the source code of this file.

Functions

template<typename Shape >
bool testCompareEstimator (const std::string &name, Shape &aShape, double h)
 
int main (int argc, char **argv)
 

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
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Jacques-Olivier Lachaud (jacqu.nosp@m.es-o.nosp@m.livie.nosp@m.r.la.nosp@m.chaud.nosp@m.@uni.nosp@m.v-sav.nosp@m.oie..nosp@m.fr ) Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
Date
2011/06/30

Functions for testing class TrueLocalEstimator.

This file is part of the DGtal library.

Definition in file testEstimatorComparator.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 199 of file testEstimatorComparator.cpp.

References DGtal::Trace::beginBlock(), DGtal::Trace::info(), and DGtal::trace.

200 {
201  trace.beginBlock ( "Testing class CompareLocalEstimator" );
202  trace.info() << "Args:";
203  for ( int i = 0; i < argc; ++i )
204  trace.info() << " " << argv[ i ];
205  trace.info() << endl;
206 
207  typedef Flower2D< Z2i::Space > MyFlower;
208  MyFlower flower( 0.5, -2.3, 5.0, 0.7, 6, 0.3 );
209  bool res = testCompareEstimator<MyFlower>("Flower", flower, 0.25);
210  return res ? 0 : 1;
211 
212 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
std::ostream & info()

◆ testCompareEstimator()

template<typename Shape >
bool testCompareEstimator ( const std::string &  name,
Shape &  aShape,
double  h 
)

Definition at line 69 of file testEstimatorComparator.cpp.

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::begin(), DGtal::Trace::beginBlock(), compare(), domain(), DGtal::Trace::emphase(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::end(), DGtal::Trace::endBlock(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getDomain(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getLowerBound(), DGtal::GridCurve< TKSpace >::getPointsRange(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getUpperBound(), DGtal::Trace::info(), DGtal::TrueLocalEstimatorOnPoints< TConstIteratorOnPoints, TParametricShape, TParametricShapeFunctor >::init(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), DGtal::GridCurve< TKSpace >::initFromVector(), K, and DGtal::trace.

70 {
71  using namespace Z2i;
72 
73  trace.beginBlock ( ( "Testing CompareEstimator on digitization of "
74  + name ). c_str() );
75 
76  // Creates a digitizer on the window (xLow, xUp).
78  RealPoint xLow( -10.0, -10.0 );
79  RealPoint xUp( 10.0, 10.0 );
81  dig.attach( aShape ); // attaches the shape.
82  dig.init( xLow, xUp, h );
83 
84  // The domain size is given by the digitizer according to the window
85  // and the step.
86  Domain domain = dig.getDomain();
87 
88  // Create cellular space
89  KSpace K;
90  bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
91  if ( ! ok )
92  {
93  std::cerr << "[testCompareEstimators]"
94  << " error in creating KSpace." << std::endl;
95  }
96  else
97  try {
98  // Extracts shape boundary
100  SCell bel = Surfaces<KSpace>::findABel( K, dig, 10000 );
101  // Getting the consecutive surfels of the 2D boundary
102  std::vector<Point> points;
103  Surfaces<KSpace>::track2DBoundaryPoints( points, K, SAdj, dig, bel );
104  // Create GridCurve
105  GridCurve<KSpace> gridcurve;
106  gridcurve.initFromVector( points );
107  typedef GridCurve<KhalimskySpaceND<2> >::PointsRange Range;
108  typedef Range::ConstIterator ConstIteratorOnPoints;
109  Range r = gridcurve.getPointsRange();//building range
110 
111  unsigned int nb = 0;
112  unsigned int nbok = 0;
113  //curvature
116  TrueCurvature curvatureEstimator;
117  TrueCurvature curvatureEstimatorBis;
118  curvatureEstimator.init( h, r.begin(), r.end() );
119  curvatureEstimator.attach( &aShape );
120  curvatureEstimatorBis.init( h, r.begin(), r.end() );
121  curvatureEstimatorBis.attach( &aShape );
122 
124 
125  trace.info()<< "True curvature comparison at "<< *r.begin() << " = "
126  << Comparator::compare(curvatureEstimator,curvatureEstimatorBis, r.begin())
127  << std::endl;
128 
129  typename Comparator::OutputStatistic error
130  =Comparator::compare(curvatureEstimator, curvatureEstimatorBis,
131  r.begin(),
132  r.end());
133 
134  trace.info() << "Nb samples= "<< error.samples()<<std::endl;
135  trace.info() << "Error mean= "<< error.mean()<<std::endl;
136  trace.info() << "Error max= "<< error.max()<<std::endl;
137  nbok += ( ( ( (unsigned int)error.samples() ) == r.size())
138  && (error.max() == 0) )
139  ? 1 : 0;
140  nb++;
141  trace.info() << nbok << "/" << nb << std::endl;
142 
143  //tangents
146 
148  SegmentComputer;
151  MSTangentEstimator;
152 
153  SegmentComputer sc;
154  Functor f;
155 
156  TrueTangent tang1;
157  MSTangentEstimator tang2(sc, f);
158 
159  tang1.init( h, r.begin(), r.end() );
160  tang1.attach( &aShape );
161  tang2.init( h, r.begin(), r.end() );
162 
164 
165  trace.info()<< "Tangent comparison at "<< *r.begin() << " = "
166  << ComparatorTan::compareVectors( tang1, tang2, r.begin())
167  << std::endl;
168 
169  typename ComparatorTan::OutputVectorStatistic error2
170  =ComparatorTan::compareVectors(tang1, tang2,
171  r.begin(),
172  r.end());
173 
174  trace.info()<< "Nb samples= "<< error2.samples()<<std::endl;
175  trace.info()<< "Error mean= "<< error2.mean()<<std::endl;
176  trace.info()<< "Error max= "<< error2.max()<<std::endl;
177  nbok += (error.samples() == r.size())?1:0;
178  nb++;
179  trace.info() << nbok << "/" << nb << std::endl;
180  ok += (nb == nbok);
181 
182  }
183  catch ( InputException e )
184  {
185  std::cerr << "[testCompareEstimator]"
186  << " error in finding a bel." << std::endl;
187  ok = false;
188  }
189  trace.emphase() << ( ok ? "Passed." : "Error." ) << endl;
190  trace.endBlock();
191  return ok;
192 
193 }
void beginBlock(const std::string &keyword="")
InHalfPlaneBySimple3x3Matrix< Point, double > Functor
const Domain domain(Point(1, 2), Point(6, 5))
Aim: Functor to compare two local geometric estimators.
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
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
Aim: A model of CLocalCurveGeometricEstimator that assigns to each element of a (sub)range a quantity...
double endBlock()
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
void attach(const EuclideanShape &shape)
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
PointsRange getPointsRange() const
Definition: GridCurve.h:426
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
MessageStream error
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
void init(const double h, const ConstIterator &itb, const ConstIterator &ite)
std::ostream & emphase()
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: Computes the true quantity to each element of a range associated to a parametric shape...
std::ostream & info()
Aim: implements a functor that computes the tangent vector at a given point of a parametric shape...
Space::RealPoint RealPoint
Definition: StdDefs.h:97
KSpace K
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:172
Domain getDomain() const
bool compare(const Range1 &pts, const Range2 &groundTruth)
Definition: testFP.cpp:98
Aim: implements a functor that computes the curvature at a given point of a parametric shape...