Area Fill Algorithms For Various Graphics Primitives: Amity University, Haryana
Area Fill Algorithms For Various Graphics Primitives: Amity University, Haryana
• Pattern-fill
the polygon is filled with an arbitrary
predefined pattern.
Polygon Representation
The polygon can be represented by listing its n
vertices in an ordered list.
P = {(x1, y1), (x2, y2), ……., (xn, yn)}.
int main( )
{
int gd=DETECT, gm;
int points[]={150,130,350,130,350,400,250,400,150,130};
initgraph(&gd,&gm,"C:\\tc\\bgi");
// read result of initialization
// graphresult return error code of graphics
errorcode=graphresult( );
if( errorcode!=grOk ) // grOk is graphics error constant
{// an error has now been occurred
// grapherrormsg return address of error message string
printf(“graphics error:%s”,grapherrormsg(errorcode));
printf(“press any key to halt:”);
getch();
// terminate with error code
exit(1);
}
drawpoly(5,points);
getch();
closegraph();
return 0;
}
Types of Polygons: Convex and Concave
Convex Polygon - For any two points P1, P2 inside the
polygon, all points on the line segment which
connects P1 and P2 are inside the polygon.
Concave Polygon
- A polygon which is not convex.
?
Larry Hodges, Zachary Wartell
Inside-Outside Tests
when filling polygons we should decide whether a
particular point is interior or exterior to a polygon.
A rule called the odd-parity (or the odd-even rule)
is applied to test whether a point is interior or not.
To apply this rule, we conceptually draw a line
starting from the particular point and extending to a
distance point outside the coordinate extends of the
object in any direction such that no polygon vertex
intersects with the line.
Inside-Outside Tests (Even – odd method)
The point is considered to be interior if the number
of intersections between the line and the polygon
edges is odd. Otherwise, The point is exterior point.
Outside 8
7
6
5
4
3
2
1
0
0 1 2 3 4 5 6 7 8 9 10 11
Inside
WINDING NUMBER METHOD FOR INSIDE OUT
SIDE TEST
Odd Intersection
Color Filling Start
Even Intersection
Color Filling Stop
Student Please make correction,
Here please count number of
intersection 1.
The Scan-Line Polygon Fill Algorithm
Determining Edge Intersections
m = (yk+1 – yk) / (xk+1 – xk)
yk+1 – yk = 1
xk+1 = xk + 1/m
The Scan-Line Polygon Fill Algorithm
Dealing with vertices
• When the endpoint y coordinates of the two edges are
increasing, the y value of the upper endpoint for the
current edge is decreased by one (a)
• When the endpoint y values are decreasing, the y value
of the next edge is decreased by one (b)
The Scan-Line Polygon Fill Algorithm
(Example) Polygon = {A, B, C, D, E, F, G}
Polygon = {(2, 7), (4, 12), (8,15), (16, 9), (11, 5), (8, 7), (5, 5)}
Correction: A’(3,6)
The Scan-Line Polygon Fill Algorithm
(Example) Edge
no-0
Edge Table
-sort vertices by y coordinate building Edge Table (ET)
yG GF T5
G T6
T4
yE EF ED
E
T3
yB BC B
H T2
yH HG
T1
yA AH AB
A
y=
Zachary Wartell
Scan AET with AEL
-scan up through ET and track Active Edge Table (AET). At
each scan-line fill in span of pixel for each edge pair.
ET AETk
ymax (k = 1..10)
D C
[(DE,BC)]
F
[(GF,EF),
yG GF T5 (DE,BC)]
G T6
[(HG,EF),
T4
yE EF ED
E (DE,BC)]
T3 [(HG,BC)]
yB BC B
H T2 [(HG,AB)]
yH HG
T1
AH AB
[(AH,AB)]
yA
A
y=0
Boundary Fill Algorithm
• 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 color, the fill
algorithm processed outward pixel by pixel until the
boundary color is encountered.
• A boundary-fill procedure accepts as input the
coordinate of the interior point (x, y), a fill color,
and a boundary color.
Boundary Fill Algorithm
The following steps illustrate the idea of the
recursive boundary-fill algorithm:
Start Position
Boundary Fill Algorithm
4-connected (Example)
3
2
1
1
2 3
Boundary Fill Algorithm
4-connected (Example)
4
2
1 4
1
2
Boundary Fill Algorithm
4-connected (Example)
2
1
1
2
Boundary Fill Algorithm
4-connected (Example)
5
5 1
1
Boundary Fill Algorithm
4-connected (Example)
1
1
Boundary Fill Algorithm
4-connected (Example)
Boundary Fill Algorithm
8-connected (Example)
Start Position
Boundary Fill Algorithm
8-connected (Example)
4 1 5
5
2 3
4
3
2
1
Boundary Fill Algorithm
8-connected (Example)
6
4 1
6
2 3
4
3
2
1
Boundary Fill Algorithm
8-connected (Example)
7 8
8
4 1
7
2 3
4
3
2
1
Boundary Fill Algorithm
8-connected (Example)
12
11 9 12
11
7 10
10
9
4 1
7
2 3
4
3
2
1
Boundary Fill Algorithm
8-connected (Example)
11 9
11
7 10
10
9
4 1
7
2 3
4
3
2
1
Boundary Fill Algorithm
8-connected (Example)
9
7 10
10
9
4 1
7
2 3
4
3
2
1
Boundary Fill Algorithm
8-connected (Example)
9
7
9
4 1
7
2 3
4
3
2
1
Boundary Fill Algorithm
8-connected (Example)
4 1
7
2 3
4
3
2
1
Boundary Fill Algorithm
8-connected (Example)
4 1
2 3
4
3
2
1
Boundary Fill Algorithm
8-connected (Example)
1
2 3
3
2
1
Boundary Fill Algorithm
8-connected (Example)
1
2
2
1
Boundary Fill Algorithm
8-connected (Example)
1
Boundary Fill Algorithm
8-connected (Example)
Boundary Fill Algorithm
If the area has more than one interior color, we can first
reassign pixel values so that all interior pixels have the
same color.
52
THANKS