Vous êtes sur la page 1sur 13

Filled- Area Primitives

A standard output primitive in general graphics packages is a solid-color or patterned polygon area. There are two basic approaches to area filling on raster systems:
1.

The scan-line approach Determine the overlap intervals for scan lines that cross the area. is typically used in general graphics packages to fill polygons, circles, ellipses

2.

Filling approaches 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.

Fill Area Algorithms

Fill-Area algorithms are used to fill the interior of a polygonal shape. Many algorithms perform fill operations by first identifying the interior points, given the polygon boundary.

Basic Filling Algorithm


The basic filling algorithm is commonly used in interactive graphics packages, where the user specifies an interior point of the region to be filled.

4-connected pixels

Basic Filling Algorithm

Requires an interior point.

Involves considerable amount of stack operations. The boundary has to be closed.


Not suitable for self-intersecting polygons
7

Types of Basic Filling Algorithms

Boundary Fill Algorithm

Condition for setting pixels:


Color is not the same as border color Color is not the same as fill color

Starting from (x, y), the algorithm

tests neighboring pixels to determine whether they are of the boundary color. If not, they are painted with the fill color, and their neighbors are tested. This process continues until all pixels up to the boundary have been tested.

1.

There are two methods for proceeding to neighboring pixels from the current test position, The 4-connected method.

2.

The 8-connected method.

TCS2111

Boundary Fill Algorithm (Code)


void boundaryFill(int x, int y, int fillColor, int borderColor) { getPixel(x, y, color); if ((color != borderColor) && (color != fillColor)) { setPixel(x,y); boundaryFill(x+1,y,fillColor,borderColor); boundaryFill(x-1,y,fillColor,borderColor); boundaryFill(x,y+1,fillColor,borderColor); boundaryFill(x,y-1,fillColor,borderColor); } } 10

Flood Fill Algorithm


For filling a region with multiple boundary colors. Condition for setting pixels:

Color is same as the old interior color

We start from a specified interior point (x, y) and reassign all pixel values that are currently set to a given interior color with the desired fill color.

11

If the area we want to paint has more than one interior color, we can first reassign pixel values so that all interior points have the same color. Using either a 4-connected or 8connected approach, we then step through pixel positions until all interior points have been repainted.

12

TCS2111

Flood Fill Algorithm (Code)


void floodFill(int x, int y, int fillColor, int oldColor) { getPixel(x, y, color); if (color != oldColor) { setPixel(x,y); floodFill(x+1, y, fillColor, oldColor); floodFill(x-1, y, fillColor, oldColor); floodFill(x, y+1, fillColor, oldColor); floodFill(x, y-1, fillColor, oldColor); } }

13

Vous aimerez peut-être aussi