DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
voronoimap2D.cpp
Go to the documentation of this file.
1
16
29
38
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
57
using namespace
std
;
58
using namespace
DGtal
;
59
using namespace
DGtal::functors
;
60
62
63
int
main
(
int
/*argc*/
,
char
**
/*argv*/
)
64
{
65
trace
.
beginBlock
(
"Example voronoimap2D"
);
66
68
typedef
ExactPredicateLpSeparableMetric<Z2i::Space, 2>
L2Metric;
69
L2Metric l2;
71
73
Z2i::Point
lower
(0,0);
74
Z2i::Point
upper
(16,16);
75
Z2i::Domain
domain
(
lower
,
upper
);
76
77
Z2i::DigitalSet
set(
domain
);
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
93
typedef
VoronoiMap<Z2i::Space, NotPredicate, L2Metric >
Voronoi2D;
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
125
typedef
ExactPredicateLpSeparableMetric<Z2i::Space, 8>
L8Metric;
126
L8Metric l8;
127
typedef
VoronoiMap<Z2i::Space, NotPredicate, L8Metric >
Voronoi2D_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
143
typedef
DistanceTransformation<Z2i::Space, NotPredicate, L2Metric >
DT;
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
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::Color::Color
Color()
Definition
Color.h:139
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition
DistanceTransformation.h:99
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition
ExactPredicateLpSeparableMetric.h:88
DGtal::HueShadeColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition
HueShadeColorMap.h:91
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::endBlock
double endBlock()
DGtal::VoronoiMap
Aim: Implementation of the linear in time Voronoi map construction.
Definition
VoronoiMap.h:127
LibBoard::Board::clear
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition
Board.cpp:151
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1011
dt
float dt
Definition
dgtalCalculus-geodesic.cpp:63
DGtal::Z2i::Point
Space::Point Point
Definition
StdDefs.h:95
DGtal::Z2i::DigitalSet
DigitalSetSelector< Domain, BIG_DS+HIGH_BEL_DS >::Type DigitalSet
Definition
StdDefs.h:100
DGtal::Z2i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:99
DGtal::functors
functors namespace gathers all DGtal functors.
Definition
BasicBoolFunctors.h:49
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition
Board2D.h:279
DGtal::CustomStyle::CustomStyle
CustomStyle(std::string classname, DrawableWithBoard2D *style)
Definition
Board2D.h:224
DGtal::Display2DFactory::draw
static void draw(DGtal::Board2D &board, const DGtal::DiscreteExteriorCalculus< dimEmbedded, dimAmbient, TLinearAlgebraBackend, TInteger > &calculus)
DGtal::functors::NotPointPredicate
Aim: The predicate returns true when the point predicate given at construction return false....
Definition
BasicPointPredicates.h:208
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
lower
Vector lower(const Vector &z, unsigned int k)
Definition
viewDualSurface.cpp:189
upper
Vector upper(const Vector &z, unsigned int k)
Definition
viewDualSurface.cpp:196
examples
geometry
volumes
distance
voronoimap2D.cpp
Generated on
for DGtal by
1.18.0