DGtal 1.3.0
Loading...
Searching...
No Matches
voronoimap2D.cpp
Go to the documentation of this file.
1
40#include <iostream>
41#include "DGtal/base/Common.h"
42#include "DGtal/helpers/StdDefs.h"
43
45#include "DGtal/kernel/BasicPointPredicates.h"
46#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
47#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
48#include "DGtal/geometry/volumes/distance/VoronoiMap.h"
49#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
50
51#include "DGtal/io/colormaps/HueShadeColorMap.h"
52#include "DGtal/io/boards/Board2D.h"
54
56
57using namespace std;
58using namespace DGtal;
59using namespace DGtal::functors;
60
62
63int main( int /*argc*/, char** /*argv*/ )
64{
65 trace.beginBlock ( "Example voronoimap2D" );
66
69 L2Metric l2;
71
73 Z2i::Point lower(0,0);
74 Z2i::Point upper(16,16);
76
78 set.insertNew(Z2i::Point(2,3));
79 set.insertNew(Z2i::Point(7,15));
80 set.insertNew(Z2i::Point(12,5));
81 Board2D board;
82
83 board<< domain << set;
84 board.saveSVG("voronoimap-inputset.svg");
86
88 typedef NotPointPredicate<Z2i::DigitalSet> NotPredicate;
89 NotPredicate notSetPred(set);
91
94 Voronoi2D voronoimap(domain,notSetPred,l2);
96
98 board.clear();
99 board << domain;
100 for(Voronoi2D::Domain::ConstIterator it = voronoimap.domain().begin(),
101 itend = voronoimap.domain().end(); it != itend; ++it)
102 {
103 Voronoi2D::Value site = voronoimap( *it ); //closest site to (*it)
104 if (site != (*it))
105 Display2DFactory::draw( board, site - (*it), (*it)); //Draw an arrow
106 }
107 board.saveSVG("voronoimap-voro.svg");
109
111 board.clear();
112 for(Voronoi2D::Domain::ConstIterator it = voronoimap.domain().begin(),
113 itend = voronoimap.domain().end(); it != itend; ++it)
114 {
115 Voronoi2D::Value site = voronoimap( *it ); //closest site to (*it)
116 unsigned char c = (site[1]*13 + site[0] * 7) % 256; //basic hashfunction
117 board << CustomStyle( (*it).className(), new CustomColors(Color(c,c,c),Color(c,c,c)))
118 << (*it);
119 }
120 board.saveSVG("voronoimap-cells.svg");
122
123
126 L8Metric l8;
128 Voronoi2D_l8 voronoimap_l8(domain,notSetPred,l8);
129 board.clear();
130 board << domain;
131 for(Voronoi2D_l8::Domain::ConstIterator it = voronoimap_l8.domain().begin(),
132 itend = voronoimap_l8.domain().end(); it != itend; ++it)
133 {
134 Voronoi2D::Value site = voronoimap_l8( *it ); //closest site to (*it)
135 unsigned char c = (site[1]*13 + site[0] * 7) % 256; //basic hashfunction
136 board << CustomStyle( (*it).className(), new CustomColors(Color(c,c,c),Color(c,c,c)))
137 << (*it);
138 }
139 board.saveSVG("voronoimap-vorol8.svg");
141
144 DT dt(domain,notSetPred,l2);
145 board.clear();
146 board << domain;
147
148 //Fast max computation on the range value
149 DT::Value maxDT=0.0;
150 for(DT::ConstRange::ConstIterator it = dt.constRange().begin(), itend = dt.constRange().end();
151 it != itend ; ++it)
152 if ((*it)>maxDT) maxDT = (*it);
153
154 //Colormap
155 HueShadeColorMap<DT::Value,1> hueMap(0.0,maxDT);
156
157 //Drawing
158 for(DT::Domain::ConstIterator it = dt.domain().begin(),
159 itend = dt.domain().end(); it != itend; ++it)
160 {
161 DT::Value dist = dt( *it ); //distance to closest site to (*it)
162 board << CustomStyle( (*it).className(), new CustomColors( hueMap(dist), hueMap(dist)))
163 << (*it);
164 }
165 board.saveSVG("voronoimap-dt.svg");
167
168
169 trace.endBlock();
170 return 0;
171}
172// //
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
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Aim: Implementation of the linear in time distance transformation for separable metrics.
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 beginBlock(const std::string &keyword="")
double endBlock()
Aim: Implementation of the linear in time Voronoi map construction.
Definition: VoronoiMap.h:127
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
functors namespace gathers all DGtal functors.
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)
Aim: The predicate returns true when the point predicate given at construction return false....
int main()
Definition: testBits.cpp:56
Domain domain
Vector lower(const Vector &z, unsigned int k)
Vector upper(const Vector &z, unsigned int k)