Newer
Older
#include "scannerprovider.h"
#include "directionalscannero2.h"
#include "directionalscannero7.h"
#include "directionalscannero1.h"
#include "directionalscannero8.h"
#include "vhscannero2.h"
#include "vhscannero7.h"
#include "vhscannero1.h"
#include "vhscannero8.h"
DirectionalScanner *ScannerProvider::getScanner (Pt2i p1, Pt2i p2)
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
{
// Enforces P1 to be lower than P2
// or to left of P2 in cas of equality
if ((p1.y () > p2.y ())
|| ((p1.y () == p2.y ()) && (p1.x () > p2.x ())))
{
Pt2i tmp = p1;
p1 = p2;
p2 = tmp;
}
// Computes the steps position array
int nbs = 0;
bool *steps = p1.stepsTo (p2, &nbs);
// Equation of the strip support lines : ax + by = c
int a = p2.x () - p1.x ();
int b = p2.y () - p1.y ();
if (a < 0 || (a == 0 && b < 0)) // Enforces a >= 0, then b > 0
{
a = -a;
b = -b;
}
int c2 = a * p2.x () + b * p2.y ();
// Builds and returns the appropriate scanner
if (b < 0)
if (-b > a)
{
if (isOrtho)
{
int repx = (p1.x () + p2.x ()) / 2; // central scan start
int repy = p1.y () - (int) ((p1.x () - repx) * (p1.x () - p2.x ())
/ (p2.y () - p1.y ()));
return (new VHScannerO1 (xmin, ymin, xmax, ymax,
a, b, c2, nbs, steps, repx, repy));
}
else return (new DirectionalScannerO1 (xmin, ymin, xmax, ymax,
a, b, c2, nbs, steps, p1.x (), p1.y ()));
}
else
{
if (isOrtho)
{
int repy = (p1.y () + p2.y ()) / 2; // central scan start
int repx = p1.x () + (int) ((repy - p1.y ()) * (p2.y () - p1.y ())
/ (p1.x () - p2.x ()));
return (new VHScannerO2 (xmin, ymin, xmax, ymax,
a, b, c2, nbs, steps, repx, repy));
}
else return (new DirectionalScannerO2 (xmin, ymin, xmax, ymax,
a, b, c2, nbs, steps, p1.x (), p1.y ()));
}
else
if (b > a)
{
if (isOrtho)
{
int repx = (p1.x () + p2.x ()) / 2; // central scan start
int repy = p1.y () - (int) ((repx - p1.x ()) * (p2.x () - p1.x ())
/ (p2.y () - p1.y ()));
return (new VHScannerO8 (xmin, ymin, xmax, ymax,
a, b, c2, nbs, steps, repx, repy));
}
else return (new DirectionalScannerO8 (xmin, ymin, xmax, ymax,
a, b, c2, nbs, steps, p1.x (), p1.y ()));
}
else
{
if (isOrtho)
{
int repy = (p1.y () + p2.y ()) / 2; // central scan start
int repx = p1.x () - (int) ((repy - p1.y ()) * (p2.y () - p1.y ())
/ (p2.x () - p1.x ()));
return (new VHScannerO7 (xmin, ymin, xmax, ymax,
a, b, c2, nbs, steps, repx, repy));
}
else return (new DirectionalScannerO7 (xmin, ymin, xmax, ymax,
a, b, c2, nbs, steps, p1.x (), p1.y ()));
}
}
DirectionalScanner *ScannerProvider::getScanner (Pt2i p1, Pt2i p2,
Pt2i v1, Pt2i v2)
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
{
// Get the scan strip center
int cx = (p1.x () + p2.x ()) / 2;
int cy = (p1.y () + p2.y ()) / 2;
// Gets the steps position array
int nbs = 0;
bool *steps = v1.stepsTo (v2, &nbs);
// Equation of the straight line passing through the center : ax - by = mu
int a = v2.y () - v1.y ();
int b = v1.x () - v2.x ();
if (a < 0 || (a == 0 && b < 0))
{
a = -a;
b = -b;
}
// Equation of the support lines of the scan strip
int c1 = a * p1.x () + b * p1.y ();
int c2 = a * p2.x () + b * p2.y ();
// Builds and returns the appropriate scanner
if (b < 0)
if (-b > a)
return (new DirectionalScannerO1 (xmin, ymin, xmax, ymax,
a, b, c1, c2, nbs, steps, cx, cy));
else
return (new DirectionalScannerO2 (xmin, ymin, xmax, ymax,
a, b, c1, c2, nbs, steps, cx, cy));
else
if (b > a)
return (new DirectionalScannerO8 (xmin, ymin, xmax, ymax,
a, b, c1, c2, nbs, steps, cx, cy));
else
return (new DirectionalScannerO7 (xmin, ymin, xmax, ymax,
DirectionalScanner *ScannerProvider::getScanner (Pt2i centre, Vr2i normal,
int length)
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
{
// Gets the steps position array
int nbs = 0;
bool *steps = normal.steps (&nbs);
// Orients the direction rightwards
int a = normal.x ();
int b = normal.y (); // as equation is (ax - by)
if (a < 0 || (a == 0 && b < 0))
{
a = -a;
b = -b;
}
// Builds and returns the appropriate scanner
if (b < 0)
if (-b > a)
return (new DirectionalScannerO1 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length));
else
return (new DirectionalScannerO2 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length));
else
if (b > a)
return (new DirectionalScannerO8 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length));
else
return (new DirectionalScannerO7 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length));
}
DirectionalScanner *ScannerProvider::getScanner (Pt2i centre, Vr2i normal,
int length, bool controlable)
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
{
// Gets the steps position array
int nbs = 0;
bool *steps = normal.steps (&nbs);
// Orients the direction rightwards
int a = normal.x ();
int b = normal.y (); // as equation is (ax - by)
if (a < 0 || (a == 0 && b < 0))
{
a = -a;
b = -b;
}
if (b < 0)
if (-b > a)
return (controlable ?
(isOrtho ?
(DirectionalScanner *)
new VHScannerO1 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length) :
(DirectionalScanner *)
new DynamicalScannerO1 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length)) :
(DirectionalScanner *)
new DirectionalScannerO1 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length));
else
return (controlable ?
(isOrtho ?
(DirectionalScanner *)
new VHScannerO2 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length) :
(DirectionalScanner *)
new DynamicalScannerO2 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length)) :
(DirectionalScanner *)
new DirectionalScannerO2 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length));
else
if (b > a)
return (controlable ?
(isOrtho ?
(DirectionalScanner *)
new VHScannerO8 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length) :
(DirectionalScanner *)
new DynamicalScannerO8 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length)) :
(DirectionalScanner *)
new DirectionalScannerO8 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length));
else
return (controlable ?
(isOrtho ?
(DirectionalScanner *)
new VHScannerO7 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length) :
(DirectionalScanner *)
new DynamicalScannerO7 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length)) :
(DirectionalScanner *)
new DirectionalScannerO7 (xmin, ymin, xmax, ymax,
a, b, nbs, steps,
centre.x (), centre.y (), length));
}