DGtal  1.2.0
FMM.h
1 
17 #pragma once
18 
35 #if defined(FMM_RECURSES)
36 #error Recursive header files inclusion detected in FMM.h
37 #else // defined(FMM_RECURSES)
39 #define FMM_RECURSES
40 
41 #if !defined FMM_h
43 #define FMM_h
44 
46 // Inclusions
47 #include <iostream>
48 #include <limits>
49 #include <map>
50 #include <set>
51 #include "DGtal/base/Common.h"
52 #include "DGtal/base/ConstAlias.h"
53 #include "DGtal/images/CImage.h"
54 #include "DGtal/images/ImageHelper.h"
55 #include "DGtal/kernel/sets/CDigitalSet.h"
56 #include "DGtal/kernel/CPointPredicate.h"
57 #include "DGtal/kernel/CPointFunctor.h"
58 #include "DGtal/geometry/volumes/distance/FMMPointFunctors.h"
59 
61 
62 namespace DGtal
63 {
64 
65  namespace detail
66  {
68  // template class PointValueCompare
76  template<typename T>
78  public:
87  bool operator()(const T& a, const T& b) const
88  {
89  if ( std::abs(a.second) == std::abs(b.second) )
90  { //point comparison
91  return (a.first < b.first);
92  }
93  else //distance comparison
94  //(in absolute value in order to deal with
95  //signed distance values)
96  return ( std::abs(a.second) < std::abs(b.second) );
97  }
98  };
99  }
100 
102  // template class FMM
148  template <typename TImage, typename TSet, typename TPointPredicate,
149  typename TPointFunctor = L2FirstOrderLocalDistance<TImage,TSet> >
150  class FMM
151  {
152 
153  // ----------------------- Types ------------------------------
154  public:
155 
156 
157  //concept assert
162 
163  typedef TImage Image;
164  typedef TSet AcceptedPointSet;
165  typedef TPointPredicate PointPredicate;
166 
167  //points
168  typedef typename Image::Point Point;
169  BOOST_STATIC_ASSERT(( boost::is_same< Point, typename AcceptedPointSet::Point >::value ));
170  BOOST_STATIC_ASSERT(( boost::is_same< Point, typename PointPredicate::Point >::value ));
171 
172  //dimension
173  typedef typename Point::Dimension Dimension;
174  static const Dimension dimension;
175 
176  //distance
177  typedef TPointFunctor PointFunctor;
178  typedef typename PointFunctor::Value Value;
179 
180 
181  private:
182 
183  //intern data types
184  typedef std::pair<Point, Value> PointValue;
185  typedef std::set<PointValue,
188 
189  // ------------------------- Private Datas --------------------------------
190  private:
191 
196 
201 
206 
213 
219  const bool myFlagIsOwning;
220 
227 
233 
238 
243 
248 
249 
250  // ----------------------- Standard services ------------------------------
251  public:
252 
258  FMM(Image& aImg, AcceptedPointSet& aSet,
259  ConstAlias<PointPredicate> aPointPredicate);
260 
266  FMM(Image& aImg, AcceptedPointSet& aSet,
267  ConstAlias<PointPredicate> aPointPredicate,
268  const Area& aAreaThreshold, const Value& aValueThreshold);
269 
275  FMM(Image& aImg, AcceptedPointSet& aSet,
276  ConstAlias<PointPredicate> aPointPredicate,
277  PointFunctor& aPointFunctor );
278 
284  FMM(Image& aImg, AcceptedPointSet& aSet,
285  ConstAlias<PointPredicate> aPointPredicate,
286  const Area& aAreaThreshold, const Value& aValueThreshold,
287  PointFunctor& aPointFunctor );
288 
292  ~FMM();
293 
294 
295  // ----------------------- Interface --------------------------------------
296  public:
297 
306  void compute();
307 
321  bool computeOneStep(Point& aPoint, Value& aValue);
322 
328  Value min() const;
329 
335  Value max() const;
336 
344  Value getMin() const;
345 
353  Value getMax() const;
354 
359  void selfDisplay ( std::ostream & out ) const;
360 
365  bool isValid() const;
366 
367  // ------------------------- static functions for init --------------------
368 
369 
380  template <typename TIteratorOnPoints>
381  static void initFromPointsRange(const TIteratorOnPoints& itb, const TIteratorOnPoints& ite,
382  Image& aImg, AcceptedPointSet& aSet,
383  const Value& aValue);
384 
400  template <typename KSpace, typename TIteratorOnBels>
401  static void initFromBelsRange(const KSpace& aK,
402  const TIteratorOnBels& itb, const TIteratorOnBels& ite,
403  Image& aImg, AcceptedPointSet& aSet,
404  const Value& aValue,
405  bool aFlagIsPositive = true);
406 
425  template <typename KSpace, typename TIteratorOnBels, typename TImplicitFunction>
426  static void initFromBelsRange(const KSpace& aK,
427  const TIteratorOnBels& itb, const TIteratorOnBels& ite,
428  const TImplicitFunction& aF,
429  Image& aImg, AcceptedPointSet& aSet,
430  bool aFlagIsPositive = true);
431 
432 
447  template <typename TIteratorOnPairs>
448  static void initFromIncidentPointsRange(const TIteratorOnPairs& itb, const TIteratorOnPairs& ite,
449  Image& aImg, AcceptedPointSet& aSet,
450  const Value& aValue,
451  bool aFlagIsPositive = true);
452 
453  private:
454 
460  FMM ( const FMM & other );
461 
468  FMM & operator= ( const FMM & other );
469 
470  // ------------------------- Internals ------------------------------------
471  private:
472 
476  void init();
477 
490 
497  void update(const Point& aPoint);
498 
512 
513 
514  }; // end of class FMM
515 
516 
523  template <typename TImage, typename TSet, typename TPointPredicate, typename TPointFunctor >
524  std::ostream&
525  operator<< ( std::ostream & out, const FMM<TImage, TSet, TPointPredicate, TPointFunctor> & object );
526 
527 } // namespace DGtal
528 
529 
531 // Includes inline functions.
532 #include "DGtal/geometry/volumes/distance/FMM.ih"
533 
534 // //
536 
537 #endif // !defined FMM_h
538 
539 #undef FMM_RECURSES
540 #endif // else defined(FMM_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition: FMM.h:151
AcceptedPointSet & myAcceptedPoints
Definition: FMM.h:200
Image & myImage
Definition: FMM.h:195
TPointPredicate PointPredicate
Definition: FMM.h:165
TPointFunctor PointFunctor
Definition: FMM.h:177
DGtal::uint64_t Area
Definition: FMM.h:187
static void initFromIncidentPointsRange(const TIteratorOnPairs &itb, const TIteratorOnPairs &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue, bool aFlagIsPositive=true)
void update(const Point &aPoint)
const PointPredicate & myPointPredicate
Definition: FMM.h:226
bool addNewAcceptedPoint(Point &aPoint, Value &aValue)
TImage Image
Definition: FMM.h:163
bool addNewCandidate(const Point &aPoint)
Value myMinValue
Definition: FMM.h:242
void compute()
FMM(Image &aImg, AcceptedPointSet &aSet, ConstAlias< PointPredicate > aPointPredicate, PointFunctor &aPointFunctor)
FMM(Image &aImg, AcceptedPointSet &aSet, ConstAlias< PointPredicate > aPointPredicate)
Image::Point Point
Definition: FMM.h:168
bool computeOneStep(Point &aPoint, Value &aValue)
BOOST_CONCEPT_ASSERT((concepts::CPointFunctor< TPointFunctor >))
TSet AcceptedPointSet
Definition: FMM.h:164
FMM(Image &aImg, AcceptedPointSet &aSet, ConstAlias< PointPredicate > aPointPredicate, const Area &aAreaThreshold, const Value &aValueThreshold)
void init()
PointFunctor::Value Value
Definition: FMM.h:178
Value myValueThreshold
Definition: FMM.h:237
Value min() const
PointFunctor * myPointFunctorPtr
Definition: FMM.h:212
std::set< PointValue, detail::PointValueCompare< PointValue > > CandidatePointSet
Definition: FMM.h:186
bool isValid() const
static void initFromBelsRange(const KSpace &aK, const TIteratorOnBels &itb, const TIteratorOnBels &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue, bool aFlagIsPositive=true)
Value getMin() const
CandidatePointSet myCandidatePoints
Definition: FMM.h:205
Value getMax() const
std::pair< Point, Value > PointValue
Definition: FMM.h:184
FMM(const FMM &other)
const bool myFlagIsOwning
Definition: FMM.h:219
void selfDisplay(std::ostream &out) const
BOOST_STATIC_ASSERT((boost::is_same< Point, typename PointPredicate::Point >::value))
BOOST_CONCEPT_ASSERT((concepts::CPointPredicate< TPointPredicate >))
BOOST_STATIC_ASSERT((boost::is_same< Point, typename AcceptedPointSet::Point >::value))
Point::Dimension Dimension
Definition: FMM.h:173
BOOST_CONCEPT_ASSERT((concepts::CDigitalSet< TSet >))
FMM(Image &aImg, AcceptedPointSet &aSet, ConstAlias< PointPredicate > aPointPredicate, const Area &aAreaThreshold, const Value &aValueThreshold, PointFunctor &aPointFunctor)
Value myMaxValue
Definition: FMM.h:247
Value max() const
Area myAreaThreshold
Definition: FMM.h:232
BOOST_CONCEPT_ASSERT((concepts::CImage< TImage >))
static void initFromPointsRange(const TIteratorOnPoints &itb, const TIteratorOnPoints &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue)
FMM & operator=(const FMM &other)
static void initFromBelsRange(const KSpace &aK, const TIteratorOnBels &itb, const TIteratorOnBels &ite, const TImplicitFunction &aF, Image &aImg, AcceptedPointSet &aSet, bool aFlagIsPositive=true)
static const Dimension dimension
Definition: FMM.h:174
Aim: This class is a model of CCellularGridSpaceND. It represents the cubical grid as a cell complex,...
DGtal::Dimension Dimension
Copy of the dimension type.
Definition: PointVector.h:623
Aim: Small binary predicate to order candidates points according to their (absolute) distance value.
Definition: FMM.h:77
bool operator()(const T &a, const T &b) const
Definition: FMM.h:87
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
boost::uint64_t uint64_t
unsigned 64-bit integer.
Definition: BasicTypes.h:65
Aim: Represents a set of points within the given domain. This set of points is modifiable by the user...
Definition: CDigitalSet.h:141
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:103
Aim: Defines a functor on points.
Definition: CPointFunctor.h:89
Aim: Defines a predicate on a point.
const Point aPoint(3, 4)