DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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/CUnsignedInteger.h"
47 #include "DGtal/kernel/CInteger.h"
48 #include "DGtal/kernel/SpaceND.h"
50 
51 namespace DGtal
52 {
53 
55  // template class IntegerComputer
81  template <typename TInteger>
83  {
84  // ----------------------- Associated types ------------------------------
85  public:
89 
92 
97 
100 
101  // ----------------------- Standard services ------------------------------
102  public:
103 
108 
117  IntegerComputer();
118 
127  IntegerComputer ( const Self & other );
128 
138  Self & operator= ( const Self & other );
139 
140 
141  // ----------------------- Integer services ------------------------------
142  public:
143 
148  static bool isZero( IntegerParamType a );
149 
154  static bool isNotZero( IntegerParamType a );
155 
160  static bool isPositive( IntegerParamType a );
161 
166  static bool isNegative( IntegerParamType a );
167 
172  static bool isPositiveOrZero( IntegerParamType a );
173 
178  static bool isNegativeOrZero( IntegerParamType a );
179 
184  static Integer abs( IntegerParamType a );
185 
192 
200 
207 
215 
229  void getEuclideanDiv( Integer & q, Integer & r,
230  IntegerParamType a, IntegerParamType b ) const;
231 
239 
247 
256  void getFloorCeilDiv( Integer & fl, Integer & ce,
257  IntegerParamType na, IntegerParamType nb ) const;
258 
268 
278 
287  void getGcd( Integer & g, IntegerParamType a, IntegerParamType b ) const;
288 
299  Integer getCFrac( std::vector<Integer> & quotients,
300  IntegerParamType a, IntegerParamType b ) const;
316  template <typename OutputIterator>
317  Integer getCFrac( OutputIterator outIt,
318  IntegerParamType a, IntegerParamType b ) const;
319 
330  Point2I convergent( const std::vector<Integer> & quotients,
331  unsigned int k ) const;
332 
333  // ----------------------- Point2I services ------------------------------
334  public:
340  void reduce( Vector2I & p ) const ;
341 
342 
350  Integer crossProduct( const Vector2I & u, const Vector2I & v) const;
351 
359  void getCrossProduct( Integer & cp,
360  const Vector2I & u, const Vector2I & v) const;
361 
369  Integer dotProduct( const Vector2I & u, const Vector2I & v ) const;
370 
378  void getDotProduct( Integer & dp,
379  const Vector2I & u, const Vector2I & v) const;
380 
393  IntegerParamType c ) const;
394 
409  void getCoefficientIntersection( Integer & fl, Integer & ce,
410  const Vector2I & p,
411  const Vector2I & u,
412  const Vector2I & N,
413  IntegerParamType c ) const;
414 
440  void getValidBezout ( Vector2I & v,
441  const Point2I & A, const Vector2I & u,
442  const Vector2I & N, IntegerParamType c,
443  const Vector2I & N2, IntegerParamType c2,
444  bool compute_v = true ) const;
445 
446  // ----------------------- Point3I services ------------------------------
447  public:
448 
454  void reduce( Vector3I & p ) const;
455 
463  Integer dotProduct( const Vector3I & u, const Vector3I & v) const;
464 
472  void getDotProduct( Integer & dp,
473  const Vector3I & u, const Vector3I & v) const;
474 
475 
476  // ----------------------- Interface --------------------------------------
477  public:
478 
483  void selfDisplay ( std::ostream & out ) const;
484 
489  bool isValid() const;
490 
491  // ------------------------- Protected Datas ------------------------------
492  private:
493  // ------------------------- Private Datas --------------------------------
494  private:
495 
497  mutable Integer _m_a;
499  mutable Integer _m_b;
501  mutable Integer _m_a0;
503  mutable Integer _m_a1;
505  mutable Integer _m_q;
507  mutable Integer _m_r;
511  mutable std::vector<Integer> _m_bezout[ 4 ];
513  mutable Vector2I _m_v;
515  mutable Vector2I _m_v0;
517  mutable Vector2I _m_v1;
519  mutable Integer _m_c0;
521  mutable Integer _m_c1;
523  mutable Integer _m_c2;
524 
525  // ------------------------- Hidden services ------------------------------
526  protected:
527 
528 
529  // ------------------------- Internals ------------------------------------
530  private:
531 
532  }; // end of class IntegerComputer
533 
534 
541  template <typename TInteger>
542  std::ostream&
543  operator<< ( std::ostream & out, const IntegerComputer<TInteger> & object );
544 
545 } // namespace DGtal
546 
547 
549 // Includes inline functions.
550 #include "DGtal/arithmetic/IntegerComputer.ih"
551 
552 // //
554 
555 #endif // !defined IntegerComputer_h
556 
557 #undef IntegerComputer_RECURSES
558 #endif // else defined(IntegerComputer_RECURSES)