0% found this document useful (0 votes)
86 views

Interior Pixels Along A Scan Line Passing Through A Polygon Area

The document describes the scan line polygon fill algorithm. It discusses: 1. Determining the intersection points of polygon edges with scan lines and filling interior regions between intersections. 2. Handling intersections at polygon vertices by shortening edges to count vertex intersections correctly. 3. Using a sorted edge table and active edge list to efficiently calculate intersections and fill interior regions scan line by scan line.

Uploaded by

Nivedita k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

Interior Pixels Along A Scan Line Passing Through A Polygon Area

The document describes the scan line polygon fill algorithm. It discusses: 1. Determining the intersection points of polygon edges with scan lines and filling interior regions between intersections. 2. Handling intersections at polygon vertices by shortening edges to count vertex intersections correctly. 3. Using a sorted edge table and active edge list to efficiently calculate intersections and fill interior regions scan line by scan line.

Uploaded by

Nivedita k
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 32

Scan Line Polygon

• 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

• In the given example, four pixel intersections are at


x=10, x=13, x=16 and x=19

• These intersection points are then sorted from left to


right , and the corresponding frame buffer positions
between each intersection pair are set to specified color
– 10 to 13, and 16 to 19
Scan Line Polygon
Fill
• Some scan line intersections at polygon
vertices require special handling:
– A scan line passing through a vertex
intersects two polygon edges at that position
Scan Line y’
1 2 1

Scan Line y
1 2 1 1

Intersection points along the scan lines that intersect polygon


vertices.
Scan line y’ generates an even number of intersections that
can be paired to identify correctly the interior pixel spans.
To identify the interior pixels for scan line y, we must count
the vertex intersection as only one point.
Scan Line Polygon

Fill
The topological difference between scan Line y and scan
Line y’
• For scan line y, the two edges sharing an intersection
vertex are on opposite sides of the scan line.
– Count this vertex as one intersection point

For scan line y’, the two intersecting edges are both
above the scan line
Scan Line Polygon
• We canFill
distinguish these cases by tracing around the
polygon boundary either in clockwise or
counterclockwise order and observing the relative
changes in vertex y coordinates as we move from one
edge to the next.

• 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

– When the endpoint y values are monotonically


decreasing, we decrease the y coordinate of the
upper endpoint of the edge following the
current edge
Scan Line Polygon Fill Algorithm

(a) (b)

Adjusting endpoint values for a polygon, as we process edges in order


around the polygon perimeter. The edge currently being processed is
indicated as a solid like. In (a), the y coordinate of the upper endpoint of
the current edge id decreased by 1. In (b), the y coordinate of the upper
end point of the next edge is decreased by 1
The scan conversion algorithm works as follows
i.Intersect each scanline with all edges
ii.Sort intersections in x
iii.Calculate parity of intersections to determine in/out
iv.Fill the “in” pixels
Special cases to be handled:
v. Horizontal edges
should be
excluded
vi.
- Vertices
Edges thatlying on scanline y are likely to intersect y + 1
intersect
- scanlines
X changes handled
predictably from scanline y to y + 1 (Incremental
by shortening
Calculation of
Possible)
edges,
• Coherence between (X , Y ) Scan Line yk + 1
k+1 k+ 1

scanlines tells us that


(Xk , Yk )
Scan Line yk
• The slope of the edge is constant from one scan line to the next:
– let m denote the slope of the edge.


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

• Initial scanline counter = 0


• Next scanlines
– Counter =3
– Counter =6
– Counter =9
• increment x intercept by 1
• Reset counter to 9-7 = 2
decrement 0
4
decrement 1
5
decrement2
6
3
0 y0
counter
x0
• Above scheme truncates integers.
• How do we round to nearest integer?
– We need to compare the counter to y/2.
– Can be done by integer arithmetic by incrementing counter by
2x at each step and comparing with y
– When the counter is greater than or equal to y, increase x
value by 1 and decrement the counter by 2y
• Example: m=7/3

• Initial scanline counter = 0


• Next scanlines
– Counter =6
– Counter =12
• increment x intercept by 1
• Reset counter to 12-(2*7) = -2
0
decrement -6
2
decrement -4
4
decrement -2

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.)

4. Increment y by 1 (to the coordinate of the next scanline).


5. For each nonvertical edge remaining in the AEL, update x for the
new
y.
Polygon Clipping
To clip a polygon, we cannot directly apply a line-
clipping method to the individual polygon edges
because this approach would produce a series of
unconnected line segments as shown in figure
The clipped polygons must be a bounded area after
clipping as shown in figure.

• For polygon clipping, we require an algorithm that will


generate one or more closed areas that are then scan
converted for the area fill.
• The output of a polygon clipper should be a sequence
of vertices that defines the clipped polygon
boundaries.
Sutherland-Hodgman
Polygon Clipping
•Clip a polygon by processing the polygon boundary as
a whole against each window edge.
• Processing all polygon vertices against each clip
rectangle boundary in turn.
• Beginning with the initial set of polygon vertices, we
could first clip the polygon against the left rectangle
boundary to produce a new sequence of vertices.
• The new set of vertices could be successively passed
to a right boundary clipper, a bottom boundary clipper,
and a top boundary clipper.
Sutherland-Hodgman Polygon Clipping

Lift Clipper Right


Clipper

At each step, a new sequence of output Bottom


vertices is generated and passed to the next Clipper
window boundary clipper.

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

You might also like