Unit 2

You might also like

Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 34

Polygons

Introduction to Polygons
P 0 P2 P3 P4
Polyline

P 1

P 0 P2

P 1

P4
Polygon

Different types of Polygons

Convex

Concave

Convex

Concave

Polygons

convex
all interior angles are <1800

concave
at least one angle is >1800

Representation Of Polygons
p1 p8 p5 p6 p7

p4

p3

p2

Polygon drawing primitive approach

Polygon representation using Table s


Vertex Table
v1: v2: v3: v4: v5:
v5

Edge Table
E1: E2: E3: E4: E5: E5: v1, v2, x3, v3, v4, v5, v2 v3 v1 v4 v5 v1

v1

E6
E1 E3 S1 v3 E4 S2 E5

x1, x2, x3, x4, x5,

y1, y2, y3, y4, y5,

z1 z2 z3 z4 z5

Surface Table
S1: E1, E2, E3 S2: E3, E4, E5, E6

E2 v2

v4

Inside test
Even odd method

Winding number method

Polygon Filling

Seed Fill Approaches 2 algorithms: Boundary Fill and Flood Fill works at the pixel level suitable for interactive painting apllications Scanline Fill Approaches works at the polygon level better performance

Seed Fill Algorithms: Connectedness


4-connected region: From a given pixel, the region that you can get to b y a series of 4 way moves (N, S, E and W) 8-connected region: From a given pixel, the region that you can get to b y a series of 8 way moves (N, S, E, W, NE, NW, SE, and SW)

4-connected

8-connected

8-connected region:

4-connected region:

If the selected pixel is (x, y) the 8 neighbouring pixels are (x+1, y) ,(x-1, y), (x, y-1), (x, y+1) (x+1, y+1) ,(x-1, y+1) (x-1, y-1), (x+1, y-1)

If the selected pixel is (x, y) the neighbouring pixels are (x+1, y),(x-1, y) ,(x, y+1) , (x, y-1) 4-connected fill is faster, but can have problems

8-connected

4-connected

Boundary Fill Algorithm


Start at a point inside a region Paint the interior outward to the edge The edge must be specified in a single color Fill the 4-connected or 8-connected region 4-connected fill is faster, but can have problems:

Boundary-Fill Algorithm
void boundaryFill4 (int x, int y,int fillColor,int borderColor) { int interiorColor; /*Set current color to fillColor*/ getPixel (x, y, interiorColor); if ((interiorColor != borderColor) && (interiorColor != fillColor)) { setPixel (x, y); boundaryFill4 (x boundaryFill4 (x boundaryFill4 (x boundaryFill4 (x } }

+ , ,

// Set pixel color to fillColor 1, y , fillColor, borderColor); 1, y , fillColor, borderColor); y + 1, fillColor, borderColor); y - 1, fillColor, borderColor)

Flood Fill Algorithm


Used when an area defined with multiple color bo undaries Start at a point inside a region Replace a specified interior color (old color) with fill color Fill the 4-connected or 8-connected region until all interior points being replaced

Flood Fill Algorithm


void FloodFill4(int x, int y, color newcolor, color oldColor ) { if(ReadPixel(x, y) == oldColor) { putpixel(x,y,newcolor) FloodFill4(x+1, y, newcolor, oldColor); FloodFill4(x-1, y, newcolor, oldColor); FloodFill4(x, y+1, newcolor, oldColor); FloodFill4(x, y-1, newcolor, oldColor); } }

Edge Fill Algorithm


basic idea

Complement the pixels on the right of an edge.

Edge Fill Algorithm (Cont)


8 P 5 6 4 2 P1 0 2 4 6 P4 P2 8 10 0 2 4 6 8 10 0 2 4 6 8 10 8 P3 6 4 2 8 6 4 2

edge P2P3
8 6 4 2 0 2 4 6 8 10 8 6 4 2 0 2 4 6

edge P3P4

10

edge P4P5

edge P5P1

Fence Fill Algorithm

fence
To Left of fence-complement all pixels having mid point to right of line To right of fence-complement all pixels having mid point to left of line

Fence Fill Algorithm (Cont)


8 P 5 6 4 2 P1 0 2 4 6 P4 8 fence P3 fence 6 4 2 6 4 2 0 2 4 6 8 10 0 2 4 6 8 10 8 fence

P2
8 10

edge P2P3
8 fence 6 4 2 0 2 4 6 8 10 6 4 2 0 2 4 6 8 fence

edge P3P4

10

edge P4P5

edge P5P1

Edge Flag Algorithm

Edge Flag Algorithm (Cont)


8 P 5 6 4 2 0 P1 2 4 P4 6 P2 8 10 P3

0 1 2 3 4 5 6 7 8 9 10

Each pixel is visited only once !!! No sorting and maintaining edge lists !!

Scan line algorithm

Scan line algorithm (cont.)

1. Preliminaries
scan conversion

seed filling

Scan conversion Methods


Real Time scan conversion

using geometry and visual attributes

Run-Length Encoding

344

intensity run-length
Cell Organization Frame Buffer

Ordered Edge List Algorithm


B

1
C 2 A 3

1 BCb BA BD e CD AD

2 BC BAb BD CDe AD

3 BC BA BDb CDe AD

Real-time Scan Conversion (Cont)


1
2 3 4

y_bucket
B C
1 2 3 1

indexed list
2 3 4 5

5
6 7

A
4

6 7 8 9 10 11 12 13 14 15

xBA DxBA DyBA xBC DxBC DyBC xCD DxCD DyCD xAD DxAD DyAD

5 6

12

7 8

link completion or null, end of scan line

y_bucket
8 6 4 2
P1 P4 P5 P3
7 6 5 8 1 2 3 4 5 6 7 8 9 3 2 1 10 11 12 13 14 15

indexed list
x45 Dx45 Dy45 x51 Dx51 Dy51
1.5 1 3

1 9

5
1 0 5 8 0 4 7.5 -1 2

P2

10

end of data group, = n gives the location of the next data group on that scanline. link completion or null, = end of scan line

x23 Dx23 Dy23 13 x34 Dx34 Dy34

1
2 3 4

B
C

active edge list

6 7

A D

scan line 3: xBA + DxBA, DxBA, DyBA - 1, xBC + DxBC, DxBC, DyBC - 1,
scan line 5: xBA +3 DxBA, DxBA, DyBA - 3, xCD + DxCD, DxCD, DyCD - 1, scan line 7: xCD + 3DxCD, DxCD, DyCD - 3, xAD + DxAD, DxAD, DyAD - 1

y_bucket 1 null 2 (xBA , DxBA , DyBA) (xBC , DxBC , DyBC) 3 null 4 (xCD , DxCD , DyCD) 5 null 6 (xAD , DxAD , DyAD) 7 null 8 null

Run-length Encoding
intensity run length

color : R G B run length


0 30

0 7 1 1 0 6 1 1 0 15

1 30

Run-length Encoding (Cont)


0 30

0 7 1 8 0 15

1 30

Run-length Encoding (Cont)

15 1 1 0 1

Cell Encoding
8 6 4 2 0 2 4 6 8

Good for repeating patterns !!!

Cell Encoding (Cont)


representing drawings
2n2 patterns !!!
n n

Looks impossible for representing drawings

You might also like