34#include "DGtal/base/Common.h"
36#include "DGtal/kernel/SpaceND.h"
37#include "DGtal/kernel/domains/HyperRectDomain.h"
38#include "DGtal/kernel/BasicPointPredicates.h"
39#include "DGtal/kernel/domains/DomainPredicate.h"
40#include "DGtal/kernel/sets/DigitalSetFromMap.h"
41#include "DGtal/images/ImageContainerBySTLMap.h"
42#include "DGtal/images/SimpleThresholdForegroundPredicate.h"
45#include "DGtal/images/ImageSelector.h"
46#include "DGtal/geometry/volumes/distance/DistanceTransformation.h"
47#include "DGtal/geometry/volumes/distance/ExactPredicateLpSeparableMetric.h"
50#include "DGtal/geometry/volumes/distance/FMM.h"
53#include "DGtal/io/colormaps/HueShadeColorMap.h"
54#include "DGtal/io/boards/Board2D.h"
57#include "DGtal/shapes/ShapeFactory.h"
58#include "DGtal/shapes/Shapes.h"
59#include "DGtal/topology/helpers/Surfaces.h"
60#include "DGtal/shapes/GaussDigitizer.h"
61#include "DGtal/geometry/curves/GridCurve.h"
71template <
typename TImage,
typename TSet,
int norm>
77template <
typename TImage,
typename TSet>
85template <
typename TPo
int>
99 double d = std::sqrt( std::pow( (
myCx-
aPoint[0] ), 2)
101 if (d <=
myR)
return true;
108template <
typename TPo
int>
118 { ASSERT(
myR > 0); };
122 double d = std::sqrt( std::pow( (
myCx-
aPoint[0] ), 2)
131template<
typename TKSpace>
136 ASSERT( aR < (
double) size );
145 bool ok =
K.init(
Point(-size,-size),
Point(size,size),
true );
148 std::cerr <<
" error in creating KSpace." << std::endl;
157 std::vector<Point> points;
163 std::cerr <<
" error in finding a bel." << std::endl;
167template<
typename TIterator >
168void draw(
const TIterator& itb,
const TIterator& ite,
const int& size, std::string basename)
170 typedef typename std::iterator_traits<TIterator>::value_type Pair;
171 typedef typename Pair::first_type
Point;
178 for ( ; it != ite; ++it)
186 s << basename <<
".eps";
168void draw(
const TIterator& itb,
const TIterator& ite,
const int& size, std::string basename) {
…}
203 Domain d(Point::diagonal(-size), Point::diagonal(size));
208 Image map( d, (size*size) );
209 map.setValue( Point::diagonal(0), 0.0 );
214 trace.beginBlock (
"Display 2d FMM results " );
217 FMM fmm(map, set, dp, area, distance);
219 trace.info() << fmm << std::endl;
225 s <<
"DTFrom2dPt-" << size <<
"-" << area <<
"-" << distance;
226 draw(map.begin(), map.end(), size, s.str());
241 Domain d(Point::diagonal(-size), Point::diagonal(size));
242 double h = 1.0/(double)size;
245 int radius = (size/2);
247 Predicate predicate( 0, 0, radius );
249 trace.beginBlock (
"test of accuracy" );
250 trace.info() <<
" # circle of radius 0.5 "
251 <<
"digitized in a square of size 1 "
252 <<
"at step h=" << h << endl;
256 KSpace K;
K.init( Point::diagonal(-size), Point::diagonal(size),
true);
259 std::vector<KSpace::SCell> vSCells;
262 double diff1, diff2, diff3 = 0.0;
277 vSCells.begin(), vSCells.end(),
283 FMM fmm(map, set, predicate);
285 trace.info() << fmm << std::endl;
289 double truth = radius*h;
290 double found = ( std::max(std::abs(fmm.
max()),std::abs(fmm.
min())) )*h;
291 double diff = std::abs(found-truth);
292 trace.info() <<
" # radius (low accuracy)" << std::endl;
293 trace.info() <<
" # truth: " << truth << std::endl;
294 trace.info() <<
" # found: " << found << std::endl;
295 trace.info() <<
" # diff.: " << diff << std::endl;
311 Functor functor( 0, 0, radius );
314 vSCells.begin(), vSCells.end(),
319 FMM fmm(map, set, predicate);
321 trace.info() << fmm << std::endl;
324 double truth = radius*h;
325 double found = ( std::max(std::abs(fmm.
max()),std::abs(fmm.
min())) )*h;
326 double diff = std::abs(found-truth);
327 trace.info() <<
" # radius (medium accuracy)" << std::endl;
328 trace.info() <<
" # truth: " << truth << std::endl;
329 trace.info() <<
" # found: " << found << std::endl;
330 trace.info() <<
" # diff.: " << diff << std::endl;
349 Functor functor( 0, 0, radius );
352 vSCells.begin(), vSCells.end(),
356 Distance distance(map, set);
357 FMM fmm(map, set, predicate, distance);
359 trace.info() << fmm << std::endl;
362 double truth = radius*h;
363 double found = ( std::max(std::abs(fmm.
max()),std::abs(fmm.
min())) )*h;
364 double diff = std::abs(found-truth);
365 trace.info() <<
" # radius (high accuracy)" << std::endl;
366 trace.info() <<
" # truth: " << truth << std::endl;
367 trace.info() <<
" # found: " << found << std::endl;
368 trace.info() <<
" # diff.: " << diff << std::endl;
375 return ( (diff1 >= diff2)&&(diff2 >= diff3) );
390 Domain d(Point::diagonal(-size), Point::diagonal(size));
396 map.setValue( Point::diagonal(0), 0.0 );
401 trace.beginBlock (
"Display 3d FMM results " );
404 FMM fmm(map, set, dp, area, distance);
406 trace.info() << fmm << std::endl;
417 for ( ; it != d.end(); ++it)
430 s <<
"DTFrom3dPt-" << size <<
"-" << area <<
"-" << distance
446 Domain d(Point::diagonal(-size), Point::diagonal(size));
456 double radius = (rand()%size);
457 trace.info() <<
" #ball c(" << 0 <<
"," << 0 <<
") r=" << radius << endl;
461 unsigned int nbok = 0;
465 trace.beginBlock (
"Interior " );
477 Predicate bp(0,0,radius);
478 FMM fmm(map, set, bp);
480 trace.info() << fmm << std::endl;
482 trace.info() << nbok <<
"/" << ++nb << std::endl;
489 s <<
"DTInCircle-" << size;
490 draw(map.begin(), map.end(), size, s.str());
496 trace.beginBlock (
"Exterior " );
511 PointPredicate nbp( bp );
512 Predicate pred( nbp, dp,
andBF2 );
513 FMM fmm(map, set, pred);
515 trace.info() << fmm << std::endl;
517 trace.info() << nbok <<
"/" << ++nb << std::endl;
524 s <<
"DTOutCircle-" << size;
525 draw(map.begin(), map.end(), size, s.str());
531 trace.beginBlock (
"Both " );
543 FMM fmm(map, set, dp);
545 trace.info() << fmm << std::endl;
547 trace.info() << nbok <<
"/" << ++nb << std::endl;
555 s <<
"DTfromCircle-" << size;
556 draw(map.begin(), map.end(), size, s.str());
560 trace.beginBlock (
"Comparison " );
562 double epsilon = 0.0001;
563 nbok += ( ( (std::abs(-dmaxInt - dmin) < epsilon)
564 && (std::abs(dmaxExt - dmax) < epsilon) )?1:0);
565 trace.info() << nbok <<
"/" << ++nb << std::endl;
578template<Dimension dim,
int norm>
587 Domain d(Point::diagonal(-size), Point::diagonal(size));
593 map.setValue( Point::diagonal(0), 0);
596 set.insert( Point::diagonal(0) );
599 typedef Image Image2;
603 for ( ; dit != ditEnd; ++dit)
605 image.setValue(*dit, 128);
607 image.setValue(Point::diagonal(0), 0);
610 trace.beginBlock (
" FMM computation " );
614 Distance distance(map, set);
615 FMM fmm( map, set, dp, area, dist, distance );
617 trace.info() << fmm << std::endl;
621 trace.beginBlock (
" DT computation " );
623 Predicate aPredicate(
image,0);
627 DT
dt(&d,&aPredicate, &lnorm);
628 trace.info() <<
dt << std::endl;
632 bool flagIsOk =
true;
634 trace.beginBlock (
" Comparison " );
638 for ( ; ( (it != itEnd)&&(flagIsOk) ); ++it)
640 if (set.find(*it) == set.end())
644 if (
dt(*it) != map(*it))
659int main (
int argc,
char** argv )
661 trace.beginBlock (
"Testing FMM" );
662 trace.info() <<
"Args:";
663 for (
int i = 0; i < argc; ++i )
664 trace.info() <<
" " << argv[ i ];
665 trace.info() << endl;
669 int area = int( std::pow(
double(2*size+1),2) )+1;
679 area = 4*int( std::pow(
double(size),3) );
686 area = int( std::pow(
double(2*size+1),3) )+1;
691 area = int( std::pow(
double(2*size+1),4) ) + 1;
697 trace.emphase() << ( res ?
"Passed." :
"Error." ) << endl;
659int main (
int argc,
char** argv ) {
…}
Value operator()(const TPoint &aPoint) const
BallFunctor(double aCx, double aCy, double aR)
bool operator()(const TPoint &aPoint) const
BallPredicate(double aCx, double aCy, double aR)
Aim: This class specializes a 'Board' class so as to display DGtal objects more naturally (with <<)....
ConstIterator begin() const
ConstIterator end() const
Aim: A container class for storing sets of digital points within some given domain.
Aim: An adapter for viewing an associative image container like ImageContainerBySTLMap as a simple di...
Aim: implements separable l_p metrics with exact predicates.
Aim: Fast Marching Method (FMM) for nd distance transforms.
static void initFromIncidentPointsRange(const TIteratorOnPairs &itb, const TIteratorOnPairs &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue, bool aFlagIsPositive=true)
static void initFromBelsRange(const KSpace &aK, const TIteratorOnBels &itb, const TIteratorOnBels &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue, bool aFlagIsPositive=true)
static void initFromPointsRange(const TIteratorOnPoints &itb, const TIteratorOnPoints &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue)
Aim: describes, in a cellular space of dimension n, a closed or open sequence of signed d-cells (or d...
bool initFromPointsVector(const std::vector< Point > &aVectorOfPoints)
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToInnerPoint< KSpace >, Point > InnerPointsRange
IncidentPointsRange getIncidentPointsRange() const
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToIncidentPoints< KSpace >, std::pair< Point, Point > > IncidentPointsRange
OuterPointsRange getOuterPointsRange() const
InnerPointsRange getInnerPointsRange() const
ConstRangeAdapter< typename Storage::const_iterator, functors::SCellToOuterPoint< KSpace >, Point > OuterPointsRange
Aim: This class template may be used to (linearly) convert scalar values in a given range into a colo...
Aim: Parallelepidec region of a digital space, model of a 'CDomain'.
HyperRectDomain_Iterator< Point > Iterator
Aim: implements association bewteen points lying in a digital domain and values.
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
SignedKhalimskyCell< dim, Integer > SCell
SpaceND< dim, Integer > Space
Aim: Class for the computation of the L1-distance at some point p, from the available distance values...
Aim: Class for the computation of the Euclidean distance at some point p, from the available distance...
Aim: Class for the computation of the LInf-distance at some point p, from the available distance valu...
Aim: Implements basic operations that will be used in Point and Vector classes.
std::string className() const
PointVector< dim, Integer > Point
static void track2DBoundaryPoints(std::vector< Point > &aVectorOfPoints, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
static SCell findABel(const KSpace &K, const PointPredicate &pp, unsigned int nbtries=1000)
static void track2DBoundary(std::vector< SCell > &aSCellContour2D, const KSpace &K, const SurfelAdjacency< KSpace::dimension > &surfel_adj, const PointPredicate &pp, const SCell &start_surfel)
Aim: Represent adjacencies between surfel elements, telling if it follows an interior to exterior ord...
Aim: Define a simple Foreground predicate thresholding image values given a single thresold....
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
functors namespace gathers all DGtal functors.
static const BoolFunctor2 andBF2
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::uint32_t Dimension
Custom style class redefining the fill color. You may use Board2D::Color::None for transparent color.
Aim: The predicate returns true when the given binary functor returns true for the two PointPredicate...
Aim: The predicate returning true iff the point is in the domain given at construction....
Aim: The predicate returns true when the point predicate given at construction return false....
L1LocalDistance< TImage, TSet > Distance
LInfLocalDistance< TImage, TSet > Distance
bool testComparison(int size, int area, double dist)
bool accuracyTest(int size)
bool testDisplayDT3d(int size, int area, double distance)
bool testDisplayDT2d(int size, int area, double distance)
void draw(const TIterator &itb, const TIterator &ite, const int &size, std::string basename)
bool testDisplayDTFromCircle(int size)
void ballGenerator(const int &size, double aCx, double aCy, double aR, GridCurve< TKSpace > &gc)