DGtal  0.9.2
dvcm-2d.cpp
1
30 #include <iostream>
32 #include "DGtal/base/Common.h"
33 #include "DGtal/helpers/StdDefs.h"
34 #include "DGtal/kernel/BasicPointPredicates.h"
35 #include "DGtal/math/linalg/EigenDecomposition.h"
36 #include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
37 #include "DGtal/geometry/volumes/estimation/VoronoiCovarianceMeasure.h"
39 #include "DGtal/io/boards/Board2D.h"
40 #include "ConfigExamples.h"
41
42
44
45 using namespace std;
46 using namespace DGtal;
47
49 int main( int /* argc */, char** /* argv */ )
50 {
51  typedef Z2i::Space Space;
52  typedef Z2i::Point Point;
53  typedef Z2i::RealPoint RealPoint;
56  typedef ExactPredicateLpSeparableMetric<Space, 2> Metric; // L2-metric
57  typedef EigenDecomposition<2,double> LinearAlgebraTool;
58  typedef LinearAlgebraTool::Matrix Matrix;
59
61  typedef functors::HatPointFunction<Point,double> KernelFunction;
62
63  // Gets the points
64  vector<unsigned int> vPos;
65  vPos.push_back(0);
66  vPos.push_back(1);
67  string inputSDP = examplesPath + "samples/flower-30-8-3.sdp";
68  // string inputSDP = examplesPath + "samples/ellipse-20-7-0.4.sdp";
69  // string inputSDP = examplesPath + "samples/accflower-20-5-5-0.1.sdp";
70  trace.info() << "Reading input 2d discrete points file: " << inputSDP;
71  std::vector<Point> pts = PointListReader<Point>::getPointsFromFile(inputSDP, vPos);
72  trace.info() << " [done] " << std::endl ;
73  const double R = 20;
74  trace.info() << "Big radius R = " << R << std::endl;
75  const double r = 5;
76  trace.info() << "Small radius r = " << r << std::endl;
77  const double T = 0.1;
78  trace.info() << "Feature thres. T = " << T << std::endl; // threshold for displaying features as red.
79  const double size = 3.0; // size of displayed normals
80
81  Metric l2;
82  VCM vcm( R, ceil( r ), l2, true );
83  vcm.init( pts.begin(), pts.end() );
84  Domain domain = vcm.domain();
85  KernelFunction chi( 1.0, r );
86
87  // Flat zones are metallic blue, slightly curved zones are white,
88  // more curved zones are yellow till red.
89  GradientColorMap<double> colormap( 0.0, T );
90  colormap.addColor( Color( 128, 128, 255 ) );
91  colormap.addColor( Color( 255, 255, 255 ) );
92  colormap.addColor( Color( 255, 255, 0 ) );
93  colormap.addColor( Color( 255, 0, 0 ) );
94  Board2D board;
95  Matrix vcm_r, evec;
96  RealVector eval;
97  for ( std::vector<Point>::const_iterator it = pts.begin(), itE = pts.end();
98  it != itE; ++it )
99  {
100  // Compute VCM and diagonalize it.
101  vcm_r = vcm.measure( chi, *it );
102  LinearAlgebraTool::getEigenDecomposition( vcm_r, evec, eval );
103  double feature = eval[ 0 ] / ( eval[ 0 ] + eval[ 1 ] );
104  board << CustomStyle( it->className(),
105  new CustomColors( Color::Black, colormap( feature > T ? T : feature ) ) )
106  << *it;
107  // Display normal
108  RealVector normal = evec.column( 1 );
109  RealPoint p( (*it)[ 0 ], (*it)[ 1 ] );
110  Display2DFactory::draw( board, size*normal, p );
111  Display2DFactory::draw( board, -size*normal, p );
112  }
113  board.saveSVG("dvcm-hat-r.svg");
114
115  return 0;
116 }
117 // //
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Trace trace
Definition: Common.h:130
STL namespace.
Aim: This class provides methods to compute the eigen decomposition of a matrix. Its objective is to ...
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: Implements method to read a set of points represented in each line of a file.
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()
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Space::RealPoint RealPoint
Definition: StdDefs.h:97
Space::RealVector RealVector
Definition: StdDefs.h:98
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70