DGtal  1.1.0
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,
65  class ArithmeticalDSS;
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:
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;
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
213
219  ConstIterator( const ArithmeticalDSL* aDSL, const Point& aPoint );
220
225  ConstIterator( const ConstIterator & aOther );
232
237
238  // ------------------------- useful services -------------------------
239  public:
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
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
343
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
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
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 -------------------------------
591
598  ConstIterator end(const Point& aPoint) const;
599
607
615
616
617  // ------------------------- Other services ------------------------------
618  public:
619  static Coordinate toCoordinate(const Integer& aI);
620
621  // ------------------------- Protected Datas ------------------------------
622  protected:
623
624  // -------------------------vectors ---------------------------------------
636
637  //------------------------ parameters of the DSL --------------------------
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:
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>
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 <>
865  {
866
867  inline
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)
DGtal::StandardDSL::Coordinate
Super::Coordinate Coordinate
Definition: ArithmeticalDSL.h:716
DGtal::NaiveDSL::NaiveDSL
NaiveDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aMu)
DGtal::BigInteger
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Definition: BasicTypes.h:79
DGtal::ArithmeticalDSL::ConstIterator::ConstIterator
ConstIterator(const ConstIterator &aOther)
DGtal::StandardDSL
Aim: This class is an alias of ArithmeticalDSS for standard DSL. It represents a standard digital str...
Definition: ArithmeticalDSL.h:710
DGtal::ArithmeticalDSL::operator()
bool operator()(const Point &aPoint) const
ConstIterator
MyDigitalSurface::ConstIterator ConstIterator
Definition: greedy-plane-segmentation-ex2.cpp:93
DGtal::ArithmeticalDSL::ConstIterator::dereference
Point const dereference() const
DGtal::ArithmeticalDSL::checkShiftAndSteps
bool checkShiftAndSteps() const
DGtal::ArithmeticalDSL::myB
Coordinate myB
Definition: ArithmeticalDSL.h:645
Quantity to add to the current remainder.
Definition: ArithmeticalDSL.h:198
DGtal::ArithmeticalDSL::orthogonalPosition
Integer orthogonalPosition(const Point &aPoint) const
DGtal::ArithmeticalDSL::before
bool before(const Point &aP1, const Point &aP2) const
DGtal::ArithmeticalDSL::operator==
bool operator==(const ArithmeticalDSL &aOther) const
DGtal::concepts::CInteger
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:88
DGtal::detail::toCoordinateImpl< DGtal::BigInteger, DGtal::BigInteger >::cast
static DGtal::BigInteger cast(const DGtal::BigInteger &aInput)
Definition: ArithmeticalDSL.h:868
DGtal::ArithmeticalDSL::end
ConstIterator end(const Point &aPoint) const
DGtal::detail::toCoordinateImpl::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInput >))
max
int max(int a, int b)
Definition: testArithmeticalDSS.cpp:1108
DGtal::ArithmeticalDSL::Vector
Space::Vector Vector
Definition: ArithmeticalDSL.h:145
DGtal::ArithmeticalDSL::ConstIterator::myDSLPtr
const ArithmeticalDSL * myDSLPtr
Constant aliasing pointer to the DSL visited by the iterator.
Definition: ArithmeticalDSL.h:192
DGtal::detail::toCoordinateImpl::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CSignedNumber< TInput >))
DGtal::ArithmeticalDSL::begin
ConstIterator begin(const Point &aPoint) const
DGtal::ArithmeticalDSL::isValid
bool isValid() const
DGtal::ArithmeticalDSL::Steps
std::pair< Vector, Vector > Steps
Definition: ArithmeticalDSL.h:149
DGtal::detail::toCoordinateImpl< DGtal::BigInteger, TOutput >::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CInteger< TOutput >))
DGtal::ArithmeticalDSL::Coordinate
TCoordinate Coordinate
Definition: ArithmeticalDSL.h:127
DGtal::StandardDSL::Super
ArithmeticalDSL< TCoordinate, TInteger, 4 > Super
Definition: ArithmeticalDSL.h:715
DGtal::detail::toCoordinateImpl::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CSignedNumber< TOutput >))
DGtal::ArithmeticalDSL::ConstIterator::increment
void increment()
aPoint
const Point aPoint(3, 4)
DGtal::StandardDSL::operator=
StandardDSL & operator=(const StandardDSL &aOther)
DGtal::StandardDSL::Integer
Super::Integer Integer
Definition: ArithmeticalDSL.h:717
DGtal::NaiveDSL::Coordinate
Super::Coordinate Coordinate
Definition: ArithmeticalDSL.h:784
DGtal::ArithmeticalDSL::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
DGtal::ReverseIterator
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa.
Definition: ReverseIterator.h:70
DGtal::ArithmeticalDSL::getPoint
Point getPoint() const
DGtal::ArithmeticalDSL::ArithmeticalDSL
ArithmeticalDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aMu)
DGtal::NaiveDSL::NaiveDSL
NaiveDSL(const NaiveDSL &aOther)
DGtal::NaiveDSL
Aim: This class is an alias of ArithmeticalDSS for naive DSL. It represents a naive digital straight ...
Definition: ArithmeticalDSL.h:778
DGtal::concepts::CSignedNumber
Aim: Concept checking for Signed Numbers. Models of this concept should be listed in NumberTraits cla...
Definition: CSignedNumber.h:98
DGtal::ArithmeticalDSL::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::ArithmeticalDSL::remainder
Integer remainder(const Point &aPoint) const
DGtal::ArithmeticalDSL::Space
Definition: ArithmeticalDSL.h:137
DGtal::detail::toCoordinateImpl::cast
static TOutput cast(const TInput &aInput)
Definition: ArithmeticalDSL.h:842
DGtal::StandardDSL::StandardDSL
StandardDSL(const StandardDSL &aOther)
DGtal::ArithmeticalDSL::steps
Steps steps() const
DGtal::SpaceND
Definition: SpaceND.h:96
DGtal::ArithmeticalDSL::ConstIterator::~ConstIterator
~ConstIterator()
DGtal::ArithmeticalDSL::ConstIterator
Aim: This class aims at representing an iterator that provides a way to scan the points of a DSL....
Definition: ArithmeticalDSL.h:186
DGtal::ArithmeticalDSL::mu
Integer mu() const
DGtal::ArithmeticalDSL::ConstIterator::myQuantityToRemove
Integer myQuantityToRemove
Quantity to remove to the current remainder.
Definition: ArithmeticalDSL.h:201
DGtal::ArithmeticalDSL::ConstIterator::remainder
Integer remainder() const
DGtal::ArithmeticalDSL::Octant
std::pair< unsigned char, unsigned char > Octant
Definition: ArithmeticalDSL.h:158
DGtal::ArithmeticalDSL::ConstIterator::ConstIterator
ConstIterator(const ArithmeticalDSL *aDSL, const Point &aPoint)
DGtal::ArithmeticalDSL::~ArithmeticalDSL
~ArithmeticalDSL()
DGtal::ArithmeticalDSL::operator!=
bool operator!=(const ArithmeticalDSL &aOther) const
DGtal::ArithmeticalDSL::isLowerLeaningPoint
bool isLowerLeaningPoint(const Point &aPoint) const
DGtal::ArithmeticalDSL::ArithmeticalDSL
ArithmeticalDSL(const ArithmeticalDSL &aOther)
DGtal::ArithmeticalDSL::shift
Vector shift() const
DGtal::ArithmeticalDSL::ConstIterator::operator=
ConstIterator & operator=(const ConstIterator &aOther)
DGtal::detail::toCoordinateImpl< DGtal::BigInteger, TOutput >::cast
static TOutput cast(const DGtal::BigInteger &aInput)
Definition: ArithmeticalDSL.h:856
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition: ClosedIntegerHalfPlane.h:49
DGtal::ArithmeticalDSL::a
Coordinate a() const
DGtal::ArithmeticalDSL::myLowerBound
Integer myLowerBound
Definition: ArithmeticalDSL.h:651
DGtal::ArithmeticalDSS
Aim: This class represents a naive (resp. standard) digital straight segment (DSS),...
Definition: ArithmeticalDSS.h:96
DGtal::detail::toCoordinateImpl< DGtal::BigInteger, TOutput >::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CSignedNumber< TOutput >))
DGtal::ArithmeticalDSL::ConstIterator::distance_to
Position distance_to(const ConstIterator &aOther) const
DGtal::ArithmeticalDSL::isInDSL
bool isInDSL(const Point &aPoint) const
DGtal::ArithmeticalDSL::mySteps
Steps mySteps
Definition: ArithmeticalDSL.h:630
DGtal::ArithmeticalDSL::myUpperBound
Integer myUpperBound
Definition: ArithmeticalDSL.h:658
DGtal::ArithmeticalDSL::ConstIterator::decrement
void decrement()
DGtal::ArithmeticalDSL::operator=
ArithmeticalDSL & operator=(const ArithmeticalDSL &aOther)
DGtal::ArithmeticalDSL::ConstIterator::myCurrentRemainder
Integer myCurrentRemainder
Remainder of the current point.
Definition: ArithmeticalDSL.h:204
DGtal::ArithmeticalDSL::ConstIterator::iterator_core_access
friend class boost::iterator_core_access
Definition: ArithmeticalDSL.h:248
DGtal::ArithmeticalDSL::rend
ConstReverseIterator rend(const Point &aPoint) const
DGtal::detail::toCoordinateImpl
Aim: Define a simple functor that can cast a signed integer (possibly a DGtal::BigInteger) into anoth...
Definition: ArithmeticalDSL.h:832
DGtal::ArithmeticalDSL::position
Position position(const Point &aPoint) const
DGtal::ArithmeticalDSL::patternLength
Position patternLength() const
DGtal::NaiveDSL::Integer
Super::Integer Integer
Definition: ArithmeticalDSL.h:785
DGtal::NaiveDSL::operator=
NaiveDSL & operator=(const NaiveDSL &aOther)
DGtal::ArithmeticalDSL::equalsTo
bool equalsTo(const ArithmeticalDSL &aOther) const
DGtal::ArithmeticalDSL::b
Coordinate b() const
DGtal::ArithmeticalDSL::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CInteger< Coordinate >))
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
DGtal::StandardDSL::StandardDSL
StandardDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aMu)
DGtal::ArithmeticalDSL
Aim: This class represents a naive (resp. standard) digital straight line (DSL), ie....
Definition: ArithmeticalDSL.h:107
DGtal::ArithmeticalDSL::toCoordinate
static Coordinate toCoordinate(const Integer &aI)
DGtal::ArithmeticalDSL::omega
Integer omega() const
DGtal::ArithmeticalDSL::beforeOrEqual
bool beforeOrEqual(const Point &aP1, const Point &aP2) const
DGtal::ArithmeticalDSL::remainder
static Integer remainder(const Coordinate &aA, const Coordinate &aB, const Point &aPoint)
DGtal::ArithmeticalDSL::ConstIterator::myCurrentPoint
Point myCurrentPoint
The current point.
Definition: ArithmeticalDSL.h:195
DGtal::ArithmeticalDSL::octant
Octant octant() const
DGtal::ArithmeticalDSL::Point
Space::Point Point
Definition: ArithmeticalDSL.h:141
DGtal::NaiveDSL::Super
ArithmeticalDSL< TCoordinate, TInteger, 8 > Super
Definition: ArithmeticalDSL.h:783
DGtal::ArithmeticalDSL::ConstIterator::ConstIterator
ConstIterator()
DGtal::PointVector< dim, Integer >
DGtal::ArithmeticalDSL::myA
Coordinate myA
Definition: ArithmeticalDSL.h:641
DGtal::ArithmeticalDSL::Integer
TInteger Integer
Definition: ArithmeticalDSL.h:132
Definition: ArithmeticalDSL.h:118
DGtal::ArithmeticalDSL::isUpperLeaningPoint
bool isUpperLeaningPoint(const Point &aPoint) const
DGtal::ArithmeticalDSL::negate
ArithmeticalDSL negate() const
DGtal::ArithmeticalDSL::ConstReverseIterator
DGtal::ReverseIterator< ConstIterator > ConstReverseIterator
Definition: ArithmeticalDSL.h:297
DGtal::ArithmeticalDSL::sameOctant
bool sameOctant(const ArithmeticalDSL &aOther, typename Octant::first_type *theOctant) const
DGtal::ArithmeticalDSL::myShift
Vector myShift
Definition: ArithmeticalDSL.h:635
DGtal::ArithmeticalDSL::ArithmeticalDSL
ArithmeticalDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aLowerIntercept, const Integer &aUpperIntercept, const Steps &aSteps, const Vector &aShift)
DGtal::ArithmeticalDSL::ConstIterator::equal
bool equal(const ConstIterator &aOther) const
DGtal::ArithmeticalDSL::rbegin
ConstReverseIterator rbegin(const Point &aPoint) const
DGtal::detail::toCoordinateImpl::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CInteger< TOutput >))
DGtal::ArithmeticalDSL::Position
Coordinate Position
Definition: ArithmeticalDSL.h:153
DGtal::ArithmeticalDSL::getPoint
Point getPoint(const Position &aPosition) const