DGtal 1.3.0
Loading...
Searching...
No Matches
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)
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/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
58namespace DGtal
59{
60
61 //forward declaration of ArithmeticalDSS for the friendship
62 template <typename TCoordinate,
63 typename TInteger,
64 unsigned short adjacency>
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:
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;
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
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
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
317 const Integer& aLowerIntercept, const Integer& aUpperIntercept,
318 const Steps& aSteps, const Vector& aShift);
319
328 const Integer& aMu);
329
330
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
504
514
523
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
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
680namespace DGtal
681{
707 template <typename TCoordinate, typename TInteger = TCoordinate>
709 public ArithmeticalDSL<TCoordinate, TInteger, 4>
710 {
711 public:
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:
785 typedef typename Super::Integer Integer;
786
787 public:
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
818namespace 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)
Aim: This class aims at representing an iterator that provides a way to scan the points of a DSL....
Integer myQuantityToAdd
Quantity to add to the current remainder.
Point myCurrentPoint
The current point.
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)
Aim: This class represents a naive (resp. standard) digital straight line (DSL), ie....
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 >))
static const unsigned short foregroundAdjacency
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),...
Aim: This class is an alias of ArithmeticalDSS for naive DSL. It represents a naive digital straight ...
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.
Aim: This class is an alias of ArithmeticalDSS for standard DSL. It represents a standard digital str...
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)
mpz_class BigInteger
Multi-precision integer with GMP implementation.
Definition: BasicTypes.h:79
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...
Definition: CSignedNumber.h:98
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)