Interior Pixels Along A Scan Line Passing Through A Polygon Area
Interior Pixels Along A Scan Line Passing Through A Polygon Area
• Fill
Determine overlap Intervals for scan lines that cross that area.
– Requires determining intersection positions of the edges of the
polygon with the scan lines
– Fill colors are applied to each section of the scanline that lies
within the interior of the region.
– Interior regions determined as in odd-even test
10 13 16 19
Interior pixels along a scan line passing through a
polygon area
10 13 16 19
Scan Line y
1 2 1 1
• Let (y1, y2) and (y2, y3) be the endpoint y values of two
consecutive edges. If y1, y2, y3 monotonically increase
or decrease, we need to count the middle vertex as a
single intersection point for any scan line passing
through that vertex.
Scan Line Polygon
• Fill
One method for implementing the adjustment
to the vertex intersection count is to shorten
some polygon edges to split those vertices that
should be counted as one intersection
– When the end point y coordinates of the two edges
are increasing , the y value of the upper endpoint for
the current edge is decreased by 1
(a) (b)
yk 1 yk
1
x k xk 1
1 m
• Each successive x is computed by adding the inverse of the slope and
rounding to the nearest integer
Integer operations
• Recall that slope is the ratio of two integers:
y
m
x
• So, incremental calculation of x can be expressed as
x
xk 1 x k
y
Integer operations
• How to compute x intercepts incrementally using
integer operations:
– Initialize a counter to 0
– Increment counter by x each time we move up to a
new scan line.
– If counter becomes greater or equal to y, increment
the current x intersection value by 1 and decrease the
counter by y
• Example: m=7/3
6
0 y0
counter
x0
Sorted Edge Table (SET)
In SET, there is an entry for each scanline.
Traverse edges of the polygon to construct a Sorted Edge Table (SET)
1. Eliminate horizontal edges
2. Add edge to linked-list for the scan line corresponding to the y_min
vertex. Shorten edges if necessary to resolve the vertex-intersection
problem.
3. For each edge entry, store the following:
- y_max: the largest y value on that edge (last scanline to
consider)
- x_min: the x intercept at that scanline (initial x value)
- 1/m: for incrementing x
4. For each scan line the edges are sorted from left to right
(based on x)
B
y x
yB 1/
C
C
mBC
C yA y x 1/ y x 1/ mAB
E A mAE B A
C’ E
A
Active Edge List (AEL)
• Construct Active Edge List during scan conversion. AEL
is a linked list of active edges on the current scanline,
y. The active edges are kept sorted by x
– The active edge list contains all the edges crossed by that scan
line.
– As we move up, update the active edge list using the sorted
edge table if necessary.
Algorithm
1. Set y to the smallest y coordinate that has an entry in the SET; i.e, y for the
first nonempty bucket.
2. Initialize the AEL to be empty.
3. For each scanline y repeat:
1. Copy from SET bucket y to the AEL those edges whose y_min = y
(entering edges).
2. Then sort the AEL on x is easier because SET is presorted.
3. Fill in desired pixel values on scanline y by using pairs of x
coordinates from AEL.
3.1 Remove from the AEL those entries for which y = y_max (edges not
involved in the next scanline.)
Top Clipper
26
Sutherland-Hodgman Polygon Clipping
There are four possible cases when processing
vertices in sequence around the perimeter of a
polygon.
As each pair of adjacent polygon vertices is passed
to a next window boundary clipper, we make the
following tests:
27
Sutherland-Hodgman Polygon Clipping
1. If the first vertex is outside the window
boundary and the second vertex is inside
Then , both the intersection point of the polygon
edge with the window boundary and the second
vertex are added to the output vertex list.
28
Sutherland-Hodgman Polygon Clipping
2. If both input vertices are inside the window
boundary.
Then, only the second vertex is added to the
output vertex list.
29
Sutherland-Hodgman Polygon Clipping
3. If the first vertex is inside the window
boundary and the second vertex is outside.
Then, only the edge intersection with the window
boundary is added to the output vertex list.
30
Sutherland-Hodgman Polygon Clipping
4. If both input vertices are outside the window
boundary.
Then, nothing is added to the output vertex list.
31