DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
testArithmeticDSS-benchmark.cpp
1 
30 
31 #include <cstdlib>
32 #include <iostream>
33 #include "DGtal/base/Common.h"
34 #include "DGtal/kernel/CPointPredicate.h"
35 #include "DGtal/arithmetic/IntegerComputer.h"
36 #include "DGtal/arithmetic/SternBrocot.h"
37 #include "DGtal/arithmetic/Pattern.h"
38 #include "DGtal/arithmetic/StandardDSLQ0.h"
39 #include "DGtal/geometry/curves/ArithmeticalDSS.h"
41 
42 using namespace std;
43 using namespace DGtal;
44 
46 // Functions for testing class SternBrocot.
48 
49 template <typename DSL>
50 bool checkSubArithmeticDSS( const DSL & D,
51  const typename DSL::Point & A,
52  const typename DSL::Point & B )
53 {
54  typedef typename DSL::Fraction Fraction;
55  typedef typename DSL::Integer Integer;
56  typedef typename DSL::Quotient Quotient;
57  typedef typename DSL::Point Point;
58  typedef typename DSL::ConstIterator ConstIterator;
59  typedef typename DSL::Point2I Point2I;
60  typedef typename DSL::Vector2I Vector2I;
62 
63  ConstIterator it = D.begin( A );
64  ConstIterator it_end = D.end( B );
65  ADSS dss;
66  dss.init( it );
67  while ( ( dss.end() != it_end )
68  && ( dss.extendForward() ) ) {}
69  std::cout << D.a() << " " << D.b() << " " << D.mu() << " "
70  << dss.getA() << " " << dss.getB() << " " << dss.getMu() << " "
71  << A[0] << " " << A[1] << " " << B[0] << " " << B[1]
72  << std::endl;
73 
74  return true;
75 }
76 
77 // template <typename Fraction>
78 // bool testSubStandardDSLQ0( unsigned int nbtries )
79 // {
80 // typedef StandardDSLQ0<Fraction> DSL;
81 // typedef typename Fraction::Integer Integer;
82 // typedef typename Fraction::Quotient Quotient;
83 // typedef typename DSL::Point Point;
84 // typedef typename DSL::ConstIterator ConstIterator;
85 // typedef typename DSL::Point2I Point2I;
86 // typedef typename DSL::Vector2I Vector2I;
87 // IntegerComputer<Integer> ic;
88 
89 // std::cout << "# a b mu a1 b1 mu1 Ax Ay Bx By" << std::endl;
90 // for ( unsigned int i = 0; i < nbtries; ++i )
91 // {
92 // Integer a( random() % 12000 + 1 );
93 // Integer b( random() % 12000 + 1 );
94 // if ( ic.gcd( a, b ) == 1 )
95 // {
96 // for ( Integer mu = 0; mu < 5; ++mu )
97 // {
98 // DSL D( a, b, random() % 10000 );
99 // for ( Integer x = 0; x < 10; ++x )
100 // {
101 // Integer x1 = random() % 1000;
102 // Integer x2 = x1 + 1 + ( random() % 1000 );
103 // Point A = D.lowestY( x1 );
104 // Point B = D.lowestY( x2 );
105 // checkSubArithmeticDSS<DSL>( D, A, B );
106 // }
107 // }
108 // }
109 // }
110 // return true;
111 // }
112 
113 template <typename Fraction>
114 bool testSubStandardDSLQ0( unsigned int nbtries,
115  typename Fraction::Integer moda,
116  typename Fraction::Integer modb,
117  typename Fraction::Integer modx )
118 {
119  typedef StandardDSLQ0<Fraction> DSL;
120  typedef typename Fraction::Integer Integer;
121  typedef typename Fraction::Quotient Quotient;
122  typedef typename DSL::Point Point;
123  typedef typename DSL::ConstIterator ConstIterator;
124  typedef typename DSL::Point2I Point2I;
125  typedef typename DSL::Vector2I Vector2I;
128 
129  std::cout << "# a b mu a1 b1 mu1 Ax Ay Bx By" << std::endl;
130  for ( unsigned int i = 0; i < nbtries; ++i )
131  {
132  Integer a( random() % moda + 1 );
133  Integer b( random() % modb + 1 );
134  if ( ic.gcd( a, b ) == 1 )
135  {
136  for ( Integer mu = 0; mu < 5; ++mu )
137  {
138  DSL D( a, b, random() % (moda+modb) );
139  for ( Integer x = 0; x < 10; ++x )
140  {
141  Integer x1 = random() % modx;
142  Integer x2 = x1 + 1 + ( random() % modx );
143  Point A = D.lowestY( x1 );
144  Point B = D.lowestY( x2 );
145  checkSubArithmeticDSS<DSL>( D, A, B );
146  }
147  }
148  }
149  }
150  return true;
151 }
152 
153 
155 // Standard services - public :
156 
157 int main( int argc, char** argv)
158 {
160  typedef SB::Fraction Fraction;
161  typedef Fraction::Integer Integer;
162  unsigned int nbtries = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 10000;
163  Integer moda = ( argc > 2 ) ? atoll( argv[ 2 ] ) : 12000;
164  Integer modb = ( argc > 3 ) ? atoll( argv[ 3 ] ) : 12000;
165  Integer modx = ( argc > 4 ) ? atoll( argv[ 4 ] ) : 1000;
166  testSubStandardDSLQ0<Fraction>( nbtries, moda, modb, modx );
167  return true;
168 }
169 
170 // //