Scan Conversion of Polygons
description
Transcript of Scan Conversion of Polygons
1
Dr. Scott Schaefer
Scan Conversion of Polygons
2/70
Drawing Rectangles
Which pixels should be filled?
3/70
Drawing Rectangles
Is this correct?
4/70
Drawing Rectangles
What if two rectangles overlap?
5/70
Drawing Rectangles
Is this correct?
6/70
Drawing Rectangles
Is this correct? Overlap!!!
7/70
Drawing Rectangles
Solution: Exclude pixels on top and right
8/70
Drawing Rectangles
Artifacts are possible
9/70
General Polygons – Basic Idea
Intersect scan lines with edges Find ranges along x Fill interior of those
ranges
Don’t fill top/right
Edges may NOT match
with line drawing algo
10/70
General Polygons – Basic Idea
Intersect scan lines with edges Find ranges along x Fill interior of those
ranges
Don’t fill top/right
Edges may NOT match
with line drawing algo
Use coherence to
speed up
11/70
General Polygons – Basic Idea
Intersect scan lines with edges Find ranges along x Fill interior of those
ranges
Use coherence to
speed up
Edges intersection one scan line are
mostly same as those intersecting
previous scan line
12/70
General Polygons – Basic Idea
Intersect scan lines with edges Find ranges along x Fill interior of those
ranges
Use coherence to
speed up
The x-value of an intersection with
one scan line is close to the
intersection with the previous one
13/70
General Polygons – Data Structures
Edge:
maxY:
currentX:
xIncr:
maxY
currentX
xIncr
Edge),max( 1ii yy
otherwisex
yyyx
i
iiii
,
),min(,
1
1
ii
ii
yyxx
1
1
),(),( 11 iiii yxyx
14/70
General Polygons – Data Structures
Edge:
maxY:
currentX:
xIncr:
maxY
currentX
xIncr
Edge),max( 1ii yy
otherwisex
yyyx
i
iiii
,
),min(,
1
1
ii
ii
yyxx
1
1
),(),( 11 iiii yxyx
Horizontal edges will not be used!!!
15/70
General Polygons – Data Structures
Active Edge Table:
01234567
Sca
n L
ines
Edges
Store a linked-list per scan-line.
Insert edges into table at scan-
line associated with lowest end-
point.
16/70
General Polygons – Data Structures
Active Edge List:
Edges
List of all edges intersecting
current scan-line sorted by their
x-values
17/70
General Polygons – Algorithm
line = 0
While (line < height )
Add edges to Active Edge List from Active Edge Table starting at line
Remove edges that end at line
Fill pixels
Increment x-values on edges in Active Edge List
Increment line
18/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
Active Edge Table
Active Edge List
19/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB
Active Edge Table
Active Edge List
20/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB
BC
Active Edge Table
Active Edge List
21/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB
CD
BC
Active Edge Table
Active Edge List
22/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB
ED
CD
BC
Active Edge Table
Active Edge List
23/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB
ED
CD
BC
Active Edge Table
Active Edge List
24/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB
FG ED
CD
BC
Active Edge Table
Active Edge List
25/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
26/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
maxY
currentX
xIncr
AG
30
32
600
AB
27/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
AG
33
2
32
600
AB
maxY
currentX
xIncr
ED
55
21
33
21
FG
28/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
AG
33
2
32
600
AB
maxY
currentX
xIncr
ED
55
21
33
21
FG
29/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
AG
33
4
32
600
AB
maxY
currentX
xIncr
ED
52
15
21
32
12
21
FG
30/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
AG
33
4
32
600
AB
maxY
currentX
xIncr
ED
52
15
21
32
12
21
FG
31/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
AG
32
32
600
AB
maxY
currentX
xIncr
ED
56
21
32
21
FG
32/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
600
AB
maxY
currentX
xIncr
ED
56
21
33/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
600
AB
maxY
currentX
xIncr
ED
56
21
34/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
600
AB
maxY
currentX
xIncr
ED
52
16
21
35/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
600
AB
maxY
currentX
xIncr
ED
52
16
21
36/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
600
AB
maxY
currentX
xIncr
ED
57
21
CD
77
2
37/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
600
AB
maxY
currentX
xIncr
ED
52
16
21
CD
772
38/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
600
AB
maxY
currentX
xIncr
CD
772
39/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
600
AB
maxY
currentX
xIncr
CD
772
40/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
703
BC
maxY
currentX
xIncr
CD
752
600
AB
41/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
703
BC
maxY
currentX
xIncr
CD
752
600
AB
42/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
703
BC
maxY
currentX
xIncr
CD
752
43/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
703
BC
maxY
currentX
xIncr
CD
752
44/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
733
BC
maxY
currentX
xIncr
CD
732
45/70
General Polygons – Example
0 1 2 3 4 5 6 70
1
2
3
4
5
6
7
A
B
C
D
EF
G
01234567
AB AG
FG ED
CD
BC
Active Edge Table
Active Edge List
733
BC
maxY
currentX
xIncr
CD
732
46/70
General Polygons – Problems
Sliver polygons may not be drawn correctly
No simple solution Long, thin triangles
cause problems Want triangles with
good aspect ratio (close to equilateral)
47/70
Boundary Fill
Start with drawn outline of a polygon and an interior point
Recursively recolor outward from that point
• If neighbor different, then recolor and recur
Everything within the boundary is changed to that color
48/70
Boundary Fill
How to define a neighbor?
4-connected 8-connected
49/70
Boundary Fill – Example
50/70
Boundary Fill – Example
51/70
Boundary Fill – Example
52/70
Boundary Fill – Example
53/70
Boundary Fill – Example
54/70
Boundary Fill – Example
55/70
Flood Fill
Start with a point Define color under that point as the interior
color Recursively recolor outward from that point• If neighbor is interior color, then recolor
and recur
Contiguous regions of the same color are recolored
56/70
Flood Fill – Example
57/70
Flood Fill – Example
58/70
Flood Fill – Example
59/70
Flood Fill – Example
60/70
Flood Fill – Example
61/70
Flood Fill – Example
62/70
Flood Fill – Example
63/70
Flood Fill – Example
64/70
Flood Fill – Example
65/70
Flood Fill – Example
66/70
Flood Fill – Example
67/70
Flood Fill – Example
68/70
Flood Fill – Example
69/70
OpenGL: Drawing Polygons
Lots of different primitives supported GPU only draws triangles
• OpenGL triangulates all polygons
• Problems with concave polygons! How data is passed to GPU makes a
significant difference in speed
GL_QUAD_STRIPGL_QUAD_STRIPGL_TRIANGLE_STRIPGL_TRIANGLE_STRIP GL_TRIANGLE_FANGL_TRIANGLE_FAN GL_POLYGONGL_POLYGONGL_QUADSGL_QUADSGL_TRIANGLESGL_TRIANGLES
70/70
Performance
Nvidia 7300 GT1
Nvidia 8800 GTX1
ATI Radeon
HD 48502
ATI Radeon
HD 48502
New Drivers
Immediate Mode 15.5 15.5 21.0 33.0
Display Lists 28.3 22.0 463.5 497.5
Vertex Arrays 33.5 35.5 75.0 335.0
Vertex Buffer Objects
50.0 200.0 476.3 506.0
Frames per second displaying a 413,236 triangle model. CPU was an Intel Core 2 67001
or Core i7 9402
.