DGtal  1.0.beta
shapeGridCurveEstimator.cpp
1 
31 #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 using namespace DGtal;
69 
70 int main()
71 {
72  //shape
74  //implicit digitization of a shape of type Flower
75  //into a digital space of type Space
76  typedef Flower2D<Z2i::Space> Flower;
77  Flower2D<Z2i::Space> flower(Z2i::Point(0,0), 20, 5, 5, 0);
78 
79  double h = 1;
81  dig.attach( flower );
82  dig.init( flower.getLowerBound()+Z2i::Vector(-1,-1),
83  flower.getUpperBound()+Z2i::Vector(1,1), h );
85 
87  //Khalimsky space
88  Z2i::KSpace ks;
89  ks.init( dig.getLowerBound(), dig.getUpperBound(), true );
90  //adjacency (4-connectivity)
91  SurfelAdjacency<2> sAdj( true );
93 
95  //searching for one boundary element
96  Z2i::SCell bel = Surfaces<Z2i::KSpace>::findABel( ks, dig, 1000 );
97  //tracking
98  std::vector<Z2i::Point> boundaryPoints;
100  ::track2DBoundaryPoints( boundaryPoints, ks, sAdj, dig, bel );
102 
104  Z2i::Curve c;
105  c.initFromVector( boundaryPoints );
107 
108  DGtal::Board2D aBoard;
109  aBoard << c;
110  aBoard.saveEPS("DisplayGridCurve1.eps");
111 
113  //range of points
115  Range r = c.getPointsRange();
117 
119  //length estimation
121  DSSlength.init( h, r.c(), r.c() );
122  double length1 = DSSlength.eval();
123  trace.info() << "Length (h=" << h << "): " << length1 << std::endl;
125 
126 //@TODO correct init method of trueLengthEstimator (remove &flower)
131  Flower,
132  Length > trueLengthEstimator;
133  trueLengthEstimator.init( h, r.begin(), r.end(), &flower, c.isClosed());
134  double trueLength = trueLengthEstimator.eval();
135  trace.info() << "ground truth: " << trueLength << std::endl;
137 
139  //implicit digitization at higher resolution
140  h = 0.1;
141  dig.init( flower.getLowerBound()+Z2i::Vector(-1,-1),
142  flower.getUpperBound()+Z2i::Vector(1,1), h );
143  //a greater domain is needed in the Khalimsky space
144  ks.init( dig.getLowerBound(), dig.getUpperBound(), true );
145  //searching for one boundary element
146  bel = Surfaces<Z2i::KSpace>::findABel( ks, dig, 10000 );
147  //tracking
149  ::track2DBoundaryPoints( boundaryPoints, ks, sAdj, dig, bel );
150  //reset grid curve and its points range
151  c.initFromVector( boundaryPoints );
152  Range r2 = c.getPointsRange();
153  //estimate length
154  DSSlength.init( h, r2.c(), r2.c() );
155  double length2 = DSSlength.eval();
156  trace.info() << "Length (h=" << h << "): " << length2 << std::endl;
158 
159  aBoard.clear();
160  aBoard << c;
161  aBoard.saveEPS("DisplayGridCurve01.eps");
162 
163  return 0;
164 
165 }
166 
const Point & getUpperBound() 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
void attach(ConstAlias< EuclideanShape > shape)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
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.
Quantity eval() const
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...
void init(const double h, const ConstIterator &itb, const ConstIterator &ite)
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
Aim: a model of CGlobalCurveEstimator that segments the digital curve into DSS and computes the lengt...
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...
std::ostream & info()
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value...
const Point & getLowerBound() const
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:172
Space::Vector Vector
Definition: StdDefs.h:96
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Aim: Computes the true quantity to each element of a range associated to a parametric shape...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70