34 #include "DGtal/base/Common.h"
35 #include "DGtal/kernel/SpaceND.h"
36 #include "DGtal/kernel/domains/HyperRectDomain.h"
37 #include "DGtal/kernel/sets/DigitalSetSelector.h"
38 #include "DGtal/topology/KhalimskySpaceND.h"
39 #include "DGtal/topology/SurfelAdjacency.h"
40 #include "DGtal/topology/SurfelNeighborhood.h"
42 #include "DGtal/shapes/Shapes.h"
43 #include "DGtal/shapes/ShapeFactory.h"
44 #include "DGtal/shapes/GaussDigitizer.h"
46 #include "DGtal/geometry/curves/GridCurve.h"
47 #include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
48 #include "DGtal/geometry/curves/estimation/CCurveLocalGeometricEstimator.h"
49 #include "DGtal/geometry/curves/estimation/TrueLocalEstimatorOnPoints.h"
50 #include "DGtal/geometry/curves/estimation/TrueGlobalEstimatorOnPoints.h"
51 #include "DGtal/geometry/curves/estimation/ParametricShapeCurvatureFunctor.h"
52 #include "DGtal/geometry/curves/estimation/ParametricShapeTangentFunctor.h"
53 #include "DGtal/geometry/curves/estimation/ParametricShapeArcLengthFunctor.h"
54 #include "DGtal/geometry/curves/estimation/MostCenteredMaximalSegmentEstimator.h"
55 #include "DGtal/geometry/curves/estimation/CompareLocalEstimators.h"
58 #include "ConfigTest.h"
63 using namespace DGtal;
72 bool testTrueLocalEstimator(
const std::string &filename)
74 trace.
info() <<
"Reading GridCurve " << endl;
76 instream.open (filename.c_str(), ifstream::in);
100 TrueCurvatureEstimator curvatureEstimator;
101 TrueTangentEstimator tangentEstimator;
102 TrueLengthEstimator lengthEstimator;
104 curvatureEstimator.init( 1, r.
begin(), r.
end() );
105 curvatureEstimator.attach( &ball );
106 tangentEstimator.init( 1, r.
begin(), r.
end() );
107 tangentEstimator.attach( &ball );
110 ConstIteratorOnPoints it = r.
begin();
111 ConstIteratorOnPoints it2 = it+15;
112 lengthEstimator.init( 1, it, it2, &ball,
true);
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;
125 template <
typename Shape>
127 testTrueLocalEstimatorOnShapeDigitization(
const string & name,
128 Shape & aShape,
double h )
137 RealPoint xLow( -10.0, -10.0 );
138 RealPoint xUp( 10.0, 10.0 );
141 dig.
init( xLow, xUp, h );
152 std::cerr <<
"[testTrueLocalEstimatorOnShapeDigitization]"
153 <<
" error in creating KSpace." << std::endl;
161 std::vector<Point> points;
172 curvatureEstimator.
attach( &aShape );
173 std::cout <<
"# idx x y kappa" << endl;
175 for ( ConstIteratorOnPoints it = r.
begin(), ite = r.
end();
176 it != ite; ++it, ++i )
179 double kappa = curvatureEstimator.
eval( it );
180 std::cout << i <<
" " << x[ 0 ] <<
" " << x[1]
181 <<
" " << kappa << std::endl;
186 std::cerr <<
"[testTrueLocalEstimatorOnShapeDigitization]"
187 <<
" error in finding a bel." << std::endl;
190 trace.
emphase() << ( ok ?
"Passed." :
"Error." ) << endl;
199 int main(
int argc,
char** argv )
203 for (
int i = 0; i < argc; ++i )
209 std::string sinus2D4 = testPath +
"samples/sinus2D4.dat";
211 bool res = testTrueLocalEstimator(sinus2D4);
212 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
216 MyEllipse ellipse( 1.2, 0.1, 4.0, 3.0, 0.3 );
218 testTrueLocalEstimatorOnShapeDigitization<MyEllipse>
219 (
"Ellipse-4-3-0.3-s1", ellipse, 1 );
221 testTrueLocalEstimatorOnShapeDigitization<MyEllipse>
222 (
"Ellipse-4-3-0.3-s0.5", ellipse, 0.5 );
225 MyFlower flower( 0.5, -2.3, 5.0, 0.7, 6, 0.3 );
227 testTrueLocalEstimatorOnShapeDigitization<MyFlower>
228 (
"Flower-5-0.3-6-0.3-s1", flower, 1 );
230 testTrueLocalEstimatorOnShapeDigitization<MyFlower>
231 (
"Flower-5-0.3-6-0.3-s0.25", flower, 0.25 );
void beginBlock(const std::string &keyword="")
PointsRange getPointsRange() const
const Point & getUpperBound() const
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Quantity eval(const ConstIterator &it) const
KhalimskySpaceND< 2, Integer > KSpace
void attach(ParametricShape *aShapePtr)
Aim: Model of the concept StarShaped represents any ellipse in the plane.
void attach(const EuclideanShape &shape)
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Aim: Model of the concept StarShaped represents any circle in the plane.
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Aim: implements a functor that estimates the arc length of a paramtric curve.
void init(const double h, const ConstIterator &itb, const ConstIterator &ite)
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...
DGtal is the top-level namespace which contains all DGtal functions and types.
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)
const Point & getLowerBound() const
Aim: implements a functor that computes the tangent vector at a given point of a parametric shape...
TConstIterator ConstIterator
Space::RealPoint RealPoint
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
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...