ALGORITHM AND SCANLINE ALGORITHM -...
-
Upload
truonghuong -
Category
Documents
-
view
219 -
download
0
Transcript of ALGORITHM AND SCANLINE ALGORITHM -...
BRESENHAM’S
ALGORITHM AND
SCANLINE
ALGORITHM Lecture 5 – Supp Notes
Comp3080 Computer Graphics
HKBU
BRESENHAM’S ALGORITHM
COMP3080 COMPUTER GRAPHICS , HKBU
DDA requires one floating
point addition per step
We can eliminate all fp through
Bresenham’s algorithm
Consider only 1 m 0
Other cases by symmetry
Assume pixel centers are at half
integers
If we start at a pixel that has
been written, there are only
two candidates for the next
pixel to be written into the
frame buffer
OCTOBER 24 , 2011 2
CANDIDATE PIXELS
1 m 0
COMP3080 COMPUTER GRAPHICS , HKBU
last pixel
candidates
Note that line could have
passed through any
part of this pixel
OCTOBER 24 , 2011 3
DECISION VARIABLE
COMP3080 COMPUTER GRAPHICS , HKBU
d = Δx(a - b)
d is an integer
d < 0 use upper pixel
d > 0 use lower pixel
OCTOBER 24 , 2011 4
where Δx and mΔx are integers. Notice Δy = mΔx
INCREMENTAL FORM
OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU 5
ak+1 = ak – m bk+1 = bk + m
ak+1 = ak + (1 – m) bk+1 = bk – (1 – m)
INCREMENTAL FORM
More efficient if we look at dk, the value of the decision variable
at x = k
For each x, we need do only an integer addition and a test
Single instruction on graphics chips
COMP3080 COMPUTER GRAPHICS , HKBU
dk+1 = dk – 2 Δy, if dk < 0 dk+1 = dk – 2(Δy - Δx), otherwise
OCTOBER 24 , 2011 6
BRESENHAM’S ALGORITHM
AN EXAMPLE
7
4 5 6 7 8 9
7
8
9
10
11
12
22
3
4
)11,9(),(
)8,5(),(
0
44
00
yxd
y
x
yx
yx
upper is choice first
OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU
8
BRESENHAM’S ALGORITHM
AN EXAMPLE
4 5 6 7 8 9
7
8
9
10
11
12
lower is choice second
0)1(22
)(201
xydd
OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU
9
BRESENHAM’S ALGORITHM
AN EXAMPLE
4 5 6 7 8 9
7
8
9
10
11
12
upper is choice third
660212
ydd
OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU
SCAN LINE POLYGON FILL:
THE ALGORITHM
10
Set y to smallest y coordinate that
has an entry in ET
Initialize the active edge table (AET)
to empty
Repeat until the ET and AET are
both empty:
Move from ET bucket at y to
AET those edges whose ymin
= y. (entering edges)
Remove from AET those edges
for which y = ymax.
Sort AET on x
Fill in desired pixels on scan
line using even-odd parity from
AET
Increment y by one (next scan
line)
For each edge in the AET,
update x by adding Δx/Δy
OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU
11
EXAMPLE
Given a sequence of ordered vertices
(10,10) (10,16) (16,20) (28,10) (28,16) (22,10)
(10,10)
(10,16)
(16,20)
(22,10) (28,10)
(28,16)
Edge 1
Edge 2
Edge 3
Edge 4
Edge 5
Edge 6
Extracted from :http://www.cs.rit.edu/~icss571/filling/example.html
OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU
12
EDGE TABLE VS GLOBAL EDGE TABLE (GET)
Extracted from :http://www.cs.rit.edu/~icss571/filling/example.html
OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU
13
GLOBAL EDGE TABLE VS ACTIVE EDGE TABLE
Extracted from :http://www.cs.rit.edu/~icss571/filling/example.html OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU
14
FILLING THE
POLYGON
Ymin = 10
Result
Sorted by x-val
Extracted from :http://www.cs.rit.edu/~icss571/filling/example.html OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU
15
FILLING THE POLYGON – 2ND SCANLINE TO SCANLINE 15
Y-max reaches the scanline
Extracted from :http://www.cs.rit.edu/~icss571/filling/example.html OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU
16
FILLING THE POLYGON – CON’T
Combine
reorder
Final Result
Extracted from :http://www.cs.rit.edu/~icss571/filling/example.html OCTOBER 24 , 2011 COMP3080 COMPUTER GRAPHICS , HKBU