Example of a Voronoi map construction in dimension 2 for the Euclidean metric.
#include <iostream>
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/kernel/BasicPointPredicates.h"
#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
#include "DGtal/geometry/volumes/distance/VoronoiMap.h"
#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
{
typedef ExactPredicateLpSeparableMetric<Z2i::Space, 2>
L2Metric;
Board2D board;
board.saveSVG("voronoimap-inputset.svg");
typedef NotPointPredicate<Z2i::DigitalSet> NotPredicate;
NotPredicate notSetPred(set);
typedef VoronoiMap<Z2i::Space, NotPredicate, L2Metric > Voronoi2D;
Voronoi2D voronoimap(
domain,notSetPred,l2);
board.clear();
itend = voronoimap.domain().end(); it != itend; ++it)
{
if (site != (*it))
}
board.saveSVG("voronoimap-voro.svg");
board.clear();
itend = voronoimap.domain().end(); it != itend; ++it)
{
unsigned char c = (site[1]*13 + site[0] * 7) % 256;
board << CustomStyle( (*it).className(), new CustomColors(Color(c,c,c),Color(c,c,c)))
<< (*it);
}
board.saveSVG("voronoimap-cells.svg");
typedef ExactPredicateLpSeparableMetric<Z2i::Space, 8> L8Metric;
L8Metric l8;
typedef VoronoiMap<Z2i::Space, NotPredicate, L8Metric > Voronoi2D_l8;
Voronoi2D_l8 voronoimap_l8(
domain,notSetPred,l8);
board.clear();
itend = voronoimap_l8.domain().end(); it != itend; ++it)
{
unsigned char c = (site[1]*13 + site[0] * 7) % 256;
board << CustomStyle( (*it).className(), new CustomColors(Color(c,c,c),Color(c,c,c)))
<< (*it);
}
board.saveSVG("voronoimap-vorol8.svg");
typedef DistanceTransformation<Z2i::Space, NotPredicate, L2Metric > DT;
board.clear();
it != itend ; ++it)
if ((*it)>maxDT) maxDT = (*it);
HueShadeColorMap<DT::Value,1> hueMap(0.0,maxDT);
itend =
dt.domain().end(); it != itend; ++it)
{
board << CustomStyle( (*it).className(), new CustomColors( hueMap(dist), hueMap(dist)))
<< (*it);
}
board.saveSVG("voronoimap-dt.svg");
return 0;
}
void beginBlock(const std::string &keyword="")
MyDigitalSurface::ConstIterator ConstIterator
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
functors namespace gathers all DGtal functors.
DGtal is the top-level namespace which contains all DGtal functions and types.
int main(int argc, char **argv)
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
HyperRectDomain< Space > Domain
Z2i::DigitalSet DigitalSet
Vector lower(const Vector &z, unsigned int k)
Vector upper(const Vector &z, unsigned int k)