DGtal 1.4.0
Loading...
Searching...
No Matches
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 192 of file testEstimatorComparator.cpp.

193{
194 trace.beginBlock ( "Testing class CompareLocalEstimator" );
195 trace.info() << "Args:";
196 for ( int i = 0; i < argc; ++i )
197 trace.info() << " " << argv[ i ];
198 trace.info() << endl;
199
200 typedef Flower2D< Z2i::Space > MyFlower;
201 MyFlower flower( 0.5, -2.3, 5.0, 0.7, 6, 0.3 );
202 bool res = testCompareEstimator<MyFlower>("Flower", flower, 0.25);
203 return res ? 0 : 1;
204
205}
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition Flower2D.h:65
void beginBlock(const std::string &keyword="")
std::ostream & info()
Trace trace
Definition Common.h:153
bool testCompareEstimator(const std::string &name, const Shape &aShape, double h)

References DGtal::Trace::beginBlock(), DGtal::Trace::info(), testCompareEstimator(), 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).
77 RealPoint xLow( -10.0, -10.0 );
78 RealPoint xUp( 10.0, 10.0 );
80 dig.attach( aShape ); // attaches the shape.
81 dig.init( xLow, xUp, h );
82
83 // The domain size is given by the digitizer according to the window
84 // and the step.
85 Domain domain = dig.getDomain();
86
87 // Create cellular space
88 KSpace K;
89 bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
90 if ( ! ok )
91 {
92 std::cerr << "[testCompareEstimators]"
93 << " error in creating KSpace." << std::endl;
94 }
95 else
96 try {
97 // Extracts shape boundary
99 SCell bel = Surfaces<KSpace>::findABel( K, dig, 10000 );
100 // Getting the consecutive surfels of the 2D boundary
101 std::vector<Point> points;
102 Surfaces<KSpace>::track2DBoundaryPoints( points, K, SAdj, dig, bel );
103 // Create GridCurve
104 GridCurve<KSpace> gridcurve;
105 gridcurve.initFromVector( points );
106 typedef GridCurve<KhalimskySpaceND<2> >::PointsRange Range;
107 typedef Range::ConstIterator ConstIteratorOnPoints;
108 Range r = gridcurve.getPointsRange();//building range
109
110 unsigned int nb = 0;
111 unsigned int nbok = 0;
112 //curvature
115 TrueCurvature curvatureEstimator;
116 TrueCurvature curvatureEstimatorBis;
117 curvatureEstimator.attach( aShape );
118 curvatureEstimatorBis.attach( aShape );
119
121
122 trace.info()<< "True curvature comparison at "<< *r.begin() << " = "
123 << Comparator::compare(curvatureEstimator,curvatureEstimatorBis, r.begin(), h)
124 << std::endl;
125
126 typename Comparator::OutputStatistic error =
127 Comparator::compare(curvatureEstimator, curvatureEstimatorBis,
128 r.begin(), r.end(), h);
129
130 trace.info() << "Nb samples= "<< error.samples()<<std::endl;
131 trace.info() << "Error mean= "<< error.mean()<<std::endl;
132 trace.info() << "Error max= "<< error.max()<<std::endl;
133 nbok += ( ( ( (unsigned int)error.samples() ) == r.size())
134 && (error.max() == 0) )
135 ? 1 : 0;
136 nb++;
137 trace.info() << nbok << "/" << nb << std::endl;
138
139 //tangents
142
147 MSTangentEstimator;
148
150 Functor f;
151
152 TrueTangent tang1;
153 MSTangentEstimator tang2(sc, f);
154
155 tang1.attach( aShape );
156 tang2.init( r.begin(), r.end() );
157
159
160 trace.info()<< "Tangent comparison at "<< *r.begin() << " = "
161 << ComparatorTan::compareVectors( tang1, tang2, r.begin(), h)
162 << std::endl;
163
164 typename ComparatorTan::OutputVectorStatistic error2
165 = ComparatorTan::compareVectors(tang1, tang2, r.begin(), r.end(), h);
166
167 trace.info()<< "Nb samples= "<< error2.samples()<<std::endl;
168 trace.info()<< "Error mean= "<< error2.mean()<<std::endl;
169 trace.info()<< "Error max= "<< error2.max()<<std::endl;
170 nbok += (error.samples() == r.size())?1:0;
171 nb++;
172 trace.info() << nbok << "/" << nb << std::endl;
173 ok += (nb == nbok);
174
175 }
176 catch ( InputException& e )
177 {
178 std::cerr << "[testCompareEstimator]"
179 << " error in finding a bel." << std::endl;
180 ok = false;
181 }
182 trace.emphase() << ( ok ? "Passed." : "Error." ) << endl;
183 trace.endBlock();
184 return ok;
185
186}
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
const Point & getUpperBound() const
void attach(ConstAlias< EuclideanShape > shape)
const Point & getLowerBound() const
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Domain getDomain() const
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition GridCurve.h:173
PointsRange getPointsRange() const
Definition GridCurve.h:426
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
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 CLocalCurveGeometricEstimator that assigns to each element of a (sub)range a quantity...
Aim: implements a functor that computes the curvature at a given point of a parametric shape.
Aim: implements a functor that computes the tangent vector at a given point of a parametric shape.
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
static void track2DBoundaryPoints(std::vector< Point > &aVectorOfPoints, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
std::ostream & emphase()
double endBlock()
Aim: Computes the true quantity to each element of a range associated to a parametric shape.
void attach(const ParametricShape &aShape)
MessageStream error
Aim: Functor to compare two local geometric estimators.
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
InHalfPlaneBySimple3x3Matrix< Point, double > Functor
KSpace K
Domain domain

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::TrueLocalEstimatorOnPoints< TConstIteratorOnPoints, TParametricShape, TParametricShapeFunctor >::attach(), DGtal::Trace::beginBlock(), domain, DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Surfaces< TKSpace >::findABel(), 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, DGtal::trace, and DGtal::Surfaces< TKSpace >::track2DBoundaryPoints().

Referenced by main().