DGtal 1.3.0
Loading...
Searching...
No Matches
dvcm-2d.cpp
1
50#include <iostream>
51#include "DGtal/base/Common.h"
52#include "DGtal/helpers/StdDefs.h"
53#include "DGtal/kernel/BasicPointPredicates.h"
54#include "DGtal/math/linalg/EigenDecomposition.h"
55#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
56#include "DGtal/geometry/volumes/estimation/VoronoiCovarianceMeasure.h"
57#include "DGtal/io/colormaps/GradientColorMap.h"
58#include "DGtal/io/boards/Board2D.h"
59#include "ConfigExamples.h"
60
61
63
64using namespace std;
65using namespace DGtal;
66
68int main( int /* argc */, char** /* argv */ )
69{
70 typedef Z2i::Space Space;
71 typedef Z2i::Point Point;
75 typedef ExactPredicateLpSeparableMetric<Space, 2> Metric; // L2-metric
76 typedef EigenDecomposition<2,double> LinearAlgebraTool;
77 typedef LinearAlgebraTool::Matrix Matrix;
78
80 typedef functors::HatPointFunction<Point,double> KernelFunction;
81
82 // Gets the points
83 vector<unsigned int> vPos;
84 vPos.push_back(0);
85 vPos.push_back(1);
86 string inputSDP = examplesPath + "samples/flower-30-8-3.sdp";
87 // string inputSDP = examplesPath + "samples/ellipse-20-7-0.4.sdp";
88 // string inputSDP = examplesPath + "samples/accflower-20-5-5-0.1.sdp";
89 trace.info() << "Reading input 2d discrete points file: " << inputSDP;
90 std::vector<Point> pts = PointListReader<Point>::getPointsFromFile(inputSDP, vPos);
91 trace.info() << " [done] " << std::endl ;
92 const double R = 20;
93 trace.info() << "Big radius R = " << R << std::endl;
94 const double r = 5;
95 trace.info() << "Small radius r = " << r << std::endl;
96 const double T = 0.1;
97 trace.info() << "Feature thres. T = " << T << std::endl; // threshold for displaying features as red.
98 const double size = 3.0; // size of displayed normals
99
100 Metric l2;
101 VCM vcm( R, ceil( r ), l2, true );
102 vcm.init( pts.begin(), pts.end() );
103 Domain domain = vcm.domain();
104 KernelFunction chi( 1.0, r );
105
106 // Flat zones are metallic blue, slightly curved zones are white,
107 // more curved zones are yellow till red.
108 GradientColorMap<double> colormap( 0.0, T );
109 colormap.addColor( Color( 128, 128, 255 ) );
110 colormap.addColor( Color( 255, 255, 255 ) );
111 colormap.addColor( Color( 255, 255, 0 ) );
112 colormap.addColor( Color( 255, 0, 0 ) );
113 Board2D board;
114 Matrix vcm_r, evec;
115 RealVector eval;
116 for ( std::vector<Point>::const_iterator it = pts.begin(), itE = pts.end();
117 it != itE; ++it )
118 {
119 // Compute VCM and diagonalize it.
120 vcm_r = vcm.measure( chi, *it );
121 LinearAlgebraTool::getEigenDecomposition( vcm_r, evec, eval );
122 double feature = eval[ 0 ] / ( eval[ 0 ] + eval[ 1 ] );
123 board << CustomStyle( it->className(),
124 new CustomColors( Color::Black, colormap( feature > T ? T : feature ) ) )
125 << *it;
126 // Display normal
127 RealVector normal = evec.column( 1 );
128 RealPoint p( (*it)[ 0 ], (*it)[ 1 ] );
129 Display2DFactory::draw( board, size*normal, p );
130 Display2DFactory::draw( board, -size*normal, p );
131 }
132 board.saveSVG("dvcm-hat-r.svg");
133
134 return 0;
135}
136// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
static const Color Black
Definition: Color.h:413
Aim: This class provides methods to compute the eigen decomposition of a matrix. Its objective is to ...
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: Parallelepidec region of a digital space, model of a 'CDomain'.
std::ostream & info()
Aim: This class precomputes the Voronoi Covariance Measure of a set of points. It can compute the cov...
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
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
static void draw(DGtal::Board2D &board, const DGtal::DiscreteExteriorCalculus< dimEmbedded, dimAmbient, TLinearAlgebraBackend, TInteger > &calculus)
static std::vector< TPoint > getPointsFromFile(const std::string &filename, std::vector< unsigned int > aVectPosition=std::vector< unsigned int >())
Z2i::RealPoint RealPoint
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
HyperRectDomain< Space > Domain