Professional Documents
Culture Documents
CG Lecture 8 PDF
CG Lecture 8 PDF
University of Dhaka
Lecture 7
Basic Raster Graphics Algorithm for
Drawing 2D Primitives
3. c.d We can consider odd-parity concept to fill the line segment which is inside the
polygon (initially, parity bit is 0, when an intersecting point is occurred, parity is
changed to 1, and then filling is performed before getting a new intersecting point.
Once another intersecting point is occurred, parity is converted to even and no filling is
performed until a new intersecting point is obtained.
Polygon Filling (Polyfill)..
Basic Algorithm (without exception handling)
1. Find the minimum enclosed rectangle
2. Calculate number of scanlines (Ymax-Ymin +1)
3. For each scanline Do
a. Obtain intersection points of scanline with polygon edges
b. Sort intersections from left to right
c. For pairs of intersections from the list
d. Fill within pairs
e. Intersections points are updated for each scanline
3. c.d We can consider odd-parity concept to fill the line segment which is inside the
polygon (initially, parity bit is 0, when an intersecting point is occurred, parity is
changed to 1, and then filling is performed before getting a new intersecting point.
Once another intersecting point is occurred, parity is converted to even and no filling is
performed until a new intersecting point is obtained.
Polygon Filling (Polyfill)..
Normal Case
Problematic
Polygon Filling (Polyfill).. intersection
point
Special Case-1
Problem Solution
Number of Add an extra
intersecting points is intersection point
odd which is the same
where two polygon
edges are meeting
Problematic
intersection
point
Special Case-2
Problem Solution
Number of No need to add any
intersecting points is extra intersecting
even, but one point
intersecting point is
the vertex itself
Polygon Filling (Polyfill)..
Differentiating Special Case-1 and Special Case-2
If the intersecting point is a vertex and two sides of that vertex are in same
side, must add that point again in the list of intersecting points
If the intersecting point is a vertex and two sides of that vertex are in two
sides, don’t add that point again in the list of intersecting points
Span Extrema
• Only turn on pixels whose centers are interior to the polygon:
– Otherwise will intrude other adjacent polygons
• round up values on the left edge of a span, round down on
the right edge
Edge Coherence
Edges intersected by scanline “i” are typically intersected by
scanline “i+1” (except you are entering or leaving)
Edge Coherence
• Computing the intersections between scan lines and
edges can be costly
• Use a method similar to the midpoint algorithm
• y = mx + b, x = (y – b) / m
• At y = s, xs = (s – b ) / m
At y = s + 1, xs+1 = (s+1 - b) / m = xs + 1 / m
• Incremental calculation: xs+1 = xs + 1 / m
Pseudo code of computing the left
11
10
9
8 (EF)
7 9 7 -5/2 11 7 6/4
6 (DE)
(CD)
5 11 13 0
4
(FA)
3
9 2 0
2
1 3 7 -5/2 5 7 6/4
0 (AB) (BC)
Active Edge List (AEL)
Contains all the edges crossed by a scanline at the current
stage of iteration
This is the list of edges that are active for this scanline, sorted
by increasing X intersection
Active Edge List (AEL)
FA EF
AET (8) 9 2 0 9 4 -5/2
DE CD
11 9 6/4 11 13 0
Active Edge List (AEL)
Practice:
http://www.cs.rit.edu/~icss571/filling/example.html
Antialiasing
Antialiasing..
Simple idea for lines: Intersect thin (1 pixel wide) rectangle with
grid of pixels (known as unweighted are sampling)