DGtal  0.9.3
Functions
voronoimap2D.cpp File Reference
#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"
Include dependency graph for voronoimap2D.cpp:

Go to the source code of this file.

Functions

int main (int, char **)
 

Detailed Description

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
David Coeurjolly (david.nosp@m..coe.nosp@m.urjol.nosp@m.ly@l.nosp@m.iris..nosp@m.cnrs.nosp@m..fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2013/01/17

An example file named voronoimap2D.

This file is part of the DGtal library.

Definition in file voronoimap2D.cpp.

Function Documentation

◆ main()

int main ( int  ,
char **   
)

[Voro2D-Metric]

[Voro2D-Metric]

[Voro2D-SmallImage]

[Voro2D-SmallImage]

[Voro2D-Predicate]

[Voro2D-Predicate]

[Voro2D-Voro]

[Voro2D-Voro]

[Voro2D-trace]

[Voro2D-trace]

[Voro2D-traceCell]

[Voro2D-traceCell]

[Voro2D-l8Metric]

[Voro2D-l8Metric]

[Voro2D-DT]

[Voro2D-DT]

Definition at line 63 of file voronoimap2D.cpp.

References DGtal::Trace::beginBlock(), LibBoard::Board::clear(), domain(), draw(), DGtal::Trace::endBlock(), DGtal::DigitalSetByAssociativeContainer< TDomain, TContainer >::insertNew(), lower(), LibBoard::Board::saveSVG(), DGtal::trace, and upper().

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 }
void beginBlock(const std::string &keyword="")
Aim: The predicate returns true when the point predicate given at construction return false...
Aim: Implementation of the linear in time Voronoi map construction.
Definition: VoronoiMap.h:126
Aim: Implementation of the linear in time distance transformation for separable metrics.
const Domain domain(Point(1, 2), Point(6, 5))
MyDigitalSurface::ConstIterator ConstIterator
Trace trace
Definition: Common.h:137
ExactPredicateLpSeparableMetric< Space, 2 > L2Metric
Definition: StdDefs.h:118
Vector lower(const Vector &z, unsigned int k)
double endBlock()
Custom style class redefining the pen color and the fill color. You may use Board2D::Color::None for ...
Definition: Board2D.h:278
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void saveSVG(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition: Board.cpp:1012
Aim: implements separable l_p metrics with exact predicates.
void clear(const DGtal::Color &color=DGtal::Color::None)
Definition: Board.cpp:152
Aim: A wrapper class around a STL associative container for storing sets of digital points within som...
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
Vector upper(const Vector &z, unsigned int k)
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
Aim: This class specializes a &#39;Board&#39; class so as to display DGtal objects more naturally (with <<)...
Definition: Board2D.h:70