0% found this document useful (0 votes)
14 views6 pages

Assignment No 4

The document outlines an assignment to implement polygon filling methods, specifically flood fill and boundary fill, using mouse clicks and keyboard interfaces. It explains the types of polygons (convex and concave), their representation, and the algorithms for filling polygons, including seed fill and scan-line algorithms. Additionally, it provides algorithms for boundary fill and flood fill, detailing the processes involved in each method.

Uploaded by

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

Assignment No 4

The document outlines an assignment to implement polygon filling methods, specifically flood fill and boundary fill, using mouse clicks and keyboard interfaces. It explains the types of polygons (convex and concave), their representation, and the algorithms for filling polygons, including seed fill and scan-line algorithms. Additionally, it provides algorithms for boundary fill and flood fill, detailing the processes involved in each method.

Uploaded by

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

Assignment No 4

Assignment Name:
Implement the following polygon filling methods : i) Flood fill / Seed fill ii) Boundary fill ;
using mouse click, keyboard interface and menu driven programming-
Prerequisite: Basic of polygon types and polygon filling algorithms.
Relevant Theory:
Polygon
When starting and ending point of any polyline is same i.e. when polyline is closed then it is
called polygon

There are two types of polygon


The classification of polygons is based on where the line segment joining any two points within
the polygon is going to lie.
1) Convex polygon
It is a polygon in which any two points taken are surely inside the polygon lies complete
inside the polygon, then that polygon is called as convex polygon

2) Concave polygon
It is a polygon in which the line segment joining any two points within the polygon may not
lie completely inside the polygon.
Representation of Polygon
To display polygon on graphic system, it must first be decided, now to represent it. These
are 3 approaches to represent polygons accordingly.
1) Polygon drawing primitive approach
Some graphics device supports polygon drawing primitive approach. Directly drawn polygon
in graphics system is stored & that polygon acts as a whole unit.
2) Trapezoid primitive Approach
Some graphics devices support trapezoid primitive Trapezoids are formed from two scan
line and two scan lines and two line segments.

`
3) Line & Point Approach
Most of the graphics devices to not provide any polygon support at all. In such cases,
Polygon can be broken into lines & points and stored the full polygon in the display file The
display polygon is then done using line commands.
Convex polygon
A convex polygon is defined as a polygon with all its interior angles less than 180°. This means
that all the vertices of the polygon will point outwards, away from the interior of the shape.
Think of it as a 'bulging' polygon. Note that a triangle (3-gon) is always convex.
Polygon filling
It is the process of coloring in a fixed area or region. It also means high lighting all the pixels
which lie inside the polygon with any color then other background color. There are two basic
approaches used to fill the polygon. One way to fill polygon is to start from a given “seed “point
known to be inside the polygon & highlight outward from the point in neighboring pixels. Until
we encounter the boundary pixel. The approach is called “seed fill.” Another approach to fill
polygon is “scan line” in which it is checked whether pixel is inside the polygon or outside the
polygon.

Seed Fill
The seed fill algorithm is further classified as flood algorithm and boundary fill algorithm.
Algorithms that fill interior defined regions are called flood-fill algorithms; those that fill
boundary defined regions are called boundary fill algorithms or edge fill algorithms.
Boundary fill
algorithm In this algorithm, one point which is surely inside the polygon is taken. This point is
called seed point which is nothing but a point from which filling process starts. Boundary defines
region may be either 4-connected or 8-connected.
Check the color of pixel If boundary color i.e pixel are not reached, pixels are highlighted (by fill
colored) & the process is continued until boundary pixels are reached.
Algorithm
Boundary_fill(x,y,f_color,b_color)
{
if(getpixel(x,y)!=b_color &&getpixel(x,y)!=f_color)
{
putpixel(x,y,f_color)
Boundary_fill(x+1,y,f_color,b_color)
Boundary_fill(x,y,+1f_color,b_color)
Boundary_fill(x-1,y,f_color,b_color)
Boundary_fill(x,y-1,f_color,b_color)
}
}

Flood Fill Algorithm


In this algorithm, areas are filled by replacing a specified interior color instead of searching a
specified interior boundary color. Here, instead of checking boundary color, whether pixels are
having polygons original color is checked. Using either 4-connected or 8-connected approach
step through pixel position until all interior point has been filled.
Algorithm
Flood_fill (x,y, old_color, new_color)
{
If (getpixel(x,y)=old_color)
{
Putpixel (x,y,new color)
Flood_fill (x+1,y, old_color, new_color)
Flood_fill (x-1,y, old_color, new_color)
Flood_fill (x,y,+1 old_color, new_color)
Flood_fill (x,y-1, old_color, new_color)
Flood_fill (x+1,y+1, old_color, new_color)
Flood_fill (x-1,y-1, old_color, new_color)
Flood_fill (x+1,y-1, old_color, new_color)
Flood_fill (x-1,y+1, old_color, new_color)
}
}
Hence, getpixel function gives color of specified pixel & putpixel function draws pixel specified
color.

Scan-line algorithm
The following illustrates the scan line algorithm for filling of polygon. Identify rightmost and
leftmost pixels of the seed pixel and then drawing a horizontal line between these boundary
pixels. This procedure is repeated until complete polygon is filled. We have to stack only
beginning position of each horizontal line. For each scan line crossing a polygon, this algorithm
locates the intersection points of scan line with polygon edges.
These intersection points are then sorted from left to right & the corresponding positions
between each intersection pair are set to the specified fill color. The scan line algorithm first
finds the largest & smallest y values of the polygon.
Then it starts with the largest y value & works it may down. Scanning is done from left to right
in the manner of a raster display.
Features of scan line algorithm
1. Scan line algorithm is used for filling of polygons.
2. This algorithm solves the problem of hidden surfaces while generating display scan line.
3. It is used in orthogonal projection.
4. It is non recursive algorithm.
5. In scan line algorithm we have to stack only a beginning position for horizontal pixel scan,
instead of stacking all unprocessed neighboring positions around the current position. Therefore
it is sufficient algorithm.
Conclusion:- In This way we have studied that how to draw a convex polygon and how to fill a
polygon by using different polygon filling algorithm

You might also like