DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
exampleFMM2D.cpp
Go to the documentation of this file.
1
16
28
29
40
41
43
#include <iostream>
44
#include <iomanip>
45
#include <functional>
46
#include <iostream>
47
48
#include "DGtal/base/Common.h"
49
50
//space, domain and image
51
#include "DGtal/kernel/SpaceND.h"
52
#include "DGtal/kernel/domains/HyperRectDomain.h"
53
#include "DGtal/kernel/sets/DigitalSetFromMap.h"
54
#include "DGtal/images/ImageContainerBySTLMap.h"
55
#include "DGtal/topology/SCellsFunctors.h"
56
57
//shape and tracking
58
#include "DGtal/shapes/ShapeFactory.h"
59
#include "DGtal/shapes/Shapes.h"
60
#include "DGtal/helpers/StdDefs.h"
61
#include "DGtal/topology/helpers/Surfaces.h"
62
#include "DGtal/shapes/GaussDigitizer.h"
63
64
65
//FMM
67
#include "DGtal/geometry/volumes/distance/FMM.h"
69
70
//Display
71
#include "DGtal/io/colormaps/HueShadeColorMap.h"
72
#include "DGtal/io/boards/Board2D.h"
73
75
76
using namespace
std
;
77
using namespace
DGtal
;
78
79
81
88
template
<
typename
TImage >
89
void
draw
(
const
TImage aImg,
const
double
& aMaxValue, std::string aBasename)
90
{
91
typedef
typename
TImage::Domain::ConstIterator ConstIteratorOnPoints;
92
typedef
typename
TImage::Domain::Point
Point
;
93
HueShadeColorMap<double, 2>
colorMap(0,aMaxValue);
94
95
Board2D
b;
96
b.
setUnit
(
LibBoard::Board::UCentimeter
);
97
98
for
(ConstIteratorOnPoints it = aImg.domain().begin(), itEnd = aImg.domain().end();
99
it != itEnd; ++it)
100
{
101
Point
p = *it;
102
b <<
CustomStyle
( p.className(),
new
CustomFillColor
( colorMap( aImg(p) ) ) );
103
b << p;
104
}
105
106
{
107
std::stringstream s;
108
s << aBasename <<
".eps"
;
109
b.
saveEPS
(s.str().c_str());
110
}
111
#ifdef DGTAL_WITH_CAIRO
112
{
113
std::stringstream s;
114
s << aBasename <<
".png"
;
115
b.
saveCairo
(s.str().c_str(),
Board2D::CairoPNG
);
116
}
117
#endif
118
}
119
121
124
void
example
()
125
{
126
127
trace
.
beginBlock
(
"DT by FMM from one point"
);
128
129
//Typedefs
131
typedef
ImageContainerBySTLMap<Z2i::Domain,double>
DistanceImage;
132
typedef
DigitalSetFromMap<DistanceImage>
AcceptedPointSet;
133
typedef
Z2i::Domain::Predicate
DomainPredicate;
134
typedef
FMM<DistanceImage, AcceptedPointSet, DomainPredicate>
FMM
;
136
137
//Constructions
138
int
size = 25;
140
Z2i::Domain
domain
(
Z2i::Point::diagonal
(-size),
141
Z2i::Point::diagonal
(size) );
142
DistanceImage distanceImage(
domain
);
143
AcceptedPointSet set( distanceImage );
145
147
Z2i::Point
origin =
Z2i::Point::diagonal
(0);
148
set.insert( origin );
149
distanceImage.setValue( origin, 0.0 );
151
153
FMM
fmm( distanceImage, set,
domain
.predicate() );
155
156
trace
.
info
() <<
"Init: "
<< fmm << std::endl;
157
159
fmm.
compute
();
161
162
trace
.
info
() <<
"End: "
<< fmm << std::endl;
163
164
//display - you should see concentric circles
165
//around the center point.
166
std::stringstream s;
167
s <<
"DTbyFMM-"
<< size;
168
draw
(distanceImage, fmm.
max
(), s.str());
169
170
trace
.
endBlock
();
171
}
172
173
174
175
176
177
179
// Standard services - public :
180
181
int
main
(
int
argc,
char
** argv )
182
{
183
trace
.
beginBlock
(
"Example 2d FMM"
);
184
trace
.
info
() <<
"Args:"
;
185
for
(
int
i = 0; i < argc; ++i )
186
trace
.
info
() <<
" "
<< argv[ i ];
187
trace
.
info
() << endl;
188
189
//computation
190
example
();
191
192
trace
.
endBlock
();
193
return
1;
194
}
195
// //
DGtal::Board2D
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition
Board2D.h:71
DGtal::DigitalSetFromMap
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Definition
DigitalSetFromMap.h:75
DGtal::FMM
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition
FMM.h:151
DGtal::FMM::compute
void compute()
DGtal::FMM::max
Value max() const
DGtal::HueShadeColorMap
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Definition
HueShadeColorMap.h:91
DGtal::HyperRectDomain< Space >::Predicate
functors::IsWithinPointPredicate< Point > Predicate
Definition
HyperRectDomain.h:128
DGtal::ImageContainerBySTLMap
Definition
ImageContainerBySTLMap.h:98
DGtal::PointVector< dim, Integer >::diagonal
static Self diagonal(Component val=1)
DGtal::Point
DGtal::Trace::beginBlock
void beginBlock(const std::string &keyword="")
DGtal::Trace::info
std::ostream & info()
DGtal::Trace::endBlock
double endBlock()
LibBoard::Board::UCentimeter
@ UCentimeter
Definition
Board.h:43
LibBoard::Board::saveEPS
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:804
LibBoard::Board::CairoPNG
@ CairoPNG
Definition
Board.h:40
LibBoard::Board::setUnit
void setUnit(Unit unit)
Definition
Board.cpp:239
LibBoard::Board::saveCairo
void saveCairo(const char *filename, CairoType type=CairoPNG, PageSize size=Board::BoundingBox, double margin=10.0) const
Definition
Board.cpp:1138
example
void example()
We use FMM to compute a distance field from a given point.
Definition
exampleFMM2D.cpp:124
DGtal::Z2i::Point
Space::Point Point
Definition
StdDefs.h:95
DGtal::Z2i::Domain
HyperRectDomain< Space > Domain
Definition
StdDefs.h:99
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::trace
Trace trace
std
STL namespace.
DGtal::CustomFillColor
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color.
Definition
Board2D.h:343
DGtal::CustomStyle::CustomStyle
CustomStyle(std::string classname, DrawableWithBoard2D *style)
Definition
Board2D.h:224
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
domain
Domain domain
Definition
testProjection.cpp:88
draw
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
Definition
testSegmentation.cpp:75
examples
geometry
volumes
distance
exampleFMM2D.cpp
Generated on
for DGtal by
1.18.0