Академический Документы
Профессиональный Документы
Культура Документы
SCAN CONVERSION
of a POLYGON
Pixels are not at the center of the grid,
but at the intersection of two orthogonal
scan lines
sca es (o
(on the
eggrid
d intersection
e sec o popoints).
s)
SCAN CONVERSION - POLYFILL
SCANLINE POLYFILL ALGORITHM
Steps (conceptual):
• No.
No of scanlines = Ymax – Ymin + 1
• Stop
p when scanline has reached Ymax
Case - I
3 ->
>4
Case - II
Add one more
intersection:
5 -> 6;
Do nott add
D dd
intersection,
keep 4;
HOW ??
What is the difference between the intersection
of the scanlines Y and Y’, with the vertices?
Y
Y’
Y
Y’
Before
Before After
processing After
processing processing
processing
To implement the above:
Before
f
processing Before After
After
processing
i
processing processing
Scanline PolyFill Algorithm
(revisited, in brief)
Intersect scanline with polygon edges
edges.
Basic Structure:
Two important
p features of scanline-based
polygon filling are:
• edge
d coherence
h - edges
d iintersected
dbby
scanline “i” are typically intersected by
scanline
li “i+1”.
“i+1”
(Xk+1, Yk+1)
(
(Yk+1 = Yk + 1)
L
Yk +1 − Yk
If, Yk+1 = Yk + 1; m=
X k +1 − X k
Then, Xk+1 = Xk + 1/m
Xk+1
k = round (Xk + 1/m)
1/m), where m = ΔY/ΔX.
ΔY/ΔX
How to implement this using integer arithmetic ?
Take an example: m = ΔY/ΔX = 7/3.
7/3
Set Counter, C=0
and counter-increment, ΔC = ΔX = 3;
SET is
i typically
t i ll built
b ilt using
i a bucket
b k t sort,
t
with a many buckets as there are scan lines.
7 E
C
5
A
3
1
2 4 6 8 10 12
B
Bucket-sorted Edge
g Table
11 λ for Polygon
10 λ
9 λ
EF DE
8 λ −5 6
7 9 7 2 11 7
4 λ
6 λ CD
5
4 λ 11 13 0 λ FA
3 9 2 0 λ
2 λ AB BC
1 −5 6
0 λ
3 7 2 5 7 4 λ
1
ymax xmin m
AB BC
AB: 1 −5 6
m = ΔY/ΔX = - (2/5).
3 7 2 5 7 4 λ
Set Counter
Counter, C=0; and
counter-increment, ΔC = min (
(ΔX, ΔY)
)=2(
(= ΔY);
)
Update for AB (-ve m), when YK = 2; Y = 1:
For the next three left (-ve) vertical (Y) scan lines,
successive values of C are : 2, 4, 6; X = 7 - 3 = 4;
Thus only
y at 3rd iteration: C >= ΔX.
3
FA BC
6
9 2 0 5 10 4 λ
Home task:
Complete the next two sets of iterations
lf till you gett :
yourself,
5
FA BC
6
9 2 0 5 ** 4 λ
** = 10 + 3 = 13, why ??
After post-processing
post processing (update from SET) at 5th scanline:
5
FA CD
9 2 0 11 13 0 λ
D
11
F
9
7 E
C
5
A
3
1
2 4 6 8 10 12
B
Status of AET at Scanline 8
AET
Pointer FA EF
9 2 0 9 4
−5
2
ymax x 1
m
DE CD
6
11 9 4 11 13 0 λ
AET Status of AET at Scanline 9
Pointer FA EF
9 2 0 9 2
−5
2
ymax x 1
m
DE CD
6
11 10 4 11 13 0 λ
• Sett Y to
S t smallest
ll t Y in
i SET entry
t (first
(fi t non-
empty bucket)
( ) Remove from
(v) f AET those
h entries
i ffor which
hi h
Y = Ymax (edges not involved).
END LOOP
END-LOOP
The algorithm:
g
scan-fill(polygon)
AET = null
ll
f
for Y = Ymin to
t Ymax
F E
B C
What
at about vertex
e te pprocessing
ocess g oon bot
both s
sides
des o
of a horizontal
o o ta edge ?
Problem with HORIZONTAL EDGES
G F
I
H
E
B C
Wh d
What do you d
do to fill till
ill vertex D – odd
dd number
b off iintersections
i
Problem with HORIZONTAL EDGES
Problem with
adjacent polygons: G F
(the LOC problem )
I H
E
B C
Think of the background surrounding polygon,
producing the same problem at the edges.
Problem with HORIZONTAL EDGES
Problem with
adjacent polygons:
(the LOC problem ) G F
I
H
E
Adjust finishing
B C
Problem with HORIZONTAL EDGES
Problem with
adjacent polygons:
(the LOC problem ) G F
I
H
E
B C
End of Lectures on
POLYFILL -
SCAN CONVERSION
of a POLYGON