DGtal  0.9.2
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)
36 
37 #define StandardDSLQ0_RECURSES
38 
39 #if !defined StandardDSLQ0_h
40 
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:
188  Point myP;
189 
190  };
191  // ----------------------- Standard services ------------------------------
192  public:
193 
197  ~StandardDSLQ0();
198 
202  StandardDSLQ0();
203 
208  StandardDSLQ0 ( const StandardDSLQ0 & other );
209 
215  StandardDSLQ0 & operator= ( const StandardDSLQ0 & other );
216 
222  StandardDSLQ0( Fraction aSlope, IntegerParamType aMu );
223 
230  StandardDSLQ0( IntegerParamType a1, IntegerParamType b1,
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 
256  ConstIterator begin( Point p ) const;
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 
279  Point lowestY( IntegerParamType x ) const;
282  Point uppermostY( IntegerParamType x ) const;
285  Point lowestX( IntegerParamType y ) const;
288  Point uppermostX( IntegerParamType y ) const;
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 
327  Self reversedSmartDSS( Point U1, Point U2,
328  const Point & A, const Point & B ) const;
329 
342  Self DSSWithinTwoPatterns( Point U1, Point U2,
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:
381  Integer myMu;
382 
383  // ------------------------- Private Datas --------------------------------
384  private:
386  IC ic;
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)
Self DSSWithinTwoPatterns(Point U1, Point U2, const Point &A, const Point &B) const
bool beforeOrEqual(const Point &p1, const Point &p2) const
Point lowestY(IntegerParamType x) const
Point L() const
std::forward_iterator_tag iterator_category
Aim: Represents a digital straight line with slope in the first quadrant (Q0: x >= 0...
Definition: StandardDSLQ0.h:79
bool isValid() const
Aim: This class encapsulates its parameter class so that to indicate to the user that the object/poin...
Definition: ConstAlias.h:186
Integer b() const
Self & operator=(const Self &other)
NumberTraits< Integer >::ParamType IntegerParamType
IC::IntegerParamType IntegerParamType
Definition: StandardDSLQ0.h:92
Fraction::Quotient Quotient
Definition: StandardDSLQ0.h:87
Point U() const
SpaceND< 2, Integer >::Point Point2I
Integer myMu
the shift to origin.
Integer a() const
const Integer & mu() const
Fraction::Integer Integer
Definition: StandardDSLQ0.h:85
Fraction slope() const
Vector2I v() const
StandardDSLQ0 & operator=(const StandardDSLQ0 &other)
IC ic
Used in some computations.
static Fraction deepest(Fraction f1, Fraction f2, Fraction f3)
void selfDisplay(std::ostream &out) const
Point uppermostX(IntegerParamType y) const
ConstIterator begin(Point p) const
bool operator==(const Self &other) const
Self smartDSS(const Point &A, const Point &B) const
Point uppermostY(IntegerParamType x) const
Integer mup() const
bool before(const Point &p1, const Point &p2) const
DGtal is the top-level namespace which contains all DGtal functions and types.
ConstIterator end(Point p) const
Integer r(const Point &p) const
const StandardDSLQ0< TFraction > * myPtrDSL
const Pattern< Fraction > & pattern() const
ConstIterator(ConstAlias< StandardDSLQ0< TFraction > > myDSL, const Point &p)
Self reversedSmartDSS(const Point &A, const Point &B) const
Fraction::UnsignedInteger UnsignedInteger
Definition: StandardDSLQ0.h:86
IC::Vector2I Vector2I
Definition: StandardDSLQ0.h:93
StandardDSLQ0< TFraction > Self
Definition: StandardDSLQ0.h:84
bool operator()(const Point &p) const
SpaceND< 2, Integer >::Vector Vector2I
Pattern< Fraction > myPattern
the characteristic pattern of this DSL.
Point lowestX(IntegerParamType y) const
IntegerComputer< Integer > IC
Definition: StandardDSLQ0.h:91
bool operator!=(const Self &other) const