DGtal  0.9.4beta
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:

DTbyFMM-25.png
#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 DigitalSetFromMap<DistanceImage> AcceptedPointSet;
typedef Z2i::Domain::Predicate DomainPredicate;
//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;
}
// //