05.scan Conversion3
05.scan Conversion3
Concave
Interior angles can be greater
than 180 degrees
line that connected two points
in a polygon some part
remain outside the polygon
boundary
Inside-outside Test
To determine the status of a point
(xp,yp)
consider a horizontal line
emanating from (xp,yp) to the right.
If the number of times this ray
intersects the line segments
making up the polygon is even
then the point is outside the
polygon.
Whereas if the number of
intersections is odd then the point
(xp,yp) lies inside the polygon.
for the purposes 0 will be
considered even
this algorithm also works for
polygons with holes
Inside-outside Test
Odd-Even rule:
Let (x,y) be the point we are trying to determine if it is
inside or outside of an object. Draw a line between
this point and a distant point P. If the number of edges
it crosses is odd then it is an interior point.
(Set distant point P to be outside bounding box)
P
Inside-outside Test
Counts the number of times nonzero winding number
the polygon edges wind rule
around a particular point in
the counterclockwise
direction.
This count is called the
winding number,
The interior points of a two-
dimensional object are –1 –1 +1
+1
defined to be those that
have a nonzero value for
the winding number
Inside-outside Test
Initialize the winding number nonzero winding number
to 0 rule
Imagine a line drawn from
any position P to a distant
point beyond the coordinate
extents of the object.
The line must not pass
through any vertices.
–1 –1 +1 +1
Inside-outside Test
As move along the line from nonzero winding number
position P to the distant point, rule
we count the number of
edges that cross the line in
each direction.
Add 1 to the winding
number if the line intersect
a polygon edge that
crosses the line from right +1
to left, and –1 –1 +1
Subtract 1 every time if the
line intersect an edge that
crosses from left to right.
Inside-outside Test
The final value of the winding nonzero winding number
number, after all edge crossings rule
have been counted.
If the winding number is
nonzero, P is defined to be
an interior point. Otherwise,
P is taken to be an exterior
point.
For standard polygons and
other simple shapes, the –1 –1 +1 +1
nonzero winding number rule
and the odd-even rule give the
same results.
But for more complicated
shapes, the two methods may
yield different interior and
exterior regions.
Filled-Area Primitives
There are two basic approaches to area filling on raster
systems.
One way to fill an area is to determine the overlap
intervals for scan lines that cross the area.
The scan-line approach is typically used in general
graphics packages to fill polygons, circles, ellipses,
and other simple curves.
Another method for area filling is to start from a given
interior position and paint outward from this point until we
encounter the specified boundary conditions.
All methods starting from an interior point are useful
with more complex boundaries and in interactive
painting systems.
Boundary-Fill Algorithm
Boundary-fill procedure accepts
an interior point (x, y)
a boundary color
a fill color
useful in interactive painting packages, where interior
points are easily selected
fill color
4-connected area
8-connected area
Boundary-Fill Algorithm
4 connected 8 connected
start point
Flood-Fill Algorithm
Sometimes we want to fill in (or
recolor) an area that is not
defined within a single color
boundary but bordered by
several different color regions
We can paint such areas by
replacing a specified interior
color instead of searching for a
boundary color value
Start from a specified interior
point (x, y) called seed.
Flood-Fill Algorithm
Reassign all pixel values that
are currently set to a given
interior color with the desired fill
color.
If the area we want to paint has
more than one interior color, we start point
can first reassign pixel values so
that all interior points have the
same color.
Using either a 4 connected or 8-
connected approach, we then
step through pixel positions until
all interior points have been
repainted.
Scan-line Polygon Filling Algorithm
Each scan line crossing
a polygon, the area-fill
algorithm locates polygon
1. The intersection
points of the scan
line with the polygon
edges. scan-line
2. These intersection
points are then
sorted from left to 10 14 18 24
right,
3. The corresponding two stretches of interior pixels from x = 10
frame-buffer to x = 14 and from x = 18 to x = 24
positions between
each intersection
pair are set to the
specified fill color
Scan-line Polygon Filling Algorithm
1 2 1
difference between
scan line y and scan scan-line y
1 2 1 1
line y' is identified by
noting the position of
the intersecting edges
relative to the scan
line. • Scan line y generates an odd number (5)
of intersections,
• Scan line y‘ generals an even number of
intersections that can be paired to identify
correctly the interior pixel spans.
Scan-line Polygon Filling Algorithm
For scan line y,
the two intersecting
edges sharing a scan-line y/
vertex are on 1 2 1
opposite sides of
the scan line. scan-line y
1 2 1 1
For scan line y',
the two intersecting
edges are both
above the scan line.
The vertices that have
connecting edges on These vertices are identified by tracing
opposite sides of the around the polygon boundary either in
scan line clockwise or counterclockwise order and
require additional observing the relative changes in vertex
processing y coordinates as we move from one edge
to the next
Scan-line Polygon Filling Algorithm
• These vertices are
identified by
• Tracing around the
scan-line y/
polygon boundary 1 2 1
either in clockwise or
counterclockwise scan-line y
order 1 2 1 1
• Observing the relative
changes in vertex y
coordinates as we
move from one edge
to the next
• If the endpoint y values of • Otherwise, the shared vertex
two consecutive edges represents a local extremum
monotonically increase or (minimum or maximum) on the
decrease,
• the middle vertex
polygon boundary
counts as a single • The two edge intersections with the
intersection point scan line passing through that vertex
can be added to the intersection list
Scan-line Polygon Filling Algorithm
when a scan line intersects an edge endpoint, it intersects two
edges.
Two cases:
Case A: edges are monotonically increasing or decreasing
Case B: edges reverse direction at endpoint
In Case A, we should consider this as only ONE edge intersection
the lower edge can be shortened to ensure that only one intersection
point is generated for the scan line
In Case B, we should consider this as TWO edge intersections
Scan-line
Scan-line
Case B
Case A
Scan-line Polygon Filling Algorithm
(a) (b)
Decrement counter by y
Example:
Suppose m = 7/3 [y = 7; x=3]
Initially, set counter to 0, and increment to x = 3.
When move to next scan line, increment counter by 3
When counter is equal or greater than 7 (y), increment the x-
intercept by 1 and and decrement counter by 7.
Scan-line Polygon Filling Algorithm
Line with slope 7/3
yk
xk
Scan-line Polygon Filling Algorithm
Line with slope 7/3
decrement 0 7
4
decrement 1 8
5
decrement 2 9
6
3
0 yk
xk
Scan-line Polygon Filling Algorithm
Active Edge List
Start with the sorted edge table.
In this table, there is an entry for each scan-line.
Add only the non-horizontal edges into the table.
For each edge, we add it to the scan-line that it begins with
(that is, the scan-line equal to its lowest y-value).
For each edge entry, store (1) the x-intercept with the scan-
line, (2) the largest y-value of the edge, and (3) the inverse of
the slope.
Each scan-line entry thus contains a sorted list of edges. The
edges are sorted left to right. (To maintain sorted order, just use
insertion based on their x value.)
Next, we process the scan lines from bottom to top.
We maintain an active edge list for the current scan-line.
The active edge list contains all the edges crossed by that scan
line. As we move up, update the active edge list by the sorted
edge table if necessary.
Use iterative coherence calculations to obtain edge intersections
quickly.
Antialiasing
Aliasing is the jagged effect seen on lines and polygon
boundaries after rasterization and is caused by under-sampling
Aliasing is caused by finite addressability of the display
Antialiasing is the process of getting rid of the jaggedness of
rasterized geometric primitives.
Antialiasing by super-sampling:
Assign intensities to pixels dependent on the percentage of the
ideal line that crosses the pixel. This can be thought of as area
averaging or linear filtering of sub-sampled pixels.
aliasing anti-aliasing
Aliasing / Antialiasing Examples
Antialiasing
super-sampling
10 6
pixel blue red
16 16
Half-toning and Dithering
Half-toning
technique to simulate gray levels by creating patterns of
black dots of varying size
Dithering (= digital half-toning)
use digital halftone to simulate halftoning with fixed sized
pixels