DGtal  1.3.beta
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/DrawWithDisplay3DModifier.h"
#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/Viewer3D.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.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();
try {
//getting a bel
bel = Surfaces<KSpace>::findABel( ks, binaryImage, domain.size() );
trace.info() << "starting bel: "
<< bel
<< std::endl;
} catch (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,
typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
typedef Domain::Predicate DomainPredicate;
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;
//visualisation
QApplication application(argc,argv);
Viewer3D<> viewer;
viewer.show();
//
GradientColorMap<double> colorMap( 0, 2*maximalDistance );
colorMap.addColor( Color( 255, 0, 0 ) );
colorMap.addColor( Color( 0, 250, 0 ) );
for (DistanceImage::const_iterator it = imageDistance.begin(), itEnd = imageDistance.end();
it != itEnd; ++it)
{
Point p = it->first;
viewer << CustomColors3D( colorMap(it->second), colorMap(it->second) ) ;
viewer << p;
}
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 << CustomColors3D(Color(200, 200, 200, 100),Color(200, 200,200, 20));
viewer << ClippingPlane(a,b,c,mu);
viewer << Viewer3D<>::updateDisplay;
return application.exec();
}
// //
DGtal::functors::Thresholder
Aim: A small functor with an operator () that compares one value to a threshold value according to tw...
Definition: BasicFunctors.h:500
DGtal::Surfaces
Aim: A utility class for constructing surfaces (i.e. set of (n-1)-cells).
Definition: Surfaces.h:78
DGtal::HyperRectDomain< Space >
DGtal::Trace::endBlock
double endBlock()
DGtal::HyperRectDomain::size
Size size() const
Definition: HyperRectDomain.h:565
DGtal::ImageContainerBySTLVector
Definition: ImageContainerBySTLVector.h:126
DGtal::SurfelAdjacency< KSpace::dimension >
DGtal::Color
Structure representing an RGB triple with alpha component.
Definition: Color.h:66
DGtal::HyperRectDomain::upperBound
const Point & upperBound() const
DGtal::KhalimskySpaceND::init
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
DGtal::Trace::emphase
std::ostream & emphase()
DGtal::trace
Trace trace
Definition: Common.h:154
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::functors::Identity
Aim: Define a simple default functor that just returns its argument.
Definition: BasicFunctors.h:287
DGtal::ConstImageAdapter
Aim: implements a const image adapter with a given domain (i.e. a subdomain) and 2 functors : g for d...
Definition: ConstImageAdapter.h:105
DGtal::SignedKhalimskyCell
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
Definition: KhalimskySpaceND.h:208
DGtal::functors::IsWithinPointPredicate< Point >
DGtal::ImageContainerBySTLMap
Definition: ImageContainerBySTLMap.h:96
DGtal::FMM
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition: FMM.h:150
DGtal::LightExplicitDigitalSurface
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
Definition: LightExplicitDigitalSurface.h:118
DGtal::Trace::info
std::ostream & info()
DGtal::Viewer3D
Definition: Viewer3D.h:135
DGtal::FMM::compute
void compute()
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::HyperRectDomain::predicate
const Predicate & predicate() const
DGtal::functors::FrontierPredicate
Aim: The predicate on surfels that represents the frontier between two regions in an image....
Definition: FrontierPredicate.h:67
DGtal::DigitalSetFromMap
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Definition: DigitalSetFromMap.h:74
DGtal::CustomColors3D
Definition: DrawWithDisplay3DModifier.h:129
DGtal::ClippingPlane
Class for adding a Clipping plane through the Viewer3D stream. Realizes the concept CDrawableWithView...
Definition: DrawWithDisplay3DModifier.h:156
Vector
FreemanChain< int >::Vector Vector
Definition: testCombinDSS.cpp:60
main
int main(int argc, char **argv)
Definition: testArithmeticDSS-benchmark.cpp:147
DGtal::GradientColorMap::addColor
void addColor(const Color &color)
domain
Domain domain
Definition: testProjection.cpp:88
DGtal::VolReader
Aim: implements methods to read a "Vol" file format.
Definition: VolReader.h:89
DGtal::Viewer3D::show
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
Point
MyPointD Point
Definition: testClone2.cpp:383
DGtal::GradientColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition: GradientColorMap.h:119
DGtal::HyperRectDomain::lowerBound
const Point & lowerBound() const
DGtal::functors::SCellToIncidentPoints
Aim: transforms a signed cell c into a pair of points corresponding to the signed cells of greater di...
Definition: SCellsFunctors.h:474
DGtal::InputException
Definition: Exceptions.h:63
DGtal::KhalimskySpaceND
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
Definition: KhalimskySpaceND.h:64