DGtal  1.1.0
geometry/volumes/distance/voronoimap2D.cpp

Example of a Voronoi map construction in dimension 2 for the Euclidean metric.

Digital Voronoi Diagram Computation
Distance transformation for the l_2 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/boards/Board2D.h"
using namespace std;
using namespace DGtal;
using namespace DGtal::functors;
int main( int /*argc*/, char** /*argv*/ )
{
trace.beginBlock ( "Example voronoimap2D" );
Z2i::Point upper(16,16);
set.insertNew(Z2i::Point(2,3));
set.insertNew(Z2i::Point(7,15));
set.insertNew(Z2i::Point(12,5));
Board2D board;
board<< domain << set;
board.saveSVG("voronoimap-inputset.svg");
typedef NotPointPredicate<Z2i::DigitalSet> NotPredicate;
NotPredicate notSetPred(set);
Voronoi2D voronoimap(domain,notSetPred,l2);
board.clear();
board << domain;
for(Voronoi2D::Domain::ConstIterator it = voronoimap.domain().begin(),
itend = voronoimap.domain().end(); it != itend; ++it)
{
Voronoi2D::Value site = voronoimap( *it ); //closest site to (*it)
if (site != (*it))
Display2DFactory::draw( board, site - (*it), (*it)); //Draw an arrow
}
board.saveSVG("voronoimap-voro.svg");
board.clear();
for(Voronoi2D::Domain::ConstIterator it = voronoimap.domain().begin(),
itend = voronoimap.domain().end(); it != itend; ++it)
{
Voronoi2D::Value site = voronoimap( *it ); //closest site to (*it)
unsigned char c = (site[1]*13 + site[0] * 7) % 256; //basic hashfunction
board << CustomStyle( (*it).className(), new CustomColors(Color(c,c,c),Color(c,c,c)))
<< (*it);
}
board.saveSVG("voronoimap-cells.svg");
L8Metric l8;
Voronoi2D_l8 voronoimap_l8(domain,notSetPred,l8);
board.clear();
board << domain;
for(Voronoi2D_l8::Domain::ConstIterator it = voronoimap_l8.domain().begin(),
itend = voronoimap_l8.domain().end(); it != itend; ++it)
{
Voronoi2D::Value site = voronoimap_l8( *it ); //closest site to (*it)
unsigned char c = (site[1]*13 + site[0] * 7) % 256; //basic hashfunction
board << CustomStyle( (*it).className(), new CustomColors(Color(c,c,c),Color(c,c,c)))
<< (*it);
}
board.saveSVG("voronoimap-vorol8.svg");
DT dt(domain,notSetPred,l2);
board.clear();
board << domain;
//Fast max computation on the range value
DT::Value maxDT=0.0;
for(DT::ConstRange::ConstIterator it = dt.constRange().begin(), itend = dt.constRange().end();
it != itend ; ++it)
if ((*it)>maxDT) maxDT = (*it);
//Colormap
//Drawing
for(DT::Domain::ConstIterator it = dt.domain().begin(),
itend = dt.domain().end(); it != itend; ++it)
{
DT::Value dist = dt( *it ); //distance to closest site to (*it)
board << CustomStyle( (*it).className(), new CustomColors( hueMap(dist), hueMap(dist)))
<< (*it);
}
board.saveSVG("voronoimap-dt.svg");
return 0;
}
// //
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::VoronoiMap
Aim: Implementation of the linear in time Voronoi map construction.
Definition: VoronoiMap.h:127
lower
Vector lower(const Vector &z, unsigned int k)
Definition: viewDualSurface.cpp:190
DGtal::functors
functors namespace gathers all DGtal functors.
Definition: BasicBoolFunctors.h:49
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:67
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
DGtal::trace
Trace trace
Definition: Common.h:150
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
LibBoard::Board::clear
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
DGtal::DigitalSetByAssociativeContainer::insertNew
void insertNew(const Point &p)
DGtal::CustomStyle
Definition: Board2D.h:217
draw
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
Definition: testSegmentation.cpp:75
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::CustomColors
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:279
LibBoard::Board::saveSVG
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
DGtal::Z2i::L2Metric
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
DGtal::functors::NotPointPredicate
Aim: The predicate returns true when the point predicate given at construction return false....
Definition: BasicPointPredicates.h:208
DGtal::ExactPredicateLpSeparableMetric
Aim: implements separable l_p metrics with exact predicates.
Definition: ExactPredicateLpSeparableMetric.h:88
upper
Vector upper(const Vector &z, unsigned int k)
Definition: viewDualSurface.cpp:197
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::PointVector< dim, Integer >
DGtal::DistanceTransformation
Aim: Implementation of the linear in time distance transformation for separable metrics.
Definition: DistanceTransformation.h:100
Value
double Value
Definition: testSimpleRandomAccessRangeFromPoint.cpp:38
DGtal::DigitalSetByAssociativeContainer
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Definition: DigitalSetByAssociativeContainer.h:90