DGtal  1.5.beta
StandardDSLQ0.h
1 
17 #pragma once
18 
33 #if defined(StandardDSLQ0_RECURSES)
34 #error Recursive header files inclusion detected in StandardDSLQ0.h
35 #else // defined(StandardDSLQ0_RECURSES)
37 #define StandardDSLQ0_RECURSES
38 
39 #if !defined StandardDSLQ0_h
41 #define StandardDSLQ0_h
42 
44 // Inclusions
45 #include <iostream>
46 #include "DGtal/base/Common.h"
47 #include "DGtal/base/ConstAlias.h"
48 #include "DGtal/arithmetic/IntegerComputer.h"
49 #include "DGtal/arithmetic/Pattern.h"
51 
52 namespace DGtal
53 {
54 
56  // template class StandardDSLQ0
78  template <typename TFraction>
80  {
81  // ----------------------- Standard types ------------------------------
82  public:
83  typedef TFraction Fraction;
85  typedef typename Fraction::Integer Integer;
86  typedef typename Fraction::UnsignedInteger UnsignedInteger;
87  typedef typename Fraction::Quotient Quotient;
88 
89  // BOOST_CONCEPT_ASSERT(( CFraction<Fraction> ));
90 
93  typedef typename IC::Vector2I Vector2I;
94  typedef typename IC::Point2I Point2I;
95 
96  // Model of concepts::CPointPredicate
97  typedef typename IC::Point2I Point;
98 
110  struct ConstIterator {
112  typedef Point Value;
113 
114  // stl iterator types.
115  typedef std::forward_iterator_tag iterator_category;
116  typedef Point value_type;
117  typedef std::ptrdiff_t difference_type;
118  typedef const Point* pointer;
119  typedef const Point& reference;
120 
121  inline ConstIterator()
122  : myPtrDSL( 0 )
123  {}
125  const Point & p )
126  : myPtrDSL( & myDSL ), myP( p )
127  {}
128  inline ConstIterator( const Self & other )
129  : myPtrDSL( other.myPtrDSL ), myP( other.myP )
130  {}
131  inline Self& operator=( const Self & other )
132  {
133  if ( this != &other )
134  {
135  myPtrDSL = other.myPtrDSL;
136  myP = other.myP;
137  }
138  return *this;
139  }
140 
141  inline reference operator*() const
142  {
143  ASSERT( myPtrDSL != 0 );
144  return myP;
145  }
146 
147  inline pointer operator->() const
148  {
149  ASSERT( myPtrDSL != 0 );
150  return &myP;
151  }
152 
153  inline Self& operator++()
154  {
155  Integer rem = myPtrDSL->r( myP );
156  if ( rem - myPtrDSL->b() >= myPtrDSL->mu() )
157  ++myP[ 1 ]; // +y;
158  else
159  ++myP[ 0 ]; // +x;
160  return *this;
161  }
162 
163  inline
164  Self
166  {
167  Self __tmp = *this;
168  this->operator++();
169  return __tmp;
170  }
171 
172  inline
173  bool operator==( const Self & other ) const
174  {
175  ASSERT( myPtrDSL == other.myPtrDSL );
176  return myP == other.myP;
177  }
178 
179  inline
180  bool operator!=( const Self & other ) const
181  {
182  return ! ( this->operator==( other ) );
183  }
184 
185 
186  private:
189 
190  };
191  // ----------------------- Standard services ------------------------------
192  public:
193 
198 
203 
208  StandardDSLQ0 ( const StandardDSLQ0 & other );
209 
216 
223 
231  IntegerParamType mu1 );
232 
235  bool operator()( const Point & p ) const;
236 
238  Fraction slope() const;
239 
242  const Integer & mu() const;
243 
245  Integer mup() const;
246 
248  Integer a() const;
250  Integer b() const;
252  Vector2I v() const;
253 
257 
260  ConstIterator end( Point p ) const;
261 
263  const Pattern<Fraction> & pattern() const;
264 
268  Integer r( const Point & p ) const;
269 
272  Point U() const;
275  Point L() const;
276 
289 
291  bool before( const Point & p1, const Point & p2 ) const;
293  bool beforeOrEqual( const Point & p1, const Point & p2 ) const;
294 
295 
309  Self reversedSmartDSS( const Point & A, const Point & B ) const;
310 
328  const Point & A, const Point & B ) const;
329 
343  const Point & A, const Point & B ) const;
344 
345 
359  Self smartDSS( const Point & A, const Point & B ) const;
360 
361  // ----------------------- Interface --------------------------------------
362  public:
363 
368  void selfDisplay ( std::ostream & out ) const;
369 
374  bool isValid() const;
375 
376  // ------------------------- Protected Datas ------------------------------
377  protected:
382 
383  // ------------------------- Private Datas --------------------------------
384  private:
387 
388  // ------------------------- Hidden services ------------------------------
389  protected:
390 
391  // ------------------------- Internals ------------------------------------
392  private:
393  static Fraction deepest( Fraction f1, Fraction f2, Fraction f3 );
394  static Fraction deepest( Fraction f1, Fraction f2 );
395  }; // end of class StandardDSLQ0
396 
397 
404  template <typename TFraction>
405  std::ostream&
406  operator<< ( std::ostream & out, const StandardDSLQ0<TFraction> & object );
407 
408 } // namespace DGtal
409 
410 
412 // Includes inline functions.
413 #include "DGtal/arithmetic/StandardDSLQ0.ih"
414 
415 // //
417 
418 #endif // !defined StandardDSLQ0_h
419 
420 #undef StandardDSLQ0_RECURSES
421 #endif // else defined(StandardDSLQ0_RECURSES)
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:187
SpaceND< 2, Integer >::Vector Vector2I
SpaceND< 2, Integer >::Point Point2I
NumberTraits< Integer >::ParamType IntegerParamType
Aim: Represents a digital straight line with slope in the first quadrant (Q0: x >= 0,...
Definition: StandardDSLQ0.h:80
StandardDSLQ0(Fraction aSlope, IntegerParamType aMu)
const Pattern< Fraction > & pattern() const
StandardDSLQ0 & operator=(const StandardDSLQ0 &other)
bool before(const Point &p1, const Point &p2) const
Point uppermostY(IntegerParamType x) const
Self DSSWithinTwoPatterns(Point U1, Point U2, const Point &A, const Point &B) const
StandardDSLQ0(IntegerParamType a1, IntegerParamType b1, IntegerParamType mu1)
Self reversedSmartDSS(const Point &A, const Point &B) const
IC::IntegerParamType IntegerParamType
Definition: StandardDSLQ0.h:92
Vector2I v() const
Self smartDSS(const Point &A, const Point &B) const
Integer r(const Point &p) const
Fraction::Integer Integer
Definition: StandardDSLQ0.h:85
Fraction slope() const
Fraction::Quotient Quotient
Definition: StandardDSLQ0.h:87
IntegerComputer< Integer > IC
Definition: StandardDSLQ0.h:91
IC ic
Used in some computations.
void selfDisplay(std::ostream &out) const
Point lowestY(IntegerParamType x) const
Integer mup() const
Pattern< Fraction > myPattern
the characteristic pattern of this DSL.
Integer myMu
the shift to origin.
Integer a() const
static Fraction deepest(Fraction f1, Fraction f2)
IC::Vector2I Vector2I
Definition: StandardDSLQ0.h:93
ConstIterator begin(Point p) const
ConstIterator end(Point p) const
Self reversedSmartDSS(Point U1, Point U2, const Point &A, const Point &B) const
Point uppermostX(IntegerParamType y) const
Point lowestX(IntegerParamType y) const
static Fraction deepest(Fraction f1, Fraction f2, Fraction f3)
bool operator()(const Point &p) const
StandardDSLQ0(const StandardDSLQ0 &other)
bool beforeOrEqual(const Point &p1, const Point &p2) const
bool isValid() const
const Integer & mu() const
Integer b() const
StandardDSLQ0< TFraction > Self
Definition: StandardDSLQ0.h:84
Fraction::UnsignedInteger UnsignedInteger
Definition: StandardDSLQ0.h:86
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
const StandardDSLQ0< TFraction > * myPtrDSL
Self & operator=(const Self &other)
bool operator==(const Self &other) const
ConstIterator(ConstAlias< StandardDSLQ0< TFraction > > myDSL, const Point &p)
bool operator!=(const Self &other) const
std::forward_iterator_tag iterator_category