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 );
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";
203 Domain d(Point::diagonal(-size), Point::diagonal(size));
208 Image map( d, (size*size) );
209 map.setValue( Point::diagonal(0), 0.0 );
217 FMM fmm(map, set, dp, area, distance);
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 );
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);
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);
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);
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 );
404 FMM fmm(map, set, dp, area, distance);
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;
477 Predicate bp(0,0,radius);
478 FMM fmm(map, set, bp);
482 trace.
info() << nbok <<
"/" << ++nb << std::endl;
489 s <<
"DTInCircle-" << size;
490 draw(map.begin(), map.end(), size, s.str());
511 PointPredicate nbp( bp );
512 Predicate pred( nbp, dp, andBF2 );
513 FMM fmm(map, set, pred);
517 trace.
info() << nbok <<
"/" << ++nb << std::endl;
524 s <<
"DTOutCircle-" << size;
525 draw(map.begin(), map.end(), size, s.str());
543 FMM fmm(map, set, dp);
547 trace.
info() << nbok <<
"/" << ++nb << std::endl;
555 s <<
"DTfromCircle-" << size;
556 draw(map.begin(), map.end(), size, s.str());
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)
614 Distance distance(map, set);
615 FMM fmm( map, set, dp, area, dist, distance );
623 Predicate aPredicate(
image,0);
627 DT
dt(&d,&aPredicate, &lnorm);
632 bool flagIsOk =
true;
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 )
663 for (
int i = 0; i < argc; ++i )
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;
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 between points lying in a digital domain and values.
void setValue(const Point &aPoint, const Value &aValue)
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
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
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...
void beginBlock(const std::string &keyword="")
Aim: Define a simple Foreground predicate thresholding image values given a single threshold....
void saveEPS(const char *filename, PageSize size=Board::BoundingBox, double margin=10.0) const
functors namespace gathers all DGtal functors.
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.
CustomStyle(std::string classname, DrawableWithBoard2D *style)
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)
bool testDisplayDTFromCircle(int size)
void draw(const Iterator &itb, const Iterator &ite, Board &aBoard)
void ballGenerator(const TKSpace &aKSpace, GridCurve< TKSpace > &aGC, const Integer &aR, const bool &aFlagIsCW)