Skip to main content
. Author manuscript; available in PMC: 2013 Jan 24.
Published in final edited form as: Proceedings VLDB Endowment. 2012 Jul;5(11):1543–1554. doi: 10.14778/2350229.2350268

Algorithm 1.

The PixelBox GPU algorithm.

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:    tidthreadIdx.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:          toptop − 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 jtid 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:                   jj + blockDim.x
28:                end for
29:             else
30:                subbox ← SubSampBox(box, tid)
31:                ϕ1 ← BoxPosition(box, pi)
32:                ϕ2 ← BoxPosition(box, qi)
33:                c ← BoxContinue1, ϕ2)
34:                t ← BoxContribute1, ϕ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:                toptop + 1 + blockDim.x
40:             end if
41:          end if
42:       end while
43:       ii + gridDim.x
44:    end for
45: end procedure