DGtal 1.3.0
Loading...
Searching...
No Matches
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 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());
trace.endBlock();
}
// 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;
}
// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
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
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void setUnit(Unit unit)
Definition: Board.cpp:240
void example()
We use FMM to compute a distance field from a given point.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:343
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383
Domain domain
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)