DGtal 1.3.0
Loading...
Searching...
No Matches
Functions
exampleFMM3D.cpp File Reference

The aim of this example is to use the FMM (fast marching method) class in order to incrementally compute a signed distance field from a digital surface. The resulting field is visualized with QGLViewer. More...

#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"
#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"
#include "DGtal/topology/SurfelAdjacency.h"
#include "DGtal/topology/helpers/FrontierPredicate.h"
#include "DGtal/topology/LightExplicitDigitalSurface.h"
#include "DGtal/geometry/volumes/distance/FMM.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

The aim of this example is to use the FMM (fast marching method) class in order to incrementally compute a signed distance field from a digital surface. The resulting field is visualized with QGLViewer.

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Author
Tristan Roussillon (trist.nosp@m.an.r.nosp@m.oussi.nosp@m.llon.nosp@m.@liri.nosp@m.s.cn.nosp@m.rs.fr ) Laboratoire d'InfoRmatique en Image et Systèmes d'information - LIRIS (CNRS, UMR 5205), CNRS, France
Date
2012/02/23

This file is part of the DGtal library.

Definition in file exampleFMM3D.cpp.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

FMM types [FMMSimpleTypeDef3D]

[FMMSimpleTypeDef3D]

FMM init [FMMSimpleInit3D]

[FMMSimpleInit3D]

FMM main [FMMUsage3D]

[FMMUsage3D]

Definition at line 80 of file exampleFMM3D.cpp.

81{
82
83
84 //Parse options
85 //threshold
86 int t =0;
87 //width
88 double maximalDistance = 3.0;
89
90
92 // image binarization and surface extraction
93 //types
98
99 //reading image
100 std::string imageFileName = examplesPath + "samples/Al.100.vol";
101
102 trace.emphase() << imageFileName <<std::endl;
103 DGtal::trace.beginBlock("image reading...");
104 LabelImage labelImage = VolReader<LabelImage>::importVol( imageFileName);
106
107 DGtal::trace.beginBlock("binarization...");
108
111 BinaryImage binaryImage(labelImage, labelImage.domain(), g, thresholder);
112 trace.info() << "threshold: "
113 << t
114 << std::endl;
115
116 //space and starting bel
117 KSpace ks;
118 Domain domain = labelImage.domain();
119 ks.init( domain.lowerBound(), domain.upperBound(), true );
120 KSpace::SCell bel;
121
122 try {
123 //getting a bel
124 bel = Surfaces<KSpace>::findABel( ks, binaryImage, domain.size() );
125
126 trace.info() << "starting bel: "
127 << bel
128 << std::endl;
129
130 } catch (DGtal::InputException i) {
131 trace.emphase() << "starting bel not found" << std::endl;
132 return 0;
133 }
134
135 //implicit frontier
137 std::pair<Point,Point> bpair = functor(bel);
138 SurfelPredicate surfelPredicate( ks, binaryImage,
139 binaryImage( bpair.first ),
140 binaryImage( bpair.second ) );
141 Frontier frontier( ks, surfelPredicate,
143
145
149 typedef ImageContainerBySTLMap<Domain,double> DistanceImage;
150 typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
151 typedef Domain::Predicate DomainPredicate;
154
155 DGtal::trace.beginBlock("FMM...");
156
159 DistanceImage imageDistance( domain, 0.0 );
160 AcceptedPointSet initialPointSet( imageDistance );
161 FMM::initFromBelsRange( ks, frontier.begin(), frontier.end(),
162 imageDistance, initialPointSet, 0.5 );
164
167 FMM fmm( imageDistance, initialPointSet, domain.predicate(),
168 domain.size(), maximalDistance );
169 fmm.compute();
170 trace.info() << fmm << std::endl;
172
174
176 //visualisation
177 QApplication application(argc,argv);
178 Viewer3D<> viewer;
179 viewer.show();
180
181 //
182 GradientColorMap<double> colorMap( 0, 2*maximalDistance );
183 colorMap.addColor( Color( 255, 0, 0 ) );
184 colorMap.addColor( Color( 0, 250, 0 ) );
185 for (DistanceImage::const_iterator it = imageDistance.begin(), itEnd = imageDistance.end();
186 it != itEnd; ++it)
187 {
188 Point p = it->first;
189 viewer << CustomColors3D( colorMap(it->second), colorMap(it->second) ) ;
190 viewer << p;
191 }
192 Point p = Point::diagonal(1);
193 Vector extent = (domain.upperBound() - domain.lowerBound()) + p;
194 double a = -extent[0]/2, b = extent[1]/2;
195 double c = 0, mu = (a+b);
196 trace.info() << "clipping plane ("
197 << a << ", " << b << ", " << c << ", " << mu << ")"
198 << std::endl;
199 viewer << CustomColors3D(Color(200, 200, 200, 100),Color(200, 200,200, 20));
200 viewer << ClippingPlane(a,b,c,mu);
201
202 viewer << Viewer3D<>::updateDisplay;
203 return application.exec();
204}
Structure representing an RGB triple with alpha component.
Definition: Color.h:68
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
static void initFromBelsRange(const KSpace &aK, const TIteratorOnBels &itb, const TIteratorOnBels &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue, bool aFlagIsPositive=true)
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
const Point & lowerBound() const
const Predicate & predicate() const
const Point & upperBound() const
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
static Self diagonal(Component val=1)
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...
void beginBlock(const std::string &keyword="")
std::ostream & emphase()
std::ostream & info()
double endBlock()
virtual void show()
Overload QWidget method in order to add a call to updateList() method (to ensure that the lists are w...
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...
Trace trace
Definition: Common.h:154
Class for adding a Clipping plane through the Viewer3D stream. Realizes the concept CDrawableWithView...
Represents a signed cell in a cellular grid space by its Khalimsky coordinates and a boolean value.
static ImageContainer importVol(const std::string &filename, const Functor &aFunctor=Functor())
Aim: Define a simple default functor that just returns its argument.
Domain domain

References DGtal::GradientColorMap< PValue, PDefaultPreset, PDefaultFirstColor, PDefaultLastColor >::addColor(), DGtal::Trace::beginBlock(), DGtal::FMM< TImage, TSet, TPointPredicate, TPointFunctor >::compute(), DGtal::PointVector< dim, Integer >::diagonal(), domain, DGtal::Trace::emphase(), DGtal::Trace::endBlock(), DGtal::Surfaces< TKSpace >::findABel(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::Trace::info(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::FMM< TImage, TSet, TPointPredicate, TPointFunctor >::initFromBelsRange(), DGtal::HyperRectDomain< TSpace >::lowerBound(), DGtal::HyperRectDomain< TSpace >::predicate(), DGtal::Viewer3D< TSpace, TKSpace >::show(), DGtal::HyperRectDomain< TSpace >::size(), DGtal::trace, and DGtal::HyperRectDomain< TSpace >::upperBound().