DGtal  1.4.2
shapeGridCurveEstimator.cpp
1 
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 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  double length1 = DSSlength.eval(r.c(), r.c(), h);
122  trace.info() << "Length (h=" << h << "): " << length1 << std::endl;
124 
129  Flower,
130  Length > trueLengthEstimator;
131  trueLengthEstimator.attach(flower);
132  // Note: Not equivalent to eval(r.c(), r.c(), h)
133  double trueLength = trueLengthEstimator.eval();
134  trace.info() << "ground truth: " << trueLength << std::endl;
136 
138  //implicit digitization at higher resolution
139  h = 0.1;
140  dig.init( flower.getLowerBound()+Z2i::Vector(-1,-1),
141  flower.getUpperBound()+Z2i::Vector(1,1), h );
142  //a greater domain is needed in the Khalimsky space
143  ks.init( dig.getLowerBound(), dig.getUpperBound(), true );
144  //searching for one boundary element
145  bel = Surfaces<Z2i::KSpace>::findABel( ks, dig, 10000 );
146  //tracking
148  ::track2DBoundaryPoints( boundaryPoints, ks, sAdj, dig, bel );
149  //reset grid curve and its points range
150  c.initFromVector( boundaryPoints );
151  Range r2 = c.getPointsRange();
152  //estimate length
153  double length2 = DSSlength.eval(r2.c(), r2.c(), h);
154  trace.info() << "Length (h=" << h << "): " << length2 << std::endl;
156 
157  aBoard.clear();
158  aBoard << c;
159  aBoard.saveEPS("DisplayGridCurve01.eps");
160 
161  return 0;
162 
163 }
164 
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:86
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Aim: a model of CGlobalCurveEstimator that segments the digital curve into DSS and computes the lengt...
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:65
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
const Point & getLowerBound() const
void attach(ConstAlias< EuclideanShape > shape)
const Point & getUpperBound() const
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: implements a functor that estimates the arc length of a paramtric curve.
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
static void track2DBoundaryPoints(std::vector< Point > &aVectorOfPoints, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
std::ostream & info()
Aim: Computes the true quantity associated to a parametric shape or to a subrange associated to a par...
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:151
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:804
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
int main(int argc, char **argv)