DGtal  1.5.beta
exampleFMM2D.cpp File Reference

Computation of a distance field from a given point
More...

#include <iostream>
#include <iomanip>
#include <functional>
#include "DGtal/base/Common.h"
#include "DGtal/kernel/SpaceND.h"
#include "DGtal/kernel/domains/HyperRectDomain.h"
#include "DGtal/kernel/sets/DigitalSetFromMap.h"
#include "DGtal/images/ImageContainerBySTLMap.h"
#include "DGtal/topology/SCellsFunctors.h"
#include "DGtal/shapes/ShapeFactory.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/topology/helpers/Surfaces.h"
#include "DGtal/shapes/GaussDigitizer.h"
#include "DGtal/geometry/volumes/distance/FMM.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/boards/Board2D.h"
Include dependency graph for exampleFMM2D.cpp:

Go to the source code of this file.

Functions

template<typename TImage >
void draw (const TImage aImg, const double &aMaxValue, std::string aBasename)
 
void example ()
 We use FMM to compute a distance field from a given point. More...
 
int main (int argc, char **argv)
 

Detailed Description

Computation of a distance field from a given point

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
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/02/23

This file is part of the DGtal library.

Definition in file exampleFMM2D.cpp.

Function Documentation

◆ draw()

template<typename TImage >
void draw ( const TImage  aImg,
const double &  aMaxValue,
std::string  aBasename 
)

Function that displays an image with Board2D

Parameters
aImgan image
aMaxValuemaximal value used in the color map
aBasenamebase name of the file
Template Parameters
TImagea model of CImage

Definition at line 89 of file exampleFMM2D.cpp.

90 {
91  typedef typename TImage::Domain::ConstIterator ConstIteratorOnPoints;
92  typedef typename TImage::Domain::Point Point;
93  HueShadeColorMap<double, 2> colorMap(0,aMaxValue);
94 
95  Board2D b;
97 
98  for (ConstIteratorOnPoints it = aImg.domain().begin(), itEnd = aImg.domain().end();
99  it != itEnd; ++it)
100  {
101  Point p = *it;
102  b << CustomStyle( p.className(), new CustomFillColor( colorMap( aImg(p) ) ) );
103  b << p;
104  }
105 
106  {
107  std::stringstream s;
108  s << aBasename << ".eps";
109  b.saveEPS(s.str().c_str());
110  }
111  #ifdef WITH_CAIRO
112  {
113  std::stringstream s;
114  s << aBasename << ".png";
115  b.saveCairo(s.str().c_str(), Board2D::CairoPNG);
116  }
117  #endif
118 }
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void setUnit(Unit unit)
Definition: Board.cpp:239
MyDigitalSurface::ConstIterator ConstIterator
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:343
MyPointD Point
Definition: testClone2.cpp:383

References LibBoard::Board::setUnit(), and LibBoard::Board::UCentimeter.

Referenced by example().

◆ example()

void example ( )

We use FMM to compute a distance field from a given point.

[FMMSimpleTypeDef]

[FMMSimpleTypeDef]

[FMMSimpleExternalData]

[FMMSimpleExternalData]

[FMMSimpleInit]

[FMMSimpleInit]

[FMMSimpleCtor]

[FMMSimpleCtor]

[FMMSimpleComputation]

[FMMSimpleComputation]

Examples
geometry/volumes/distance/exampleFMM2D.cpp.

Definition at line 124 of file exampleFMM2D.cpp.

125 {
126 
127  trace.beginBlock ( "DT by FMM from one point" );
128 
129  //Typedefs
131  typedef ImageContainerBySTLMap<Z2i::Domain,double> DistanceImage;
132  typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
133  typedef Z2i::Domain::Predicate DomainPredicate;
136 
137  //Constructions
138  int size = 25;
140  Z2i::Domain domain(Z2i::Point::diagonal(-size),
141  Z2i::Point::diagonal(size) );
142  DistanceImage distanceImage( domain );
143  AcceptedPointSet set( distanceImage );
145 
147  Z2i::Point origin = Z2i::Point::diagonal(0);
148  set.insert( origin );
149  distanceImage.setValue( origin, 0.0 );
151 
153  FMM fmm( distanceImage, set, domain.predicate() );
155 
156  trace.info() << "Init: " << fmm << std::endl;
157 
159  fmm.compute();
161 
162  trace.info() << "End: " << fmm << std::endl;
163 
164  //display - you should see concentric circles
165  //around the center point.
166  std::stringstream s;
167  s << "DTbyFMM-" << size;
168  draw(distanceImage, fmm.max(), s.str());
169 
170  trace.endBlock();
171 }
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition: FMM.h:151
const Predicate & predicate() const
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void draw(const TImage aImg, const double &aMaxValue, std::string aBasename)
Trace trace
Definition: Common.h:153
Domain domain

References DGtal::Trace::beginBlock(), DGtal::FMM< TImage, TSet, TPointPredicate, TPointFunctor >::compute(), domain, draw(), DGtal::Trace::endBlock(), DGtal::Trace::info(), DGtal::FMM< TImage, TSet, TPointPredicate, TPointFunctor >::max(), DGtal::HyperRectDomain< TSpace >::predicate(), and DGtal::trace.

Referenced by main().

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 181 of file exampleFMM2D.cpp.

182 {
183  trace.beginBlock ( "Example 2d FMM" );
184  trace.info() << "Args:";
185  for ( int i = 0; i < argc; ++i )
186  trace.info() << " " << argv[ i ];
187  trace.info() << endl;
188 
189  //computation
190  example();
191 
192  trace.endBlock();
193  return 1;
194 }
void example()
We use FMM to compute a distance field from a given point.

References DGtal::Trace::beginBlock(), DGtal::Trace::endBlock(), example(), DGtal::Trace::info(), and DGtal::trace.