Title: CSCE 441: Computer Graphics Scan Conversion of Polygons
1CSCE 441 Computer GraphicsScan Conversion of
Polygons
Jinxiang Chai
2OpenGL Geometric Primitives
- All geometric primitives are specified by vertices
3OpenGL Geometric Primitives
- All geometric primitives are specified by vertices
4OpenGL Geometric Primitives
- All geometric primitives are specified by vertices
5Drawing General Polygons
- How to draw every interior pixels?
?
6Drawing Curved Objects
- How to draw every interior pixels?
?
7Outline
- Methods for drawing polygons or curved objects
- - Scanline conversion of polygons
- - Boundary-fill
- - Flood-fill
- Required readings
- - HB 4-9 to 4-14
8Drawing Rectangles
- Which pixels should be filled?
9Drawing Rectangles
10Drawing Rectangles
- What if two rectangles overlap?
11Drawing Rectangles
12Drawing Rectangles
Overlap!!!
13Drawing Rectangles
- Solution Exclude pixels on top and right
14Drawing Rectangles
15General Polygons Basic Idea
- How to draw every interior pixels?
16General Polygons Basic Idea
- How to draw every interior pixels for a scan line?
17General 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
18General 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
19General Polygons Basic Idea
Use coherence to speed up
- Intersect scan lines with edges
- Find ranges along x
- Fill interior of those
- ranges
Edges intersecting one scan line are mostly same
as those intersecting previous scan line
20General 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
21How to store polygon edges?
22General 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
23General Polygons Example
C
Sorted Edge Table
B
D
G
E
F
A
24General Polygons Example
C
Sorted Edge Table
B
D
G
E
F
A
25General Polygons Example
C
Sorted Edge Table
B
D
G
AB
AG
E
F
A
26General Polygons Example
C
Sorted Edge Table
B
D
G
AB
AG
E
F
Exclude horizontal edges!
A
27General Polygons Example
C
Sorted Edge Table
B
D
G
FG
ED
AB
AG
E
F
A
28General Polygons Example
C
Sorted Edge Table
B
D
CD
G
FG
ED
AB
AG
E
F
A
29General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
E
F
A
30General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
E
F
Which edges are intersecting with the current
scan line?
A
31General Polygons Data Structures
List of all edges intersecting current scan-line
sorted by their x-values
Edges
32General Polygons Data Structures
List of all edges intersecting current scan-line
sorted by their x-values
Edges
Implement active edge list with linked list
33General Polygons Data Structures
List of all edges intersecting current scan-line
sorted by their x-values
Edges
Implement active edge list with linked list
So what kind of information should be stored in
the linked list for our polygon drawing algorithm?
34General Polygons Data Structures
maxY highest y-value currentX x-value of
end-point with lowest y-value xIncr 1 / slope
Edge
mazY
currentX
xIncr
35Scan line intersection
Scan line yk1
Scan line yk
36Scan line intersection
Scan line yk1
Scan line yk
37General 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!!!
38General Polygons Algorithm
- line 0
- While (line lt height )
- Add edges to Active Edge List from Sorted Edge
Table starting at line - Remove edges that end at line
- Fill pixels
- Increment x-values on edges in Active Edge List
- Increment line
39General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
A
40General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
A
maxY
currentX
xIncr
41General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List?
E
F
A
42General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
ED
FG
A
maxY
currentX
xIncr
43General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
ED
FG
A
maxY
Is it correct?
currentX
xIncr
44General Polygons Example
C
Sorted Edge Table
B
BC
D
CD
G
FG
ED
AB
AG
Active Edge List
E
F
AG
AB
ED
FG
A
maxY
currentX
xIncr
45General Polygons Algorithm
- line 0
- While (line lt height )
- Add edges to Active Edge List from Sorted Edge
Table starting at line - Remove edges that end at line
- Fill pixels
- Increment x-values on edges in Active Edge List
- Increment line
46General 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
47General 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
48General 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
49General 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
50General 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
51General 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 scan line
52General 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
53General 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
54General 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
55General 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
56General 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
57General 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
58General 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
59General 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
60General 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
61General 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
62General 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
63General 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
64General 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
65General Polygons Algorithm
- line 0
- While (line lt height )
- Add edges to Active Edge List from Sorted Edge
Table starting at line - Remove edges that end at line
- Fill pixels
- Increment x-values on edges in Active Edge List
- Increment scan line
66Pixel Fill-in
- Which intervals should we draw?
67Pixel Fill-in
- Which intervals should we draw?
- - Odd intervals. But need to pay attention
to scan lines passing through vertices.
68General 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)
69Curved Boundaries
- How to deal with curved boundaries?
70Boundary Fill
- Start with drawn boundaries 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
71Boundary Fill
- Start with drawn boundaries 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
72Boundary Fill
- Work for inner and outer boundaries
73Boundary 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
74Boundary Fill
- How to define a neigbhbor?
8-connected
4-connected
75Boundary Fill Example
Black pixels indicate boundary pixels
76Boundary Fill Example
77Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
78Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
79Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
80Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
81Boundary Fill Example
Continue checking neighboring pixels until
reaching boundary pixels or previously visited
pixels!
82Boundary Fill
83How to deal with this?
- Multiple color boundaries?
How to paint this region to yellow?
84How to deal with this?
- Multiple color boundaries?
- Three keys
- a start pixel
- a target color
- a paint color
How to paint this region to yellow?
85Flood 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 are recolored
86Flood Fill Example
87Flood Fill Example
88Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
89Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
90Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
91Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
92Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
93Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
94Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
95Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
96Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
97Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!
98Flood Fill Example
Continue setting the colors for neighboring
pixels if it is interior pixels!