DGtal
0.6.devel
Main Page
Related Pages
Modules
Namespaces
Data Structures
Examples
All
Data Structures
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
src
DGtal
arithmetic
StandardDSLQ0.h
1
17
#pragma once
18
33
#if defined(StandardDSLQ0_RECURSES)
34
#error Recursive header files inclusion detected in StandardDSLQ0.h
35
#else // defined(StandardDSLQ0_RECURSES)
36
37
#define StandardDSLQ0_RECURSES
38
39
#if !defined StandardDSLQ0_h
40
41
#define StandardDSLQ0_h
42
44
// Inclusions
45
#include <iostream>
46
#include "DGtal/base/Common.h"
47
#include "DGtal/arithmetic/IntegerComputer.h"
48
#include "DGtal/arithmetic/Pattern.h"
50
51
namespace
DGtal
52
{
53
55
// template class StandardDSLQ0
56
/*
57
Description of template class 'StandardDSLQ0' <p> \brief Aim:
58
Represents a digital straight line with slope in the first quadrant (Q0: x >= 0,
59
y >= 0 ).
60
61
It is the 4-connected set of points (x,y) of Z2 satisfying:
62
63
\f$ mu <= ax - by < mu + a + b \f$
64
65
You may move on it point by point with iterators ConstIterator.
66
You can find upper and lower leaning points, find points on the
67
DSL given one coordinate. You may extract subsegment with smartDSS and
68
reversedSmartDSS algorithms.
69
70
@param TFraction the type chosen to represent fractions, a model
71
of CFraction. You may use SternBrocot<>::Fraction for instance.
72
73
Model of boost::CopyConstructible, boost::Assignable, CPointPredicate
74
75
@see dgtal_digstraighness_sec3
76
*/
77
template
<
typename
TFraction>
78
class
StandardDSLQ0
79
{
80
// ----------------------- Standard types ------------------------------
81
public
:
82
typedef
TFraction
Fraction
;
83
typedef
StandardDSLQ0<TFraction>
Self
;
84
typedef
typename
Fraction::Integer
Integer
;
85
typedef
typename
Fraction::UnsignedInteger
UnsignedInteger
;
86
typedef
typename
Fraction::Quotient
Quotient
;
87
88
// BOOST_CONCEPT_ASSERT(( CFraction<Fraction> ));
89
90
typedef
IntegerComputer<Integer>
IC
;
91
typedef
typename
IC::IntegerParamType
IntegerParamType
;
92
typedef
typename
IC::Vector2I
Vector2I
;
93
typedef
typename
IC::Point2I
Point2I
;
94
95
// Model of CPointPredicate
96
typedef
typename
IC::Point2I
Point
;
97
109
struct
ConstIterator
{
110
typedef
ConstIterator
Self
;
111
typedef
Point
Value
;
112
113
// stl iterator types.
114
typedef
std::input_iterator_tag
iterator_category
;
115
typedef
Point
value_type
;
116
typedef
std::ptrdiff_t
difference_type
;
117
typedef
const
Point
*
pointer
;
118
typedef
const
Point
&
reference
;
119
120
inline
ConstIterator
()
121
:
myPtrDSL
( 0 )
122
{}
123
inline
ConstIterator
(
const
StandardDSLQ0<TFraction>
& myDSL,
124
const
Point
& p )
125
:
myPtrDSL
( & myDSL ),
myP
( p )
126
{}
127
inline
ConstIterator
(
const
Self
& other )
128
:
myPtrDSL
( other.
myPtrDSL
),
myP
( other.
myP
)
129
{}
130
inline
Self
&
operator=
(
const
Self
& other )
131
{
132
if
(
this
!= &other )
133
{
134
myPtrDSL
= other.
myPtrDSL
;
135
myP
= other.
myP
;
136
}
137
return
*
this
;
138
}
139
140
inline
reference
operator*
()
const
141
{
142
ASSERT(
myPtrDSL
!= 0 );
143
return
myP
;
144
}
145
146
inline
pointer
operator->
()
const
147
{
148
ASSERT(
myPtrDSL
!= 0 );
149
return
&
myP
;
150
}
151
152
inline
Self
&
operator++
()
153
{
154
Integer
rem =
myPtrDSL
->r(
myP
);
155
if
( rem -
myPtrDSL
->b() >=
myPtrDSL
->mu() )
156
++
myP
[ 1 ];
// +y;
157
else
158
++
myP
[ 0 ];
// +x;
159
return
*
this
;
160
}
161
162
inline
163
Self
164
operator++
(
int
)
165
{
166
Self
__tmp = *
this
;
167
this->
operator++
();
168
return
__tmp;
169
}
170
171
inline
172
bool
operator==
(
const
Self
& other )
const
173
{
174
ASSERT(
myPtrDSL
== other.
myPtrDSL
);
175
return
myP
== other.
myP
;
176
}
177
178
inline
179
bool
operator!=
(
const
Self
& other )
const
180
{
181
return
! ( this->
operator==
( other ) );
182
}
183
184
185
private
:
186
const
StandardDSLQ0<TFraction>
*
myPtrDSL
;
187
Point
myP
;
188
189
};
190
// ----------------------- Standard services ------------------------------
191
public
:
192
196
~StandardDSLQ0
();
197
201
StandardDSLQ0
();
202
207
StandardDSLQ0
(
const
StandardDSLQ0
& other );
208
214
StandardDSLQ0
&
operator=
(
const
StandardDSLQ0
& other );
215
221
StandardDSLQ0
(
Fraction
aSlope,
IntegerParamType
aMu );
222
229
StandardDSLQ0
(
IntegerParamType
a1,
IntegerParamType
b1,
230
IntegerParamType
mu1 );
231
234
bool
operator()
(
const
Point
& p )
const
;
235
237
Fraction
slope
()
const
;
238
241
const
Integer
&
mu
()
const
;
242
244
Integer
mup
()
const
;
245
247
Integer
a
()
const
;
249
Integer
b
()
const
;
251
Vector2I
v
()
const
;
252
255
ConstIterator
begin
(
Point
p )
const
;
256
259
ConstIterator
end
(
Point
p )
const
;
260
262
const
Pattern<Fraction>
&
pattern
()
const
;
263
267
Integer
r
(
const
Point
& p )
const
;
268
271
Point
U
()
const
;
274
Point
L
()
const
;
275
278
Point
lowestY
(
IntegerParamType
x )
const
;
281
Point
uppermostY
(
IntegerParamType
x )
const
;
284
Point
lowestX
(
IntegerParamType
y )
const
;
287
Point
uppermostX
(
IntegerParamType
y )
const
;
288
290
bool
before
(
const
Point
& p1,
const
Point
& p2 )
const
;
292
bool
beforeOrEqual
(
const
Point
& p1,
const
Point
& p2 )
const
;
293
294
308
Self
reversedSmartDSS
(
const
Point
& A,
const
Point
& B )
const
;
309
326
Self
reversedSmartDSS
(
Point
U1,
Point
U2,
327
const
Point
& A,
const
Point
& B )
const
;
328
341
Self
DSSWithinTwoPatterns
(
Point
U1,
Point
U2,
342
const
Point
& A,
const
Point
& B )
const
;
343
344
358
Self
smartDSS
(
const
Point
& A,
const
Point
& B )
const
;
359
360
// ----------------------- Interface --------------------------------------
361
public
:
362
367
void
selfDisplay
( std::ostream & out )
const
;
368
373
bool
isValid
()
const
;
374
375
// ------------------------- Protected Datas ------------------------------
376
protected
:
378
Pattern<Fraction>
myPattern
;
380
Integer
myMu
;
381
382
// ------------------------- Private Datas --------------------------------
383
private
:
385
IC
ic
;
386
387
// ------------------------- Hidden services ------------------------------
388
protected
:
389
390
// ------------------------- Internals ------------------------------------
391
private
:
392
static
Fraction
deepest
(
Fraction
f1,
Fraction
f2,
Fraction
f3 );
393
static
Fraction
deepest
(
Fraction
f1,
Fraction
f2 );
394
};
// end of class StandardDSLQ0
395
396
403
template
<
typename
TFraction>
404
std::ostream&
405
operator<< ( std::ostream & out, const StandardDSLQ0<TFraction> & object );
406
407
}
// namespace DGtal
408
409
411
// Includes inline functions.
412
#include "DGtal/arithmetic/StandardDSLQ0.ih"
413
414
// //
416
417
#endif // !defined StandardDSLQ0_h
418
419
#undef StandardDSLQ0_RECURSES
420
#endif // else defined(StandardDSLQ0_RECURSES)
Generated on Wed Dec 19 2012 19:10:35 for DGtal by
1.8.1.1