DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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/images/CImage.h"
53 #include "DGtal/images/ImageHelper.h"
54 #include "DGtal/kernel/sets/CDigitalSet.h"
55 #include "DGtal/kernel/sets/SetPredicate.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 details
66  {
68  // template class PointValueCompare
76  template<typename T>
78  public:
87  bool operator()(const T& a, const T& b)
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
146  template <typename TImage, typename TSet, typename TPointPredicate,
147  typename TPointFunctor = L2FirstOrderLocalDistance<TImage,TSet> >
148  class FMM
149  {
150 
151  // ----------------------- Types ------------------------------
152  public:
153 
154 
155  //concept assert
160 
161  typedef TImage Image;
162  typedef TSet AcceptedPointSet;
163  typedef TPointPredicate PointPredicate;
164 
165  //points
166  typedef typename Image::Point Vector;
167  typedef typename Image::Point Point;
168  BOOST_STATIC_ASSERT(( boost::is_same< Point, typename AcceptedPointSet::Point >::value ));
169  BOOST_STATIC_ASSERT(( boost::is_same< Point, typename PointPredicate::Point >::value ));
170 
171  //dimension
172  typedef typename Point::Dimension Dimension;
174 
175  //distance
176  typedef TPointFunctor PointFunctor;
177  typedef typename PointFunctor::Value Value;
178 
179 
180  private:
181 
182  //intern data types
183  typedef std::pair<Point, Value> PointValue;
184  typedef std::set<PointValue,
186  typedef unsigned long Area;
187 
188  // ------------------------- Private Datas --------------------------------
189  private:
190 
195 
200 
205 
212 
218  const bool myFlagIsOwning;
219 
226 
232 
237 
242 
247 
248 
249  // ----------------------- Standard services ------------------------------
250  public:
251 
257  FMM(Image& aImg, AcceptedPointSet& aSet,
258  const PointPredicate& aPointPredicate);
259 
265  FMM(Image& aImg, AcceptedPointSet& aSet,
266  const PointPredicate& aPointPredicate,
267  const Area& aAreaThreshold, const Value& aValueThreshold);
268 
274  FMM(Image& aImg, AcceptedPointSet& aSet,
275  const PointPredicate& aPointPredicate,
276  PointFunctor& aPointFunctor );
277 
283  FMM(Image& aImg, AcceptedPointSet& aSet,
284  const PointPredicate& aPointPredicate,
285  const Area& aAreaThreshold, const Value& aValueThreshold,
286  PointFunctor& aPointFunctor );
287 
291  ~FMM();
292 
293 
294  // ----------------------- Interface --------------------------------------
295  public:
296 
305  void compute();
306 
320  bool computeOneStep(Point& aPoint, Value& aValue);
321 
327  Value min() const;
328 
334  Value max() const;
335 
343  Value getMin() const;
344 
352  Value getMax() const;
353 
358  void selfDisplay ( std::ostream & out ) const;
359 
364  bool isValid() const;
365 
366  // ------------------------- static functions for init --------------------
367 
368 
379  template <typename TIteratorOnPoints>
380  static void initFromPointsRange(const TIteratorOnPoints& itb, const TIteratorOnPoints& ite,
381  Image& aImg, AcceptedPointSet& aSet,
382  const Value& aValue);
383 
397  template <typename KSpace, typename TIteratorOnBels>
398  static void initFromBelsRange(const KSpace& aK,
399  const TIteratorOnBels& itb, const TIteratorOnBels& ite,
400  Image& aImg, AcceptedPointSet& aSet,
401  const Value& aValue,
402  bool aFlagIsPositive = false);
416  template <typename KSpace, typename TIteratorOnBels, typename TImplicitFunction>
417  static void initFromBelsRange(const KSpace& aK,
418  const TIteratorOnBels& itb, const TIteratorOnBels& ite,
419  const TImplicitFunction& aF,
420  Image& aImg, AcceptedPointSet& aSet,
421  bool aFlagIsPositive = false);
422 
423 
437  template <typename TIteratorOnPairs>
438  static void initFromIncidentPointsRange(const TIteratorOnPairs& itb, const TIteratorOnPairs& ite,
439  Image& aImg, AcceptedPointSet& aSet,
440  const Value& aValue,
441  bool aFlagIsPositive = false);
442 
443  private:
444 
450  FMM ( const FMM & other );
451 
458  FMM & operator= ( const FMM & other );
459 
460  // ------------------------- Internals ------------------------------------
461  private:
462 
466  void init();
467 
479  bool addNewAcceptedPoint(Point& aPoint, Value& aValue);
480 
487  void update(const Point& aPoint);
488 
501  bool addNewCandidate(const Point& aPoint);
502 
503 
504  }; // end of class FMM
505 
506 
513  template <typename TImage, typename TSet, typename TPointPredicate, typename TPointFunctor >
514  std::ostream&
515  operator<< ( std::ostream & out, const FMM<TImage, TSet, TPointPredicate, TPointFunctor> & object );
516 
517 } // namespace DGtal
518 
519 
521 // Includes inline functions.
522 #include "DGtal/geometry/volumes/distance/FMM.ih"
523 
524 // //
526 
527 #endif // !defined FMM_h
528 
529 #undef FMM_RECURSES
530 #endif // else defined(FMM_RECURSES)