DGtal  1.4.beta
geometry/curves/estimation/exampleCurvature.cpp

Example of curvature estimation based on Digital Circular Arc (DCA) estimator.

Curvature estimated using DCA estimator on a flower shape.
#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/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"
using namespace std;
using namespace DGtal;
template <typename Shape, typename RealPoint>
bool
estimatorOnShapeDigitization( const string& name,
Shape & aShape,
const RealPoint& low, const RealPoint& up,
double h )
{
using namespace Z2i;
trace.beginBlock ( ( "Curvature estimation on digitization of "
+ name ). c_str() );
// Creates a digitizer on the window (low, up).
dig.attach( aShape ); // attaches the shape.
dig.init( low, up, h );
// The domain size is given by the digitizer
// according to the window and the step.
// Create cellular space
bool ok = K.init( dig.getLowerBound(), dig.getUpperBound(), true );
if ( ! ok )
{
std::cerr << "[estimatorOnShapeDigitization]"
<< " error in creating KSpace." << std::endl;
}
else
try {
// Extracts shape boundary
SCell bel = Surfaces<KSpace>::findABel( K, dig, 10000 );
// Getting the consecutive surfels of the 2D boundary
std::vector<Point> points;
Surfaces<KSpace>::track2DBoundaryPoints( points, K, SAdj, dig, bel );
// Create GridCurve
GridCurve<KSpace> gridcurve( K );
gridcurve.initFromVector( points );
// Create range of incident points
typedef Range::ConstIterator ClassicIterator;
typedef Range::ConstCirculator CircularIterator;
Range r = gridcurve.getIncidentPointsRange();//building range
// Estimation
std::vector<double> estimations;
if (gridcurve.isOpen())
{
SCEstimator sce;
CurvatureEstimator estimator(sc, sce);
std::cout << "# open grid curve" << endl;
estimator.init( r.begin(), r.end() );
estimator.eval( r.begin(), r.end(), std::back_inserter(estimations), h );
}
else
{
SCEstimator sce;
CurvatureEstimator estimator(sc, sce);
std::cout << "# closed grid curve" << endl;
estimator.init( r.c(), r.c() );
estimator.eval( r.c(), r.c(), std::back_inserter(estimations), h );
}
// Print (standard output)
std::cout << "# idx kappa" << endl;
unsigned int i = 0;
for ( ClassicIterator it = r.begin(), ite = r.end();
it != ite; ++it, ++i )
{
std::cout << i << " " << estimations.at(i) << std::endl;
}
}
catch ( InputException& e )
{
std::cerr << "[estimatorOnShapeDigitization]"
<< " error in finding a bel." << std::endl;
ok = false;
}
trace.emphase() << ( ok ? "Passed." : "Error." ) << endl;
return ok;
}
int main( )
{
trace.beginBlock ( "Example exampleCurvature" );
trace.info() << " Curvature estimation using shape to digitize: flower" << std::endl
<< " with Grid step: 0.01" << std::endl;
// grid step
double h = 0.01;
// shape
string shapeName = "flower";
// parse shape
bool res = true;
typedef Z2i::Space Space;
if (shapeName == "flower")
{
Flower2D<Space> flower( 0.5, 0.5, 5.0, 3.0, 5, 0.3 );
res = estimatorOnShapeDigitization("flower", flower,
h);
}
else if (shapeName == "ellipse")
{
Ellipse2D<Space> ellipse( 0.5, 0.5, 5.0, 3.0, 0.3 );
res = estimatorOnShapeDigitization("ellipse", ellipse,
h);
}
else if (shapeName == "ball")
{
Ball2D<Space> ball( 0.5, 0.5, 5.0 );
res = estimatorOnShapeDigitization("ball", ball,
h);
}
return res;
}
// //
DGtal::GaussDigitizer
Aim: A class for computing the Gauss digitization of some Euclidean shape, i.e. its intersection with...
Definition: GaussDigitizer.h:79
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::GaussDigitizer::getDomain
Domain getDomain() const
DGtal::Astroid2D< Space >
DGtal::GridCurve::initFromVector
bool initFromVector(const std::vector< Point > &aVectorOfPoints)
DGtal::Circulator
Aim: Provides an adapter for classical iterators that can iterate through the underlying data structu...
Definition: Circulator.h:85
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::GaussDigitizer::getUpperBound
const Point & getUpperBound() const
DGtal::ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 >
Aim: model of CConstBidirectionalRange that adapts any range of elements bounded by two iterators [it...
SegmentComputer
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
Definition: testArithmeticalDSSComputerOnSurfels.cpp:55
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::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::GaussDigitizer::attach
void attach(ConstAlias< EuclideanShape > shape)
K
KSpace K
Definition: testCubicalComplex.cpp:62
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:172
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::StabbingCircleComputer
Aim: On-line recognition of a digital circular arcs (DCA) defined as a sequence of connected grid edg...
Definition: StabbingCircleComputer.h:112
DGtal::PointVector::diagonal
static Self diagonal(Component val=1)
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::Ball2D
Aim: Model of the concept StarShaped represents any circle in the plane.
Definition: Ball2D.h:60
DGtal::SpaceND< 2, Integer >
DGtal::GaussDigitizer::init
void init(const RealPoint &xLow, const RealPoint &xUp, typename RealVector::Component gridStep)
DGtal::MostCenteredMaximalSegmentEstimator
Aim: A model of CLocalCurveGeometricEstimator that assigns to each element of a (sub)range a quantity...
Definition: MostCenteredMaximalSegmentEstimator.h:83
DGtal::Trace::info
std::ostream & info()
estimatorOnShapeDigitization
bool estimatorOnShapeDigitization(const string &name, Shape &aShape, const RealPoint &low, const RealPoint &up, double h)
Definition: exampleCurvature.cpp:65
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::SimpleRandomAccessRangeFromPoint
Aim: model of CBidirectionalRangeFromPoint that adapts any range of elements bounded by two iterators...
Definition: SimpleRandomAccessRangeFromPoint.h:73
DGtal::GridCurve::isOpen
bool isOpen() const
Range
Image::Range Range
Definition: testSimpleRandomAccessRangeFromPoint.cpp:46
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Ellipse2D
Aim: Model of the concept StarShaped represents any ellipse in the plane.
Definition: Ellipse2D.h:64
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:165
Space
SpaceND< 2 > Space
Definition: testSimpleRandomAccessRangeFromPoint.cpp:42
DGtal::Flower2D
Aim: Model of the concept StarShaped represents any flower with k-petals in the plane.
Definition: Flower2D.h:64
RealPoint
Z2i::RealPoint RealPoint
Definition: testAstroid2D.cpp:46
DGtal::SimpleRandomAccessRangeFromPoint::ConstIterator
TConstIterator ConstIterator
Definition: SimpleRandomAccessRangeFromPoint.h:87
DGtal::GaussDigitizer::getLowerBound
const Point & getLowerBound() const
DGtal::GridCurve::getIncidentPointsRange
IncidentPointsRange getIncidentPointsRange() const
Definition: GridCurve.h:486
DGtal::InputException
Definition: Exceptions.h:63
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64