DGtal  0.9.3
Functions
testTrueLocalEstimator.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.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/Shapes.h"
#include "DGtal/shapes/ShapeFactory.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
#include "DGtal/geometry/curves/estimation/CCurveLocalGeometricEstimator.h"
#include "DGtal/geometry/curves/estimation/TrueLocalEstimatorOnPoints.h"
#include "DGtal/geometry/curves/estimation/TrueGlobalEstimatorOnPoints.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/estimation/CompareLocalEstimators.h"
#include "ConfigTest.h"
Include dependency graph for testTrueLocalEstimator.cpp:

Go to the source code of this file.

Functions

bool testTrueLocalEstimator (const std::string &filename)
 
template<typename Shape >
bool testTrueLocalEstimatorOnShapeDigitization (const 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 testTrueLocalEstimator.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 199 of file testTrueLocalEstimator.cpp.

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

200 {
201  trace.beginBlock ( "Testing class TrueLocalEstimator" );
202  trace.info() << "Args:";
203  for ( int i = 0; i < argc; ++i )
204  trace.info() << " " << argv[ i ];
205  trace.info() << endl;
206 
207 
208 
209  std::string sinus2D4 = testPath + "samples/sinus2D4.dat";
210 
211  bool res = testTrueLocalEstimator(sinus2D4); // && ... other tests
212  trace.emphase() << ( res ? "Passed." : "Error." ) << endl;
213  trace.endBlock();
214 
215  typedef Ellipse2D< Z2i::Space > MyEllipse;
216  MyEllipse ellipse( 1.2, 0.1, 4.0, 3.0, 0.3 );
217  res = res &&
218  testTrueLocalEstimatorOnShapeDigitization<MyEllipse>
219  ( "Ellipse-4-3-0.3-s1", ellipse, 1 );
220  res = res &&
221  testTrueLocalEstimatorOnShapeDigitization<MyEllipse>
222  ( "Ellipse-4-3-0.3-s0.5", ellipse, 0.5 );
223 
224  typedef Flower2D< Z2i::Space > MyFlower;
225  MyFlower flower( 0.5, -2.3, 5.0, 0.7, 6, 0.3 );
226  res = res &&
227  testTrueLocalEstimatorOnShapeDigitization<MyFlower>
228  ( "Flower-5-0.3-6-0.3-s1", flower, 1 );
229  res = res &&
230  testTrueLocalEstimatorOnShapeDigitization<MyFlower>
231  ( "Flower-5-0.3-6-0.3-s0.25", flower, 0.25 );
232 
233  return res ? 0 : 1;
234 
235 }
void beginBlock(const std::string &keyword="")
Trace trace
Definition: Common.h:137
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:64
double endBlock()
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
std::ostream & emphase()
bool testTrueLocalEstimator(const std::string &filename)
std::ostream & info()

◆ testTrueLocalEstimator()

bool testTrueLocalEstimator ( const std::string &  filename)

Example of a test. To be completed.

Definition at line 72 of file testTrueLocalEstimator.cpp.

References DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::begin(), DGtal::SimpleRandomAccessRangeFromPoint< TConstIterator, TIterator, DistanceFunctor >::end(), DGtal::GridCurve< TKSpace >::getPointsRange(), DGtal::Trace::info(), DGtal::GridCurve< TKSpace >::initFromVectorStream(), and DGtal::trace.

Referenced by main().

73 {
74  trace.info() << "Reading GridCurve " << endl;
75  ifstream instream; // input stream
76  instream.open (filename.c_str(), ifstream::in);
77  typedef KhalimskySpaceND<2> Kspace; //space
79  c.initFromVectorStream(instream); //building grid curve
81  Range r = c.getPointsRange();//building range
82 
83 
84  typedef Ball2D<Z2i::Space> Shape;
85  typedef GridCurve<KhalimskySpaceND<2> >::PointsRange Range;
86  typedef Range::ConstIterator ConstIteratorOnPoints;
90 
91  Shape ball(Z2i::Point(0,0), 30);
92 
93 
97 
100  TrueCurvatureEstimator curvatureEstimator;
101  TrueTangentEstimator tangentEstimator;
102  TrueLengthEstimator lengthEstimator;
103 
104  curvatureEstimator.init( 1, r.begin(), r.end() );
105  curvatureEstimator.attach( &ball );
106  tangentEstimator.init( 1, r.begin(), r.end() );
107  tangentEstimator.attach( &ball );
108 
109 
110  ConstIteratorOnPoints it = r.begin();
111  ConstIteratorOnPoints it2 = it+15;
112  lengthEstimator.init( 1, it, it2, &ball, true);
113 
114 
115  trace.info() << "Current point = "<<*it<<std::endl;
116  trace.info() << "Current point+15 = "<<*it2<<std::endl;
117  trace.info() << "Eval curvature (begin, h=1) = "<< curvatureEstimator.eval(it2)<<std::endl;
118  trace.info() << "Eval tangent (begin, h=1) = "<< tangentEstimator.eval(it2)<<std::endl;
119  trace.info() << "Eval length ( h=1) = "<< lengthEstimator.eval(it,it2)<<std::endl;
120 
121  return true;
122 
123 }
Trace trace
Definition: Common.h:137
PointsRange getPointsRange() const
Definition: GridCurve.h:426
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition: Ball2D.h:60
Aim: implements a functor that estimates the arc length of a paramtric curve.
Aim: Computes the true quantity to each element of a range associated to a parametric shape...
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Aim: This concept describes an object that can process a range so as to return one estimated quantity...
bool initFromVectorStream(std::istream &in)
std::ostream & info()
Aim: implements a functor that computes the tangent vector at a given point of a parametric shape...
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:172
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Aim: implements a functor that computes the curvature at a given point of a parametric shape...
Aim: Computes the true quantity to each element of a range associated to a parametric shape...

◆ testTrueLocalEstimatorOnShapeDigitization()

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

Definition at line 127 of file testTrueLocalEstimator.cpp.

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

129 {
130  using namespace Z2i;
131 
132  trace.beginBlock ( ( "Testing TrueLocalEstimator on digitization of "
133  + name ). c_str() );
134 
135  // Creates a digitizer on the window (xLow, xUp).
136  typedef Space::RealPoint RealPoint;
137  RealPoint xLow( -10.0, -10.0 );
138  RealPoint xUp( 10.0, 10.0 );
140  dig.attach( aShape ); // attaches the shape.
141  dig.init( xLow, xUp, h );
142 
143  // The domain size is given by the digitizer according to the window
144  // and the step.
145  Domain domain = dig.getDomain();
146 
147  // Create cellular space
148  KSpace K;
149  bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
150  if ( ! ok )
151  {
152  std::cerr << "[testTrueLocalEstimatorOnShapeDigitization]"
153  << " error in creating KSpace." << std::endl;
154  }
155  else
156  try {
157  // Extracts shape boundary
159  SCell bel = Surfaces<KSpace>::findABel( K, dig, 10000 );
160  // Getting the consecutive surfels of the 2D boundary
161  std::vector<Point> points;
162  Surfaces<KSpace>::track2DBoundaryPoints( points, K, SAdj, dig, bel );
163  // Create GridCurve
164  GridCurve<KSpace> gridcurve;
165  gridcurve.initFromVector( points );
166  typedef GridCurve<KhalimskySpaceND<2> >::PointsRange Range;
167  typedef Range::ConstIterator ConstIteratorOnPoints;
170  Range r = gridcurve.getPointsRange();//building range
171  curvatureEstimator.init( h, r.begin(), r.end() );
172  curvatureEstimator.attach( &aShape );
173  std::cout << "# idx x y kappa" << endl;
174  unsigned int i = 0;
175  for ( ConstIteratorOnPoints it = r.begin(), ite = r.end();
176  it != ite; ++it, ++i )
177  {
178  RealPoint x = *it;
179  double kappa = curvatureEstimator.eval( it );
180  std::cout << i << " " << x[ 0 ] << " " << x[1]
181  << " " << kappa << std::endl;
182  }
183  }
184  catch ( InputException e )
185  {
186  std::cerr << "[testTrueLocalEstimatorOnShapeDigitization]"
187  << " error in finding a bel." << std::endl;
188  ok = false;
189  }
190  trace.emphase() << ( ok ? "Passed." : "Error." ) << endl;
191  trace.endBlock();
192  return ok;
193 }
void beginBlock(const std::string &keyword="")
const Domain domain(Point(1, 2), Point(6, 5))
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
void attach(ParametricShape *aShapePtr)
double endBlock()
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
void attach(const EuclideanShape &shape)
PointsRange getPointsRange() const
Definition: GridCurve.h:426
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
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...
Quantity eval(const ConstIterator &it) const
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
Aim: implements a functor that computes the curvature at a given point of a parametric shape...