Loading [MathJax]/extensions/TeX/AMSsymbols.js
DGtal 2.0.0
ArithmeticalDSL.h
1
16
17#pragma once
18
30
31#if defined(ArithmeticalDSL_RECURSES)
32#error Recursive header files inclusion detected in ArithmeticalDSL.h
33#else // defined(ArithmeticalDSL_RECURSES)
35#define ArithmeticalDSL_RECURSES
36
37#if !defined ArithmeticalDSL_h
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/NumberTraits.h"
49#include "DGtal/kernel/CInteger.h"
50#include "DGtal/kernel/CSignedNumber.h"
51#include "DGtal/kernel/SpaceND.h"
52#include "DGtal/kernel/PointVector.h"
53#include "DGtal/arithmetic/IntegerComputer.h"
54
55#include "DGtal/geometry/curves/ArithmeticalDSLKernel.h"
56
58
59namespace DGtal
60{
61
62 //forward declaration of ArithmeticalDSS for the friendship
63 template <typename TCoordinate,
64 typename TInteger,
65 unsigned short adjacency>
66 class ArithmeticalDSS;
67
69 // template class ArithmeticalDSL
104 template <typename TCoordinate,
105 typename TInteger = TCoordinate,
106 unsigned short adjacency = 8>
108 {
109
110 // ----------------------- Friend class -----------------------------------
111 public:
112 friend class ArithmeticalDSS<TCoordinate, TInteger, adjacency>;
113
114 // ----------------------- static members -----------------------------------
115 public:
119 static const unsigned short foregroundAdjacency = adjacency;
120
121 // ----------------------- Inner types -----------------------------------
122 public:
123
128 typedef TCoordinate Coordinate;
133 typedef TInteger Integer;
142 typedef typename Space::Point Point;
146 typedef typename Space::Vector Vector;
150 typedef std::pair<Vector,Vector> Steps;
155
159 typedef std::pair<unsigned char, unsigned char> Octant;
160
161
162
179 : public boost::iterator_facade<ConstIterator, //derived type, the ConstIterator class itself
180 Point const, //value type
181 boost::random_access_traversal_tag, //traversal tag
182 Point const, //reference type
183 //NB: since there is no underlying container,
184 //we cannot return a reference.
185 Position //difference type
186 >
187 {
188
189 // ------------------------- Private data -----------------------
190 private:
191
194
197
200
203
206
207 // ------------------------- Standard services -----------------------
208 public:
209
214
221
226 ConstIterator( const ConstIterator & aOther );
233
238
239 // ------------------------- useful services -------------------------
240 public:
246
247 // ------------------------- iteration services -------------------------
248 private:
250
255 Point const dereference() const;
256
260 void increment();
261
265 void decrement();
266
275 bool equal(const ConstIterator& aOther) const;
276
283 void advance(const Position& aShift);
284
291 Position distance_to(const ConstIterator& aOther) const;
292
293 };
294
299
300 // ----------------------- Standard services ------------------------------
301 public:
302
318 const Integer& aLowerIntercept, const Integer& aUpperIntercept,
319 const Steps& aSteps, const Vector& aShift);
320
329 const Integer& aMu);
330
331
337
344
351
358 bool equalsTo ( const ArithmeticalDSL & aOther ) const;
359
368 bool operator== ( const ArithmeticalDSL & aOther ) const;
369
376 bool operator!= ( const ArithmeticalDSL & aOther ) const;
377
385 bool sameOctant ( const ArithmeticalDSL & aOther, typename Octant::first_type *theOctant ) const;
386
387
393 bool isUpperLeaningPoint(const Point& aPoint) const;
394
400 bool isLowerLeaningPoint(const Point& aPoint) const;
401
402
411
412 Octant octant() const;
413
414
419
420 // ----------------------- Interface --------------------------------------
421 public:
422
427 void selfDisplay ( std::ostream & out ) const;
428
436 bool checkShiftAndSteps() const;
437
445 bool isValid() const;
446
450 Coordinate a() const;
451
455 Coordinate b() const;
456
460 Integer mu() const;
461
466 Integer omega() const;
467
473
478 Vector shift() const;
479
483 Steps steps() const;
484
494 static Integer remainder(const Coordinate& aA,
495 const Coordinate& aB,
496 const Point& aPoint);
497
505
515
524
532
540 Point getPoint(const Position& aPosition) const;
541
552 bool before (const Point& aP1, const Point& aP2) const;
553
564 bool beforeOrEqual (const Point& aP1, const Point& aP2) const;
565
571 bool isInDSL(const Point& aPoint) const;
572
573
574
581 bool operator()(const Point& aPoint) const;
582
583
584 // ----------------------- Iterator services -------------------------------
591 ConstIterator begin(const Point& aPoint) const;
592
599 ConstIterator end(const Point& aPoint) const;
600
608
616
617
618 // ------------------------- Other services ------------------------------
619 public:
620 static Coordinate toCoordinate(const Integer& aI);
621
622 // ------------------------- Protected Datas ------------------------------
623 protected:
624
625 // -------------------------vectors ---------------------------------------
637
638 //------------------------ parameters of the DSL --------------------------
660
661
662
663 }; // end of class ArithmeticalDSL
664
665
672 template <typename TCoordinate, typename TInteger, unsigned short adjacency>
673 std::ostream&
674 operator<< ( std::ostream & out, const ArithmeticalDSL<TCoordinate, TInteger, adjacency> & object );
675
676} // namespace DGtal
677
678
680// Aliases
681namespace DGtal
682{
708 template <typename TCoordinate, typename TInteger = TCoordinate>
710 public ArithmeticalDSL<TCoordinate, TInteger, 4>
711 {
712 public:
718 typedef typename Super::Integer Integer;
719
720 public:
729 const Coordinate& aB,
730 const Integer& aMu);
731
736 StandardDSL ( const StandardDSL & aOther );
737
743 StandardDSL & operator= ( const StandardDSL & aOther );
744
745 };
746
776 template <typename TCoordinate, typename TInteger = TCoordinate>
777 class NaiveDSL:
778 public ArithmeticalDSL<TCoordinate, TInteger, 8>
779 {
780 public:
786 typedef typename Super::Integer Integer;
787
788 public:
797 const Coordinate& aB,
798 const Integer& aMu);
799
800
805 NaiveDSL ( const NaiveDSL & aOther );
806
812 NaiveDSL & operator= ( const NaiveDSL & aOther );
813
814 };
815} // namespace DGtal
816
818// Tools
819namespace DGtal
820{
821 namespace detail {
822
831 template <typename TInput, typename TOutput >
833 {
842 inline
843 static TOutput cast(const TInput& aInput)
844 {
845 return static_cast<TOutput>(aInput);
846 }
847 };
848
849 //specialized versions for DGtal::BigInteger
850 template <typename TOutput>
852 {
855
856 inline
857 static TOutput cast(const DGtal::BigInteger& aInput)
858 {
859 ASSERT( (aInput <= static_cast<DGtal::BigInteger>(std::numeric_limits<TOutput>::max())) &&
860 (aInput >= static_cast<DGtal::BigInteger>(std::numeric_limits<TOutput>::min())) );
861 return static_cast<TOutput>(aInput);
862 }
863 };
864 template <>
866 {
867
868 inline
870 {
871 return aInput;
872 }
873 };
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)
Integer myQuantityToAdd
Quantity to add to the current remainder.
Position distance_to(const ConstIterator &aOther) const
ConstIterator(const ArithmeticalDSL *aDSL, const Point &aPoint)
ConstIterator(const ConstIterator &aOther)
Integer myCurrentRemainder
Remainder of the current point.
void advance(const Position &aShift)
bool equal(const ConstIterator &aOther) const
const ArithmeticalDSL * myDSLPtr
Constant aliasing pointer to the DSL visited by the iterator.
Integer myQuantityToRemove
Quantity to remove to the current remainder.
ConstIterator & operator=(const ConstIterator &aOther)
bool isUpperLeaningPoint(const Point &aPoint) const
bool equalsTo(const ArithmeticalDSL &aOther) const
bool operator()(const Point &aPoint) const
ArithmeticalDSL & operator=(const ArithmeticalDSL &aOther)
ArithmeticalDSL negate() const
Point getPoint(const Position &aPosition) const
std::pair< Vector, Vector > Steps
bool before(const Point &aP1, const Point &aP2) const
BOOST_CONCEPT_ASSERT((concepts::CInteger< Coordinate >))
ArithmeticalDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aLowerIntercept, const Integer &aUpperIntercept, const Steps &aSteps, const Vector &aShift)
Coordinate b() const
ArithmeticalDSL(const ArithmeticalDSL &aOther)
std::pair< unsigned char, unsigned char > Octant
Integer remainder(const Point &aPoint) const
ConstIterator begin(const Point &aPoint) const
bool checkShiftAndSteps() const
bool beforeOrEqual(const Point &aP1, const Point &aP2) const
Position patternLength() const
bool isInDSL(const Point &aPoint) const
void selfDisplay(std::ostream &out) const
Point getPoint() const
Integer omega() const
Vector shift() const
DGtal::ReverseIterator< ConstIterator > ConstReverseIterator
ArithmeticalDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aMu)
bool operator==(const ArithmeticalDSL &aOther) const
bool sameOctant(const ArithmeticalDSL &aOther, typename Octant::first_type *theOctant) const
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
ArithmeticalDSLKernel< Coordinate, adjacency >::Space Space
bool operator!=(const ArithmeticalDSL &aOther) const
bool isLowerLeaningPoint(const Point &aPoint) const
ConstIterator end(const Point &aPoint) const
Integer mu() const
Integer orthogonalPosition(const Point &aPoint) const
Octant octant() const
static Coordinate toCoordinate(const Integer &aI)
ConstReverseIterator rend(const Point &aPoint) const
Position position(const Point &aPoint) const
ConstReverseIterator rbegin(const Point &aPoint) const
static Integer remainder(const Coordinate &aA, const Coordinate &aB, const Point &aPoint)
Coordinate a() const
Aim: This class represents a naive (resp. standard) digital straight segment (DSS),...
NaiveDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aMu)
NaiveDSL(const NaiveDSL &aOther)
NaiveDSL & operator=(const NaiveDSL &aOther)
Super::Coordinate Coordinate
ArithmeticalDSL< TCoordinate, TInteger, 8 > Super
Super::Integer Integer
This class adapts any bidirectional iterator so that operator++ calls operator-- and vice versa.
PointVector< dim, Integer > Point
Points in DGtal::SpaceND.
Definition SpaceND.h:110
PointVector< dim, Integer > Vector
Vectors in DGtal::SpaceND.
Definition SpaceND.h:113
Super::Coordinate Coordinate
StandardDSL(const StandardDSL &aOther)
StandardDSL(const Coordinate &aA, const Coordinate &aB, const Integer &aMu)
StandardDSL & operator=(const StandardDSL &aOther)
Super::Integer Integer
ArithmeticalDSL< TCoordinate, TInteger, 4 > Super
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ClosedIntegerHalfPlane< TSpace > &object)
boost::multiprecision::number< boost::multiprecision::cpp_int_backend<>, boost::multiprecision::et_off > BigInteger
Definition BasicTypes.h:75
SpaceND< 2, TCoordinate > Space
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition CInteger.h:88
Aim: Concept checking for Signed Numbers. Models of this concept should be listed in NumberTraits cla...
static DGtal::BigInteger cast(const DGtal::BigInteger &aInput)
BOOST_CONCEPT_ASSERT((concepts::CSignedNumber< TOutput >))
static TOutput cast(const DGtal::BigInteger &aInput)
Aim: Define a simple functor that can cast a signed integer (possibly a DGtal::BigInteger) into anoth...
BOOST_CONCEPT_ASSERT((concepts::CSignedNumber< TInput >))
BOOST_CONCEPT_ASSERT((concepts::CInteger< TOutput >))
BOOST_CONCEPT_ASSERT((concepts::CSignedNumber< TOutput >))
BOOST_CONCEPT_ASSERT((concepts::CInteger< TInput >))
static TOutput cast(const TInput &aInput)
const Point aPoint(3, 4)