DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testArithmeticDSS-benchmark.cpp
Go to the documentation of this file.
1
16
29
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/ArithmeticalDSSComputer.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::Integer
Integer
;
55
typedef
typename
DSL::ConstIterator
ConstIterator
;
56
typedef
ArithmeticalDSSComputer<ConstIterator, Integer, 4>
ADSS;
57
58
ConstIterator
it = D.begin(
A
);
59
ConstIterator
it_end = D.end(
B
);
60
ADSS dss;
61
dss.init( it );
62
while
( ( dss.end() != it_end )
63
&& ( dss.extendFront() ) ) {}
64
std::cout << D.a() <<
" "
<< D.b() <<
" "
<< D.mu() <<
" "
65
<< dss.a() <<
" "
<< dss.b() <<
" "
<< dss.mu() <<
" "
66
<<
A
[0] <<
" "
<<
A
[1] <<
" "
<<
B
[0] <<
" "
<<
B
[1]
67
<< std::endl;
68
69
return
true
;
70
}
71
72
// template <typename Fraction>
73
// bool testSubStandardDSLQ0( unsigned int nbtries )
74
// {
75
// typedef StandardDSLQ0<Fraction> DSL;
76
// typedef typename Fraction::Integer Integer;
77
// typedef typename Fraction::Quotient Quotient;
78
// typedef typename DSL::Point Point;
79
// typedef typename DSL::ConstIterator ConstIterator;
80
// typedef typename DSL::Point2I Point2I;
81
// typedef typename DSL::Vector2I Vector2I;
82
// IntegerComputer<Integer> ic;
83
84
// std::cout << "# a b mu a1 b1 mu1 Ax Ay Bx By" << std::endl;
85
// for ( unsigned int i = 0; i < nbtries; ++i )
86
// {
87
// Integer a( rand() % 12000 + 1 );
88
// Integer b( rand() % 12000 + 1 );
89
// if ( ic.gcd( a, b ) == 1 )
90
// {
91
// for ( Integer mu = 0; mu < 5; ++mu )
92
// {
93
// DSL D( a, b, rand() % 10000 );
94
// for ( Integer x = 0; x < 10; ++x )
95
// {
96
// Integer x1 = rand() % 1000;
97
// Integer x2 = x1 + 1 + ( rand() % 1000 );
98
// Point A = D.lowestY( x1 );
99
// Point B = D.lowestY( x2 );
100
// checkSubArithmeticDSS<DSL>( D, A, B );
101
// }
102
// }
103
// }
104
// }
105
// return true;
106
// }
107
108
template
<
typename
Fraction>
109
bool
testSubStandardDSLQ0
(
unsigned
int
nbtries,
110
typename
Fraction::Integer moda,
111
typename
Fraction::Integer modb,
112
typename
Fraction::Integer modx )
113
{
114
typedef
StandardDSLQ0<Fraction>
DSL;
115
typedef
typename
Fraction::Integer
Integer
;
116
typedef
typename
DSL::Point
Point
;
117
IntegerComputer<Integer>
ic;
118
119
std::cout <<
"# a b mu a1 b1 mu1 Ax Ay Bx By"
<< std::endl;
120
for
(
unsigned
int
i = 0; i < nbtries; ++i )
121
{
122
Integer
a( rand() % moda + 1 );
123
Integer
b( rand() % modb + 1 );
124
if
( ic.
gcd
( a, b ) == 1 )
125
{
126
for
(
Integer
mu = 0; mu < 5; ++mu )
127
{
128
DSL D( a, b, rand() % (moda+modb) );
129
for
(
Integer
x = 0; x < 10; ++x )
130
{
131
Integer
x1 = rand() % modx;
132
Integer
x2 = x1 + 1 + ( rand() % modx );
133
Point
A
= D.lowestY( x1 );
134
Point
B
= D.lowestY( x2 );
135
checkSubArithmeticDSS<DSL>
( D,
A
,
B
);
136
}
137
}
138
}
139
}
140
return
true
;
141
}
142
143
145
// Standard services - public :
146
147
int
main
(
int
argc,
char
** argv)
148
{
149
typedef
SternBrocot<DGtal::int64_t,DGtal::int32_t>
SB;
150
typedef
SB::Fraction Fraction;
151
typedef
Fraction::Integer
Integer
;
152
unsigned
int
nbtries = ( argc > 1 ) ? atoi( argv[ 1 ] ) : 10000;
153
Integer
moda = ( argc > 2 ) ? atoll( argv[ 2 ] ) : 12000;
154
Integer
modb = ( argc > 3 ) ? atoll( argv[ 3 ] ) : 12000;
155
Integer
modx = ( argc > 4 ) ? atoll( argv[ 4 ] ) : 1000;
156
testSubStandardDSLQ0<Fraction>
( nbtries, moda, modb, modx );
157
return
0;
158
}
159
160
// //
B
Definition
testPartialTemplateSpecialization.cpp:63
DGtal::ArithmeticalDSSComputer
Aim: This class is a wrapper around ArithmeticalDSS that is devoted to the dynamic recognition of dig...
Definition
ArithmeticalDSSComputer.h:87
DGtal::IntegerComputer
Aim: This class gathers several types and methods to make computation with integers.
Definition
IntegerComputer.h:83
DGtal::IntegerComputer::gcd
Integer gcd(IntegerParamType a, IntegerParamType b) const
DGtal::ConstIterator
DGtal::Point
DGtal::StandardDSLQ0
Aim: Represents a digital straight line with slope in the first quadrant (Q0: x >= 0,...
Definition
StandardDSLQ0.h:80
DGtal::SternBrocot
Aim: The Stern-Brocot tree is the tree of irreducible fractions. This class allows to construct it pr...
Definition
SternBrocot.h:78
Integer
Point::Coordinate Integer
Definition
examplePlaneProbingParallelepipedEstimator.cpp:44
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
std
STL namespace.
A
Definition
testCountedConstPtrOrConstPtr.cpp:43
checkSubArithmeticDSS
bool checkSubArithmeticDSS(const DSL &D, const typename DSL::Point &A, const typename DSL::Point &B)
Definition
testArithmeticDSS-benchmark.cpp:50
main
int main(int, char **)
Definition
testIntegerComputer.cpp:331
testSubStandardDSLQ0
bool testSubStandardDSLQ0()
Definition
testLighterSternBrocot.cpp:657
tests
benchmarks
arithmetic
testArithmeticDSS-benchmark.cpp
Generated on
for DGtal by
1.18.0