DGtal  0.9.2
FP.h
1 
17 #pragma once
18 
31 #if defined(FP_RECURSES)
32 #error Recursive header files inclusion detected in FP.h
33 #else // defined(FP_RECURSES)
34 
35 #define FP_RECURSES
36 
37 #if !defined FP_h
38 
39 #define FP_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <list>
45 #include "DGtal/kernel/CInteger.h"
46 #include "DGtal/kernel/PointVector.h"
47 #include "DGtal/geometry/curves/ArithmeticalDSSComputer.h"
48 #include "DGtal/base/Circulator.h"
49 #include "DGtal/base/Exceptions.h"
50 #include "DGtal/base/Common.h"
51 #include "DGtal/io/Color.h"
53 
54 namespace DGtal
55 {
56 
57  namespace detail
58  {
60 
73  template <typename TDSS>
74  class DSSDecorator
75  {
76  public:
80  typedef TDSS DSS;
81  protected:
85  TDSS* myDSS;
86  public:
91  bool isExtendableFront() const
92  {
93  return myDSS->isExtendableFront();
94  }
100  bool extendFront()
101  {
102  return myDSS->extendFront();
103  }
109  bool retractBack()
110  {
111  return myDSS->retractBack();
112  }
117  typename DSS::ConstIterator end()
118  {
119  return myDSS->end();
120  }
121 
126  virtual ~DSSDecorator() {}
131  virtual typename TDSS::Point firstLeaningPoint() const = 0;
136  virtual typename TDSS::Point lastLeaningPoint() const = 0;
141  virtual bool isInConvexPart() const = 0;
142  };
143 
159  template <typename TDSS>
160  class DSSDecorator4ConvexPart : public DSSDecorator<TDSS>
161  {
162  public:
168  {
169  this->myDSS = &aDSS;
170  }
175  typename TDSS::Point firstLeaningPoint() const
176  {
177  return this->myDSS->Uf();
178  }
183  typename TDSS::Point lastLeaningPoint() const
184  {
185  return this->myDSS->Ul();
186  }
191  bool isInConvexPart() const { return true; }
192 
193  };
194 
210  template <typename TDSS>
212  {
213  public:
219  {
220  this->myDSS = &aDSS;
221  }
226  typename TDSS::Point firstLeaningPoint() const
227  {
228  return this->myDSS->Lf();
229  }
234  typename TDSS::Point lastLeaningPoint() const
235  {
236  return this->myDSS->Ll();
237  }
242  bool isInConvexPart() const { return false; }
243  };
244 
245  } //end namespace detail
247 
248 
250  // template class FP
291  template <typename TIterator, typename TInteger, int connectivity>
292  class FP
293  {
294 
295  // ----------------------- Types ------------------------------
296  public:
297 
298 
300 
303 
306 
308 
309  typedef std::list<Point> Polygon;
310 
311 
312 
313  // ----------------------- Standard services ------------------------------
314  public:
315 
321  FP(const TIterator& itb, const TIterator& ite) throw( InputException ) ;
322 
326  ~FP();
327 
328  // ----------------------- Interface --------------------------------------
329  public:
330 
334  const Polygon& polygon() const;
335 
339  bool isClosed() const;
340 
341 
346  bool isValid() const;
347 
348 
352  typename Polygon::size_type size() const;
353 
354 
359  template <typename OutputIterator>
360  OutputIterator copyFP(OutputIterator result) const;
361 
366  template <typename OutputIterator>
367  OutputIterator copyMLP(OutputIterator result) const;
368 
369 
370  // ------------------------- Protected Datas ------------------------------
371  private:
372 
373  // ------------------------- Private Datas --------------------------------
374  private:
375 
379  Polygon myPolygon;
380 
381  protected:
382 
383 
384 
385  // ------------------------- Hidden services ------------------------------
386  private:
387 
396  template<typename Adapter>
397  Adapter* initConvexityConcavity( typename Adapter::DSS &aDSS );
398 
408  template<typename Adapter>
409  bool removingStep( Adapter* adapter );
410 
422  template<typename Adapter>
423  bool addingStep( Adapter* adapter,
424  const typename Adapter::DSS::ConstIterator& itEnd );
425 
433  template<typename Adapter>
434  void addingStep( Adapter* adapter );
435 
436 
442  void algorithm(const TIterator& itb, const TIterator& ite) throw( InputException );
443 
450  void algorithm(const TIterator& itb, const TIterator& ite, IteratorType ) throw( InputException );
451 
458  void algorithm(const TIterator& itb, const TIterator& ite, CirculatorType ) throw( InputException );
459 
460 
461 
462  // ------------------------- Hidden helpers ------------------------------
463 
471  bool isValid(const Point& a,const Point& b, const Point& c) const;
472 
479  bool quadrant (const Vector& v, const int& q) const;
480 
489  RealPoint getRealPoint (const Point& a,const Point& b, const Point& c) const;
490 
491 
492  // ----------------------------------------------------------------------
498  FP ( const FP & other );
499 
506  FP & operator= ( const FP & other );
507 
508  // ------------------------- Display ------------------------------------
509  public:
510 
515  void selfDisplay ( std::ostream & out ) const;
516 
517 
518  // --------------- CDrawableWithBoard2D realization --------------------
519  public:
520 
524  std::string className() const;
525 
526  }; // end of class FP
527 
528 
535  template <typename TIterator, typename TInteger, int connectivity>
536  std::ostream&
537  operator<< ( std::ostream & out, const FP<TIterator,TInteger,connectivity> & object );
538 
539 } // namespace DGtal
540 
541 
543 // Includes inline functions.
544 #include "DGtal/geometry/curves/FP.ih"
545 
546 // //
548 
549 #endif // !defined FP_h
550 
551 #undef FP_RECURSES
552 #endif // else defined(FP_RECURSES)
FP(const TIterator &itb, const TIterator &ite)
virtual TDSS::Point lastLeaningPoint() const =0
const Polygon & polygon() const
void selfDisplay(std::ostream &out) const
Aim: adapter for TDSS used by FP in CONVEX parts. Has 2 methods:
Definition: FP.h:160
Adapter * initConvexityConcavity(typename Adapter::DSS &aDSS)
virtual TDSS::Point firstLeaningPoint() const =0
TDSS::Point lastLeaningPoint() const
Definition: FP.h:234
DGtal::PointVector< 2, TInteger > Vector
Definition: FP.h:302
bool quadrant(const Vector &v, const int &q) const
STL namespace.
DGtal::ArithmeticalDSSComputer< TIterator, TInteger, connectivity > DSSComputer
Definition: FP.h:307
OutputIterator copyMLP(OutputIterator result) const
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition: PointVector.h:141
bool isClosed() const
Polygon::size_type size() const
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
Polygon myPolygon
Definition: FP.h:379
TDSS::Point firstLeaningPoint() const
Definition: FP.h:175
TDSS::Point lastLeaningPoint() const
Definition: FP.h:183
virtual ~DSSDecorator()
Definition: FP.h:126
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInteger >))
Aim: adapter for TDSS used by FP in CONCAVE parts. Has 2 methods:
Definition: FP.h:211
bool isExtendableFront() const
Definition: FP.h:91
RealPoint getRealPoint(const Point &a, const Point &b, const Point &c) const
void algorithm(const TIterator &itb, const TIterator &ite)
DGtal is the top-level namespace which contains all DGtal functions and types.
bool isValid() const
Aim: Computes the faithful polygon (FP) of a range of 4/8-connected 2D Points.
Definition: FP.h:292
DGtal::PointVector< 2, double > RealPoint
Definition: FP.h:304
DGtal::PointVector< 2, double > RealVector
Definition: FP.h:305
bool addingStep(Adapter *adapter, const typename Adapter::DSS::ConstIterator &itEnd)
std::list< Point > Polygon
Definition: FP.h:309
virtual bool isInConvexPart() const =0
TDSS::Point firstLeaningPoint() const
Definition: FP.h:226
DSS::ConstIterator end()
Definition: FP.h:117
bool removingStep(Adapter *adapter)
DGtal::PointVector< 2, TInteger > Point
Definition: FP.h:301
Aim: Abstract DSSDecorator for ArithmeticalDSSComputer. Has 2 virtual methods returning the first and...
Definition: FP.h:74
std::string className() const
OutputIterator copyFP(OutputIterator result) const