DGtal  1.3.beta
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, const 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 193 of file testEstimatorComparator.cpp.

194 {
195  trace.beginBlock ( "Testing class CompareLocalEstimator" );
196  trace.info() << "Args:";
197  for ( int i = 0; i < argc; ++i )
198  trace.info() << " " << argv[ i ];
199  trace.info() << endl;
200 
201  typedef Flower2D< Z2i::Space > MyFlower;
202  MyFlower flower( 0.5, -2.3, 5.0, 0.7, 6, 0.3 );
203  bool res = testCompareEstimator<MyFlower>("Flower", flower, 0.25);
204  return res ? 0 : 1;
205 
206 }

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

◆ testCompareEstimator()

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

Definition at line 69 of file testEstimatorComparator.cpp.

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.attach( aShape );
119  curvatureEstimatorBis.attach( aShape );
120 
122 
123  trace.info()<< "True curvature comparison at "<< *r.begin() << " = "
124  << Comparator::compare(curvatureEstimator,curvatureEstimatorBis, r.begin(), h)
125  << std::endl;
126 
127  typename Comparator::OutputStatistic error =
128  Comparator::compare(curvatureEstimator, curvatureEstimatorBis,
129  r.begin(), r.end(), h);
130 
131  trace.info() << "Nb samples= "<< error.samples()<<std::endl;
132  trace.info() << "Error mean= "<< error.mean()<<std::endl;
133  trace.info() << "Error max= "<< error.max()<<std::endl;
134  nbok += ( ( ( (unsigned int)error.samples() ) == r.size())
135  && (error.max() == 0) )
136  ? 1 : 0;
137  nb++;
138  trace.info() << nbok << "/" << nb << std::endl;
139 
140  //tangents
143 
148  MSTangentEstimator;
149 
150  SegmentComputer sc;
151  Functor f;
152 
153  TrueTangent tang1;
154  MSTangentEstimator tang2(sc, f);
155 
156  tang1.attach( aShape );
157  tang2.init( r.begin(), r.end() );
158 
160 
161  trace.info()<< "Tangent comparison at "<< *r.begin() << " = "
162  << ComparatorTan::compareVectors( tang1, tang2, r.begin(), h)
163  << std::endl;
164 
165  typename ComparatorTan::OutputVectorStatistic error2
166  = ComparatorTan::compareVectors(tang1, tang2, r.begin(), r.end(), h);
167 
168  trace.info()<< "Nb samples= "<< error2.samples()<<std::endl;
169  trace.info()<< "Error mean= "<< error2.mean()<<std::endl;
170  trace.info()<< "Error max= "<< error2.max()<<std::endl;
171  nbok += (error.samples() == r.size())?1:0;
172  nb++;
173  trace.info() << nbok << "/" << nb << std::endl;
174  ok += (nb == nbok);
175 
176  }
177  catch ( InputException& e )
178  {
179  std::cerr << "[testCompareEstimator]"
180  << " error in finding a bel." << std::endl;
181  ok = false;
182  }
183  trace.emphase() << ( ok ? "Passed." : "Error." ) << endl;
184  trace.endBlock();
185  return ok;
186 
187 }

References DGtal::TrueLocalEstimatorOnPoints< TConstIteratorOnPoints, TParametricShape, TParametricShapeFunctor >::attach(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::Trace::beginBlock(), compare(), domain, DGtal::Trace::emphase(), 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::GaussDigitizer< TSpace, TEuclideanShape >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GridCurve< TKSpace >::initFromVector(), K, and DGtal::trace.

DGtal::GaussDigitizer
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Definition: GaussDigitizer.h:79
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::GaussDigitizer::getDomain
Domain getDomain() const
compare
bool compare(const Range1 &pts, const Range2 &groundTruth)
Definition: testFP.cpp:98
DGtal::GridCurve::initFromVector
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::GaussDigitizer::getUpperBound
const Point & getUpperBound() const
DGtal::ArithmeticalDSSComputer
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Definition: ArithmeticalDSSComputer.h:86
SegmentComputer
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
Definition: testArithmeticalDSSComputerOnSurfels.cpp:55
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::ParametricShapeTangentFunctor
Aim: implements a functor that computes the tangent vector at a given point of a parametric shape.
Definition: ParametricShapeTangentFunctor.h:63
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
K
KSpace K
Definition: testCubicalComplex.cpp:62
DGtal::GridCurve
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:172
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
Functor
InHalfPlaneBySimple3x3Matrix< Point, double > Functor
Definition: testConvexHull2DReverse.cpp:51
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::TrueLocalEstimatorOnPoints
Aim: Computes the true quantity to each element of a range associated to a parametric shape.
Definition: TrueLocalEstimatorOnPoints.h:68
DGtal::GaussDigitizer::init
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
DGtal::MostCenteredMaximalSegmentEstimator
Aim: A model of CLocalCurveGeometricEstimator that assigns to each element of a (sub)range a quantity...
Definition: MostCenteredMaximalSegmentEstimator.h:83
DGtal::Trace::info
std::ostream & info()
DGtal::TrueLocalEstimatorOnPoints::attach
void attach(const ParametricShape &aShape)
DGtal::SimpleRandomAccessRangeFromPoint
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Definition: SimpleRandomAccessRangeFromPoint.h:73
DGtal::TangentFromDSSEstimator
Definition: SegmentComputerEstimators.h:1009
Range
Image::Range Range
Definition: testSimpleRandomAccessRangeFromPoint.cpp:46
LibBoard::error
MessageStream error
DGtal::ParametricShapeCurvatureFunctor
Aim: implements a functor that computes the curvature at a given point of a parametric shape.
Definition: ParametricShapeCurvatureFunctor.h:65
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
DGtal::Flower2D
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
DGtal::CompareLocalEstimators
Aim: Functor to compare two local geometric estimators.
Definition: CompareLocalEstimators.h:66
RealPoint
Z2i::RealPoint RealPoint
Definition: testAstroid2D.cpp:46
DGtal::SimpleRandomAccessRangeFromPoint::ConstIterator
TConstIterator ConstIterator
Definition: SimpleRandomAccessRangeFromPoint.h:87
DGtal::GaussDigitizer::getLowerBound
const Point & getLowerBound() const
DGtal::GridCurve::getPointsRange
PointsRange getPointsRange() const
Definition: GridCurve.h:426
DGtal::InputException
Definition: Exceptions.h:63
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64