Loading [MathJax]/extensions/MathMenu.js
DGtal 2.0.0
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 Polyscope Viewer. More...

#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"
#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"
Include dependency graph for exampleFMM3D.cpp:

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 Polyscope Viewer.

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 79 of file exampleFMM3D.cpp.

80{
81
82
83 //Parse options
84 //threshold
85 int t =0;
86 //width
87 double maximalDistance = 3.0;
88
89
91 // image binarization and surface extraction
92 //types
97
98 //reading image
99 std::string imageFileName = examplesPath + "samples/Al.100.vol";
100
101 trace.emphase() << imageFileName <<std::endl;
102 DGtal::trace.beginBlock("image reading...");
103 LabelImage labelImage = VolReader<LabelImage>::importVol( imageFileName);
104 DGtal::trace.endBlock();
105
106 DGtal::trace.beginBlock("binarization...");
107
110 BinaryImage binaryImage(labelImage, labelImage.domain(), g, thresholder);
111 trace.info() << "threshold: "
112 << t
113 << std::endl;
114
115 //space and starting bel
116 KSpace ks;
117 Domain domain = labelImage.domain();
118 ks.init( domain.lowerBound(), domain.upperBound(), true );
119 KSpace::SCell bel;
120
121 try {
122 //getting a bel
123 bel = Surfaces<KSpace>::findABel( ks, binaryImage, domain.size() );
124
125 trace.info() << "starting bel: "
126 << bel
127 << std::endl;
128
129 } catch (const DGtal::InputException& i) {
130 trace.emphase() << "starting bel not found" << std::endl;
131 return 0;
132 }
133
134 //implicit frontier
136 std::pair<Point,Point> bpair = functor(bel);
137 SurfelPredicate surfelPredicate( ks, binaryImage,
138 binaryImage( bpair.first ),
139 binaryImage( bpair.second ) );
140 Frontier frontier( ks, surfelPredicate,
142
143 DGtal::trace.endBlock();
144
148 typedef ImageContainerBySTLMap<Domain,double> DistanceImage;
149 typedef DigitalSetFromMap<DistanceImage> AcceptedPointSet;
150 typedef Domain::Predicate DomainPredicate;
153
154 DGtal::trace.beginBlock("FMM...");
155
158 DistanceImage imageDistance( domain, 0.0 );
159 AcceptedPointSet initialPointSet( imageDistance );
160 FMM::initFromBelsRange( ks, frontier.begin(), frontier.end(),
161 imageDistance, initialPointSet, 0.5 );
163
166 FMM fmm( imageDistance, initialPointSet, domain.predicate(),
167 domain.size(), maximalDistance );
168 fmm.compute();
169 trace.info() << fmm << std::endl;
171
172 DGtal::trace.endBlock();
173
175 //visualisation
176 PolyscopeViewer<> viewer;
177 viewer.allowReuseList = true;
178
179 //
180 for (DistanceImage::const_iterator it = imageDistance.begin(), itEnd = imageDistance.end();
181 it != itEnd; ++it)
182 {
183 Point p = it->first;
184 viewer << WithQuantity(p, "value", it->second);
185 }
186 Point p = Point::diagonal(1);
187 Vector extent = (domain.upperBound() - domain.lowerBound()) + p;
188 double a = -extent[0]/2, b = extent[1]/2;
189 double c = 0, mu = (a+b);
190 trace.info() << "clipping plane ("
191 << a << ", " << b << ", " << c << ", " << mu << ")"
192 << std::endl;
193 viewer << ClippingPlane(a,b,c,mu);
194
195 viewer.show();
196 return 0;
197}
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)
functors::IsWithinPointPredicate< Point > Predicate
bool init(const Point &lower, const Point &upper, bool isClosed)
Specifies the upper and lower bounds for the maximal cells in this space.
SignedKhalimskyCell< dim, Integer > SCell
Aim: A model of CDigitalSurfaceContainer which defines the digital surface as connected surfels....
static Self diagonal(Component val=1)
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...
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
Trace trace
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.
Domain domain

References DGtal::Display3D< Space, KSpace >::allowReuseList, DGtal::FMM< TImage, TSet, TPointPredicate, TPointFunctor >::compute(), DGtal::PointVector< dim, Integer >::diagonal(), domain, DGtal::Surfaces< TKSpace >::findABel(), DGtal::VolReader< TImageContainer, TFunctor >::importVol(), DGtal::KhalimskySpaceND< dim, TInteger >::init(), DGtal::FMM< TImage, TSet, TPointPredicate, TPointFunctor >::initFromBelsRange(), DGtal::PolyscopeViewer< Space, KSpace >::show(), and DGtal::trace.