Sie sind auf Seite 1von 41

Area Filling

•A poly line is a chain of connected line segment.

•It is specified by giving vertices(p0,p1,p2…) and so on.

•The first vertex is called the initial point and the last vertex is called terminal
point.

•When starting point and terminal point of any poly line is same ,then it is
called polygon.
Types of polygons
There are 2 types of polygons:

Convex and Concave

•Convex polygon is a polygon in which the line segment joining any 2 points
within the polygon lies completely inside the polygon.

•Concave polygon is a polygon in which the line segment joining any 2 points
within the polygon may not lie completely inside the polygon.
Representation of polygons:

•Each polygon has vertices and edges.


•To add polygon to our graphics system, we must decide how to represent it.

There are 3 approaches to represent polygons:

1.Polygon drawing primitive approach:


• Some graphics devices can directly draw the polygon shapes.
• on such devices the polygon is saved as single unit.

2. Trapezoid primitive approach:


• every polygon is broken up into trapezoids and it is represented as
series of trapezoids.

3. Line and point approach:


•Polygons can be also represented using lines and points.
•the polygon is saved as single unit and stored in display file.
An inside test:
•To show the polygon as a solid object we have to set pixels inside the
polygon as well as pixels on the boundary of it.
•Now the question is to determine whether or not the point is inside of the
polygon.

There are 2 methods:


Even-odd method:
•Construct a line segment between the point in question and point known to be
outside the polygon.

•If there are odd number of intersections ,then the point is inside otherwise it is
outside.

•If the intersection point is vertex of the polygon then we have to look at other
endpoints of the 2 segments which meet at this vertex.

•If these points lie on the same side of the constructed line , then the point in
question counts
Winding number method:

•In this method we have to pictures a line segment running from outside the
polygon to the point in question and consider the polygon sides which it crosses.

•Instead of counting intersections ,we have to give direction number to each


boundary line crossed ,and we have to sum these direction numbers.

•As shown in figure point ( Xa , Ya ) is a test point and line y= Ya is horizontal line
runs from outside the polygon to the point (Xa, Ya).

•The polygon edges crossed by this line could be drawn in two ways.:

•Edge could be drawn starting below the line ,cross it, and end above the line. ---
direction number -1 Or

•Edge could be drawn starting above the line ,cross it, and end below the line.---
direction number 1.

•After giving the direction number we have to take sum of these numbers.

•This sum is called winding number .if sum is non zero --- the point is inside the
polygon.
Polygon Filling:

•Filling the polygons means highlighting all the pixels which lie inside the polygon
with any colour other than background.

•There are 2 approaches used to fill the polygon:

Seed fill:

Start from a given seed point , known to be inside the polygon and highlighting
outwards from this point.

Scan line algorithm:

Check weather the pixel is inside the polygon or outside and highlighting the pixels
which lie inside the polygon.
Seed fill:

•Seed fill algorithm is classified as flood fill algorithm --- that fill interior defined region.

•and boundary fill algorithm ------ fill boundary define regions.

boundary fill algorithm:

•In this method ,edges of polygon are drawn.

•Then starting with some seed, any point inside the polygon we examine the
neighboring pixels to check weather the boundary pixel is reached.

•If the boundary pixel is not reached ,pixels are highlighted and process is continued
until boundary pixel is reached.

•Boundary defined regions may be 4 connected or 8 connected.

.
Flood Fill algorithm:

•Sometimes it is required to fill in an area that is not defined within a single colour
boundary.

•In such cases we can fill areas by replacing a specified interior colour instead of
searching for a specified boundary colour.

• here we have to start with some seed and examine the neighboring pixel .

•The pixels are checked for specified interior colour instead of boundary colour and they
are replaced by new colour.

•Using either 4 connected or 8 connected approach we can step through pixel positions
until all interior pixels have been filled.
Scan Line Algorithm:

•For each Scan Line crossing a polygon, this algorithm locates the intersection
points of the scan line with the polygon edges.

•The intersection points are then sorted from left to right and the corresponding
position between each intersection pair are set to the specified fill color.
•As shown in the figure there are 2 stretches of interior pixels from x=6 to x=9
•And x=12 to x=15.
•The scan line algorithm first finds the largest and smallest y values of the
polygon.
•It then starts with the largest y value and works it way down,scnning from left to
right, in the manner of raster display.
•The important task in scan line algorithm is to find the intersection points of the
scan line with the polygon boundary.
• when intersection points are even ,they are sorted from left to right ,paired and
the pixels between paired points are set to fill color.
•But in some cases the intersection point is vertex.
•When scan line intersects polygon vertex a special handling mechanism is
required to find the exact intersection point.
•To handle such cases ,we must look at other end point of the 2 line segments of
the polygon which meet t this vertex.
•If these points lie of the same side of the scan line, then point in question counts
as an even number of intersections.
•If they lie on opposite side of the scan line, then point is counted as single
intersection.
•as shown in the figure ,each scan line intersects the vertex or vertices of the
polygon.
•For scan line 1, the other end points (B,D) of the 2 line segments of the polygon
lie on the same side of the scan line, hence there are 2 intersections resulting
two pairs 1-2 and 3-4 .
•For scan line 2, the other end points (D,F) of the 2 line segments of the polygon
lie on the opposite side of the scan line, hence there is single intersection.
resulting two pairs 1-2 and 3-4 .
•For scan line 3, two vertices are intersection points. for vertex F the other end
points E and G of the two line segment of the polygon lie on the same side of the
scan line. therefore vertex F there are two intersections .
Coherence Property:
•Coherence Property of a scene is a property of a scene by which we can relate
one part of the scene with the other parts of the scene.
•Here we can use a slope of an edge as a Coherence Property.

•By using this property we can determine the x intersection value on the lower
scan line if the x intersection value for current scan line is known.
•This is given as x(i+1) = X(i) – 1/m.
•As we scan from top to bottom value of y coordinate
• y(i+1)=y(1) – 1
•It will be easier to identify which polygon sides should be tested for x-
intersection, if we first sort the sides in order of their maximum y value.
•Once the sides are sorted we can process the scan line from top of the polygon
to its bottom producing an active edge list for each scan line crossing the
polygon boundaries.
Scan line conversion algorithm for polygon filling:
1. Read n, number of vertices.
2. Read x and y coordinates of all vertices in array x[n] , y[n].
3. Find Y_min ,Y_max.
4. Store the initial x value x1 , y value y1 and y2 for two end points and x
increment (delta) x from scan line to scan line for each edge in the array edges
[n][4].
while doing this check that y1>y2 , if not interchang y1 and y2 and
corresponding x1 and x2 so that for each edge ,y1represents its maximum y
coordinate and y2 represents its minimum y coordinate.
5. Sort the rows of array ,edges in descending order of y1, descending order of
y2,and ascending order of x2.
6. Set y=y_max
7. Find the active edges and update active edge list:
If (y>y2 and y<=y1)
{edge is active}

Das könnte Ihnen auch gefallen