Polygon Clipping - cse.iitd.ernet.inpkalra/csl781/polygon-clipping-filling.pdf · Clipping Polygon...

Post on 08-Apr-2018

241 views 6 download

transcript

Clipping

Polygon : Area primitive

Polygon Clipping

Simple Polygon: Planar set of ordered points No line crossings No holes

V1 V2

V3 V4

Simple Polygon Line Crossing Hole

Clipping

Non-Convex Polygon

Polygon Clipping Polygon : Area primitive

Convex Polygon

Clipping Polygon Clipping Sutherland-Hodgman

•  Window must be convex •  Polygon to be clipped can be convex or non-convex

Polygon

Window

Polygon

Clipping Polygon Clipping Sutherland-Hodgman

•  Window must be convex •  Polygon to be clipped can be convex or non-convex

Clipping Polygon Clipping Sutherland-Hodgman

Clipping Polygon Clipping Sutherland-Hodgman

Clipping Polygon Clipping Sutherland-Hodgman

Clipping Polygon Clipping Sutherland-Hodgman

Clipping Polygon Clipping Sutherland-Hodgman

Clipping Polygon Clipping Sutherland-Hodgman

Approach •  Polygon to be clipped is given as v1, v2, !, vn •  Polygon edge is a pair [vi, vi+1] •  Process all polygon edges in succession against a window edge polygon (v1, v2, !, vn) polygon (w1, w2, !, wm) •  Repeat on resulting polygon with next window edge

Clipping Polygon Clipping Sutherland-Hodgman

Approach

•  s = vi is the polygon edge starting vertex •  p = vi+1 is the polygon edge ending vertex •  i is a polygon-edge/window-edge intersection point •  wj is the next polygon vertex to be output

Four Cases

Clipping Polygon Clipping Sutherland-Hodgman

Approach

•  p is next vertex of resulting polygon •  p wj and j+1 j

Case 1: Polygon edge is entirely inside the window edge Outside Inside

p

s

Output

Clipping Polygon Clipping Sutherland-Hodgman

Approach

•  Intersection point i is next vertex of resulting polygon •  i wj and j+1 j

Case 2: Polygon edge crosses window edge going out Outside Inside

s Output

p

i

Clipping Polygon Clipping Sutherland-Hodgman

Approach

•  No output

Case 3: Polygon edge is entirely outside the window edge Outside Inside

s

p

Clipping Polygon Clipping Sutherland-Hodgman

Approach Case 4: Polygon edge crosses window edge going in

Outside Inside s

p •  Intersection point i and p are next two vertices of resulting polygon •  i wj and p wj+1 and j+2 j

i Output

Clipping Polygon Clipping Sutherland-Hodgman Example

Polygon

Window

s1

s2 s3

s4 s5

Clipping Polygon Clipping Sutherland-Hodgman Example

s1

s2 s3

s4 s5

i1 i2

Clipping Polygon Clipping Sutherland-Hodgman Example

t5

t1 t2

t3 t4

Clipping Polygon Clipping Sutherland-Hodgman Example

u4

u5 u1

u2 u3

Clipping Polygon Clipping Sutherland-Hodgman Example

v3

v4 v5

v1 v2 i3

i4 i5

i6

Clipping Polygon Clipping Sutherland-Hodgman Example

w3

w6 w1

w2

w4 w5

Polygon Scan Conversion Polygon Filling Consider first triangle

Polygon Scan Conversion Polygon Filling Consider first triangle

Color all pixels inside triangle Inside (containment) test

Polygon Scan Conversion Polygon Filling Triangle

Use horizontal spans. Process horizontal spans in scan-line order. For the next spans use edge slopes XL XR

Polygon Scan Conversion Polygon Filling Polygon

How do we decide what parts of the span should be filled ?

Polygon Scan Conversion Polygon Filling Polygon

How do we decide what parts of the span should be filled ?

Parity check if odd fill if even don’t fill

Polygon Scan Conversion Polygon Filling Polygon

What happens here?

Polygon Scan Conversion Polygon Filling Polygon

What happens here?

Polygon Scan Conversion Polygon Filling Polygon

Recursive seed filling