Page 1 of 21 Filling Algorithms • decide what pixels to fill • decide what value to fill them (solid/pattern) 1. Primitives: rectangles/polygons • scan line algorithms (text sections 3.5-3.8) 2. Regions of pixels • fill algorithms (text section 19.5) Filling Rectangles • fill each span (segment of scan-line containing the rectangle) from x min to x max while traveling from y min to y max (reversing the order is trivial of course). Span: a contiguous sequence of pixels on a scan line Scan Line span rectangle y/xmin xmax ymax
21
Embed
Primitives: rectangles/polygons€¦ · Filling Algorithms • decide what pixels to fill • decide what value to fill them (solid/pattern) 1. Primitives: rectangles/polygons •
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1 of 21
Filling Algorithms
• decide what pixels to fill• decide what value to fill them (solid/pattern)
1. Primitives: rectangles/polygons• scan line algorithms (text sections 3.5-3.8)
2. Regions of pixels• fill algorithms (text section 19.5)
Filling Rectangles
• fill each span (segment of scan-line containing therectangle) from xmin to xmax while traveling from ymin
to ymax (reversing the order is trivial of course).
Span: a contiguous sequence of pixels on a scan line
Scan Linespan
rectangle
y/xmin xmax
ymax
Page 2 of 21
Spans exhibit a primitive’s COHERENCE, the degree towhich parts of an environment or its projection exhibitlocal similarities.
• Spatial coherence:primitives do not often change from pixel to pixelwithin a span or consecutive span lines (look only forpixels where change occurs, such as boundaries)
• Span coherence:primitives do not often change from span to span (ex,all pixels set to same value for solidly shadedpolygon).
• Scan-line coherence:not much change between successive scan-lines (ex,consecutive scan-lines that intersect rectangle areidentical).
• Edge coherence:edges of polygon intersect successive scan-lines(continuity of edges, will be useful later).
• Coherence greatly increases efficiency of scan-linealgorithms (can output an entire span or scan-linerather than pixel by pixel).
Page 3 of 21
• Problem: boundary pixels may be drawn several timesfor shared edges. (what colour should a shared edgebe?)
• Partial solution, only draw “left” & “bottom” edges(skip right & top)
• Problem with this is that the left/bottom vertex stilldrawn twice, not so good for unfilled polygons (thereis no perfect solution)
Page 4 of 21
Filling Polygons
• Basic Idea: intersect the polygon with consecutivescan-lines and check for points of intersection (ie.Compute and fill the spans)
Page 5 of 21
• Could determine span extrema (outermost pixels of aspan), using midpoint algorithm, but watch out forextrema outside of polygon (want to fill the interior)
Page 6 of 21
Incremental Algorithm
1. Find the intersection of the scan-line with all edgesof the polygon.
2. Sort the intersections by increasing x.3. Fill in all pixels between pairs of intersections that
lie interior to the polygon. (Odd-parity rule: parityinitially even, each intersection inverts the parity -draw when odd only).
3.1 What is the interior pixel for a fractional xintersection?