0% found this document useful (0 votes)
9 views20 pages

Week 4 Filled Area Primitives

The document discusses filled area primitives in raster graphics, focusing on two main algorithms: the Scan Line fill algorithm and the Seed fill algorithm. It explains how the Scan Line algorithm determines intersection points to fill polygons and outlines the Boundary fill and Flood fill algorithms for filling areas defined by colors. Additionally, it highlights the differences between these algorithms, including their efficiency and memory consumption.

Uploaded by

pawanjoshi9810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views20 pages

Week 4 Filled Area Primitives

The document discusses filled area primitives in raster graphics, focusing on two main algorithms: the Scan Line fill algorithm and the Seed fill algorithm. It explains how the Scan Line algorithm determines intersection points to fill polygons and outlines the Boundary fill and Flood fill algorithms for filling areas defined by colors. Additionally, it highlights the differences between these algorithms, including their efficiency and memory consumption.

Uploaded by

pawanjoshi9810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 20

Filled Area Primitives

Filled Area Primitives


● 2 basic approaches to area filling on raster
systems
● Scan Line fill algorithm:
● Determine overlap intervals for scan lines that
cross the area
● Typically used in general graphics packages
to fill polygons, circles, ellipses, and other
simple curves.
● Seed fill Algorithms:
● Start from a given interior position and paint
outward from this point until we encounter
Scan Line Polygon Fill
● Scan line is one line, or row, in a raster
scanning pattern
● Such as a line of video on a cathode ray
tube (CRT) display of a television set or
computer monitor
● For each scan line crossing a polygon,
the area-fill algorithm locates the
intersection points of the scan line with
the polygon edges
● sorted from left to right, and
corresponding frame-buffer positions
between each intersection pair are set
Scan Line Polygon Fill

In case of
odd
number of
intersections

count the
point which
is a vertex
Scan Line Polygon Fill
● To resolve, shorten some polygon
edges to split those vertices that
should be counted as one intersection
● Process non-horizontal edges around the
polygon boundary in the order specified,
clockwise or counter-clockwise
● As we process each edge, check to
determine whether that edge and the
next non-horizontal edge have either
monotonically increasing or decreasing
endpoint y values

Scan Line Polygon Fill

Scan-conversion take advantage of various


coherence properties of a scene that is to be
displayed
Coherence is simply that the properties of one
part of a scene are related in some way to other
parts of the scene so that the relationship can be
Inside Outside Tests
● Area-filling algorithms and other
graphics processes often need to
identify interior regions of objects

● Odd Even rule:


●By conceptually drawing a line from
any position P to a distant point
outside the coordinate extents of
the object and counting the number
of edge crossings along the line.
●Ifthe number of polygon edges
crossed by this line is odd, then P is
an interior point. Otherwise, P is an
exterior point
Scan Line Fill Algorithm
• Basic algorithm:
– Assume a scan line starts from the left and is outside the
polygon.
– When an intersection with an edge of a polygon occurs, start
to color each pixel (because now we’re inside the polygon),
when an intersection with another edge occurs, stop coloring

– Odd number of edges: inside
– Even number of edges: outside

out
in
out
in
The scan fill algorithm works as follows
i. Intersect each scanline with all edges
ii. Sort intersections in x
iii. Calculate parity of intersections to determine in/out
iv. Fill the “in” pixels
Special cases to be handled:
v. Horizontal edges should be excluded
vi. For vertices lying on scanlines,
i. count twice for a change in slope.
ii. Shorten edge by one scanline for no change in slope
• Coherence between scanlines tells us that
- Edges that intersect scanline y are likely to intersect y + 1
- x changes predictably from scanline y to y + 1

(Xk + 1, Yk + 1) Scan Line yk + 1

(Xk , Yk )
Scan Line yk
Non Zero Winding Rule
• The method of the non-zero winding number rule is to
count the number of times edges wind around a point P in
a counter-clockwise direction.
– Initialize the winding number to zero.
– Draw a line from P to the exterior of the polygon without
passing through a vertex.
– Add 1 to the winding number for every edge that crosses the
line from P in one direction (clockwise or counter-clockwise)
and subtract 1 from the winding number for every crossing
edge in the opposite direction.
– If the winding number is not equal to zero, the point P is
within the polygon.
Non Zero Winding Rule
Inside Outside Tests
Boundary Fill Algorithm
● Scan line algorithm for regions with
curved boundaries require more work
because intersection calculations
involve non-linear boundaries
● Another approach to area filling is to
start at a point inside a region and
paint the interior outward toward the
boundary
● If the boundary is specified in a
single colour, the fill algorithm
proceeds outward pixel by pixel
until the boundary colour is
Boundary Fill Algorithm
● It accepts as input the coordinates of
an interior point (x, y), a fill colour,
and a boundary colour
● Starting from (x, y), the procedure
tests neighbouring positions to
determine whether they are of the
boundary colour.
● If not, they are painted with the
fill colour, and their neighbours
are tested.
● This process continues until all pixels
Boundary Fill Algorithm
●2 methods for processing
neighbouring pixels from a
current test position
● four neighbouring points - are
right, left, above, and below –
4 connected
●eight neighbouring points – right,
left, above, below and four diagonal
positions – 8 connected
Algorithm of Boundary-fill
Procedure boundary fill (p, q, fill color, boundary)
Step 1: Initialize the boundary of the region.
Step 2: Get the interior pixel (p, q). Now, define an Integer called current pixel and
assign it to (p, q).
Current_pixel= getpixel (p, q)
Step 3: If
(current_pixel != boundary) and (current_pixel != fill)
Then
Setpixel(p, q, fill);
Boundary fill (p+1, q, fill, boundary);
Boundary fill (p-1, q, fill, boundary);
Boundary fill (p, q+1, fill, boundary);
Boundary fill (p, q-1, fill, boundary);
Step 4: End;
Problems with Boundary-fill algorithm
● Recursive boundary-fill algorithms may not
fill regions correctly if some interior pixels
are already displayed in the fill colour.
● Encountering a pixel with the fill colour can
cause a recursive branch to terminate,
leaving other interior pixels unfilled.
● To avoid this, first change the colour of any
interior pixels that are initially set to the fill
colour before applying the boundary-fill
procedure.
Flood Fill Algorithm
● To fill in an area that is not defined within a
single colour boundary
● Paint areas by replacing a specified interior
colour instead of searching for a particular
boundary colour – flood-fill algorithm
● Start from a specified interior point (x, y) and
reassign all pixel values that are currently set
to a given interior colour with the desired fill
colour.
● If the area that we want to paint has more than
one interior colour, we can first reassign pixel
values so that all interior points have the
same colour.
● Using either a 4-connected or 8-connected
approach, we then step through pixel
positions until all interior points have been
Flood Fill Algorithm
Void floodfill(x, y, fillcolor, oldcolor)
{
Int current;
current=getpixel(x,y);
if(current==oldcolor)
{
putpixel (x, y, fillcolor)
floodfill (x + 1, y, fillcolor, oldcolor);
floodfill (x , y+1, fillcolor, oldcolor);
floodfill (x -1, y, fillcolor, oldcolor);
floodfill (x , y-1, fillcolor, oldcolor);
}
}
Flood-fill Algorithm Boundary-fill Algorithm

It can process the image containing more It can only process the image containing
than one boundary colours. single boundary colour.

Flood-fill algorithm is comparatively Boundary-fill algorithm is faster than the


slower than the Boundary-fill algorithm. Flood-fill algorithm.

In Flood-fill algorithm a random colour


can be used to paint the interior portion In Boundary-fill algorithm Interior points
then the old one is replaced with a new are painted by continuously searching for
one. the boundary colour.

Memory consumption is relatively low in


It requires huge amount of memory. Boundary-fill algorithm.

Flood-fill algorithms are simple and The complexity of Boundary-fill algorithm


efficient. is high.

You might also like