File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.3/config/TeX-MML-AM_CHTML/MathJax.js
DGtal 2.0.0
geometry/volumes/distance/exampleFMM3D.cpp

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

See also
nD Fast Marching Methods

This program outputs this image:

#include <iostream>
#include "DGtal/io/Color.h"
#include "DGtal/base/Common.h"
#include "DGtal/helpers/StdDefs.h"
#include "DGtal/shapes/Shapes.h"
#include "DGtal/io/colormaps/HueShadeColorMap.h"
#include "DGtal/io/colormaps/GradientColorMap.h"
#include "ConfigExamples.h"
#include "DGtal/io/viewers/PolyscopeViewer.h"
using namespace std;
using namespace DGtal;
using namespace Z3i;
//image
#include "DGtal/io/readers/VolReader.h"
#include "DGtal/images/ImageContainerBySTLVector.h"
#include "DGtal/images/ImageContainerBySTLMap.h"
#include "DGtal/images/ConstImageAdapter.h"
#include "DGtal/base/BasicFunctors.h"
#include "DGtal/kernel/BasicPointPredicates.h"
//frontier
#include "DGtal/topology/SurfelAdjacency.h"
#include "DGtal/topology/helpers/FrontierPredicate.h"
#include "DGtal/topology/LightExplicitDigitalSurface.h"
// FMM
#include "DGtal/geometry/volumes/distance/FMM.h"
// Standard services - public :
int main( int argc, char** argv )
{
//Parse options
//threshold
int t =0;
//width
double maximalDistance = 3.0;
// image binarization and surface extraction
//types
//reading image
std::string imageFileName = examplesPath + "samples/Al.100.vol";
trace.emphase() << imageFileName <<std::endl;
DGtal::trace.beginBlock("image reading...");
LabelImage labelImage = VolReader<LabelImage>::importVol( imageFileName);
DGtal::trace.endBlock();
DGtal::trace.beginBlock("binarization...");
BinaryImage binaryImage(labelImage, labelImage.domain(), g, thresholder);
trace.info() << "threshold: "
<< t
<< std::endl;
//space and starting bel
KSpace ks;
Domain domain = labelImage.domain();
ks.init( domain.lowerBound(), domain.upperBound(), true );
KSpace::SCell bel;
try {
//getting a bel
bel = Surfaces<KSpace>::findABel( ks, binaryImage, domain.size() );
trace.info() << "starting bel: "
<< bel
<< std::endl;
} catch (const DGtal::InputException& i) {
trace.emphase() << "starting bel not found" << std::endl;
return 0;
}
//implicit frontier
std::pair<Point,Point> bpair = functor(bel);
SurfelPredicate surfelPredicate( ks, binaryImage,
binaryImage( bpair.first ),
binaryImage( bpair.second ) );
Frontier frontier( ks, surfelPredicate,
DGtal::trace.endBlock();
typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
typedef Domain::Predicate DomainPredicate;
DGtal::trace.beginBlock("FMM...");
DistanceImage imageDistance( domain, 0.0 );
AcceptedPointSet initialPointSet( imageDistance );
FMM::initFromBelsRange( ks, frontier.begin(), frontier.end(),
imageDistance, initialPointSet, 0.5 );
FMM fmm( imageDistance, initialPointSet, domain.predicate(),
domain.size(), maximalDistance );
fmm.compute();
trace.info() << fmm << std::endl;
DGtal::trace.endBlock();
//visualisation
PolyscopeViewer<> viewer;
viewer.allowReuseList = true;
//
for (DistanceImage::const_iterator it = imageDistance.begin(), itEnd = imageDistance.end();
it != itEnd; ++it)
{
Point p = it->first;
viewer << WithQuantity(p, "value", it->second);
}
Point p = Point::diagonal(1);
Vector extent = (domain.upperBound() - domain.lowerBound()) + p;
double a = -extent[0]/2, b = extent[1]/2;
double c = 0, mu = (a+b);
trace.info() << "clipping plane ("
<< a << ", " << b << ", " << c << ", " << mu << ")"
<< std::endl;
viewer << ClippingPlane(a,b,c,mu);
viewer.show();
return 0;
}
// //
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
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
void compute()
static void initFromBelsRange(const KSpace &aK, const TIteratorOnBels &itb, const TIteratorOnBels &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue, bool aFlagIsPositive=true)
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
void show() override
Starts the event loop and display of elements.
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Aim: The predicate on surfels that represents the frontier between two regions in an image....
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
DigitalPlane::Point Vector
Z3i this namespace gathers the standard of types for 3D imagery.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
STL namespace.
Clipping plane.
Definition Display3D.h:299
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Attach a property to an element.
Definition Display3D.h:327
Aim: Define a simple default functor that just returns its argument.
int main()
Definition testBits.cpp:56
MyPointD Point
Domain domain
HyperRectDomain< Space > Domain