Professional Documents
Culture Documents
Module 2 Scanline - Class Way
Module 2 Scanline - Class Way
EXAMPLE
7/6/23 1
Polygon Data Structure
edges
xmin ymax 1/m
(9, 6)
1 6 8/4
07/06/2023 4
Preprocessing the edges
For a closed polygon, there should be an even number
of crossings at each scan line.
We fill between each successive pair.
7/6/23 5
13
Polygon
12 Data Structure
11
11 e6
10 e6
after preprocessing
10
9 Edge Table (ET) has a list of
8 edges for each scan line.
7 e4 e5
6
7 e3
e3 e4
e7e5
e8 13
e6
5
6 e7 e8
4 10
e3 e5 e7
3 e4 e8
2
1 e2 e1 e11 5
0 e10 e9 e9
e2 e11
e11
0
e10
e1
The Algorithm
1. Start with smallest nonempty y value in ET.
2. Initialize SLB (Scan Line Bucket) to nil.
3. While current y ≤ top y value:
a. Merge y bucket from ET into SLB; sort on xmin.
b. Fill pixels between rounded pairs of x values in SLB.
c. Remove edges from SLB whose ytop = current y.
d. Increment xmin by 1/m for edges in SLB.
e. Increment y by 1.
7/6/23 7
ET
13
12
11 e6
Running the
10
9
8 Algorithm
7 e3 e4 e5
6 e7 ve8
13
5
4
3
e6
2
1 e2 e11 10
0 e10 e9 e3 e5 e7
e4 e8
xmin ymax 1/m
e2 2 6 -2/5 5
e3 1/3 12 1/3 e9
e4 4 12 -2/5 e2 e11
e5 4 13 0
e6 6 2/3 13 -4/3 0
e10
e7 10 10 -1/2
e8 10 8 2 0 5 10 15
e9 11 8 3/8
e10 11 4 -3/4
e11 6 4 2/3
Running the
Algorithm
y=0 13
e10 e6
SCB 1011
1/4 4 -3/4
10
e3 e5 e7
e9 e4 e8
1111
3/8 8 3/8
5
e9
e2 e11
0
e10
0 5 10 15
7/6/23 9
Running the
Algorithm
y=1 13
e2 e6
SLB 1 3/5
2 6 -2/5
10
e3 e5 e7
e11 e4 e8
6 2/3
6 4 2/3
5
e9
e10 e2 e11
10
9 1/2
1/4 4 -3/4
0
e10
e9 0 5 10 15
6/8
11 3/8 8 3/8
7/6/23 10
Running the
Algorithm
y=2 13
e2 e6
SLB 1 3/5
1/5 6 -2/5
10
e3 e5 e7
e11 e4 e8
7
6 1/3
2/3 4 2/3
5
e9
e10 e2 e11
8 1/2
9 3/4 4 -3/4
0
e10
e9 0 5 10 15
12 1/8
11 6/8 8 3/8
7/6/23 11
Running the
Algorithm
y=3 13
e2 e6
SLB 14/5
1/5 6 -2/5
10
e3 e5 e7
e11 e4 e8
78
1/3 4 2/3
5
e9
e10 e2 e11
8
8 3/4 4 -3/4
0
e10
e9 0 5 10 15
12 1/8
4/8 8 3/8
7/6/23 12
Running the
Algorithm
y=4 13
e2 e6
SLB 4/5 6 -2/5
10
e3 e5 e7
e11 e4 e8
8 4 2/3
5
e9
e10 e2 e11
8 4 -3/4
0
e10
e9 0 5 10 15
12 4/8 8 3/8
Remove these edges.
7/6/23 13
Running the
Algorithm
y=4 13
e2 e6
SLB 4/5
2/5 6 -2/5
10
e3 e5 e7
e9 e4 e8
12 7/8
4/8 8 3/8
5
e9
e11 and e10 are removed. e2 e11
0
e10
0 5 10 15
7/6/23 14
Running the
Algorithm
y=5 13
e2 e6
SLB 2/5
0 6 -2/5
10
e3 e5 e7
e9 e4 e8
12 2/8
13 7/8 8 3/8
5
e9
e2 e11
0
e10
0 5 10 15
7/6/23 15
Remove this edge.
Running the
Algorithm
y=6 13
e2 e6
SLB 0 6 -2/5
10
e3 e5 e7
e7 e4 e8
910
1/2 10 -1/2
5
e9
e8 e2 e11
12
10 8 2
0
e10
e9 0 5 10 15
13 2/8
5/8 8 3/8
7/6/23 16
Add these edges.
e3
1/3 12 1/3 Running the
e4
Algorithm
4 12 -2/5 13
e6
e5 10
4 13 0 e3 e5 e7
e4 e8
y=7 e7 5
SLB 9 1/2 10 -1/2 e9
e2 e11
e8 0
e10
12 8 2
0 5 10 15
e9
13 5/8 8 3/8
Similarly do for the rest
07/06/2023 18