DGtal 1.4.0
Loading...
Searching...
No Matches
exampleCurvature.cpp File Reference
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/topology/KhalimskySpaceND.h"
#include "DGtal/topology/SurfelAdjacency.h"
#include "DGtal/topology/SurfelNeighborhood.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/shapes/ShapeFactory.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/geometry/curves/estimation/MostCenteredMaximalSegmentEstimator.h"
#include "DGtal/geometry/curves/StabbingCircleComputer.h"
Include dependency graph for exampleCurvature.cpp:

Go to the source code of this file.

Functions

template<typename Shape , typename RealPoint >
bool estimatorOnShapeDigitization (const string &name, Shape &aShape, const RealPoint &low, const RealPoint &up, double h)
 
int main ()
 

Detailed Description

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 ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/06/26

An example file named exampleCurvature.

This file is part of the DGtal library.

Definition in file exampleCurvature.cpp.

Function Documentation

◆ estimatorOnShapeDigitization()

template<typename Shape , typename RealPoint >
bool estimatorOnShapeDigitization ( const string & name,
Shape & aShape,
const RealPoint & low,
const RealPoint & up,
double h )

[MostCenteredConstruction]

[MostCenteredConstruction]

[MostCenteredInit]

[MostCenteredInit]

[MostCenteredEvaluation]

[MostCenteredEvaluation]

Examples
geometry/curves/estimation/exampleCurvature.cpp.

Definition at line 65 of file exampleCurvature.cpp.

69{
70 using namespace Z2i;
71
72 trace.beginBlock ( ( "Curvature estimation on digitization of "
73 + name ). c_str() );
74
75 // Creates a digitizer on the window (low, up).
77 dig.attach( aShape ); // attaches the shape.
78 dig.init( low, up, h );
79
80 // The domain size is given by the digitizer
81 // according to the window and the step.
82 Domain domain = dig.getDomain();
83
84 // Create cellular space
85 KSpace K;
86 bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
87 if ( ! ok )
88 {
89 std::cerr << "[estimatorOnShapeDigitization]"
90 << " error in creating KSpace." << std::endl;
91 }
92 else
93 try {
94 // Extracts shape boundary
96 SCell bel = Surfaces<KSpace>::findABel( K, dig, 10000 );
97 // Getting the consecutive surfels of the 2D boundary
98 std::vector<Point> points;
99 Surfaces<KSpace>::track2DBoundaryPoints( points, K, SAdj, dig, bel );
100 // Create GridCurve
101 GridCurve<KSpace> gridcurve( K );
102 gridcurve.initFromVector( points );
103 // Create range of incident points
105 typedef Range::ConstIterator ClassicIterator;
106 typedef Range::ConstCirculator CircularIterator;
107 Range r = gridcurve.getIncidentPointsRange();//building range
108 // Estimation
109 std::vector<double> estimations;
110 if (gridcurve.isOpen())
111 {
117 SCEstimator sce;
118 CurvatureEstimator estimator(sc, sce);
120
121 std::cout << "# open grid curve" << endl;
122
124 estimator.init( r.begin(), r.end() );
126
128 estimator.eval( r.begin(), r.end(), std::back_inserter(estimations), h );
130 }
131 else
132 {
137 SCEstimator sce;
138 CurvatureEstimator estimator(sc, sce);
139 std::cout << "# closed grid curve" << endl;
140 estimator.init( r.c(), r.c() );
141 estimator.eval( r.c(), r.c(), std::back_inserter(estimations), h );
142 }
143 // Print (standard output)
144 std::cout << "# idx kappa" << endl;
145 unsigned int i = 0;
146 for ( ClassicIterator it = r.begin(), ite = r.end();
147 it != ite; ++it, ++i )
148 {
149 std::cout << i << " " << estimations.at(i) << std::endl;
150 }
151 }
152 catch ( InputException& e )
153 {
154 std::cerr << "[estimatorOnShapeDigitization]"
155 << " error in finding a bel." << std::endl;
156 ok = false;
157 }
158 trace.emphase() << ( ok ? "Passed." : "Error." ) << endl;
159 trace.endBlock();
160 return ok;
161}
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
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 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)
Domain getDomain() const
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition GridCurve.h:173
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: A model of CLocalCurveGeometricEstimator that assigns to each element of a (sub)range a quantity...
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Aim: On-line recognition of a digital circular arcs (DCA) defined as a sequence of connected grid edg...
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...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
double endBlock()
Trace trace
Definition Common.h:153
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
KSpace K
Domain domain

References DGtal::GaussDigitizer< TSpace, TEuclideanShape >::attach(), DGtal::Trace::beginBlock(), domain, DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getDomain(), DGtal::GridCurve< TKSpace >::getIncidentPointsRange(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getLowerBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::getUpperBound(), DGtal::GaussDigitizer< TSpace, TEuclideanShape >::init(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::GridCurve< TKSpace >::initFromVector(), DGtal::GridCurve< TKSpace >::isOpen(), K, DGtal::trace, and DGtal::Surfaces< TKSpace >::track2DBoundaryPoints().

Referenced by main().

◆ main()

int main ( void )

Definition at line 164 of file exampleCurvature.cpp.

165{
166 trace.beginBlock ( "Example exampleCurvature" );
167 trace.info() << " Curvature estimation using shape to digitize: flower" << std::endl
168 << " with Grid step: 0.01" << std::endl;
169
170 // grid step
171 double h = 0.01;
172 // shape
173 string shapeName = "flower";
174
175
176 // parse shape
177 bool res = true;
178 typedef Z2i::Space Space;
180 if (shapeName == "flower")
181 {
182 Flower2D<Space> flower( 0.5, 0.5, 5.0, 3.0, 5, 0.3 );
183 res = estimatorOnShapeDigitization("flower", flower,
186 h);
187 }
188 else if (shapeName == "ellipse")
189 {
190 Ellipse2D<Space> ellipse( 0.5, 0.5, 5.0, 3.0, 0.3 );
191 res = estimatorOnShapeDigitization("ellipse", ellipse,
194 h);
195 }
196 else if (shapeName == "ball")
197 {
198 Ball2D<Space> ball( 0.5, 0.5, 5.0 );
199 res = estimatorOnShapeDigitization("ball", ball,
202 h);
203 }
204
205
206 trace.endBlock();
207
208 return res;
209}
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition Ball2D.h:61
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition Ellipse2D.h:65
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition Flower2D.h:65
Aim: Implements basic operations that will be used in Point and Vector classes.
static Self diagonal(Component val=1)
std::ostream & info()
bool estimatorOnShapeDigitization(const string &name, Shape &aShape, const RealPoint &low, const RealPoint &up, double h)
PointVector< 3, double > RealPoint

References DGtal::Trace::beginBlock(), DGtal::PointVector< 3, double >::diagonal(), DGtal::Trace::endBlock(), estimatorOnShapeDigitization(), DGtal::Trace::info(), and DGtal::trace.