cg filling polys
TRANSCRIPT
-
8/11/2019 CG Filling Polys
1/25
Polygon Filling
-
8/11/2019 CG Filling Polys
2/25
Filling the Spans
Span-filling is an important step in the whole polygon-fillingalgorithm, and it is implemented by a three-step process:
Find the intersections of the scan line with all edges of the
polygon.
Sort the intersections by increasing x coordinates.
Fill in all pixels between pairs of intersections that lie interior to
the polygon.
Now more questions arise:
How do we find and sort the intersections efficiently?
How do we judge whether a pixel lying inside or outside the polygon?
-
8/11/2019 CG Filling Polys
3/25
Parity (Odd-Even) Rule
Parity starting from even
oddodd
odd
odd
even
even
even
-
8/11/2019 CG Filling Polys
4/25
Filling Rules
Given an intersection with an arbitrary, fractional xvalue, how do we determine which pixel on either side
of that intersection is interior?
A: The strictly
inside rule:
-
8/11/2019 CG Filling Polys
5/25
Filling Rules
-
8/11/2019 CG Filling Polys
6/25
Filling Rules
How do we deal with the special case in which thevertices define a horizontal edge?
Bottom edges are drawn Top edges are not
-
8/11/2019 CG Filling Polys
7/25
Example
A B
C D
E
FG
HI
J
-
8/11/2019 CG Filling Polys
8/25
Edge Coherence Scan fill method
Brute-force technique of testing each polygon edge forintersection with each new scan lineit is inefficient andslow.
Clever Solution: if an edge intersects with a scan line, and the
slope of the edge is m,then successive scan line intersectionscan be found from:
xi+1
= xi+ 1/m
The floating-point arithmetic can be avoided by storing thenumerator, comparing to the denominator, and incrementingxwhen it overflows.
-
8/11/2019 CG Filling Polys
9/25
1/m = 2/5
xmin= 3,
the sequence is:
numerator:
denominator:
Edge Coherence (cont.)
2
5
35
16
m
,...5
14
5
63,
5
43,
5
23
5
23
5
43
5
14
2
5
4 1
-
8/11/2019 CG Filling Polys
10/25
Catch the intersection information in a table Edge Table (ET) with all edges sorted by ymin
Active Edge Table(AET) containing
The edges that intersect the current scan line
Their points of intersection
Sorted byx-coordinate, left to right
Catching Edge/Scan line intersections
-
8/11/2019 CG Filling Polys
11/25
Global edge table (ET): make the
addition of edges to the AET
efficient. It contains all edges
sorted by their smaller y
coordinate.
An Example for the Global Edge Table
ycoordinate
11 13 0 CD
9 2 0 FA
3 7 -5/2 AB
5 7 6/4 BC
9 7 -5/2 EF
11 7 6/4 DE
11
10
9
8
7
6
5
4
3
2
1
0
ymax
xmin
1/m
-
8/11/2019 CG Filling Polys
12/25
An Example of the Active Edge Table
AB
C
F
E
D
2
5
4
611 10
11 13 0
09 2
9 2
AET pointer
FA
EF
DE
CDAs each new scan-liney+1is encounter, update AET:
1). Remove edges not intersected byy+1 (ymax=y)
2). Add edges intersected byy+1 (ymin=y+1)
3). Calculate new xintersections.Y
max
xm
1
-
8/11/2019 CG Filling Polys
13/25
1. Set yto the smallest ycoordinate that has an entry in the ET, that is, yfor
the first nonempty bucket.
2. Initialise the AET to be empty.
3. Repeat until the AET and ET are empty.
3.1 Move from ET bucket yto the AET those edges whose
ymin= y (entering edges).
3.2 Remove from the AET those entries for which y=ymax (edges
not involved in the next scan line), then sort the AET onx
(made easier because ET is pre-sorted).
3.3 Fill in desired pixel values on scan line yby using pairs
ofxcoordinates from the AET.
3.4 Increment yby 1 (to the coordinate of the next scan line).
3.5 For each non-vertical edge remaining in the AET, update
xfor the new y.
Scan-Line Algorithm
-
8/11/2019 CG Filling Polys
14/25
Boundary-Fill
Algorithm
-
8/11/2019 CG Filling Polys
15/25
-
8/11/2019 CG Filling Polys
16/25
Polygon Filling:
Boundary-Fill Algorithm
1
2
21
-
8/11/2019 CG Filling Polys
17/25
Polygon Filling:
Boundary-Fill Algorithm
1
3
31
-
8/11/2019 CG Filling Polys
18/25
Polygon Filling:
Boundary-Fill Algorithm
1
46
5
41
5 6
-
8/11/2019 CG Filling Polys
19/25
Polygon Filling:
Boundary-Fill Algorithm
1
4 5
41
5
-
8/11/2019 CG Filling Polys
20/25
Polygon Filling:
Boundary-Fill Algorithm
1 41
4
-
8/11/2019 CG Filling Polys
21/25
Polygon Filling:
Boundary-Fill Algorithm
1 71
7
-
8/11/2019 CG Filling Polys
22/25
-
8/11/2019 CG Filling Polys
23/25
Polygon Filling:
Boundary-Fill Algorithm
1 919
-
8/11/2019 CG Filling Polys
24/25
Polygon Filling:
Boundary-Fill Algorithm
11
-
8/11/2019 CG Filling Polys
25/25
Flood-Fill
Algorithm
Boundar
y-Fill
Algorithm