AreaFill Algorithm
AreaFill Algorithm
Scanline Algorithms
? Examine horizontal scanlines spanning area
? Find intersection points between current
scanline and borders
? Color pixels along the scanline between
alternate pairs of intersection points
? Especially useful for filling polygons
– polygon intersection point calculations are very
simple and fast
– Use vertical and horizontal coherence to get new
intersection points from old
Boundary/Flood Fill Algorithms
? Determine which points are inside from pixel
color information
– e.g., interior color, boundary color, fill color, current
pixel color
– Color the ones that are inside.
Connected Area Boundary Fill
Algorithm
? For arbitrary closed areas
? Input:
– Boundary Color (BC), Fill Color (FC)
– (x,y) coordinates of seed point known to be
inside
? Definea recursive BndFill(x,y,BC,FC)
function:
If pixel(x,y) not set to BC or FC, then set to FC
Call BndFill() recursively for neighboring points
Preprocessing non-max/min
intersection points
? Move lower endpoint of upper edge up by
one pixel
? i.e., y <-- y + 1
? What about x?
m = ? y/? x, so ? x = (1/m) * ? y
But ? y = 1, so:
x <-- x + 1/m
Preprocessing
Active Edge
?A polygon edge intersected by the current
scanline
? As polygon is scanned, edges will become
active and inactive.
? Criterion for activating an edge:
ysl = ymin of the edge
(Here ysl = y of current scanline)
? Criterionfor deactivating an edge:
? ysl = ymax of the edge
Vertical & Horizontal
Coherence
? Moving from one scanline to next:
?y = y + 1
? If edge remains active, new intersection
point coordinates will be:
ynew = yold + 1
xnew = xold + 1/m
(1/m = inverse slope of edge)
1 2
2
3
0 4
0
Scanline Polygon Fill Algorithm
1. Set up edge table from vertex list; determine range of
scanlines spanning polygon (miny, maxy)
2. Preprocess edges with nonlocal max/min endpoints
3. Set up activation table (bin sort)
4. For each scanline spanned by polygon:
– Add new active edges to AEL using activation table
– Sort active edge list on x
– Fill between alternate pairs of points (x,y) in order of
sorted active edges
– For each edge e in active edge list:
If (y != ymax[e]) Compute & store new x (x+=1/m)
Else Delete edge e from the active edge list
Pattern Filling
Represent fill pattern with a Pattern
Matrix
Replicate it across the area until
covered by non-overlapping copies of
the matrix
– Called Tiling
Pattern Filling--Pattern Matrix
Color Patterns
SetPixel(x, y, pat_mat[x%W][y%H])
Moving the Filled Polygon
As done above, pattern doesn’t move
with polygon
Need to “anchor” pattern to polygon
Fix a polygon vertex as “pattern
reference point”, e.g., (x0,y0)
If (pat_matrix[(x-x0)%W][(y-y0)%H]==1)
SetPixel(x,y)
Now pattern moves with polygon