Page 104 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 104
Lab on Computer Graphics
Notes • Fill in the requisite pixels between the even and odd adjacent pairs of intersections in
the AET: round up, x the x-coordinate of “left” intersections, round down, x – 1
that of the “right” intersections.
• Increment y by one.
6. Update x ← x = w for every non vertical edge in the AET.
6.2 Boundary-fill Algorithm
This creates apply of coherence properties of the boundary of a primitive/figure: given a point
inside the region the algorithm recursively plots the adjacent pixels until the primitive boundary
is reached.
Given the FillColour, the BoundaryColour and a point inside the boundary, the following
algorithm recursively sets the four adjacent pixels (2 horizontal and 2 vertical) to the FillColour.
Procedure BoundaryFill (x, y: Integer, FillColour, BoundaryColour:
ColourType);
Procedure BFill (x, y: Integer);
Var
CurrentColour: ColourType;
Begin
CurrentColour: = GetPixel (x, y);
If (CurrentColour < > FillColour) and
(CurrentColour < > BoundaryColour)
then
SetPixel (x, y, FillColour);
BFill (x + 1, y);
BFill (x – 1, y);
BFill (x, y + 1);
BFill (x, y – 1)
End;
Begin
BFill (x, y)
End;
Regions which can be totally filled with this algorithm are called 4-connected regions. Some
regions cannot be filled by this algorithm. Such regions are called 8-connected and algorithms
filling such areas consider the four diagonally adjacent pixels as well as the horizontal and
vertical ones. The 8-connected algorithm is particularly susceptible.
Procedure BFill8 (x, y: Integer);
Var
CurrentColour: ColourType;
Begin
CurrentColour: = GetPixel (x, y);
If (CurrentColour < > FillColour) and
(CurrentColour < > BoundaryColour)
then
SetPixel (x, y, FillColour);
98 LOVELY PROFESSIONAL UNIVERSITY