Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
84 views

05.scan Conversion3

The document describes various methods for scan conversion and area filling of graphical objects. It discusses generating rectangles, arcs, and polygons through different approaches. It also covers algorithms for determining if a point lies inside or outside a polygon, such as the odd-even rule and winding number rule. Finally, it explains techniques for filling areas like the boundary fill, flood fill, and scan-line polygon filling algorithms.

Uploaded by

Muntasir Fahim
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views

05.scan Conversion3

The document describes various methods for scan conversion and area filling of graphical objects. It discusses generating rectangles, arcs, and polygons through different approaches. It also covers algorithms for determining if a point lies inside or outside a polygon, such as the odd-even rule and winding number rule. Finally, it explains techniques for filling areas like the boundary fill, flood fill, and scan-line polygon filling algorithms.

Uploaded by

Muntasir Fahim
Copyright
© © All Rights Reserved
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 34

Scan Conversion

Rectangles, Arcs, Polygons


Rectangle
 If two vertices P1(x1, y1) and
P1(x1, y1) P4(x2, y1)
P2(x2, y2) are given
 Then four vertices are
P1(x1, y1) P2(x2,
y2)
P3(x1, y2) P4(x2,
y1)
 Draw line from P3(x1, y2) P2(x2, y2)
P1 to P4, P1 to P3,
P3 to P4 P4 to P3
Arcs and Sectors
 An arc may be generated either polynomial
and trigonometric method
 For trigonometric method
 Starting value is set to ø1

 Ending value is set to ø2


 Use this polar equations
x = xc + r cos
y = yc + r sin
 Symmetry is not used
 For Polynomial method
 The value of x is varied from x1 to x2
 y is calculated from the relation
y  r 2  x2
Polygon

 Polygon is a closed polyline in


which the initial and terminal
points are coincide
 A surface defined by three or
more non-collinear vertices
 Represented as a number of line
segments connected end to end
to end to form a closed figure.
 Divided into two class
Convex and Concave
Polygon
 Convex
 All interior angles are less
than 180 degrees
 Or line that connected two
points in a polygon remain
inside the polygon boundary

 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

interior point (x, y)


Boundary-Fill Algorithm
boundary color
 Starting from (x, y), the
procedure tests neighboring
positions to determine whether
they are of the boundary color.
 If not, they are painted with the interior point (x, y)
fill color, and their neighbors are
tested.
 This process continues until all fill color
pixels up to the boundary color
for the area have been tested.
 Both inner and outer boundaries
can be set up to specify an area
Boundary-Fill Algorithm

 Fill methods applied to a

 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

 The basic scan-line


algorithm is as follows:
 Find the intersections of
the scan line with all
edges of the polygon
 Sort the intersections
by increasing x
For y = ymin to ymax
coordinate 1. intersect scanline y with each
 Fill in all pixels between edge
pairs of intersections 2. sort interesections by
increasing x [p0,p1,p2,p3]
that lie interior to the
3. fill pairwise (p0 - p1, p2 - p3)
polygon
Scan-line Polygon Filling Algorithm
Scan-line intersections at polygon vertices require special
handling

 The topological scan-line y /

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)

 The edge currently being processed is indicated by solid line


 When the endpoint y coordinates of the two edges are increasing, the y
value of the upper endpoint for the current edge is decreased by 1 [In
(a)]
 When the endpoint y values are monotonically decreasing, decrease
they coordinate of the upper endpoint of the edge following the current
edge [In (b)]
Scan-line Polygon Filling Algorithm
Derive next intersection
 Calculations performed in scan line conversion typically
take the advantage of various coherence properties of a
scan scene.
 Coherence: the properties of a scene are related in some way
to other parts of the scene so that the relationship can be used
to reducing processing
y k 1  y k (1)
 Slope m
xk 1  xk

 For two successive scan lines y k 1  y k  1


x k 1  x k  1 (2)
m
m  y  xk 1  x k  x (3)
x y
Scan-line Polygon Filling Algorithm
Derive next intersection
 Consider that scan line starts from ymin though practically starts it
from ymax
 Using eq-(3) x-intercepts can be found as follows
 Initialize a counter to 0
 Increment the counter by x for each scan line (move up)
 When counter value equal or greater than y
 Increment x by 1

 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

You might also like