DGtal 1.3.0
Loading...
Searching...
No Matches
exampleFMM2D.cpp
Go to the documentation of this file.
1
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
76using namespace std;
77using namespace DGtal;
78
79
81
88template< typename TImage >
89void 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;
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 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
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;
136
137 //Constructions
138 int size = 25;
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
181int 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// //
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
Definition: Board2D.h:71
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()
Value max() const
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
const Predicate & predicate() const
static Self diagonal(Component val=1)
void beginBlock(const std::string &keyword="")
std::ostream & info()
double endBlock()
void setUnit(Unit unit)
Definition: Board.cpp:240
void draw(const TImage aImg, const double &aMaxValue, std::string aBasename)
void example()
We use FMM to compute a distance field from a given point.
DGtal is the top-level namespace which contains all DGtal functions and types.
Trace trace
Definition: Common.h:154
STL namespace.
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color.
Definition: Board2D.h:343
int main()
Definition: testBits.cpp:56
MyPointD Point
Definition: testClone2.cpp:383
Domain domain