DGtal  0.9.2
IntegerComputer.h
1 
17 #pragma once
18 
31 #if defined(IntegerComputer_RECURSES)
32 #error Recursive header files inclusion detected in IntegerComputer.h
33 #else // defined(IntegerComputer_RECURSES)
34 
35 #define IntegerComputer_RECURSES
36 
37 #if !defined IntegerComputer_h
38 
39 #define IntegerComputer_h
40 
42 // Inclusions
43 #include <iostream>
44 #include "DGtal/base/Common.h"
45 #include "DGtal/kernel/NumberTraits.h"
46 #include "DGtal/kernel/CUnsignedNumber.h"
47 #include "DGtal/kernel/CIntegralNumber.h"
48 #include "DGtal/kernel/CInteger.h"
49 #include "DGtal/kernel/SpaceND.h"
51 
52 namespace DGtal
53 {
54 
56  // template class IntegerComputer
82  template <typename TInteger>
84  {
85  // ----------------------- Associated types ------------------------------
86  public:
90 
93 
98 
102 
103  // ----------------------- Standard services ------------------------------
104  public:
105 
110 
119  IntegerComputer();
120 
129  IntegerComputer ( const Self & other );
130 
140  Self & operator= ( const Self & other );
141 
142 
143  // ----------------------- Integer services ------------------------------
144  public:
145 
150  static bool isZero( IntegerParamType a );
151 
156  static bool isNotZero( IntegerParamType a );
157 
162  static bool isPositive( IntegerParamType a );
163 
168  static bool isNegative( IntegerParamType a );
169 
174  static bool isPositiveOrZero( IntegerParamType a );
175 
180  static bool isNegativeOrZero( IntegerParamType a );
181 
186  static Integer abs( IntegerParamType a );
187 
193  static Integer max( IntegerParamType a, IntegerParamType b );
194 
201  static Integer max( IntegerParamType a, IntegerParamType b, IntegerParamType c );
202 
208  static Integer min( IntegerParamType a, IntegerParamType b );
209 
216  static Integer min( IntegerParamType a, IntegerParamType b, IntegerParamType c );
217 
231  void getEuclideanDiv( Integer & q, Integer & r,
232  IntegerParamType a, IntegerParamType b ) const;
233 
240  Integer floorDiv( IntegerParamType na, IntegerParamType nb ) const;
241 
248  Integer ceilDiv( IntegerParamType na, IntegerParamType nb ) const;
249 
258  void getFloorCeilDiv( Integer & fl, Integer & ce,
259  IntegerParamType na, IntegerParamType nb ) const;
260 
269  static Integer staticGcd( IntegerParamType a, IntegerParamType b );
270 
279  Integer gcd( IntegerParamType a, IntegerParamType b ) const;
280 
289  void getGcd( Integer & g, IntegerParamType a, IntegerParamType b ) const;
290 
301  Integer getCFrac( std::vector<Integer> & quotients,
302  IntegerParamType a, IntegerParamType b ) const;
318  template <typename OutputIterator>
319  Integer getCFrac( OutputIterator outIt,
320  IntegerParamType a, IntegerParamType b ) const;
321 
332  Point2I convergent( const std::vector<Integer> & quotients,
333  unsigned int k ) const;
334 
335  // ----------------------- Point2I services ------------------------------
336  public:
342  void reduce( Vector2I & p ) const ;
343 
344 
352  Integer crossProduct( const Vector2I & u, const Vector2I & v) const;
353 
361  void getCrossProduct( Integer & cp,
362  const Vector2I & u, const Vector2I & v) const;
363 
371  Integer dotProduct( const Vector2I & u, const Vector2I & v ) const;
372 
380  void getDotProduct( Integer & dp,
381  const Vector2I & u, const Vector2I & v) const;
382 
404  Vector2I extendedEuclid( IntegerParamType a, IntegerParamType b,
405  IntegerParamType c ) const;
406 
421  void getCoefficientIntersection( Integer & fl, Integer & ce,
422  const Vector2I & p,
423  const Vector2I & u,
424  const Vector2I & N,
425  IntegerParamType c ) const;
426 
452  void getValidBezout ( Vector2I & v,
453  const Point2I & A, const Vector2I & u,
454  const Vector2I & N, IntegerParamType c,
455  const Vector2I & N2, IntegerParamType c2,
456  bool compute_v = true ) const;
457 
458  // ----------------------- Point3I services ------------------------------
459  public:
460 
466  void reduce( Vector3I & p ) const;
467 
475  Integer dotProduct( const Vector3I & u, const Vector3I & v) const;
476 
484  void getDotProduct( Integer & dp,
485  const Vector3I & u, const Vector3I & v) const;
486 
487 
488  // ----------------------- Interface --------------------------------------
489  public:
490 
495  void selfDisplay ( std::ostream & out ) const;
496 
501  bool isValid() const;
502 
503  // ------------------------- Protected Datas ------------------------------
504  private:
505  // ------------------------- Private Datas --------------------------------
506  private:
507 
509  mutable Integer _m_a;
511  mutable Integer _m_b;
513  mutable Integer _m_a0;
515  mutable Integer _m_a1;
517  mutable Integer _m_q;
519  mutable Integer _m_r;
523  mutable std::vector<Integer> _m_bezout[ 4 ];
525  mutable Vector2I _m_v;
527  mutable Vector2I _m_v0;
529  mutable Vector2I _m_v1;
531  mutable Integer _m_c0;
533  mutable Integer _m_c1;
535  mutable Integer _m_c2;
536 
537  // ------------------------- Hidden services ------------------------------
538  protected:
539 
540 
541  // ------------------------- Internals ------------------------------------
542  private:
543 
544  }; // end of class IntegerComputer
545 
546 
553  template <typename TInteger>
554  std::ostream&
555  operator<< ( std::ostream & out, const IntegerComputer<TInteger> & object );
556 
557 } // namespace DGtal
558 
559 
561 // Includes inline functions.
562 #include "DGtal/arithmetic/IntegerComputer.ih"
563 
564 // //
566 
567 #endif // !defined IntegerComputer_h
568 
569 #undef IntegerComputer_RECURSES
570 #endif // else defined(IntegerComputer_RECURSES)
void getDotProduct(Integer &dp, const Vector2I &u, const Vector2I &v) const
Integer _m_c1
Used to represent scalar products.
static Integer max(IntegerParamType a, IntegerParamType b)
Integer getCFrac(std::vector< Integer > &quotients, IntegerParamType a, IntegerParamType b) const
Aim: SpaceND is a utility class that defines the fundamental structure of a Digital Space in ND...
Definition: SpaceND.h:95
Aim: Concept checking for Unsigned numbers. Models of this concept should be listed in NumberTraits c...
void getCoefficientIntersection(Integer &fl, Integer &ce, const Vector2I &p, const Vector2I &u, const Vector2I &N, IntegerParamType c) const
static bool isNegativeOrZero(IntegerParamType a)
Integer _m_a0
Used to for successive computation in gcd.
NumberTraits< Integer >::ParamType IntegerParamType
static bool isNotZero(IntegerParamType a)
Vector2I _m_v
Used to represent the Bezout vector.
NumberTraits< TInteger >::SignedVersion Integer
static bool isPositiveOrZero(IntegerParamType a)
SpaceND< 2, Integer >::Point Point2I
void getCrossProduct(Integer &cp, const Vector2I &u, const Vector2I &v) const
boost::call_traits< T >::param_type ParamType
Definition: NumberTraits.h:83
void getEuclideanDiv(Integer &q, Integer &r, IntegerParamType a, IntegerParamType b) const
bool isValid() const
static bool isZero(IntegerParamType a)
static Integer abs(IntegerParamType a)
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
Integer crossProduct(const Vector2I &u, const Vector2I &v) const
void reduce(Vector2I &p) const
NumberTraits< TInteger >::UnsignedVersion UnsignedInteger
Aim: This class gathers several types and methods to make computation with integers.
static Integer staticGcd(IntegerParamType a, IntegerParamType b)
static Integer min(IntegerParamType a, IntegerParamType b)
Integer _m_a
Used to store parameter a.
Point2I convergent(const std::vector< Integer > &quotients, unsigned int k) const
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
IntegerComputer< TInteger > Self
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:69
Integer _m_a1
Used to for successive computation in gcd.
Integer floorDiv(IntegerParamType na, IntegerParamType nb) const
Aim: Concept checking for Integral Numbers. Models of this concept should be listed in NumberTraits c...
Integer _m_q
Used to represent a quotient.
void selfDisplay(std::ostream &out) const
DGtal is the top-level namespace which contains all DGtal functions and types.
static bool isPositive(IntegerParamType a)
Integer dotProduct(const Vector2I &u, const Vector2I &v) const
Integer _m_c0
Used to represent scalar products.
std::vector< Integer > _m_bezout[4]
Vector2I extendedEuclid(IntegerParamType a, IntegerParamType b, IntegerParamType c) const
void getFloorCeilDiv(Integer &fl, Integer &ce, IntegerParamType na, IntegerParamType nb) const
Vector2I _m_v1
Used to represent vectors.
Integer gcd(IntegerParamType a, IntegerParamType b) const
Self & operator=(const Self &other)
Vector2I _m_v0
Used to represent vectors.
SpaceND< 3, Integer >::Vector Vector3I
NumberTraits< UnsignedInteger >::ParamType UnsignedIntegerParamType
static bool isNegative(IntegerParamType a)
Integer _m_r
Used to represent a remainder.
Integer ceilDiv(IntegerParamType na, IntegerParamType nb) const
void getValidBezout(Vector2I &v, const Point2I &A, const Vector2I &u, const Vector2I &N, IntegerParamType c, const Vector2I &N2, IntegerParamType c2, bool compute_v=true) const
SpaceND< 2, Integer >::Vector Vector2I
void getGcd(Integer &g, IntegerParamType a, IntegerParamType b) const
Integer _m_c2
Used to represent scalar products.
SpaceND< 3, Integer >::Point Point3I
Integer _m_b
Used to store parameter b.