This example shows the computation of the VCM of a sequence of 2D digital points forming a 4-connected curve. The absolute curvature is estimated from the diagonalization of the VCM tensor. A red color indicates a strong curvature, flat zones are blue, in-between is yellow.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/SetOfSurfels.h"
#include "DGtal/topology/DigitalSurface.h"
#include "DGtal/geometry/curves/GridCurve.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/volumes/estimation/VoronoiCovarianceMeasure.h"
#include "DGtal/geometry/surfaces/estimation/VoronoiCovarianceMeasureOnDigitalSurface.h"
#include "DGtal/geometry/surfaces/estimation/VCMDigitalSurfaceLocalEstimator.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "DGtal/io/boards/Board2D.h"
#include "ConfigExamples.h"
using namespace std;
{
typedef Z2i::Curve
Curve;
typedef ExactPredicateLpSeparableMetric<Space, 2> Metric;
typedef Curve::SCellsRange LinelRange;
typedef SetOfSurfels<KSpace> DigitalSurfaceContainer;
typedef DigitalSurface<DigitalSurfaceContainer>
Surface;
typedef functors::BallConstantPointFunction<Point,double> KernelFunction;
typedef VoronoiCovarianceMeasureOnDigitalSurface<DigitalSurfaceContainer,Metric,KernelFunction> VCMOnSurface;
typedef functors::VCMAbsoluteCurvatureFunctor<VCMOnSurface> CurvatureFunctor;
typedef VCMDigitalSurfaceLocalEstimator<DigitalSurfaceContainer,Metric,
KernelFunction, CurvatureFunctor> VCMCurvatureEstimator;
string inputSDP = examplesPath + "samples/circle-43.sdp";
trace.
info() <<
"Reading input 2d discrete points file: " << inputSDP;
fstream inputStream( inputSDP.c_str(), ios::in);
curve.initFromVectorStream(inputStream);
inputStream.close();
DigitalSurfaceContainer* container
= new DigitalSurfaceContainer( ks, SurfelAdjacency<KSpace::dimension>( true ) );
LinelRange range = curve.getSCellsRange();
container->surfelSet().insert( *it );
CountedConstPtrOrConstPtr<Surface> ptrSurface(
new Surface( container ) );
const double R = 40;
trace.
info() <<
"Big radius R = " << R << std::endl;
const double r = 20;
trace.
info() <<
"Small radius r = " << r << std::endl;
const double T = 0.2;
trace.
info() <<
"Curvature thres. T = " << T << std::endl;
Metric l2;
KernelFunction chi( 1.0, r );
VCMCurvatureEstimator estimator( ptrSurface );
estimator.setParams(
Pointels, R, r, chi, 3.0, l2,
true );
estimator.init( 1.0, ptrSurface->begin(), ptrSurface->end() );
GradientColorMap<double> colormap( 0, T );
colormap.addColor( Color::Blue );
colormap.addColor( Color::Yellow );
colormap.addColor( Color::Red );
Board2D board;
it != itE; ++it )
{
double curv = estimator.eval( it );
curv = std::min( T, curv );
board << CustomStyle( it->className(),
new CustomColors( colormap( curv ), colormap( curv ) ) )
<< *it;
std::cout << curv << std::endl;
}
board.saveSVG("dvcm-curvature.svg");
return 0;
}
SH3::DigitalSurface Surface
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)