DGtal  0.9.2
ArithmeticalDSS.h
1 
17 #pragma once
18 
31 #if defined(ArithmeticalDSS_RECURSES)
32 #error Recursive header files inclusion detected in ArithmeticalDSS.h
33 #else // defined(ArithmeticalDSS_RECURSES)
34 
35 #define ArithmeticalDSS_RECURSES
36 
37 #if !defined ArithmeticalDSS_h
38 
39 #define ArithmeticalDSS_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/base/Exceptions.h"
46 
47 #include "DGtal/geometry/curves/ArithmeticalDSL.h"
48 #include "DGtal/geometry/curves/ArithmeticalDSSCheck.h"
49 #include "DGtal/geometry/curves/ArithmeticalDSSFactory.h"
50 #include "DGtal/geometry/curves/ArithmeticalDSSConvexHull.h"
51 #include "DGtal/arithmetic/SternBrocot.h"
52 #include "DGtal/math/linalg/SimpleMatrix.h"
54 
55 namespace DGtal
56 {
57 
59  // template class ArithmeticalDSS
92  template <typename TCoordinate,
93  typename TInteger = TCoordinate,
94  unsigned short adjacency = 8>
95  class ArithmeticalDSS
96  {
97  friend class ArithmeticalDSSFactory<TCoordinate, TInteger, adjacency>;
98 
99  // ----------------------- static members -----------------------------------
100  public:
104  static const unsigned short foregroundAdjacency = adjacency;
105 
106  // ----------------------- Inner types -----------------------------------
107  public:
108 
113  typedef TCoordinate Coordinate;
118  typedef TInteger Integer;
120 
128  typedef typename DSL::Space Space;
132  typedef typename DSL::Point Point;
136  typedef typename DSL::Vector Vector;
140  typedef typename DSL::Steps Steps;
144  typedef Coordinate Position;
148  typedef typename DSL::ConstIterator ConstIterator;
153 
159 
160  // ----------------------- Standard services ------------------------------
161  public:
162 
168  ArithmeticalDSS(const Point& aPoint);
169 
190  ArithmeticalDSS(const Coordinate& aA, const Coordinate& aB,
191  const Integer& aLowerBound, const Integer& aUpperBound,
192  const Point& aF, const Point& aL,
193  const Point& aUf, const Point& aUl,
194  const Point& aLf, const Point& aLl,
195  const Steps& aSteps, const Vector& aShift);
196 
212  ArithmeticalDSS(const DSL& aDSL,
213  const Point& aF, const Point& aL,
214  const Point& aUf, const Point& aUl,
215  const Point& aLf, const Point& aLl);
216 
238  ArithmeticalDSS(const Coordinate& aA, const Coordinate& aB,
239  const Point& aF, const Point& aL,
240  const Point& aUf, const Point& aUl,
241  const Point& aLf, const Point& aLl);
242 
243 
244 
245 
259  ArithmeticalDSS(const Point& aF, const Point& aL,
260  const bool& areOnTheUpperLine = true);
261 
273  ArithmeticalDSS(const DSL& aDSL, const Point& aF, const Point& aL);
274 
286  ArithmeticalDSS(const ArithmeticalDSS& aDSS, const Point& aF, const Point& aL);
287 
297  template <typename Iterator>
298  ArithmeticalDSS(const Iterator& aItb, const Iterator& aIte) throw( InputException );
299 
304  ArithmeticalDSS ( const ArithmeticalDSS & aOther );
305 
311  ArithmeticalDSS& operator= ( const ArithmeticalDSS & aOther );
312 
319  ArithmeticalDSS negate () const;
320 
327  bool equalsTo ( const ArithmeticalDSS & aOther ) const;
328 
336  bool operator== ( const ArithmeticalDSS & aOther ) const;
337 
344  bool operator!= ( const ArithmeticalDSS & aOther ) const;
345 
350 
351  // ----------------------- Interface --------------------------------------
352  public:
353 
358  void selfDisplay ( std::ostream & out ) const;
359 
366  bool isValid() const;
367 
374  const DSL& dsl() const;
375 
379  Coordinate a() const;
380 
384  Coordinate b() const;
385 
390  Integer mu() const;
391 
396  Integer omega() const;
397 
401  Vector shift() const;
406  Steps steps() const;
407 
412  Point back() const;
413 
418  Point front() const;
419 
423  Point Uf() const;
424 
428  Point Ul() const;
429 
433  Point Lf() const;
434 
438  Point Ll() const;
439 
446  Integer remainder(const Point& aPoint) const;
447 
456  Integer orthogonalPosition(const Point& aPoint) const;
457 
465  Position position(const Point& aPoint) const;
466 
477  bool before (const Point& aP1, const Point& aP2) const;
478 
489  bool beforeOrEqual (const Point& aP1, const Point& aP2) const;
490 
497  bool isInDSL(const Point& aPoint) const;
498 
504  bool isInDSS(const Point& aPoint) const;
505 
506  bool operator()(const Point& aPoint) const;
507 
508 
515  bool isInDSL(const DSL& aDSL) const;
516 
517 
529  bool isInDSL(const DSL& aDSL, std::vector<Point> &Ulp, std::vector<Point> &Llp, Point& outP) const;
530 
531 
532 
547  ArithmeticalDSS computeUnion(const ArithmeticalDSS & aOther) const;
548 
549 
550  // ----------------------- Iterator services -------------------------------
555  ConstIterator begin() const;
556 
561  ConstIterator end() const;
562 
567  ConstReverseIterator rbegin() const;
568 
573  ConstReverseIterator rend() const;
574 
575  // ----------------------- Dynamic methods --------------------------------
576 
599  unsigned short int isExtendableFront( const Point& aNewPoint ) const;
600 
623  unsigned short int isExtendableBack( const Point& aNewPoint ) const;
624 
637  bool extendFront( const Point& aNewPoint );
650  bool extendBack( const Point& aNewPoint );
651 
661  bool retractFront();
662 
672  bool retractBack();
673 
674  // ------------------------- Display services ------------------------------
684  PointD project( const Point& aM, double aR ) const;
685 
694  PointD project( const Point & aM, const Point & aP ) const;
695 
699  std::string className() const;
700 
701  // ------------------------- Hidden services ------------------------------
702  protected:
703 
729  bool retractUpdateLeaningPoints( const Vector& aDirection,
730  const Point& aFirst,
731  const Point& aLast,
732  const Point& aBezout,
733  const Point& aFirstAtOppositeSide,
734  Point& aLastAtOppositeSide,
735  Point& aFirstAtRemovalSide,
736  const Point& aLastAtRemovalSide);
737 
745  void retractUpdateParameters( const Vector& aNewDirection );
746 
747 
748  // ------------------------- Protected Datas ------------------------------
749  protected:
750 
751  // -------------------- first and last point, leaning points ---------------
755  Point myF;
759  Point myL;
763  Point myUf;
767  Point myUl;
771  Point myLf;
775  Point myLl;
776 
777  //------------------------ DSL ---------------------------------------------
781  DSL myDSL;
782 
783  }; // end of class ArithmeticalDSS
784 
785 
792  template <typename TCoordinate, typename TInteger, unsigned short adjacency>
793  std::ostream&
794  operator<< ( std::ostream & out, const ArithmeticalDSS<TCoordinate, TInteger, adjacency> & object );
795 
796 } // namespace DGtal
797 
798 
800 // Aliases
801 namespace DGtal
802 {
828  template <typename TCoordinate, typename TInteger = TCoordinate>
829  class StandardDSS4:
830  public ArithmeticalDSS<TCoordinate, TInteger, 4>
831  {
832  public:
834  typedef typename Super::Point Point;
835  typedef typename Super::Coordinate Coordinate;
836  typedef typename Super::DSL DSL;
837 
838  public:
839 
857  StandardDSS4(const Coordinate& aA, const Coordinate& aB,
858  const Point& aF, const Point& aL,
859  const Point& aUf, const Point& aUl,
860  const Point& aLf, const Point& aLl);
861 
875  StandardDSS4(const Point& aF, const Point& aL,
876  const bool& isOnTheUpperLine = true);
877 
888  StandardDSS4(const DSL& aDSL,
889  const Point& aF, const Point& aL);
890 
902  StandardDSS4(const StandardDSS4& aDSS,
903  const Point& aF, const Point& aL);
904 
914  template <typename Iterator>
915  StandardDSS4(const Iterator& aItb, const Iterator& aIte) throw( InputException );
916 
921  StandardDSS4 ( const StandardDSS4 & aOther );
922 
928  StandardDSS4 & operator= ( const StandardDSS4 & aOther );
929 
930  };
931 
967  template <typename TCoordinate, typename TInteger = TCoordinate>
968  class NaiveDSS8:
969  public ArithmeticalDSS<TCoordinate, TInteger, 8>
970  {
971  public:
973  typedef typename Super::Point Point;
974  typedef typename Super::Coordinate Coordinate;
975  typedef typename Super::DSL DSL;
976 
977  public:
995  NaiveDSS8(const Coordinate& aA, const Coordinate& aB,
996  const Point& aF, const Point& aL,
997  const Point& aUf, const Point& aUl,
998  const Point& aLf, const Point& aLl);
999 
1000 
1014  NaiveDSS8(const Point& aF, const Point& aL,
1015  const bool& isOnTheUpperLine = true);
1016 
1027  NaiveDSS8(const DSL& aDSL,
1028  const Point& aF, const Point& aL);
1029 
1041  NaiveDSS8(const NaiveDSS8& aDSS,
1042  const Point& aF, const Point& aL);
1043 
1053  template <typename Iterator>
1054  NaiveDSS8(const Iterator& aItb, const Iterator& aIte) throw( InputException );
1055 
1060  NaiveDSS8 ( const NaiveDSS8 & aOther );
1061 
1067  NaiveDSS8 & operator= ( const NaiveDSS8 & aOther );
1068 
1069  };
1070 } // namespace DGtal
1071 
1072 
1074 // Includes inline functions.
1075 #include "DGtal/geometry/curves/ArithmeticalDSS.ih"
1076 // //
1078 
1080 #endif // !defined ArithmeticalDSS_h
1081 
1082 #undef ArithmeticalDSS_RECURSES
1083 #endif // else defined(ArithmeticalDSS_RECURSES)
bool isInDSL(const Point &aPoint) const
Integer orthogonalPosition(const Point &aPoint) const
Coordinate a() const
Vector shift() const
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
bool operator==(const ArithmeticalDSS &aOther) const
std::string className() const
Integer remainder(const Point &aPoint) const
unsigned short int isExtendableBack(const Point &aNewPoint) const
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa...
ArithmeticalDSS(const Point &aPoint)
ConstIterator begin() const
ConstReverseIterator rbegin() const
NaiveDSS8 & operator=(const NaiveDSS8 &aOther)
bool retractUpdateLeaningPoints(const Vector &aDirection, const Point &aFirst, const Point &aLast, const Point &aBezout, const Point &aFirstAtOppositeSide, Point &aLastAtOppositeSide, Point &aFirstAtRemovalSide, const Point &aLastAtRemovalSide)
DGtal::PointVector< 2, double > PointD
Integer omega() const
static const unsigned short foregroundAdjacency
bool extendBack(const Point &aNewPoint)
ArithmeticalDSS computeUnion(const ArithmeticalDSS &aOther) const
Point front() const
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
Coordinate b() const
void selfDisplay(std::ostream &out) const
void retractUpdateParameters(const Vector &aNewDirection)
bool isValid() const
Super::Point Point
ConstIterator end() const
Aim: This class represents a standard digital straight segment (DSS), ie. the sequence of simply 4-co...
DSL::ConstReverseIterator ConstReverseIterator
Aim: Set of static methods that create digital straight segments (DSS) from some input parameters...
ConstReverseIterator rend() const
Point back() const
ArithmeticalDSL< Coordinate, Integer, adjacency > DSL
Super::Coordinate Coordinate
Aim: This class represents a naive (resp. standard) digital straight segment (DSS), ie. the sequence of simply 8- (resp. 4-)connected digital points contained in a naive (resp. standard) digital straight line (DSL) between two points of it.
DGtal is the top-level namespace which contains all DGtal functions and types.
ArithmeticalDSS & operator=(const ArithmeticalDSS &aOther)
StandardDSS4 & operator=(const StandardDSS4 &aOther)
PointD project(const Point &aM, double aR) const
ArithmeticalDSS< TCoordinate, TInteger, 4 > Super
bool extendFront(const Point &aNewPoint)
bool beforeOrEqual(const Point &aP1, const Point &aP2) const
Super::Coordinate Coordinate
const DSL & dsl() const
bool isInDSS(const Point &aPoint) const
BOOST_CONCEPT_ASSERT((concepts::CInteger< Coordinate >))
unsigned short int isExtendableFront(const Point &aNewPoint) const
bool equalsTo(const ArithmeticalDSS &aOther) const
Steps steps() const
bool before(const Point &aP1, const Point &aP2) const
ArithmeticalDSS< TCoordinate, TInteger, 8 > Super
ArithmeticalDSS negate() const
Integer mu() const
DSL::ConstIterator ConstIterator
NaiveDSS8(const Coordinate &aA, const Coordinate &aB, const Point &aF, const Point &aL, const Point &aUf, const Point &aUl, const Point &aLf, const Point &aLl)
Aim: This class represents a standard digital straight segment (DSS), ie. the sequence of simply 8-co...
bool operator()(const Point &aPoint) const
bool operator!=(const ArithmeticalDSS &aOther) const
Position position(const Point &aPoint) const
StandardDSS4(const Coordinate &aA, const Coordinate &aB, const Point &aF, const Point &aL, const Point &aUf, const Point &aUl, const Point &aLf, const Point &aLl)