Example of curvature estimation based on Digital Circular Arc (DCA) estimator.
#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"
using namespace std;
template <typename Shape, typename RealPoint>
bool
double h )
{
using namespace Z2i;
+ name ). c_str() );
GaussDigitizer<Space,Shape> dig;
dig.attach( aShape );
dig.init( low, up, h );
bool ok =
K.init( dig.getLowerBound(), dig.getUpperBound(),
true );
if ( ! ok )
{
std::cerr << "[estimatorOnShapeDigitization]"
<< " error in creating KSpace." << std::endl;
}
else
try {
SurfelAdjacency<KSpace::dimension> SAdj( true );
SCell bel = Surfaces<KSpace>::findABel(
K, dig, 10000 );
std::vector<Point> points;
Surfaces<KSpace>::track2DBoundaryPoints( points,
K, SAdj, dig, bel );
GridCurve<KSpace> gridcurve(
K );
gridcurve.initFromVector( points );
typedef GridCurve<KSpace>::IncidentPointsRange
Range;
typedef Range::ConstCirculator CircularIterator;
Range r = gridcurve.getIncidentPointsRange();
std::vector<double> estimations;
if (gridcurve.isOpen())
{
typedef CurvatureFromDCAEstimator<SegmentComputer> SCEstimator;
typedef MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator> CurvatureEstimator;
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
{
typedef CurvatureFromDCAEstimator<SegmentComputer> SCEstimator;
typedef MostCenteredMaximalSegmentEstimator<SegmentComputer,SCEstimator> CurvatureEstimator;
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 );
}
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;
}
return ok;
}
{
trace.
info() <<
" Curvature estimation using shape to digitize: flower" << std::endl
<< " with Grid step: 0.01" << std::endl;
double h = 0.01;
string shapeName = "flower";
bool res = true;
if (shapeName == "flower")
{
Flower2D<Space> flower( 0.5, 0.5, 5.0, 3.0, 5, 0.3 );
RealPoint::diagonal(-10),
RealPoint::diagonal(10),
h);
}
else if (shapeName == "ellipse")
{
Ellipse2D<Space> ellipse( 0.5, 0.5, 5.0, 3.0, 0.3 );
RealPoint::diagonal(-10),
RealPoint::diagonal(10),
h);
}
else if (shapeName == "ball")
{
Ball2D<Space> ball( 0.5, 0.5, 5.0 );
RealPoint::diagonal(-10),
RealPoint::diagonal(10),
h);
}
return res;
}
void beginBlock(const std::string &keyword="")
bool estimatorOnShapeDigitization(const string &name, Shape &aShape, const RealPoint &low, const RealPoint &up, double h)
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
ArithmeticalDSSComputer< std::vector< Z2i::Point >::const_iterator, int, 4 > SegmentComputer
HyperRectDomain< Space > Domain
PointVector< 3, double > RealPoint