DGtal  1.1.0
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
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 
DGtal::GaussDigitizer
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Definition: GaussDigitizer.h:80
Flower
Flower2D< Space > Flower
Definition: testShapeMoveCenter.cpp:60
DGtal::GridCurve::initFromVector
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
DGtal::SimpleRandomAccessRangeFromPoint::c
Circulator c()
Definition: SimpleRandomAccessRangeFromPoint.h:358
DGtal::GaussDigitizer::getUpperBound
const Point & getUpperBound() const
DGtal::ConstRangeAdapter
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
Definition: ConstRangeAdapter.h:87
DGtal::SurfelAdjacency
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Definition: SurfelAdjacency.h:66
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::trace
Trace trace
Definition: Common.h:150
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
DGtal::GridCurve
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:173
DGtal::TrueGlobalEstimatorOnPoints
Aim: Computes the true quantity associated to a parametric shape or to a subrange associated to a par...
Definition: TrueGlobalEstimatorOnPoints.h:72
LibBoard::Board::clear
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:209
DGtal::GaussDigitizer::init
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
DGtal::Trace::info
std::ostream & info()
DGtal::Surfaces::findABel
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::SimpleRandomAccessRangeFromPoint
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Definition: SimpleRandomAccessRangeFromPoint.h:74
DGtal::DSSLengthEstimator
Aim: a model of CGlobalCurveEstimator that segments the digital curve into DSS and computes the lengt...
Definition: DSSLengthEstimator.h:77
DGtal::Surfaces::track2DBoundaryPoints
static void track2DBoundaryPoints(std::vector< Point > &aVectorOfPoints, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
DGtal::ParametricShapeArcLengthFunctor
Aim: implements a functor that estimates the arc length of a paramtric curve.
Definition: ParametricShapeArcLengthFunctor.h:65
DGtal::SimpleRandomAccessRangeFromPoint::ConstCirculator
DGtal::Circulator< ConstIterator > ConstCirculator
Definition: SimpleRandomAccessRangeFromPoint.h:98
Range
Image::Range Range
Definition: testSimpleRandomAccessRangeFromPoint.cpp:46
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::DSSLengthEstimator::eval
Quantity eval(const ConstIterator &itb, const ConstIterator &ite, const double h=1.) const
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:805
DGtal::PointVector< dim, Integer >
DGtal::Flower2D
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:65
DGtal::GaussDigitizer::getLowerBound
const Point & getLowerBound() const
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:394