DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Preimage2D.h
1 
17 #pragma once
18 
31 #if defined(Preimage2D_RECURSES)
32 #error Recursive header files inclusion detected in Preimage2D.h
33 #else // defined(Preimage2D_RECURSES)
34 
35 #define Preimage2D_RECURSES
36 
37 #if !defined Preimage2D_h
38 
39 #define Preimage2D_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <list>
45 #include "DGtal/base/Common.h"
46 #include "DGtal/base/OpInSTLContainers.h"
47 #include "DGtal/shapes/fromPoints/Point2ShapePredicate.h"
48 #include "DGtal/io/Color.h"
50 
51 namespace DGtal
52 {
53 
55  // template class Preimage2D
92  template <typename Shape>
93  class Preimage2D
94  {
95 
96 
97  // ----------------------- Types ------------------------------
98  public:
99 
100  typedef typename Shape::Point Point;
101  typedef typename Shape::Point Vector;
102 
103  private:
104 
105  //container of points
106  typedef std::list<Point> Container;
107  //Iterators on the container
108  typedef typename std::list<Point>::iterator ForwardIterator;
109  typedef typename std::list<Point>::reverse_iterator BackwardIterator;
110  typedef typename std::list<Point>::const_iterator ConstForwardIterator;
111  typedef typename std::list<Point>::const_reverse_iterator ConstBackwardIterator;
112 
113  //Predicates used to decide whether the preimage
114  //has to be updated or not
123  //Predicates used to update the hulls
132 
133 
134 
135  // ----------------------- Standard services ------------------------------
136  public:
137 
144  Preimage2D(const Point & firstPoint, const Point & secondPoint, const Shape & aShape );
145 
149  ~Preimage2D();
150 
155  Preimage2D ( const Preimage2D & other );
156 
162  Preimage2D & operator= ( const Preimage2D & other );
163 
174  bool operator==( const Preimage2D & other) const;
175 
181  bool operator!=( const Preimage2D & other) const;
182 
194  bool isLeftExteriorAtTheFront(const Point & aP, const Point & aQ);
195 
207  bool isLeftExteriorAtTheBack(const Point & aP, const Point & aQ);
208 
220  bool isRightExteriorAtTheFront(const Point & aP, const Point & aQ);
221 
233  bool isRightExteriorAtTheBack(const Point & aP, const Point & aQ);
234 
246  bool canBeAddedAtTheFront(const Point & aP, const Point & aQ);
247 
259  bool canBeAddedAtTheBack(const Point & aP, const Point & aQ);
260 
275  bool addFront(const Point & aP, const Point & aQ);
276 
291  bool addBack(const Point & aP, const Point & aQ);
292 
293  // ----------------------- Interface --------------------------------------
294  public:
295 
300  void selfDisplay ( std::ostream & out ) const;
301 
306  bool isValid() const;
307 
311  Point getUf() const;
312 
316  Point getUl() const;
317 
321  Point getLf() const;
322 
326  Point getLl() const;
327 
334  void getSeparatingStraightLine(double& alpha, double& beta, double& gamma) const;
335 
339  const Shape & shape() const
340  {
341  return myShape;
342  };
343 
347  const Container & pHull() const
348  {
349  return myPHull;
350  };
351 
355  const Container & qHull() const
356  {
357  return myQHull;
358  };
359 
360  //------------------ display -------------------------------
365  //DrawableWithBoard2D* defaultStyle( std::string mode="" ) const;
366 
370  std::string className() const;
371 
372  // ------------------------- Protected Datas ------------------------------
373  private:
374  // ------------------------- Private Datas --------------------------------
375  private:
376 
380  Shape myShape;
381 
382  //lists of the vertices of the preimage
393 
394  // ------------------------- Hidden services ------------------------------
395  protected:
396 
397 
398  private:
399 
414  template <typename Iterator, typename Predicate>
415  void update(const Point & aPoint,
416  Container & aContainer,
417  Iterator & anIterator,
418  const Iterator & anEndIterator);
419 
420 
421 
422  // ------------------------- Internals ------------------------------------
423  private:
424 
425  }; // end of class Preimage2D
426 
427 
434  template <typename Shape>
435  std::ostream&
436  operator<< ( std::ostream & out, const Preimage2D<Shape> & object );
437 
438 
439 } // namespace DGtal
440 
441 
443 // Includes inline functions.
444 #include "DGtal/geometry/tools/Preimage2D.ih"
445 
446 // //
448 
449 #endif // !defined Preimage2D_h
450 
451 #undef Preimage2D_RECURSES
452 #endif // else defined(Preimage2D_RECURSES)