37 #include "DGtal/base/Common.h"
40 #include "DGtal/kernel/SpaceND.h"
41 #include "DGtal/kernel/domains/HyperRectDomain.h"
42 #include "DGtal/kernel/sets/DigitalSetFromMap.h"
43 #include "DGtal/images/ImageContainerBySTLMap.h"
44 #include "DGtal/topology/SCellsFunctors.h"
47 #include "DGtal/topology/helpers/Surfaces.h"
51 #include "DGtal/geometry/volumes/distance/FMM.h"
54 #include "DGtal/io/colormaps/HueShadeColorMap.h"
55 #include "DGtal/io/boards/Board2D.h"
60 using namespace DGtal;
65 template <
typename TPo
int>
74 myCx(aCx), myCy(aCy), myR(aR)
77 bool operator()(
const TPoint& aPoint)
const
79 double d = std::sqrt( std::pow( (myCx-aPoint[0] ), 2)
80 + std::pow( (myCy-aPoint[1] ), 2) );
81 if (d <= myR)
return true;
85 double myCx, myCy, myR;
88 template <
typename TPo
int>
97 myCx(aCx), myCy(aCy), myR(aR)
100 Value operator()(
const TPoint& aPoint)
const
102 double d = std::sqrt( std::pow( (myCx-aPoint[0] ), 2)
103 + std::pow( (myCy-aPoint[1] ), 2) );
107 double myCx, myCy, myR;
110 template<
typename TIterator >
111 void draw(
const TIterator& itb,
const TIterator& ite,
const int& size, std::string basename)
113 typedef typename std::iterator_traits<TIterator>::value_type Pair;
114 typedef typename Pair::first_type
Point;
115 typedef typename Pair::second_type Value;
121 for (TIterator it = itb; it != ite; ++it)
129 s << basename <<
".eps";
143 typedef Domain::Point Point;
145 Domain d(Point::diagonal(-size), Point::diagonal(size));
146 double h = 1.0/(double)size;
149 int radius = (size/2);
151 Predicate predicate( 0, 0, radius );
152 trace.
info() <<
" # circle of radius 0.5 "
153 <<
"digitized in a square of size 1 "
154 <<
"at step h=" << h << endl;
158 KSpace K; K.init( Point::diagonal(-size), Point::diagonal(size),
true);
161 std::vector<KSpace::SCell> vSCells;
167 DistanceImage dmap( d );
177 Functor functor( 0, 0, radius );
178 FMM::initFromBelsRange( K,
179 vSCells.begin(), vSCells.end(),
180 functor, dmap, set );
184 SpeedImage smap(d, 0.0);
187 for (std::vector<KSpace::SCell>::const_iterator it = vSCells.begin(),
188 itEnd = vSCells.end(); it != itEnd; ++it)
191 Point in = pair.first;
192 Point out = pair.second;
194 smap.setValue( in, in[0] );
195 smap.setValue( out, out[0] );
201 const double maxWidth = 10.0;
202 Distance distFunctor(dmap,
set);
203 FMM fmm(dmap,
set, d.predicate(), d.size(), maxWidth, distFunctor );
204 Point lastPt = Point::diagonal(0);
205 double lastDist = 0.0;
206 while ( (fmm.computeOneStep( lastPt, lastDist ))
207 && (std::abs( lastDist ) < maxWidth) )
210 smap.setValue( lastPt, speedFunctor( lastPt ) );
218 s <<
"SpeedExt-" << radius;
219 draw(smap.begin(), smap.end(), size, s.str());
232 int main (
int argc,
char** argv )
236 for (
int i = 0; i < argc; ++i )