DGtal  0.9.2
ArithmeticalDSL.h
1 
17 #pragma once
18 
31 #if defined(ArithmeticalDSL_RECURSES)
32 #error Recursive header files inclusion detected in ArithmeticalDSL.h
33 #else // defined(ArithmeticalDSL_RECURSES)
34 
35 #define ArithmeticalDSL_RECURSES
36 
37 #if !defined ArithmeticalDSL_h
38 
39 #define ArithmeticalDSL_h
40 
42 // Inclusions
43 #include <iostream>
44 #include <utility>
45 #include "DGtal/base/Common.h"
46 #include "DGtal/base/Exceptions.h"
47 #include "DGtal/base/ReverseIterator.h"
48 #include "DGtal/kernel/CInteger.h"
49 #include "DGtal/kernel/CSignedNumber.h"
50 #include "DGtal/kernel/SpaceND.h"
51 #include "DGtal/kernel/PointVector.h"
52 #include "DGtal/arithmetic/IntegerComputer.h"
53 
54 #include "DGtal/geometry/curves/ArithmeticalDSLKernel.h"
55 
57 
58 namespace DGtal
59 {
60 
61  //forward declaration of ArithmeticalDSS for the friendship
62  template <typename TCoordinate,
63  typename TInteger,
64  unsigned short adjacency>
66 
68  // template class ArithmeticalDSL
103  template <typename TCoordinate,
104  typename TInteger = TCoordinate,
105  unsigned short adjacency = 8>
107  {
108 
109  // ----------------------- Friend class -----------------------------------
110  public:
111  friend class ArithmeticalDSS<TCoordinate, TInteger, adjacency>;
112 
113  // ----------------------- static members -----------------------------------
114  public:
118  static const unsigned short foregroundAdjacency = adjacency;
119 
120  // ----------------------- Inner types -----------------------------------
121  public:
122 
127  typedef TCoordinate Coordinate;
132  typedef TInteger Integer;
141  typedef typename Space::Point Point;
145  typedef typename Space::Vector Vector;
149  typedef std::pair<Vector,Vector> Steps;
153  typedef Coordinate Position;
154 
158  typedef std::pair<unsigned char, unsigned char> Octant;
159 
160 
161 
178  : public boost::iterator_facade<ConstIterator, //derived type, the ConstIterator class itself
179  Point const, //value type
180  boost::random_access_traversal_tag, //traversal tag
181  Point const, //reference type
182  //NB: since there is no underlying container,
183  //we cannot return a reference.
184  Position //difference type
185  >
186  {
187 
188  // ------------------------- Private data -----------------------
189  private:
190 
193 
196 
199 
202 
205 
206  // ------------------------- Standard services -----------------------
207  public:
208 
212  ConstIterator();
213 
219  ConstIterator( const ArithmeticalDSL* aDSL, const Point& aPoint );
220 
225  ConstIterator( const ConstIterator & aOther );
231  ConstIterator& operator= ( const ConstIterator & aOther );
232 
236  ~ConstIterator();
237 
238  // ------------------------- useful services -------------------------
239  public:
244  Integer remainder() const;
245 
246  // ------------------------- iteration services -------------------------
247  private:
249 
254  Point const dereference() const;
255 
259  void increment();
260 
264  void decrement();
265 
274  bool equal(const ConstIterator& aOther) const;
275 
282  void advance(const Position& aShift);
283 
290  Position distance_to(const ConstIterator& aOther) const;
291 
292  };
293 
298 
299  // ----------------------- Standard services ------------------------------
300  public:
301 
316  ArithmeticalDSL(const Coordinate& aA, const Coordinate& aB,
317  const Integer& aLowerIntercept, const Integer& aUpperIntercept,
318  const Steps& aSteps, const Vector& aShift);
319 
327  ArithmeticalDSL(const Coordinate& aA, const Coordinate& aB,
328  const Integer& aMu);
329 
330 
335  ArithmeticalDSL ( const ArithmeticalDSL & aOther );
336 
342  ArithmeticalDSL& operator= ( const ArithmeticalDSL & aOther );
343 
349  ArithmeticalDSL negate () const;
350 
357  bool equalsTo ( const ArithmeticalDSL & aOther ) const;
358 
367  bool operator== ( const ArithmeticalDSL & aOther ) const;
368 
375  bool operator!= ( const ArithmeticalDSL & aOther ) const;
376 
384  bool sameOctant ( const ArithmeticalDSL & aOther, typename Octant::first_type *theOctant ) const;
385 
386 
392  bool isUpperLeaningPoint(const Point& aPoint) const;
393 
399  bool isLowerLeaningPoint(const Point& aPoint) const;
400 
401 
411  Octant octant() const;
412 
413 
418 
419  // ----------------------- Interface --------------------------------------
420  public:
421 
426  void selfDisplay ( std::ostream & out ) const;
427 
435  bool checkShiftAndSteps() const;
436 
444  bool isValid() const;
445 
449  Coordinate a() const;
450 
454  Coordinate b() const;
455 
459  Integer mu() const;
460 
465  Integer omega() const;
466 
471  Position patternLength() const;
472 
477  Vector shift() const;
478 
482  Steps steps() const;
483 
493  static Integer remainder(const Coordinate& aA,
494  const Coordinate& aB,
495  const Point& aPoint);
496 
503  Integer remainder(const Point& aPoint) const;
504 
513  Integer orthogonalPosition(const Point& aPoint) const;
514 
522  Position position(const Point& aPoint) const;
523 
530  Point getPoint() const;
531 
539  Point getPoint(const Position& aPosition) const;
540 
551  bool before (const Point& aP1, const Point& aP2) const;
552 
563  bool beforeOrEqual (const Point& aP1, const Point& aP2) const;
564 
570  bool isInDSL(const Point& aPoint) const;
571 
572 
573 
580  bool operator()(const Point& aPoint) const;
581 
582 
583  // ----------------------- Iterator services -------------------------------
590  ConstIterator begin(const Point& aPoint) const;
591 
598  ConstIterator end(const Point& aPoint) const;
599 
606  ConstReverseIterator rbegin(const Point& aPoint) const;
607 
614  ConstReverseIterator rend(const Point& aPoint) const;
615 
616 
617  // ------------------------- Other services ------------------------------
618  public:
619  static Coordinate toCoordinate(const Integer& aI);
620 
621  // ------------------------- Protected Datas ------------------------------
622  protected:
623 
624  // -------------------------vectors ---------------------------------------
630  Steps mySteps;
635  Vector myShift;
636 
637  //------------------------ parameters of the DSL --------------------------
641  Coordinate myA;
645  Coordinate myB;
651  Integer myLowerBound;
658  Integer myUpperBound;
659 
660 
661 
662  }; // end of class ArithmeticalDSL
663 
664 
671  template <typename TCoordinate, typename TInteger, unsigned short adjacency>
672  std::ostream&
673  operator<< ( std::ostream & out, const ArithmeticalDSL<TCoordinate, TInteger, adjacency> & object );
674 
675 } // namespace DGtal
676 
677 
679 // Aliases
680 namespace DGtal
681 {
707  template <typename TCoordinate, typename TInteger = TCoordinate>
708  class StandardDSL:
709  public ArithmeticalDSL<TCoordinate, TInteger, 4>
710  {
711  public:
716  typedef typename Super::Coordinate Coordinate;
717  typedef typename Super::Integer Integer;
718 
719  public:
727  StandardDSL (const Coordinate& aA,
728  const Coordinate& aB,
729  const Integer& aMu);
730 
735  StandardDSL ( const StandardDSL & aOther );
736 
742  StandardDSL & operator= ( const StandardDSL & aOther );
743 
744  };
745 
775  template <typename TCoordinate, typename TInteger = TCoordinate>
776  class NaiveDSL:
777  public ArithmeticalDSL<TCoordinate, TInteger, 8>
778  {
779  public:
784  typedef typename Super::Coordinate Coordinate;
785  typedef typename Super::Integer Integer;
786 
787  public:
795  NaiveDSL (const Coordinate& aA,
796  const Coordinate& aB,
797  const Integer& aMu);
798 
799 
804  NaiveDSL ( const NaiveDSL & aOther );
805 
811  NaiveDSL & operator= ( const NaiveDSL & aOther );
812 
813  };
814 } // namespace DGtal
815 
817 // Tools
818 namespace DGtal
819 {
820  namespace detail {
821 
830  template <typename TInput, typename TOutput >
832  {
841  inline
842  static TOutput cast(const TInput& aInput)
843  {
844  return static_cast<TOutput>(aInput);
845  }
846  };
847 #ifdef WITH_BIGINTEGER
848  //specialized versions for DGtal::BigInteger
849  template <typename TOutput>
850  struct toCoordinateImpl<DGtal::BigInteger, TOutput>
851  {
854 
855  inline
856  static TOutput cast(const DGtal::BigInteger& aInput)
857  {
858  ASSERT( (aInput <= static_cast<DGtal::BigInteger>(std::numeric_limits<TOutput>::max())) &&
859  (aInput >= static_cast<DGtal::BigInteger>(std::numeric_limits<TOutput>::min())) );
860  return static_cast<TOutput>(aInput.get_si());
861  }
862  };
863  template <>
864  struct toCoordinateImpl<DGtal::BigInteger, DGtal::BigInteger>
865  {
866 
867  inline
868  static DGtal::BigInteger cast(const DGtal::BigInteger& aInput)
869  {
870  return aInput;
871  }
872  };
873 #endif
874 
875  } //namespace detail
876 
877 } // namespace DGtal
878 
880 // Includes inline functions.
881 #include "DGtal/geometry/curves/ArithmeticalDSL.ih"
882 // //
884 
886 #endif // !defined ArithmeticalDSL_h
887 
888 #undef ArithmeticalDSL_RECURSES
889 #endif // else defined(ArithmeticalDSL_RECURSES)
bool operator!=(const ArithmeticalDSL &aOther) const
static const unsigned short foregroundAdjacency
DGtal::ReverseIterator< ConstIterator > ConstReverseIterator
Point getPoint() const
bool equalsTo(const ArithmeticalDSL &aOther) const
bool isInDSL(const Point &aPoint) const
ArithmeticalDSLKernel< Coordinate, adjacency >::Space Space
Aim: Define a simple functor that can cast a signed integer (possibly a DGtal::BigInteger) into anoth...
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Vector shift() const
NaiveDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aMu)
ConstIterator begin(const Point &aPoint) const
Coordinate b() const
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa...
Integer myQuantityToAdd
Quantity to add to the current remainder.
Position distance_to(const ConstIterator &aOther) const
std::pair< Vector, Vector > Steps
BOOST_CONCEPT_ASSERT((concepts::CSignedNumber< TInput >))
bool operator()(const Point &aPoint) const
bool beforeOrEqual(const Point &aP1, const Point &aP2) const
std::pair< unsigned char, unsigned char > Octant
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Definition: BasicTypes.h:79
Super::Coordinate Coordinate
bool isLowerLeaningPoint(const Point &aPoint) const
bool sameOctant(const ArithmeticalDSL &aOther, typename Octant::first_type *theOctant) const
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
BOOST_CONCEPT_ASSERT((concepts::CInteger< Coordinate >))
bool checkShiftAndSteps() const
ArithmeticalDSL negate() const
Aim: This class is an alias of ArithmeticalDSS for naive DSL. It represents a naive digital straight ...
Integer myCurrentRemainder
Remainder of the current point.
bool before(const Point &aP1, const Point &aP2) const
ConstReverseIterator rend(const Point &aPoint) const
NaiveDSL & operator=(const NaiveDSL &aOther)
Integer myQuantityToRemove
Quantity to remove to the current remainder.
Steps steps() const
Integer mu() const
bool operator==(const ArithmeticalDSL &aOther) const
ArithmeticalDSL< TCoordinate, TInteger, 4 > Super
void selfDisplay(std::ostream &out) const
Aim: This class is an alias of ArithmeticalDSS for standard DSL. It represents a standard digital str...
Coordinate a() const
Position position(const Point &aPoint) const
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.
static Integer remainder(const Coordinate &aA, const Coordinate &aB, const Point &aPoint)
Integer orthogonalPosition(const Point &aPoint) const
StandardDSL & operator=(const StandardDSL &aOther)
Octant octant() const
ConstIterator & operator=(const ConstIterator &aOther)
Aim: Concept checking for Signed Numbers. Models of this concept should be listed in NumberTraits cla...
Definition: CSignedNumber.h:97
DGtal is the top-level namespace which contains all DGtal functions and types.
StandardDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aMu)
ConstReverseIterator rbegin(const Point &aPoint) const
Aim: This class aims at representing an iterator that provides a way to scan the points of a DSL...
ArithmeticalDSL< TCoordinate, TInteger, 8 > Super
ArithmeticalDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aLowerIntercept, const Integer &aUpperIntercept, const Steps &aSteps, const Vector &aShift)
bool isUpperLeaningPoint(const Point &aPoint) const
Super::Coordinate Coordinate
Aim: This class represents a naive (resp. standard) digital straight line (DSL), ie. the set of digital points such that with , and (resp. ). Note that any DSL such that (resp. ) is simply 8-connected (resp. 4-connected).
Integer omega() const
bool equal(const ConstIterator &aOther) const
static Coordinate toCoordinate(const Integer &aI)
Super::Integer Integer
Point myCurrentPoint
The current point.
ArithmeticalDSL & operator=(const ArithmeticalDSL &aOther)
bool isValid() const
Position patternLength() const
ConstIterator end(const Point &aPoint) const
static TOutput cast(const TInput &aInput)
Super::Integer Integer
const ArithmeticalDSL * myDSLPtr
Constant aliasing pointer to the DSL visited by the iterator.
void advance(const Position &aShift)