Part VII Polygon Filling - PowerPoint PPT Presentation

1 / 11
About This Presentation
Title:

Part VII Polygon Filling

Description:

For each scan-line, we can compute two x-intersections and fill pixels between them. ... The scan-line algorithm we've discussed follows OpenGL's convention ... – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 12
Provided by: nichol62
Category:
Tags: vii | filling | part | polygon | scan

less

Transcript and Presenter's Notes

Title: Part VII Polygon Filling


1
Part VII Polygon Filling
2
Scan-line Algorithm for Polygon Filling
  • Two tasks in polygon filling
  • Which pixels to fill? Only interior pixels! ?
    now!
  • What colors for the pixels? ? later!
  • Well-known for polygon filling is the scan-line
    algorithm, which computes the x-intersections
    between each scan line and polygons edges, and
    then fill all pixels between the intersections.

inside
outside
scan line
right intersection
left intersection
fill all pixels between them
3
Convex vs. Concave
  • A polygon is convex if, given any 2 points in its
    interior, the line segment joining them is also
    in the interior.
  • Lets restrict polygon filling to convex
    polygons!!
  • In most cases, there are then 2 intersections
    between a scan-line and a convex polygon to be
    filled.
  • Why most? Why not all?
  • This will be cleared soon.

scan line
concave polygons
convex polygons
4
Scan-line Algorithm Overview
  • Suppose that we are given the following polygon.
  • Checking the y-coordinates of the vertices, we
    can easily see that the scan-lines 2 through 7
    should be processed.
  • For each scan-line, we can compute two
    x-intersections and fill pixels between them.
  • For fractional intersections, round up xleft and
    and round down xright.
  • For example, scan-line 3 lt2.4,6.5gt ? 3,6.

8 7 6 5 4 3 2 1
y
y7.3
xleft2.4
xright6.5
y1.6
x 1 2 3 4 5 6 7
5
Integer Intersections
  • How about integer intersections?
  • Problems (on the boundary)
  • inconsistency edge ownership may depend on
    drawing order.
  • Inefficiency the edges may be overwritten.
  • weird rendering possible especially for
    animation.
  • For integer intersections, take xleft,
    xright-1.
  • In summary, for both fractional and integer
    intersections, ?? xleft ? at the left end, and ?
    ?? xright ? -1 ? at the right end.

?
?
Whose edges?
X16
4 5 6 7 8 9 10 11 12 13 14 15
lt12,16gt is computed as intersections, and pixels
are filled in 12,15.
X3
6
Which Scan-lines to Process?
  • So far, x-intersections.
  • How about y-intersections? i.e. Which scan-lines
    to process?
  • If both ylow and yhigh of the polygon are
    fractional numbers, simply round up ylow and
    round down yhigh.
  • What if integer intersections? Take ylow,
    yhigh-1.
  • In summary, for both fractional and integer
    intersections, ? ylow ?? at the bottom, and ?
    yhigh ?-1 ? at the top.

yhigh
ylow
7
Computation of X-intersections
  • Suppose that we have computed x-intersection for
    scan-line i.
  • Then, for scan-line i1, the x-intersection can
    be incrementally computed using the inverse of
    the slope.
  • Once we get x-intersection at scan-line 2, we can
    compute that for scan-line 3, and then scan-line
    4, etc. Then, how about scan-line 2?

i1
1
m
i
ymxB
1
1/m
new-x old-x 1/m
old-x
8 7 6 5 4 3 2 1
y
(5.4,7.3)
(1.5?,2)
2 1
0.4
(1.5,1.6)
1
?
(1.5,1.6)
1/m
x 1 2 3 4 5 6 7
8
Edge Orientations
  • Assume that, for every polygon, vertices are
    given in CCW order.
  • An edge is at left side if it is downward. If
    upward, right side.
  • Horizontal edges (whose end points y-coordinates
    are identical) are simply ignored.

3
1
4
2
3
2
5
1
v1
v1
v1
y1
y1
c
a
y3
y3
v3
v3
v3
b
y2
y2
v2
v2
v2
y1 gt y2 left-side edge
y2 lt y3 right-side edge
y3 lt y1 right-side edge
9
Interpolation along Y
  • Reserve two arrays for the whole scene left- and
    right-bounds.
  • For left-side edges, process the left-side bound.
    For right-side edges, process the right-side
    bound.
  • For each edge E, determine the y-range ymin,
    ymax to be processed ymin ?? ylow? ? and ymax
    ?? yhigh? -1 ?.
  • Compute the x-intersection either at ymin or at
    ymax.
  • Incrementally compute the x-intersections of all
    other scan-lines in E.



x4
x3
amax cmax


c
a
cmin
x6
b
x5
bmax
x1
x2


amin bmin
x1
x2 x3 x4 x5
x6
left-side bound
right-side bound
10
Pixel Filling along X
  • Process the set S of scan-lines ymin, ymax of
    the triangle one by one.
  • For each scan-line, retrieve xleft from the
    left-side bound and xright from the right-side
    bound.
  • Then, fill pixels xmin, xmax ? ?? xleft? ? ,
    ??? xright? -1? .

ymax


xright
xleft


ymin
right-side bound
left-side bound
11
Convex vs. Concave (revisited)
  • The scan-line algorithm weve discussed follows
    OpenGLs convention and assumes convex polygons.
  • OpenGL does not restrict the number of edges of a
    polygon, but the polygon must be convex. Concave
    polygons are often be drawn awkwardly.
  • How to draw/fill concave polygons?
  • The simple solution is to subdivide it into a set
    of convex polygons and to draw each convex
    polygon.

scan line
concave polygons
Write a Comment
User Comments (0)
About PowerShow.com