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"
{
L2Metric l2;
board.
saveSVG(
"voronoimap-inputset.svg");
NotPredicate notSetPred(set);
Voronoi2D voronoimap(
domain,notSetPred,l2);
for(Voronoi2D::Domain::ConstIterator it = voronoimap.domain().begin(),
itend = voronoimap.domain().end(); it != itend; ++it)
{
Voronoi2D::Value site = voronoimap( *it );
if (site != (*it))
Display2DFactory::draw( board, site - (*it), (*it));
}
board.
saveSVG(
"voronoimap-voro.svg");
for(Voronoi2D::Domain::ConstIterator it = voronoimap.domain().begin(),
itend = voronoimap.domain().end(); it != itend; ++it)
{
Voronoi2D::Value site = voronoimap( *it );
unsigned char c = (site[1]*13 + site[0] * 7) % 256;
<< (*it);
}
board.
saveSVG(
"voronoimap-cells.svg");
L8Metric l8;
Voronoi2D_l8 voronoimap_l8(
domain,notSetPred,l8);
for(Voronoi2D_l8::Domain::ConstIterator it = voronoimap_l8.domain().begin(),
itend = voronoimap_l8.domain().end(); it != itend; ++it)
{
Voronoi2D::Value site = voronoimap_l8( *it );
unsigned char c = (site[1]*13 + site[0] * 7) % 256;
<< (*it);
}
board.
saveSVG(
"voronoimap-vorol8.svg");
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);
for(DT::Domain::ConstIterator it =
dt.domain().begin(),
itend =
dt.domain().end(); it != itend; ++it)
{
DT::Value dist =
dt( *it );
<< (*it);
}
board.
saveSVG(
"voronoimap-dt.svg");
return 0;
}
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Structure representing an RGB triple with alpha component.
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
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="")
Aim: Implementation of the linear in time Voronoi map construction.
void clear(const DGtal::Color &color=DGtal::Color::None)
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
functors namespace gathers all DGtal functors.
DGtal is the top-level namespace which contains all DGtal functions and types.
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Aim: The predicate returns true when the point predicate given at construction return false....
Vector lower(const Vector &z, unsigned int k)
Vector upper(const Vector &z, unsigned int k)