Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
exampleFMM3D.cpp
Go to the documentation of this file.
1
16
32
42
43
44
45#include <iostream>
46
47#include "DGtal/io/Color.h"
48#include "DGtal/base/Common.h"
49#include "DGtal/helpers/StdDefs.h"
50#include "DGtal/shapes/Shapes.h"
51#include "DGtal/io/colormaps/HueShadeColorMap.h"
52#include "DGtal/io/colormaps/GradientColorMap.h"
53#include "ConfigExamples.h"
54#include "DGtal/io/viewers/PolyscopeViewer.h"
55
56
57using namespace std;
58using namespace DGtal;
59using namespace Z3i;
60
61
62//image
63#include "DGtal/io/readers/VolReader.h"
64#include "DGtal/images/ImageContainerBySTLVector.h"
65#include "DGtal/images/ImageContainerBySTLMap.h"
66#include "DGtal/images/ConstImageAdapter.h"
67#include "DGtal/base/BasicFunctors.h"
68#include "DGtal/kernel/BasicPointPredicates.h"
69
70//frontier
71#include "DGtal/topology/SurfelAdjacency.h"
72#include "DGtal/topology/helpers/FrontierPredicate.h"
73#include "DGtal/topology/LightExplicitDigitalSurface.h"
74
75// FMM
76#include "DGtal/geometry/volumes/distance/FMM.h"
77
78// Standard services - public :
79int main( int argc, char** argv )
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}
198// //
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)
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...
Z3i this namespace gathers the standard of types for 3D imagery.
KhalimskySpaceND< 3, Integer > KSpace
Definition StdDefs.h:146
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
Domain domain