1: |
{pi, qi}i : the array of input polygon pairs |
2: |
{mi}i : the MBR of each polygon pair |
3: |
N : total number of polygon pairs |
4: |
stack[] : the shared stack containing sampling boxes |
5: |
I[N][blockDim.x] : partial areas of intersections |
6: |
A[N][blockDim.x] : partial summed areas of polygons |
7: |
|
8: |
procedure Kernel_SampBox
|
9: |
tid ← threadIdx.x
|
10: |
for
i = blockIdx.x to N
do
|
11: |
A[i][tid] ← A[i][tid] + PolyArea(pi) |
12: |
A[i][tid] ← A[i][tid] + PolyArea(qi) |
13: |
Thread 0: stack[0] ← {mi, 1} |
14: |
top ← 1 |
15: |
while
top > 0 do
|
16: |
top ← top − 1 |
17: |
syncthreads() |
18: |
{box, c} ← stack[top] |
19: |
if
c = 0 then
|
20: |
continue
|
21: |
else
|
22: |
if BoxSize(box) < T
then
|
23: |
for
j ← tid to BoxSize(box) do
|
24: |
ϕ1 ← PixelInPoly(box, j, pi) |
25: |
ϕ2 ← PixelInPoly(box, j, qi) |
26: |
I[i][tid] ← I[i][tid] + (ϕ1 ˄ ϕ2) |
27: |
j ← j + blockDim.x
|
28: |
end for
|
29: |
else
|
30: |
subbox ← SubSampBox(box, tid) |
31: |
ϕ1 ← BoxPosition(box, pi) |
32: |
ϕ2 ← BoxPosition(box, qi) |
33: |
c ← BoxContinue(ϕ1, ϕ2) |
34: |
t ← BoxContribute(ϕ1, ϕ2) |
35: |
a ← (1 − c) × t × BoxSize(subbox) |
36: |
I[i][tid] ← I[i][tid] + a
|
37: |
stack[top + 1 + tid] ← {subbox, c} |
38: |
Thread 0: stack[top].c ← 0 |
39: |
top ← top + 1 + blockDim.x
|
40: |
end if
|
41: |
end if
|
42: |
end while
|
43: |
i ← i + gridDim.x
|
44: |
end for
|
45: |
end procedure |