There are two basic approaches to filling areas in raster graphics - the scan line method and the boundary fill method. The scan line method works by determining the intersections of scan lines with the shape boundary and filling the pixels between intersections. The boundary fill method starts from an interior point and floods the fill color outward until it reaches the boundary color. Both use recursion to process neighboring pixels in 4 or 8 connected patterns.
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 ratings0% found this document useful (0 votes)
209 views13 pages
Week 4 Filled Area Primitives
There are two basic approaches to filling areas in raster graphics - the scan line method and the boundary fill method. The scan line method works by determining the intersections of scan lines with the shape boundary and filling the pixels between intersections. The boundary fill method starts from an interior point and floods the fill color outward until it reaches the boundary color. Both use recursion to process neighboring pixels in 4 or 8 connected patterns.
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/ 13
Filled Area Primitives
Filled Area Primitives
● 2 basic approaches to area filling on raster systems ● Determine overlap intervals for scan lines that cross the area ● Typically used in general graphics packages to fill polygons, circles, ellipses, and other simple curves. ● Start from a given interior position and paint outward from this point until we encounter the specified boundary conditions ● Useful with more complex boundaries and in interactive painting systems Scan Line Polygon Fill ● Scan line is one line, or row, in a raster scanning pattern ● Such as a line of video on a cathode ray tube (CRT) display of a television set or computer monitor ● For each scan line crossing a polygon, the area-fill algorithm locates the intersection points of the scan line with the polygon edges ● sorted from left to right, and corresponding frame-buffer positions between each intersection pair are set to fill colour Scan Line Polygon Fill
In case of odd number of intersections
count the point
which is a vertex as two points Scan Line Polygon Fill ● To resolve, shorten some polygon edges to split those vertices that should be counted as one intersection ● Process non-horizontal edges around the polygon boundary in the order specified, clockwise or counter-clockwise ● As we process each edge, check to determine whether that edge and the next non-horizontal edge have either monotonically increasing or decreasing endpoint y values ● If so, the lower edge can be shortened to ensure that Boundary Fill Algorithm ● Scan line algorithm for regions with curved boundaries require more work because intersection calculations involve non-linear boundaries ● Another approach to area filling is to start at a point inside a region and paint the interior outward toward the boundary ● If the boundary is specified in a single colour, the fill algorithm proceeds outward pixel by pixel until the boundary colour is encountered Boundary Fill Algorithm ● It accepts as input the coordinates of an interior point (x, y), a fill colour, and a boundary colour ● Starting from (x, y), the procedure tests neighbouring positions to determine whether they are of the boundary colour. ● If not, they are painted with the fill colour, and their neighbours are tested. ● This process continues until all pixels up to the boundary colour for the area have been tested Boundary Fill Algorithm ●2 methods for processing neighbouring pixels from a current test position ● four neighbouring points - are right, left, above, and below – 4 connected ●eight neighbouring points – right, left, above, below and four diagonal positions – 8 connected Boundary Fill Algorithm Void boundaryfill(x, y, fillcolor, boundary) { Int current; current=getpixel(x,y); if((current! = boundary) && (current ! = fillcolor)) { putpixel (x, y, fillcolor) boundaryfill(x + 1, y, fillcolor, boundary); boundaryfill(x , y+1, fillcolor, boundary); boundaryfill(x -1, y, fillcolor, boundary); boundaryfill(x , y-1, fillcolor, boundary); } } Flood Fill Algorithm ● To fill in an area that is not defined within a single colour boundary ● Paint areas by replacing a specified interior colour instead of searching for a particular boundary colour – flood-fill algorithm ● Start from a specified interior point (x, y) and reassign all pixel values that are currently set to a given interior colour with the desired fill colour. ● If the area that we want to paint has more than one interior colour, we can first reassign pixel values so that all interior points have the same colour. ● Using either a 4-connected or 8-connected approach, we then step through pixel positions until all interior points have been repainted Flood Fill Algorithm Void floodfill(x, y, fillcolor, oldcolor) { Int current; current=getpixel(x,y); if(current==oldcolor) { putpixel (x, y, fillcolor) floodfill (x + 1, y, fillcolor, oldcolor); floodfill (x , y+1, fillcolor, oldcolor); floodfill (x -1, y, fillcolor, oldcolor); floodfill (x , y-1, fillcolor, oldcolor); } }