Title: Dr' Scott Schaefer
1Scan Conversion of Polygons
2Drawing Rectangles
- Which pixels should be filled?
3Drawing Rectangles
4Drawing Rectangles
- What if two rectangles overlap?
5Drawing Rectangles
6Drawing Rectangles
Overlap!!!
7Drawing Rectangles
- Solution Exclude pixels on top and right
8Drawing Rectangles
9General Polygons Basic Idea
- Intersect scan lines with edges
- Find ranges along x
- Fill interior of those
- ranges
-
- Dont fill top/right
-
- Edges may NOT match
- with line drawing algo
10General Polygons Basic Idea
Use coherence to speed up
- Intersect scan lines with edges
- Find ranges along x
- Fill interior of those
- ranges
-
- Dont fill top/right
-
- Edges may NOT match
- with line drawing algo
11General Polygons Basic Idea
Use coherence to speed up
- Intersect scan lines with edges
- Find ranges along x
- Fill interior of those
- ranges
Edges intersection one scan line are mostly same
as those intersecting previous scan line
12General Polygons Basic Idea
Use coherence to speed up
- Intersect scan lines with edges
- Find ranges along x
- Fill interior of those
- ranges
The x-value of an intersection with one scan line
is close to the intersection with the previous one
13General Polygons Data Structures
Store a linked-list per scan-line. Insert edges
into table at scan-line associated with lowest
end-point.
Scan Lines
Edges
14General Polygons Data Structures
List of all edges intersecting current scan-line
sorted by their x-values
Edges
15General Polygons Data Structures
maxY highest y-value currentX x-value of
end-point with lowest y-value xIncr 1 / slope
Edge
mazY
currentX
xIncr
16General Polygons Data Structures
maxY highest y-value currentX x-value of
end-point with lowest y-value xIncr 1 / slope
Edge
mazY
currentX
xIncr
Horizontal edges will not be used!!!
17General Polygons Algorithm
- line 0
- While (line lt 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
18General Polygons Example
C
Active Edge Table
B
D
G
Active Edge List
E
F
A
19General Polygons Example
C
Active Edge Table
B
D
G
AB
AG
Active Edge List
E
F
A
20General Polygons Example
C
Active Edge Table
B
D
G
FG
ED
AB
AG
Active Edge List
E
F
A
21General Polygons Example
C
Active Edge Table
B
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
A
22General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
A
23General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
A
maxY
currentX
xIncr
24General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
25General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
26General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
27General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
28General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
29General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
A
maxY
currentX
xIncr
30General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
A
maxY
currentX
xIncr
31General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
A
maxY
currentX
xIncr
32General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
A
maxY
currentX
xIncr
33General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
CD
A
maxY
currentX
xIncr
34General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
ED
CD
A
maxY
currentX
xIncr
35General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
CD
A
maxY
currentX
xIncr
36General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AB
CD
A
maxY
currentX
xIncr
37General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
BC
CD
AB
A
maxY
currentX
xIncr
38General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
BC
CD
AB
A
maxY
currentX
xIncr
39General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
BC
CD
A
maxY
currentX
xIncr
40General Polygons Example
C
Active Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
BC
CD
A
maxY
currentX
xIncr
41General 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)
42Boundary 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
43Boundary Fill Example
44Boundary Fill Example
45Boundary Fill Example
46Boundary Fill Example
47Boundary Fill Example
48Boundary Fill Example
49Flood 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
50Flood Fill Example
51Flood Fill Example
52Flood Fill Example
53Flood Fill Example
54Flood Fill Example
55Flood Fill Example
56Flood Fill Example
57Flood Fill Example
58Flood Fill Example
59Flood Fill Example
60Flood Fill Example
61Flood Fill Example
62Flood Fill Example