Unit 1 Filled Area Primitives
Unit 1 Filled Area Primitives
Unit 1
10 14 16 18 24
y' L1
This figure shows two scan
y L2 lines at position y and y' that
intersect the edge points.
Scan line at y intersects five
polygon edges. Scan line at y'
intersects 4 (even numbers)
of edges though it passes
1
Computer Graphics and Animation BCA 5th Sem
Unit 1
Intersection points along scan line y' correctly identify the interior pixel
spans. But with scan line y, we need to do some additional processing
to determine the correct interior points.
For scan line y, the two edges sharing the intersecting vertex are on
opposite side of the scan-line. But for scan-line y' the two edges
sharing intersecting vertex are on the same side (above) the scan line
position. So the vertices those are on opposite side of scan line require
extra processing.
y line
Line y'
(a) (b)
2
Computer Graphics and Animation BCA 5th Sem
Unit 1
In successive scan lines crossing a left edge
( x k + 1, y k + 1) Scan yk + 1
of a polygon, The slope of this polygon line
boundary line can be expressed in terms of
scan-line intersection co-ordinates: ( xk , y k Scan yk .
y + 1 - yk line
m= k
xk + 1 - xk
Inside-Outside Test:
Area filling algorithms and other graphics package often need to
identify interior and exterior region for a complex polygon in a plane.
For ex. in figure below, it needs to identify interior and exterior region.
A D
We apply add-even rule, also
called C
odd-parity rule. To identify the
interior or exterior point, we can ●
G
draw a line from a point p to a Interior
distant point outside the co- E
ordinate extents of the object
and count the number of F
B Exterio
intersecting edge crossed by this
r
line. If the intersecting edge
crossed by this line is odd, P is
3
Computer Graphics and Animation BCA 5th Sem
Unit 1
Scan-Line Fill of Curved Boundary area
It requires more work then polygon filling, since intersection
calculation involves nonlinear boundary for simple curves as circle,
eclipses, performing a scan line fill is straight forward process. We only
need to calculate the two scan-line intersection on opposite sides of
the curve. then simply fill the horizontal spans of pixel between the
boundary points on opposite side of curve. Symmetries between
quadrants are used to reduce the boundary calculation we can fill
generating pixel position along curve boundary using mid point
method
Boundary-fill Algorithm:
In Boundary filling algorithm starts at a point inside a region and
paint the interior outward the boundary. If the boundary is specified in
a single color, the fill algorithm proceeds outward pixel by until the
boundary color is reached.
A boundary-fill procedure accepts as input the co-ordinates of an
interior point (x,y), a fill color, and a boundary color. Starting from (x,y),
the procedure tests neighbouring positions to determine whether they
are of boundary color. If not, they are painted with the fill color, and
their neighbours are tested. This process continue until all pixel up to
the boundary color area have tested.
The neighbouring pixels from current pixel are proceeded by two
method: 4- connected if they are adjacent horizontally and vertically.
8- connected if they adjacent horizontally, vertically and
diagonally.
4- Connected 8- Connected
4
Computer Graphics and Animation BCA 5th Sem
Unit 1
Fill method that applies and tests its 4 neighbouring pixel is called
4- connected.
Fill method that applies and tests its 8 neighbouring pixel is called
8- connected.
The out line of this algorithm is:
void Boundary_fill4(int x,int y,int b_color, int fill_color)
{
int value=get pixel (x,y);
if (value! =b_color&&value!=fill_color)
{
putpixel (x,y,fill_color);
Boundary_fill 4 (x-1,y, b_color, fill_color);
Boundary_fill 4 (x+1,y, b_color, fill_color);
Boundary_fill 4 (x,y-1, b_color, fill_color);
Boundary_fill 4 (x,y+1, b_color, fill_color);
}
}
5
Computer Graphics and Animation BCA 5th Sem
Unit 1
Flood-fill Algorithm:
Flood_fill Algorithm is applicable when we want to fill an area
that is not defined within a single color boundary. If fill area is bounded
with different color, we can paint that area by replacing a specified
interior color instead of searching of boundary color value. This
approach is called flood fill algorithm.
We start from a specified interior pixel (x,y) and reassign all pixel
values that are currently set to a given interior color with desired
fill_color.
Using either 4-connected or 8-connected region recursively
starting from input position, The algorithm fills the area by desired
color.
Algorithm:
void flood_fill4(int x,int y,int fill_color,int old_color)
{
int current;
current=getpixel (x,y);
if (current==old_color_
{
putpixel (x,y,fill_color);
flood_fill4(x-1,y, fill_color, old_color);
flood_fill4(x,y-1, fill_color, old_color);
flood_fill4(x,y+1, fill_color, old_color);
flood_fill4(x+1,y, fill_color, old_color);
}
}