DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
shapeGridCurveEstimator.cpp
1 
31 
32 #include <iostream>
33 #include <fstream>
34 #include <algorithm>
36 
38 #include "DGtal/base/Common.h"
39 #include "DGtal/helpers/StdDefs.h"
40 #include "ConfigExamples.h"
42 
44 //shape and digitizer
45 #include "DGtal/shapes/Shapes.h"
46 #include "DGtal/shapes/ShapeFactory.h"
47 #include "DGtal/shapes/GaussDigitizer.h"
49 
51 //tracking grid curve
52 #include "DGtal/topology/helpers/Surfaces.h"
53 #include "DGtal/geometry/curves/GridCurve.h"
55 
57 //length estimation knowing the shape
58 #include "DGtal/geometry/curves/estimation/TrueGlobalEstimatorOnPoints.h"
59 #include "DGtal/geometry/curves/estimation/ParametricShapeArcLengthFunctor.h"
60 //length estimation based on a DSS segmentation
61 #include "DGtal/geometry/curves/estimation/DSSLengthEstimator.h"
63 
64 #include "DGtal/io/boards/Board2D.h"
65 
67 
68 int main()
69 {
70  //shape
71  typedef Flower2D<Z2i::Space> Flower;
72  Flower2D<Z2i::Space> flower(Z2i::Point(0,0), 20, 5, 5, 0);
73 
75  //implicit digitization of a shape of type Flower
76  //into a digital space of type Space
77  double h = 1;
79  dig.attach( flower );
80  dig.init( flower.getLowerBound()+Z2i::Vector(-1,-1),
81  flower.getUpperBound()+Z2i::Vector(1,1), h );
83 
85  //Khalimsky space
86  Z2i::KSpace ks;
87  ks.init( dig.getLowerBound(), dig.getUpperBound(), true );
88  //adjacency (4-connectivity)
89  SurfelAdjacency<2> sAdj( true );
91 
93  //searching for one boundary element
94  Z2i::SCell bel = Surfaces<Z2i::KSpace>::findABel( ks, dig, 1000 );
95  //tracking
96  vector<Z2i::Point> boundaryPoints;
98  ::track2DBoundaryPoints( boundaryPoints, ks, sAdj, dig, bel );
100 
102  Z2i::Curve c;
103  c.initFromVector( boundaryPoints );
105 
106  DGtal::Board2D aBoard;
107  aBoard << c;
108  aBoard.saveEPS("DisplayGridCurve1.eps");
109 
111  //range of points
113  Range r = c.getPointsRange();
115 
117  //length estimation
119  DSSlength.init( h, r.begin(), r.end(), c.isClosed() );
120  double length1 = DSSlength.eval();
121  trace.info() << "Length (h=" << h << "): " << length1 << endl;
123 
124 //@TODO correct init method of trueLengthEstimator (remove &flower)
128  Range::ConstIterator,
129  Flower,
130  Length > trueLengthEstimator;
131  trueLengthEstimator.init( h, r.begin(), r.end(), &flower, c.isClosed());
132  double trueLength = trueLengthEstimator.eval();
133  trace.info() << "ground truth: " << trueLength << endl;
135 
137  //implicit digitization at higher resolution
138  h = 0.1;
139  dig.init( flower.getLowerBound()+Z2i::Vector(-1,-1),
140  flower.getUpperBound()+Z2i::Vector(1,1), h );
141  //a greater domain is needed in the Khalimsky space
142  ks.init( dig.getLowerBound(), dig.getUpperBound(), true );
143  //searching for one boundary element
144  bel = Surfaces<Z2i::KSpace>::findABel( ks, dig, 10000 );
145  //tracking
147  ::track2DBoundaryPoints( boundaryPoints, ks, sAdj, dig, bel );
148  //reset grid curve and its points range
149  c.initFromVector( boundaryPoints );
150  Range r2 = c.getPointsRange();
151  //estimate length
152  DSSlength.init( h, r2.begin(), r2.end(), c.isClosed() );
153  double length2 = DSSlength.eval();
154  trace.info() << "Length (h=" << h << "): " << length2 << endl;
156 
157  aBoard.clear();
158  aBoard << c;
159  aBoard.saveEPS("DisplayGridCurve01.eps");
160 
161  return 0;
162 
163 }
164