DGtal 1.3.0
Loading...
Searching...
No Matches
geometry/surfaces/dvcm-2d-curvature.cpp

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.

See also
The class VCMDigitalSurfaceLocalEstimator
$ ./examples/geometry/surfaces/dvcm-2d-curvature
Absolute curvature estimation with Voronoi Covariance Measure.
#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;
using namespace DGtal;
int main( int /* argc */, char** /* argv */ )
{
typedef Z2i::Space Space;
typedef Z2i::Curve Curve;
typedef Z2i::Point Point;
typedef ExactPredicateLpSeparableMetric<Space, 2> Metric; // L2-metric
typedef Curve::SCellsRange LinelRange;
typedef SetOfSurfels<KSpace> DigitalSurfaceContainer;
typedef VCMDigitalSurfaceLocalEstimator<DigitalSurfaceContainer,Metric,
KernelFunction, CurvatureFunctor> VCMCurvatureEstimator;
// Transform a 4-connected sequence of discrete points into a digital surface.
//string inputSDP = examplesPath + "samples/flower-30-8-3.sdp";
//string inputSDP = examplesPath + "samples/ellipse-20-7-0.4.sdp";
//string inputSDP = examplesPath + "samples/accflower-20-5-5-0.1.sdp";
string inputSDP = examplesPath + "samples/circle-43.sdp";
trace.info() << "Reading input 2d discrete points file: " << inputSDP;
KSpace ks; ks.init( Point( -1000, -1000 ), Point( 1000, 1000 ), true );
Curve curve( ks );
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();
for ( LinelRange::ConstIterator it = range.begin(), itE = range.end(); it != itE; ++it )
container->surfelSet().insert( *it );
CountedConstPtrOrConstPtr<Surface> ptrSurface( new Surface( container ) ); // acquired
trace.info() << " [done] " << std::endl ;
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; // threshold for displaying features as red.
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() );
// Flat zones are blue, more curved zones are yellow till red.
GradientColorMap<double> colormap( 0, T );
colormap.addColor( Color::Blue );
colormap.addColor( Color::Yellow );
colormap.addColor( Color::Red );
Board2D board;
for ( Surface::ConstIterator it = ptrSurface->begin(), itE = ptrSurface->end();
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;
}
// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: Smart or simple const pointer on T. It can be a smart pointer based on reference counts or a sim...
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Aim: implements separable l_p metrics with exact predicates.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void addColor(const Color &color)
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,...
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: SetOfSurfels.h:74
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
std::ostream & info()
Aim: This class adapts a VoronoiCovarianceMeasureOnDigitalSurface to be a model of CDigitalSurfaceLoc...
Aim: This class specializes the Voronoi covariance measure for digital surfaces. It adds notably the ...
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
SH3::DigitalSurface Surface
DGtal is the top-level namespace which contains all DGtal functions and types.
STL namespace.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
Aim: A functor Surfel -> Quantity that returns the absolute curvature at given surfel....
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383