CA301_CG_Filled Area Primitives-New.pptx

440 views 46 slides Oct 31, 2022
Slide 1
Slide 1 of 46
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26
Slide 27
27
Slide 28
28
Slide 29
29
Slide 30
30
Slide 31
31
Slide 32
32
Slide 33
33
Slide 34
34
Slide 35
35
Slide 36
36
Slide 37
37
Slide 38
38
Slide 39
39
Slide 40
40
Slide 41
41
Slide 42
42
Slide 43
43
Slide 44
44
Slide 45
45
Slide 46
46

About This Presentation

notes on 2d


Slide Content

Filled-Area Primitives Region filling is the process of filling image or region.

Convex and Concave Polygons P1 P2 P1 P2

Polygon Drawing

int Point[10]; OR int Point[ ]={3,12,9,15,17,11,15,4,6,5}; Point[0]=3 Point[1]=12 Point[2]=9 Point[3]=15 Point[4]=17 Point[5]=11 Point[6]=15 Point[7]=4 Point[8]=6 Point[9]=5 drawpoly (5, Point) OR line (3, 12, 9, 15) line (9, 15, 17, 11) line (17, 11 15, 4) line (15, 4, 6, 5) line (6, 5, 3, 12)

int a[20][2] printf ("\n\n\ tEnter the no. of edges of polygon : "); scanf ("% d",&n ); printf ("\n\n\ tEnter the cordinates of polygon :\n\n\n "); for( i =0;i< n;i ++) { printf ("\ tX%d Y%d : ", i,i ); scanf ("%d % d",&a [ i ][0],&a[ i ][1]); } a[n][0]=a[0][0]; a[n][1]=a[0][1]; /*- draw polygon -*/ for(i=0;i<n;i++) { line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); }

POLYGON FILLING Means highlighting all the pixels which lie inside the polygon. Colour other than background colour . Polygons are easier to fill. There are two basic approaches Seed Fill Boundary Fill Algorithm Flood Fill Algorithm 2. Scanline Algorithm

1.Seed Fill

(X , Y) (X , Y - 1) (X -1 , Y - 1) (X + 1 , Y + 1) (X - 1 , Y + 1) (X , Y + 1) (X , Y - 1) (X - 1 , Y) (X + 1 , Y) (X , Y) (X + 1 , Y - 1) (X - 1 , Y) (X + 1 , Y) (X , Y + 1)

Disadvantage: 1. Very slow algorithm 2. May be fail for large polygons 3. Initial pixel required more knowledge about surrounding pixels.

Scan-Line Method for Filling Polygons

(2 , 9) (7 , 7) (13 , 11) (13 , 5) (7 , 1) (2 , 3) m=(9-7)/(2-7) = -2/5 => 1/m = -5/2------for EF

#include < stdio.h > #include < conio.h > #include < graphics.h > main() { int n,i,j,k,gd,gm,dy,dx ; int x,y,temp ; int a[20][2],xi[20]; float slope[20]; clrscr (); printf ("\n\n\ tEnter the no. of edges of polygon : "); scanf ("% d",&n ); printf ("\n\n\ tEnter the cordinates of polygon :\n\n\n "); for( i =0;i< n;i ++) { printf ("\ tX%d Y%d : ", i,i ); scanf ("%d % d",&a [ i ][0],&a[ i ][1]); } a[n][0]=a[0][0]; a[n][1]=a[0][1]; detectgraph (& gd ,&gm); initgraph (& gd ,& gm,"c :\\tc\\bgi"); /*- draw polygon -*/ for( i =0;i< n;i ++) { line(a[ i ][0],a[ i ][1],a[i+1][0],a[i+1][1]); } getch ();

for( i =0;i< n;i ++) { dy =a[i+1][1]-a[ i ][1]; dx=a[i+1][0]-a[ i ][0]; if( dy ==0) slope[ i ]=1.0; if(dx==0) slope[ i ]=0.0; if(( dy !=0)&&(dx!=0)) /*- calculate inverse slope -*/ { slope[ i ]=(float) dx/ dy ; } } for(y=0;y< 480;y++) { k=0; for( i =0;i< n;i ++) { if( ((a[ i ][1]<=y)&&(a[i+1][1]>y))|| ((a[ i ][1]>y)&&(a[i+1][1]<=y))) { xi[k]=(int)(a[ i ][0]+slope[ i ]*(y-a[ i ][1])); k++; } } for(j=0;j<k-1;j++) /*- Arrange x-intersections in order -*/ for( i =0;i<k-1;i++) { if(xi[ i ]>xi[i+1]) { temp=xi[ i ]; xi[ i ]=xi[i+1]; xi[i+1]=temp; } }

setcolor (35); for( i =0;i< k;i +=2) { line(xi[ i ], y,xi [i+1]+1,y); getch (); } } }

Nonzero Winding Number Rule

>Unsuitable for Line based Z-Buffer >These methods can also apply to any closed curves >Suitable for Line based Z-Buffer >This method is difficult to apply to any closed curves
Tags