Sei sulla pagina 1di 29

Fill Area Algorithms

Polygon Fill Algorithm


Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting

Convex

Concave

Self-intersecting

Polygon Fill Algorithm


A scan-line fill algorithm of a region is performed as follows:
1. Determining the intersection positions of the boundaries of the fill region with the screen scan lines. . !hen the fill colors are applied to each section of a scan line that lies within the interior of the fill region.

Interior Pixel Convention


Pixels that lie in the interior of a polygon belong to that polygon, and can be filled. Pixels that lie on a left boundary or a lower boundary of a polygon belong to that polygon, and can be filled. Pixels that have centers that fall outside the polygon, are said to be exterior and should not be drawn. Pixels that lie on a right or an upper boundary do not belong to that polygon, and should not drawn.

Example
Consider the following pol"gon:

Example
#or each scan line that crosses the pol"gon$ the edge intersections are sorted from left to right$ and then the pixel positions between$ and including$ each intersection pair are set to the specified fill color. %n the previous #igure$ the four pixel intersection positions with the pol"gon boundaries define two stretches of interior pixels.

Area Fill Algorithm


%f the boundar" of some region is specified in a single color$ we can fill the interior of this region$ pixel b" pixel$ until the boundar" color is encountered. !his method$ called the boundary-fill algorithm, is emplo"ed in interactive painting pac&ages$ where interior points are easil" selected.

Example
'ne can s&etch a figure outline$ and pic& an interior point. !he figure interior is then painted in the fill color as shown in these #igures

Area Fill Algorithm


(asicall"$ a boundar"-fill algorithm starts from an interior point )x$ y* and sets the neighbouring points to the desired color. !his procedure continues until all pixels are processed up to the designated boundar" for the area.

Area Fill Algorithm


!here are two methods for processing neighbouring pixels from a current point. 1. #our neighbouring points. !hese are the pixel positions that are right$ left$ above$ and below the current pixel. Areas filled b" this method are called 4-connected.

Area Fill Algorithm


2. +ight neighbouring points.

!his method is used to fill more complex figures. ,ere the set of neighbouring points to be set includes the four diagonal pixels$ in addition to the four points in the first method. #ill methods using this approach are called 8-connected.

Area Fill Algorithm

Area Fill Algorithm


Consider the #igure in the next slide. An --connected boundar"-fill algorithm would correctl" fill the interior of the area defined in the #igure. (ut a .-connected boundar"-fill algorithm would onl" fill part of that region.

Area Fill Algorithm

Problems ith Fill Algorithm


/ecursive boundar"-fill algorithms ma" not fill regions correctl" if some interior pixels are alread" displa"ed in the fill color. !his occurs because the algorithm chec&s next pixels both for boundar" color and for fill color.

Problems ith Fill Algorithm


!o avoid this$ we can first change the color of an" interior pixels that are initiall" set to the fill color before appl"ing the boundar"-fill procedure. +ncountering a pixel with the fill color can cause a recursive branch to terminate$ leaving other interior pixels unfilled.

Problems ith Fill Algorithm


!his procedure re0uires considerable stac&ing of neighboring points$ more efficient methods are generall" emplo"ed. !hese methods fill hori1ontal pixel spans across scan lines$ instead of proceeding to .-connected or --connected neighboring points.

Problems ith Fill Algorithm


!hen we need onl" stac& a beginning position for each hori1ontal pixel span$ instead of stac&ing all unprocessed neighboring positions around the current position. Starting from the initial interior point with this method$ we first fill in the contiguous span of pixels on this starting scan line.

Problems ith Fill Algorithm


!hen we locate and stac& starting positions for spans on the ad2acent scan lines$ where spans are defined as the contiguous hori1ontal string of positions bounded b" pixels displa"ed in the border color. At each subse0uent step$ we retrieve the next start position from the top of the stac& and repeat the process.

Example
%n this figure$ the initial span has been filled$ and starting positions 1 and for spans on the next scan lines )below and above* are stac&ed.

Example
%n following #ig.$ position has been unstac&ed and processed to produce the filled span shown$ and the starting pixel )position 3* for the single span on the next scan line has been stac&ed.

Example
After position 3 is processed$ the filled spans and stac&ed positions are as shown in following #ig.

Example
And following #ig. shows the filled pixels after processing all spans in the upper right of the specified area.

Example
4osition 5 is next processed$ and spans are filled in the upper left of the region6 then position . is pic&ed up to continue the processing for the lower scan lines.

Example
#inish up the upper scan lines.

Example
Start the bottom scan lines.

Example
#inish up the bottom scan lines.

Example
#inish up the bottom scan lines.

Potrebbero piacerti anche