DGtal 2.1.0
Loading...
Searching...
No Matches
shapeGridCurveEstimator.cpp File Reference

An example of generating a grid curve from a parametric shape and estimating its length. More...

#include <iostream>
#include <fstream>
#include <algorithm>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "ConfigExamples.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/shapes/ShapeFactory.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/geometry/curves/estimation/TrueGlobalEstimatorOnPoints.h"
#include "DGtal/geometry/curves/estimation/ParametricShapeArcLengthFunctor.h"
#include "DGtal/geometry/curves/estimation/DSSLengthEstimator.h"
#include "DGtal/io/boards/Board2D.h"
Include dependency graph for shapeGridCurveEstimator.cpp:

Go to the source code of this file.

Functions

int main ()
 

Detailed Description

An example of generating a grid curve from a parametric shape and estimating its length.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr)
Date
2010/10/17

This file is part of the DGtal library.

Definition in file shapeGridCurveEstimator.cpp.

Function Documentation

◆ main()

int main ( void  )

[shapeGridCurveEstimator-dig]

[shapeGridCurveEstimator-dig]

[shapeGridCurveEstimator-prepareTracking]

[shapeGridCurveEstimator-prepareTracking]

[shapeGridCurveEstimator-tracking]

[shapeGridCurveEstimator-tracking]

[shapeGridCurveEstimator-instantiation]

[shapeGridCurveEstimator-instantiation]

[shapeGridCurveEstimator-getRange]

[shapeGridCurveEstimator-getRange]

[shapeGridCurveEstimator-lengthEstimation]

[shapeGridCurveEstimator-lengthEstimation]

[shapeGridCurveEstimator-trueLengthEstimation]

[shapeGridCurveEstimator-trueLengthEstimation]

[shapeGridCurveEstimator-higher]

[shapeGridCurveEstimator-higher]

Definition at line 70 of file shapeGridCurveEstimator.cpp.

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.initFromPointsVector( 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
128 Range::ConstCirculator,
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.initFromPointsVector( 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}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition Board2D.h:71
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 & getUpperBound() const
void attach(ConstAlias< EuclideanShape > shape)
const Point & getLowerBound() 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 initFromPointsVector(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: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition Surfaces.h:79
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 attach(const ParametricShape &aShape)
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
Trace trace
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.

References DGtal::TrueGlobalEstimatorOnPoints< TConstIteratorOnPoints, TParametricShape, TParametricShapeFunctor >::attach(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), LibBoard::Board::clear(), DGtal::DSSLengthEstimator< TConstIterator >::eval(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getLowerBound(), DGtal::Flower2D< TSpace >::getLowerBound(), DGtal::GridCurve< TKSpace >::getPointsRange(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getUpperBound(), DGtal::Flower2D< TSpace >::getUpperBound(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), DGtal::GridCurve< TKSpace >::initFromPointsVector(), LibBoard::Board::saveEPS(), and DGtal::trace.