Example of use the FMM (fast marching method) class in 2D.
#include <iostream>
#include <iomanip>
#include <functional>
#include <iostream>
#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"
using namespace std;
template< typename TImage >
void draw(
const TImage aImg,
const double& aMaxValue, std::string aBasename)
{
HueShadeColorMap<double, 2> colorMap(0,aMaxValue);
Board2D b;
for (ConstIteratorOnPoints it = aImg.domain().begin(), itEnd = aImg.domain().end();
it != itEnd; ++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
}
{
typedef ImageContainerBySTLMap<Z2i::Domain,double> DistanceImage;
typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
typedef Z2i::Domain::Predicate DomainPredicate;
typedef FMM<DistanceImage, AcceptedPointSet, DomainPredicate> FMM;
int size = 25;
Z2i::Point::diagonal(size) );
DistanceImage distanceImage(
domain );
AcceptedPointSet set( distanceImage );
set.insert( origin );
distanceImage.setValue( origin, 0.0 );
FMM fmm( distanceImage, set,
domain.predicate() );
trace.
info() <<
"Init: " << fmm << std::endl;
fmm.compute();
std::stringstream s;
s << "DTbyFMM-" << size;
draw(distanceImage, fmm.max(), s.str());
}
int main (
int argc,
char** argv )
{
for ( int i = 0; i < argc; ++i )
return 1;
}
void beginBlock(const std::string &keyword="")
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.
int main(int argc, char **argv)
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
HyperRectDomain< Space > Domain