DGtal  1.5.beta
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)
35 #define IntegerComputer_RECURSES
36 
37 #if !defined IntegerComputer_h
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
81  template <typename TInteger>
83  {
84  // ----------------------- Associated types ------------------------------
85  public:
89 
92 
97 
101 
102  // ----------------------- Standard services ------------------------------
103  public:
104 
109 
119 
128  IntegerComputer ( const Self & other );
129 
139  Self & operator= ( const Self & other );
140 
141 
142  // ----------------------- Integer services ------------------------------
143  public:
144 
149  static bool isZero( IntegerParamType a );
150 
155  static bool isNotZero( IntegerParamType a );
156 
161  static bool isPositive( IntegerParamType a );
162 
167  static bool isNegative( IntegerParamType a );
168 
174 
180 
186 
193 
201 
208 
216 
231  IntegerParamType a, IntegerParamType b ) const;
232 
240 
248 
257  void getFloorCeilDiv( Integer & fl, Integer & ce,
258  IntegerParamType na, IntegerParamType nb ) const;
259 
269 
279 
289 
300  Integer getCFrac( std::vector<Integer> & quotients,
301  IntegerParamType a, IntegerParamType b ) const;
317  template <typename OutputIterator>
318  Integer getCFrac( OutputIterator outIt,
319  IntegerParamType a, IntegerParamType b ) const;
320 
331  Point2I convergent( const std::vector<Integer> & quotients,
332  unsigned int k ) const;
333 
334  // ----------------------- Point2I services ------------------------------
335  public:
341  void reduce( Vector2I & p ) const ;
342 
343 
351  Integer crossProduct( const Vector2I & u, const Vector2I & v) const;
352 
361  const Vector2I & u, const Vector2I & v) const;
362 
370  Integer dotProduct( const Vector2I & u, const Vector2I & v ) const;
371 
379  void getDotProduct( Integer & dp,
380  const Vector2I & u, const Vector2I & v) const;
381 
404  IntegerParamType c ) const;
405 
421  const Vector2I & p,
422  const Vector2I & u,
423  const Vector2I & N,
424  IntegerParamType c ) const;
425 
452  const Point2I & A, const Vector2I & u,
453  const Vector2I & N, IntegerParamType c,
454  const Vector2I & N2, IntegerParamType c2,
455  bool compute_v = true ) const;
456 
457  // ----------------------- Point3I services ------------------------------
458  public:
459 
465  void reduce( Vector3I & p ) const;
466 
474  Integer dotProduct( const Vector3I & u, const Vector3I & v) const;
475 
483  void getDotProduct( Integer & dp,
484  const Vector3I & u, const Vector3I & v) const;
485 
486 
487  // ----------------------- Interface --------------------------------------
488  public:
489 
494  void selfDisplay ( std::ostream & out ) const;
495 
500  bool isValid() const;
501 
502  // ------------------------- Protected Datas ------------------------------
503  private:
504  // ------------------------- Private Datas --------------------------------
505  private:
506 
508  mutable Integer _m_a;
510  mutable Integer _m_b;
512  mutable Integer _m_a0;
514  mutable Integer _m_a1;
516  mutable Integer _m_q;
518  mutable Integer _m_r;
522  mutable std::vector<Integer> _m_bezout[ 4 ];
524  mutable Vector2I _m_v;
526  mutable Vector2I _m_v0;
528  mutable Vector2I _m_v1;
530  mutable Integer _m_c0;
532  mutable Integer _m_c1;
534  mutable Integer _m_c2;
535 
536  // ------------------------- Hidden services ------------------------------
537  protected:
538 
539 
540  // ------------------------- Internals ------------------------------------
541  private:
542 
543  }; // end of class IntegerComputer
544 
545 
552  template <typename TInteger>
553  std::ostream&
554  operator<< ( std::ostream & out, const IntegerComputer<TInteger> & object );
555 
556 } // namespace DGtal
557 
558 
560 // Includes inline functions.
561 #include "DGtal/arithmetic/IntegerComputer.ih"
562 
563 // //
565 
566 #endif // !defined IntegerComputer_h
567 
568 #undef IntegerComputer_RECURSES
569 #endif // else defined(IntegerComputer_RECURSES)
Aim: This class gathers several types and methods to make computation with integers.
Integer getCFrac(std::vector< Integer > &quotients, IntegerParamType a, IntegerParamType b) const
SpaceND< 3, Integer >::Vector Vector3I
void reduce(Vector3I &p) const
static Integer staticGcd(IntegerParamType a, IntegerParamType b)
void getGcd(Integer &g, IntegerParamType a, IntegerParamType b) const
static Integer max(IntegerParamType a, IntegerParamType b, IntegerParamType c)
NumberTraits< TInteger >::SignedVersion Integer
Integer crossProduct(const Vector2I &u, const Vector2I &v) const
static bool isPositiveOrZero(IntegerParamType a)
Integer getCFrac(OutputIterator outIt, IntegerParamType a, IntegerParamType b) const
IntegerComputer< TInteger > Self
Integer _m_a
Used to store parameter a.
static bool isZero(IntegerParamType a)
static Integer min(IntegerParamType a, IntegerParamType b, IntegerParamType c)
Integer _m_a1
Used to for successive computation in gcd.
Integer _m_c2
Used to represent scalar products.
static Integer abs(IntegerParamType a)
std::vector< Integer > _m_bezout[4]
Integer _m_a0
Used to for successive computation in gcd.
Integer ceilDiv(IntegerParamType na, IntegerParamType nb) const
NumberTraits< TInteger >::UnsignedVersion UnsignedInteger
Integer _m_b
Used to store parameter b.
void reduce(Vector2I &p) const
SpaceND< 2, Integer >::Vector Vector2I
Self & operator=(const Self &other)
static bool isNegativeOrZero(IntegerParamType a)
Integer dotProduct(const Vector2I &u, const Vector2I &v) const
Integer _m_q
Used to represent a quotient.
SpaceND< 2, Integer >::Point Point2I
static bool isNotZero(IntegerParamType a)
Vector2I _m_v1
Used to represent vectors.
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
void getDotProduct(Integer &dp, const Vector2I &u, const Vector2I &v) const
Point2I convergent(const std::vector< Integer > &quotients, unsigned int k) const
Vector2I extendedEuclid(IntegerParamType a, IntegerParamType b, IntegerParamType c) const
void getCrossProduct(Integer &cp, const Vector2I &u, const Vector2I &v) const
static Integer min(IntegerParamType a, IntegerParamType b)
Integer _m_c1
Used to represent scalar products.
void getCoefficientIntersection(Integer &fl, Integer &ce, const Vector2I &p, const Vector2I &u, const Vector2I &N, IntegerParamType c) const
Vector2I _m_v
Used to represent the Bezout vector.
void selfDisplay(std::ostream &out) const
NumberTraits< UnsignedInteger >::ParamType UnsignedIntegerParamType
NumberTraits< Integer >::ParamType IntegerParamType
Vector2I _m_v0
Used to represent vectors.
void getDotProduct(Integer &dp, const Vector3I &u, const Vector3I &v) 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
static bool isPositive(IntegerParamType a)
void getFloorCeilDiv(Integer &fl, Integer &ce, IntegerParamType na, IntegerParamType nb) const
Integer _m_c0
Used to represent scalar products.
IntegerComputer(const Self &other)
void getEuclideanDiv(Integer &q, Integer &r, IntegerParamType a, IntegerParamType b) const
static bool isNegative(IntegerParamType a)
Integer _m_r
Used to represent a remainder.
BOOST_CONCEPT_ASSERT((concepts::CIntegralNumber< UnsignedInteger >))
Integer dotProduct(const Vector3I &u, const Vector3I &v) const
Integer gcd(IntegerParamType a, IntegerParamType b) const
SpaceND< 3, Integer >::Point Point3I
static Integer max(IntegerParamType a, IntegerParamType b)
Integer floorDiv(IntegerParamType na, IntegerParamType nb) const
BOOST_CONCEPT_ASSERT((concepts::CUnsignedNumber< UnsignedInteger >))
DGtal is the top-level namespace which contains all DGtal functions and types.
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
boost::call_traits< std::decay< T >::type >::param_type ParamType
Defines a type that represents the "best" way to pass a parameter of type T to a function.
Definition: NumberTraits.h:96
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:564
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:88
Aim: Concept checking for Integral Numbers. Models of this concept should be listed in NumberTraits c...
Aim: Concept checking for Unsigned numbers. Models of this concept should be listed in NumberTraits c...