DGtal 1.3.0
Loading...
Searching...
No Matches
dvcm-2d-curvature.cpp
1
48#include <iostream>
49#include "DGtal/base/Common.h"
50#include "DGtal/helpers/StdDefs.h"
51#include "DGtal/topology/SetOfSurfels.h"
52#include "DGtal/topology/DigitalSurface.h"
53#include "DGtal/geometry/curves/GridCurve.h"
54#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
55#include "DGtal/geometry/volumes/estimation/VoronoiCovarianceMeasure.h"
56#include "DGtal/geometry/surfaces/estimation/VoronoiCovarianceMeasureOnDigitalSurface.h"
57#include "DGtal/geometry/surfaces/estimation/VCMDigitalSurfaceLocalEstimator.h"
58#include "DGtal/io/colormaps/GradientColorMap.h"
59#include "DGtal/io/boards/Board2D.h"
60#include "ConfigExamples.h"
61
62
64
65using namespace std;
66using namespace DGtal;
67
69int main( int /* argc */, char** /* argv */ )
70{
71 typedef Z2i::Space Space;
72 typedef Z2i::KSpace KSpace;
73 typedef Z2i::Curve Curve;
74 typedef Z2i::Point Point;
75 typedef ExactPredicateLpSeparableMetric<Space, 2> Metric; // L2-metric
76
77 typedef Curve::SCellsRange LinelRange;
78 typedef SetOfSurfels<KSpace> DigitalSurfaceContainer;
83 typedef VCMDigitalSurfaceLocalEstimator<DigitalSurfaceContainer,Metric,
84 KernelFunction, CurvatureFunctor> VCMCurvatureEstimator;
85
86 // Transform a 4-connected sequence of discrete points into a digital surface.
87 //string inputSDP = examplesPath + "samples/flower-30-8-3.sdp";
88 //string inputSDP = examplesPath + "samples/ellipse-20-7-0.4.sdp";
89 //string inputSDP = examplesPath + "samples/accflower-20-5-5-0.1.sdp";
90 string inputSDP = examplesPath + "samples/circle-43.sdp";
91 trace.info() << "Reading input 2d discrete points file: " << inputSDP;
92 KSpace ks; ks.init( Point( -1000, -1000 ), Point( 1000, 1000 ), true );
93 Curve curve( ks );
94 fstream inputStream( inputSDP.c_str(), ios::in);
95 curve.initFromVectorStream(inputStream);
96 inputStream.close();
97 DigitalSurfaceContainer* container
98 = new DigitalSurfaceContainer( ks, SurfelAdjacency<KSpace::dimension>( true ) );
99 LinelRange range = curve.getSCellsRange();
100 for ( LinelRange::ConstIterator it = range.begin(), itE = range.end(); it != itE; ++it )
101 container->surfelSet().insert( *it );
102 CountedConstPtrOrConstPtr<Surface> ptrSurface( new Surface( container ) ); // acquired
103 trace.info() << " [done] " << std::endl ;
104 const double R = 40;
105 trace.info() << "Big radius R = " << R << std::endl;
106 const double r = 20;
107 trace.info() << "Small radius r = " << r << std::endl;
108 const double T = 0.2;
109 trace.info() << "Curvature thres. T = " << T << std::endl; // threshold for displaying features as red.
110
111 Metric l2;
112 KernelFunction chi( 1.0, r );
113 VCMCurvatureEstimator estimator( ptrSurface );
114 estimator.setParams( Pointels, R, r, chi, 3.0, l2, true );
115 estimator.init( 1.0, ptrSurface->begin(), ptrSurface->end() );
116
117 // Flat zones are blue, more curved zones are yellow till red.
118 GradientColorMap<double> colormap( 0, T );
119 colormap.addColor( Color::Blue );
120 colormap.addColor( Color::Yellow );
121 colormap.addColor( Color::Red );
122 Board2D board;
123 for ( Surface::ConstIterator it = ptrSurface->begin(), itE = ptrSurface->end();
124 it != itE; ++it )
125 {
126 double curv = estimator.eval( it );
127 curv = std::min( T, curv );
128 board << CustomStyle( it->className(),
129 new CustomColors( colormap( curv ), colormap( curv ) ) )
130 << *it;
131 std::cout << curv << std::endl;
132 }
133 board.saveSVG("dvcm-curvature.svg");
134
135 return 0;
136}
137// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
static const Color Yellow
Definition: Color.h:422
static const Color Red
Definition: Color.h:416
static const Color Blue
Definition: Color.h:419
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...
DigitalSurfaceContainer::SurfelConstIterator ConstIterator
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...
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 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
GridCurve< K2 > Curve
Definition: StdDefs.h:116
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
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