DGtal  1.5.beta
geometry/volumes/distance/exampleFMM2D.cpp

Example of use the FMM (fast marching method) class in 2D.

See also
nD Fast Marching Methods

This program outputs this image:

#include <iostream>
#include <iomanip>
#include <functional>
#include <iostream>
#include "DGtal/base/Common.h"
//space, domain and image
#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"
//shape and tracking
#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"
//FMM
#include "DGtal/geometry/volumes/distance/FMM.h"
//Display
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/boards/Board2D.h"
using namespace std;
using namespace DGtal;
template< typename TImage >
void draw( const TImage aImg, const double& aMaxValue, std::string aBasename)
{
typedef typename TImage::Domain::ConstIterator ConstIteratorOnPoints;
typedef typename TImage::Domain::Point Point;
HueShadeColorMap<double, 2> colorMap(0,aMaxValue);
Board2D b;
for (ConstIteratorOnPoints it = aImg.domain().begin(), itEnd = aImg.domain().end();
it != itEnd; ++it)
{
Point p = *it;
b << CustomStyle( p.className(), new CustomFillColor( colorMap( aImg(p) ) ) );
b << p;
}
{
std::stringstream s;
s << aBasename << ".eps";
b.saveEPS(s.str().c_str());
}
#ifdef WITH_CAIRO
{
std::stringstream s;
s << aBasename << ".png";
b.saveCairo(s.str().c_str(), Board2D::CairoPNG);
}
#endif
}
void example()
{
trace.beginBlock ( "DT by FMM from one point" );
//Typedefs
typedef ImageContainerBySTLMap<Z2i::Domain,double> DistanceImage;
typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
typedef Z2i::Domain::Predicate DomainPredicate;
typedef FMM<DistanceImage, AcceptedPointSet, DomainPredicate> FMM;
//Constructions
int size = 25;
Z2i::Domain domain(Z2i::Point::diagonal(-size),
Z2i::Point::diagonal(size) );
DistanceImage distanceImage( domain );
AcceptedPointSet set( distanceImage );
Z2i::Point origin = Z2i::Point::diagonal(0);
set.insert( origin );
distanceImage.setValue( origin, 0.0 );
FMM fmm( distanceImage, set, domain.predicate() );
trace.info() << "Init: " << fmm << std::endl;
fmm.compute();
trace.info() << "End: " << fmm << std::endl;
//display - you should see concentric circles
//around the center point.
std::stringstream s;
s << "DTbyFMM-" << size;
draw(distanceImage, fmm.max(), s.str());
}
// Standard services - public :
int main ( int argc, char** argv )
{
trace.beginBlock ( "Example 2d FMM" );
trace.info() << "Args:";
for ( int i = 0; i < argc; ++i )
trace.info() << " " << argv[ i ];
trace.info() << endl;
//computation
example();
return 1;
}
// //
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void example()
We use FMM to compute a distance field from a given point.
MyDigitalSurface::ConstIterator ConstIterator
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:153
int main(int argc, char **argv)
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
HyperRectDomain< Space > Domain