DGtal  0.9.2
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)
38 
39 #define FMM_RECURSES
40 
41 #if !defined FMM_h
42 
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 
195  Image& myImage;
196 
200  AcceptedPointSet& myAcceptedPoints;
201 
205  CandidatePointSet myCandidatePoints;
206 
212  PointFunctor* myPointFunctorPtr;
213 
219  const bool myFlagIsOwning;
220 
226  const PointPredicate& myPointPredicate;
227 
233 
238 
242  Value myMinValue;
243 
247  Value myMaxValue;
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 
489  bool addNewAcceptedPoint(Point& aPoint, Value& aValue);
490 
497  void update(const Point& aPoint);
498 
511  bool addNewCandidate(const Point& aPoint);
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)
Value myMinValue
Definition: FMM.h:242
Point::Dimension Dimension
Definition: FMM.h:173
static void initFromBelsRange(const KSpace &aK, const TIteratorOnBels &itb, const TIteratorOnBels &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue, bool aFlagIsPositive=true)
bool addNewCandidate(const Point &aPoint)
Image & myImage
Definition: FMM.h:195
Aim: Small binary predicate to order candidates points according to their (absolute) distance value...
Definition: FMM.h:77
Value getMax() const
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
TPointFunctor PointFunctor
Definition: FMM.h:177
TPointPredicate PointPredicate
Definition: FMM.h:165
std::pair< Point, Value > PointValue
Definition: FMM.h:184
DGtal::Dimension Dimension
Copy of the dimension type.
Definition: PointVector.h:164
BOOST_CONCEPT_ASSERT((concepts::CImage< TImage >))
TSet AcceptedPointSet
Definition: FMM.h:164
Aim: Fast Marching Method (FMM) for nd distance transforms.
Definition: FMM.h:150
BOOST_STATIC_ASSERT((boost::is_same< Point, typename AcceptedPointSet::Point >::value))
PointFunctor * myPointFunctorPtr
Definition: FMM.h:212
static void initFromPointsRange(const TIteratorOnPoints &itb, const TIteratorOnPoints &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue)
void compute()
bool addNewAcceptedPoint(Point &aPoint, Value &aValue)
Value myValueThreshold
Definition: FMM.h:237
Aim: Defines a predicate on a point.
static void initFromIncidentPointsRange(const TIteratorOnPairs &itb, const TIteratorOnPairs &ite, Image &aImg, AcceptedPointSet &aSet, const Value &aValue, bool aFlagIsPositive=true)
DGtal::uint64_t Area
Definition: FMM.h:187
void init()
std::set< PointValue, detail::PointValueCompare< PointValue > > CandidatePointSet
Definition: FMM.h:186
void selfDisplay(std::ostream &out) const
const bool myFlagIsOwning
Definition: FMM.h:219
TImage Image
Definition: FMM.h:163
static const Dimension dimension
Definition: FMM.h:174
Image::Point Point
Definition: FMM.h:168
PointFunctor::Value Value
Definition: FMM.h:178
DGtal is the top-level namespace which contains all DGtal functions and types.
const PointPredicate & myPointPredicate
Definition: FMM.h:226
Value max() const
Value getMin() const
Area myAreaThreshold
Definition: FMM.h:232
CandidatePointSet myCandidatePoints
Definition: FMM.h:205
FMM(Image &aImg, AcceptedPointSet &aSet, ConstAlias< PointPredicate > aPointPredicate)
boost::uint64_t uint64_t
unsigned 64-bit integer.
Definition: BasicTypes.h:65
bool operator()(const T &a, const T &b) const
Definition: FMM.h:87
Value min() const
Value myMaxValue
Definition: FMM.h:247
Aim: Defines a functor on points.
Definition: CPointFunctor.h:88
void update(const Point &aPoint)
Aim: Represents a set of points within the given domain. This set of points is modifiable by the user...
Definition: CDigitalSet.h:138
bool isValid() const
Aim: Defines the concept describing a read/write image, having an output iterator.
Definition: CImage.h:102
FMM & operator=(const FMM &other)
bool computeOneStep(Point &aPoint, Value &aValue)
AcceptedPointSet & myAcceptedPoints
Definition: FMM.h:200