DGtal  0.9.2
dvcm-2d-curvature.cpp
1 
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/topology/SetOfSurfels.h"
35 #include "DGtal/topology/DigitalSurface.h"
36 #include "DGtal/geometry/curves/GridCurve.h"
37 #include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
38 #include "DGtal/geometry/volumes/estimation/VoronoiCovarianceMeasure.h"
39 #include "DGtal/geometry/surfaces/estimation/VoronoiCovarianceMeasureOnDigitalSurface.h"
40 #include "DGtal/geometry/surfaces/estimation/VCMDigitalSurfaceLocalEstimator.h"
41 #include "DGtal/io/colormaps/GradientColorMap.h"
42 #include "DGtal/io/boards/Board2D.h"
43 #include "ConfigExamples.h"
44 
45 
47 
48 using namespace std;
49 using namespace DGtal;
50 
52 int main( int /* argc */, char** /* argv */ )
53 {
54  typedef Z2i::Space Space;
55  typedef Z2i::KSpace KSpace;
56  typedef Z2i::Curve Curve;
57  typedef Z2i::Point Point;
58  typedef ExactPredicateLpSeparableMetric<Space, 2> Metric; // L2-metric
59 
60  typedef Curve::SCellsRange LinelRange;
61  typedef SetOfSurfels<KSpace> DigitalSurfaceContainer;
66  typedef VCMDigitalSurfaceLocalEstimator<DigitalSurfaceContainer,Metric,
67  KernelFunction, CurvatureFunctor> VCMCurvatureEstimator;
68 
69  // Transform a 4-connected sequence of discrete points into a digital surface.
70  //string inputSDP = examplesPath + "samples/flower-30-8-3.sdp";
71  //string inputSDP = examplesPath + "samples/ellipse-20-7-0.4.sdp";
72  //string inputSDP = examplesPath + "samples/accflower-20-5-5-0.1.sdp";
73  string inputSDP = examplesPath + "samples/circle-43.sdp";
74  trace.info() << "Reading input 2d discrete points file: " << inputSDP;
75  KSpace ks; ks.init( Point( -1000, -1000 ), Point( 1000, 1000 ), true );
76  Curve curve( ks );
77  fstream inputStream( inputSDP.c_str(), ios::in);
78  curve.initFromVectorStream(inputStream);
79  inputStream.close();
80  DigitalSurfaceContainer* container
81  = new DigitalSurfaceContainer( ks, SurfelAdjacency<KSpace::dimension>( true ) );
82  LinelRange range = curve.getSCellsRange();
83  for ( LinelRange::ConstIterator it = range.begin(), itE = range.end(); it != itE; ++it )
84  container->surfelSet().insert( *it );
85  CountedConstPtrOrConstPtr<Surface> ptrSurface( new Surface( container ) ); // acquired
86  trace.info() << " [done] " << std::endl ;
87  const double R = 40;
88  trace.info() << "Big radius R = " << R << std::endl;
89  const double r = 20;
90  trace.info() << "Small radius r = " << r << std::endl;
91  const double T = 0.2;
92  trace.info() << "Curvature thres. T = " << T << std::endl; // threshold for displaying features as red.
93 
94  Metric l2;
95  KernelFunction chi( 1.0, r );
96  VCMCurvatureEstimator estimator( ptrSurface );
97  estimator.setParams( Pointels, R, r, chi, 3.0, l2, true );
98  estimator.init( 1.0, ptrSurface->begin(), ptrSurface->end() );
99 
100  // Flat zones are blue, more curved zones are yellow till red.
101  GradientColorMap<double> colormap( 0, T );
102  colormap.addColor( Color::Blue );
103  colormap.addColor( Color::Yellow );
104  colormap.addColor( Color::Red );
105  Board2D board;
106  for ( Surface::ConstIterator it = ptrSurface->begin(), itE = ptrSurface->end();
107  it != itE; ++it )
108  {
109  double curv = estimator.eval( it );
110  curv = std::min( T, curv );
111  board << CustomStyle( it->className(),
112  new CustomColors( colormap( curv ), colormap( curv ) ) )
113  << *it;
114  std::cout << curv << std::endl;
115  }
116  board.saveSVG("dvcm-curvature.svg");
117 
118  return 0;
119 }
120 // //
Aim: A functor Surfel -> Quantity that returns the absolute curvature at given surfel. This class has meaning only in 2D.
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: This class adapts a VoronoiCovarianceMeasureOnDigitalSurface to be a model of CDigitalSurfaceLoc...
Trace trace
Definition: Common.h:130
KhalimskySpaceND< 2, Integer > KSpace
Definition: StdDefs.h:77
GridCurve< K2 > Curve
Definition: StdDefs.h:116
Aim: Smart or simple const pointer on T. It can be a smart pointer based on reference counts or a sim...
STL namespace.
Aim: Represents a set of n-1-cells in a nD space, together with adjacency relation between these cell...
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
Aim: implements separable l_p metrics with exact predicates.
Aim: This class specializes the Voronoi covariance measure for digital surfaces. It adds notably the ...
DGtal is the top-level namespace which contains all DGtal functions and types.
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
std::ostream & info()
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels...
Definition: SetOfSurfels.h:73
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
Definition: GridCurve.h:172
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex...
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70