Professional Documents
Culture Documents
Unit 2
Unit 2
Unit 2
Introduction to Polygons
P 0 P2 P3 P4
Polyline
P 1
P 0 P2
P 1
P4
Polygon
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
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
z1 z2 z3 z4 z5
Surface Table
S1: E1, E2, E3 S2: E3, E4, E5, E6
E2 v2
v4
Inside test
Even odd 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
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
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)
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
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
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
0 1 2 3 4 5 6 7 8 9 10
Each pixel is visited only once !!! No sorting and maintaining edge lists !!
1. Preliminaries
scan conversion
seed filling
Run-Length Encoding
344
intensity run-length
Cell Organization Frame Buffer
1
C 2 A 3
1 BCb BA BD e CD AD
2 BC BAb BD CDe AD
3 BC BA BDb CDe AD
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
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
1
2 3 4
B
C
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
0 7 1 1 0 6 1 1 0 15
1 30
0 7 1 8 0 15
1 30
15 1 1 0 1
Cell Encoding
8 6 4 2 0 2 4 6 8