34 #include "DGtal/base/Common.h"
36 #include "DGtal/shapes/Shapes.h"
37 #include "DGtal/shapes/ShapeFactory.h"
39 #include "DGtal/geometry/curves/estimation/TrueLocalEstimatorOnPoints.h"
40 #include "DGtal/geometry/curves/estimation/TrueGlobalEstimatorOnPoints.h"
42 #include "DGtal/geometry/curves/estimation/ParametricShapeCurvatureFunctor.h"
43 #include "DGtal/geometry/curves/estimation/ParametricShapeTangentFunctor.h"
44 #include "DGtal/geometry/curves/estimation/ParametricShapeArcLengthFunctor.h"
45 #include "DGtal/geometry/curves/estimation/MostCenteredMaximalSegmentEstimator.h"
46 #include "DGtal/geometry/curves/ArithmeticalDSS.h"
48 #include "DGtal/kernel/SpaceND.h"
49 #include "DGtal/kernel/domains/HyperRectDomain.h"
50 #include "DGtal/kernel/sets/DigitalSetSelector.h"
51 #include "DGtal/topology/KhalimskySpaceND.h"
52 #include "DGtal/topology/SurfelAdjacency.h"
53 #include "DGtal/topology/SurfelNeighborhood.h"
55 #include "DGtal/shapes/GaussDigitizer.h"
56 #include "DGtal/geometry/curves/GridCurve.h"
58 #include "DGtal/geometry/curves/estimation/CompareLocalEstimators.h"
61 #include "ConfigTest.h"
66 using namespace DGtal;
75 bool testTrueLocalEstimator(
const std::string &filename)
77 trace.
info() <<
"Reading GridCurve " << endl;
79 instream.open (filename.c_str(), ifstream::in);
89 typedef Range::ConstIterator ConstIteratorOnPoints;
102 curvatureEstimator.
attach( &ball );
104 tangentEstimator.
attach( &ball );
107 ConstIteratorOnPoints it = r.
begin();
108 ConstIteratorOnPoints it2 = it+15;
109 lengthEstimator.
init( 1, it, it2, &ball,
true);
112 trace.
info() <<
"Current point = "<<*it<<std::endl;
113 trace.
info() <<
"Current point+15 = "<<*it2<<std::endl;
114 trace.
info() <<
"Eval curvature (begin, h=1) = "<< curvatureEstimator.
eval(it2)<<std::endl;
115 trace.
info() <<
"Eval tangent (begin, h=1) = "<< tangentEstimator.
eval(it2)<<std::endl;
116 trace.
info() <<
"Eval length ( h=1) = "<< lengthEstimator.
eval(it,it2)<<std::endl;
122 template <
typename Shape>
124 testTrueLocalEstimatorOnShapeDigitization(
const string & name,
125 Shape & aShape,
double h )
133 typedef Space::RealPoint RealPoint;
134 RealPoint xLow( -10.0, -10.0 );
135 RealPoint xUp( 10.0, 10.0 );
138 dig.init( xLow, xUp, h );
142 Domain domain = dig.getDomain();
146 bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
149 std::cerr <<
"[testTrueLocalEstimatorOnShapeDigitization]"
150 <<
" error in creating KSpace." << std::endl;
158 std::vector<Point> points;
164 typedef Range::ConstIterator ConstIteratorOnPoints;
169 curvatureEstimator.
attach( &aShape );
170 std::cout <<
"# idx x y kappa" << endl;
172 for ( ConstIteratorOnPoints it = r.
begin(), ite = r.
end();
173 it != ite; ++it, ++i )
176 double kappa = curvatureEstimator.
eval( it );
177 std::cout << i <<
" " << x.at( 0 ) <<
" " << x.at( 1 )
178 <<
" " << kappa << std::endl;
183 std::cerr <<
"[testTrueLocalEstimatorOnShapeDigitization]"
184 <<
" error in finding a bel." << std::endl;
187 trace.
emphase() << ( ok ?
"Passed." :
"Error." ) << endl;
196 int main(
int argc,
char** argv )
200 for (
int i = 0; i < argc; ++i )
206 std::string sinus2D4 = testPath +
"samples/sinus2D4.dat";
208 bool res = testTrueLocalEstimator(sinus2D4);
209 trace.
emphase() << ( res ?
"Passed." :
"Error." ) << endl;
213 MyEllipse ellipse( 1.2, 0.1, 4.0, 3.0, 0.3 );
215 testTrueLocalEstimatorOnShapeDigitization<MyEllipse>
216 (
"Ellipse-4-3-0.3-s1", ellipse, 1 );
218 testTrueLocalEstimatorOnShapeDigitization<MyEllipse>
219 (
"Ellipse-4-3-0.3-s0.5", ellipse, 0.5 );
222 MyFlower flower( 0.5, -2.3, 5.0, 0.7, 6, 0.3 );
224 testTrueLocalEstimatorOnShapeDigitization<MyFlower>
225 (
"Flower-5-0.3-6-0.3-s1", flower, 1 );
227 testTrueLocalEstimatorOnShapeDigitization<MyFlower>
228 (
"Flower-5-0.3-6-0.3-s0.25", flower, 0.25 );