DGtal  1.3.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)
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
81  template <typename TInteger>
83  {
84  // ----------------------- Associated types ------------------------------
85  public:
89 
92 
97 
101 
102  // ----------------------- Standard services ------------------------------
103  public:
104 
109 
118  IntegerComputer();
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 
173  static bool isPositiveOrZero( IntegerParamType a );
174 
179  static bool isNegativeOrZero( IntegerParamType a );
180 
185  static Integer abs( IntegerParamType a );
186 
193 
201 
208 
216 
230  void getEuclideanDiv( Integer & q, Integer & r,
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 
288  void getGcd( Integer & g, IntegerParamType a, IntegerParamType b ) const;
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 
360  void getCrossProduct( Integer & cp,
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 
420  void getCoefficientIntersection( Integer & fl, Integer & ce,
421  const Vector2I & p,
422  const Vector2I & u,
423  const Vector2I & N,
424  IntegerParamType c ) const;
425 
451  void getValidBezout ( Vector2I & v,
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)
DGtal::IntegerComputer::min
static Integer min(IntegerParamType a, IntegerParamType b)
DGtal::IntegerComputer::isValid
bool isValid() const
DGtal::IntegerComputer::convergent
Point2I convergent(const std::vector< Integer > &quotients, unsigned int k) const
DGtal::concepts::CUnsignedNumber
Aim: Concept checking for Unsigned numbers. Models of this concept should be listed in NumberTraits c...
Definition: CUnsignedNumber.h:94
DGtal::IntegerComputer::getDotProduct
void getDotProduct(Integer &dp, const Vector2I &u, const Vector2I &v) const
DGtal::IntegerComputer::isPositiveOrZero
static bool isPositiveOrZero(IntegerParamType a)
DGtal::IntegerComputer::getCFrac
Integer getCFrac(std::vector< Integer > &quotients, IntegerParamType a, IntegerParamType b) const
DGtal::IntegerComputer::_m_q
Integer _m_q
Used to represent a quotient.
Definition: IntegerComputer.h:516
DGtal::IntegerComputer::_m_v
Vector2I _m_v
Used to represent the Bezout vector.
Definition: IntegerComputer.h:524
DGtal::concepts::CInteger
Aim: Concept checking for Integer Numbers. More precisely, this concept is a refinement of both CEucl...
Definition: CInteger.h:87
DGtal::IntegerComputer::dotProduct
Integer dotProduct(const Vector2I &u, const Vector2I &v) const
DGtal::IntegerComputer::Integer
NumberTraits< TInteger >::SignedVersion Integer
Definition: IntegerComputer.h:87
DGtal::IntegerComputer::ceilDiv
Integer ceilDiv(IntegerParamType na, IntegerParamType nb) const
DGtal::IntegerComputer::UnsignedIntegerParamType
NumberTraits< UnsignedInteger >::ParamType UnsignedIntegerParamType
Definition: IntegerComputer.h:91
DGtal::NumberTraits
Aim: The traits class for all models of Cinteger.
Definition: NumberTraits.h:562
DGtal::IntegerComputer::crossProduct
Integer crossProduct(const Vector2I &u, const Vector2I &v) const
DGtal::IntegerComputer::operator=
Self & operator=(const Self &other)
DGtal::IntegerComputer
Aim: This class gathers several types and methods to make computation with integers.
Definition: IntegerComputer.h:82
DGtal::IntegerComputer::_m_c0
Integer _m_c0
Used to represent scalar products.
Definition: IntegerComputer.h:530
DGtal::IntegerComputer::_m_bezout
std::vector< Integer > _m_bezout[4]
Definition: IntegerComputer.h:522
DGtal::IntegerComputer::getCrossProduct
void getCrossProduct(Integer &cp, const Vector2I &u, const Vector2I &v) const
DGtal::IntegerComputer::UnsignedInteger
NumberTraits< TInteger >::UnsignedVersion UnsignedInteger
Definition: IntegerComputer.h:90
DGtal::IntegerComputer::IntegerComputer
IntegerComputer()
DGtal::IntegerComputer::abs
static Integer abs(IntegerParamType a)
DGtal::IntegerComputer::_m_c1
Integer _m_c1
Used to represent scalar products.
Definition: IntegerComputer.h:532
DGtal::IntegerComputer::_m_v1
Vector2I _m_v1
Used to represent vectors.
Definition: IntegerComputer.h:528
DGtal::IntegerComputer::_m_a1
Integer _m_a1
Used to for successive computation in gcd.
Definition: IntegerComputer.h:514
DGtal::IntegerComputer::max
static Integer max(IntegerParamType a, IntegerParamType b)
DGtal::IntegerComputer::reduce
void reduce(Vector2I &p) const
DGtal::IntegerComputer::_m_a0
Integer _m_a0
Used to for successive computation in gcd.
Definition: IntegerComputer.h:512
DGtal::IntegerComputer::Self
IntegerComputer< TInteger > Self
Definition: IntegerComputer.h:86
DGtal::operator<<
std::ostream & operator<<(std::ostream &out, const ATu0v1< TKSpace, TLinearAlgebra > &object)
DGtal::IntegerComputer::Vector3I
SpaceND< 3, Integer >::Vector Vector3I
Definition: IntegerComputer.h:96
DGtal::SpaceND
Definition: SpaceND.h:95
DGtal::IntegerComputer::_m_r
Integer _m_r
Used to represent a remainder.
Definition: IntegerComputer.h:518
DGtal::IntegerComputer::_m_v0
Vector2I _m_v0
Used to represent vectors.
Definition: IntegerComputer.h:526
DGtal::IntegerComputer::getEuclideanDiv
void getEuclideanDiv(Integer &q, Integer &r, IntegerParamType a, IntegerParamType b) const
DGtal::IntegerComputer::getValidBezout
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
DGtal::IntegerComputer::_m_b
Integer _m_b
Used to store parameter b.
Definition: IntegerComputer.h:510
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
DGtal::IntegerComputer::Vector2I
SpaceND< 2, Integer >::Vector Vector2I
Definition: IntegerComputer.h:94
DGtal::IntegerComputer::extendedEuclid
Vector2I extendedEuclid(IntegerParamType a, IntegerParamType b, IntegerParamType c) const
DGtal::IntegerComputer::isNegativeOrZero
static bool isNegativeOrZero(IntegerParamType a)
DGtal::IntegerComputer::~IntegerComputer
~IntegerComputer()
DGtal::IntegerComputer::isNotZero
static bool isNotZero(IntegerParamType a)
DGtal::IntegerComputer::Point3I
SpaceND< 3, Integer >::Point Point3I
Definition: IntegerComputer.h:95
DGtal::IntegerComputer::IntegerParamType
NumberTraits< Integer >::ParamType IntegerParamType
Definition: IntegerComputer.h:88
DGtal::IntegerComputer::isPositive
static bool isPositive(IntegerParamType a)
DGtal::PointVector< dim, Integer >
DGtal::IntegerComputer::isZero
static bool isZero(IntegerParamType a)
DGtal::IntegerComputer::getGcd
void getGcd(Integer &g, IntegerParamType a, IntegerParamType b) const
DGtal::IntegerComputer::_m_c2
Integer _m_c2
Used to represent scalar products.
Definition: IntegerComputer.h:534
DGtal::IntegerComputer::Point2I
SpaceND< 2, Integer >::Point Point2I
Definition: IntegerComputer.h:93
DGtal::IntegerComputer::getCoefficientIntersection
void getCoefficientIntersection(Integer &fl, Integer &ce, const Vector2I &p, const Vector2I &u, const Vector2I &N, IntegerParamType c) const
DGtal::IntegerComputer::gcd
Integer gcd(IntegerParamType a, IntegerParamType b) const
DGtal::IntegerComputer::getFloorCeilDiv
void getFloorCeilDiv(Integer &fl, Integer &ce, IntegerParamType na, IntegerParamType nb) const
DGtal::IntegerComputer::floorDiv
Integer floorDiv(IntegerParamType na, IntegerParamType nb) const
DGtal::IntegerComputer::selfDisplay
void selfDisplay(std::ostream &out) const
DGtal::IntegerComputer::_m_a
Integer _m_a
Used to store parameter a.
Definition: IntegerComputer.h:508
DGtal::NumberTraitsImpl< std::decay< T >::type >::ParamType
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
DGtal::concepts::CIntegralNumber
Aim: Concept checking for Integral Numbers. Models of this concept should be listed in NumberTraits c...
Definition: CIntegralNumber.h:101
DGtal::IntegerComputer::BOOST_CONCEPT_ASSERT
BOOST_CONCEPT_ASSERT((concepts::CInteger< Integer >))
DGtal::IntegerComputer::isNegative
static bool isNegative(IntegerParamType a)
DGtal::IntegerComputer::staticGcd
static Integer staticGcd(IntegerParamType a, IntegerParamType b)