Clipping Yiorgos Chrysanthou 2001 Anthony Steed 2002 2003

  • Slides: 20
Download presentation
Clipping ©Yiorgos Chrysanthou 2001, Anthony Steed 2002 -2003, Celine Loscos 2004 1

Clipping ©Yiorgos Chrysanthou 2001, Anthony Steed 2002 -2003, Celine Loscos 2004 1

Clipping Summary n It’s the process of finding the exact part of a polygon

Clipping Summary n It’s the process of finding the exact part of a polygon lying inside the view volume n To maintain consistency, clipping of a polygon should result in a polygon, not a sequence of partially unconnected lines n We will first look at 2 different 2 D solutions and then extend one to 3 D 2

Sutherland-Hodgman Algorithm p 0 p 1 n n n Clip the polygon against each

Sutherland-Hodgman Algorithm p 0 p 1 n n n Clip the polygon against each boundary of the clip region successively Result is possibly NULL if polygon is outside Can be generalised to work for any polygonal clip region, not just rectangular p 4 p 2 Clip to top p 3 Clip to right etc 3

Clipping To A Region n To find the new polygon • iterate through each

Clipping To A Region n To find the new polygon • iterate through each of the polygon edges and construct a new sequence of points • starting with an empty sequence • for each edge there are 4 possible cases to consider right clip boundary P 2 P 1 P 0 P 3 clip region 4

Clipping a polygon edge against the boundary n Visible Side Given an edge P

Clipping a polygon edge against the boundary n Visible Side Given an edge P 0, P 1 we have 4 cases: p • entering the clipping region p 1 p – add P and P 1 • leaving the region p – add only P p • entirely outside p Where P is the point of intersection p 1 p • entirely inside n p 0 – do nothing – add only P 1 0 1 p IN 1 0 0 OUT 5

Still the Sutherland-Hodgman n n We can determine which of the 4 cases and

Still the Sutherland-Hodgman n n We can determine which of the 4 cases and also the point of intersection with just if statements To sum it up, an example: P 1 P 2 P 0 P 3 Pa P 0 Pb P 3 6

Weiler-Atherton Algorithm n n n When we have non-convex polygons then the algorithm above

Weiler-Atherton Algorithm n n n When we have non-convex polygons then the algorithm above might produce polygons with coincident edges This is fine for rendering but maybe not for other applications (eg shadows) The Weiler-Atherton algorithm produces separate polygons for each visible fragment 7

Weiler-Atherton Algorithm polygon 1 1 2 8 a i 0 A 0 j 9

Weiler-Atherton Algorithm polygon 1 1 2 8 a i 0 A 0 j 9 5 4 7 b k 2 3 4 5 6 l 3 c 7 8 clip region b 6 c d B a 9 d loop of region vertices loop of polygon vertices 8

Find the intersection vertices and connect them in the two lists polygon 0 1

Find the intersection vertices and connect them in the two lists polygon 0 1 2 8 a 0 A j i 7 b 9 5 k 4 l clip region 2 3 4 6 5 c d B 1 3 6 7 Add vertex i: i a l b k c j d 8 9 9

Find the intersection vertices and connect them in the two lists polygon 0 1

Find the intersection vertices and connect them in the two lists polygon 0 1 2 8 a 0 A j i 7 b 9 5 k 4 l clip region 2 3 4 6 5 c d B 1 3 6 7 Add vertex l: i a l b k c j d 8 9 10

Find the intersection vertices and connect them in the two lists polygon 0 1

Find the intersection vertices and connect them in the two lists polygon 0 1 2 8 a 0 A j i 7 b 9 5 k 4 l clip region 2 3 4 6 5 c d B 1 3 6 7 Add vertex k: i a l b k c j d 8 9 11

Completed Loop polygon 0 1 2 8 a 0 A j i 7 b

Completed Loop polygon 0 1 2 8 a 0 A j i 7 b 9 5 k 4 l clip region 2 3 4 6 5 c d B 1 3 6 7 Add vertex j: i a l b k c j d 8 9 12

Classify each intersection vertex as Entering or Leaving polygon 0 1 2 8 a

Classify each intersection vertex as Entering or Leaving polygon 0 1 2 8 a A j i 0 Entering Leaving 7 b 9 5 k 4 l clip region 2 3 4 6 5 c d B 1 3 6 7 i a l b k c j d 8 9 13

Capture clipped polygons Entering Leaving 0 1 2 3 4 5 6 7 i

Capture clipped polygons Entering Leaving 0 1 2 3 4 5 6 7 i n n a n l k b n c n j d Start at an entering vertex If you encounter a leaving vertex swap to right hand (clip polygon) loop If you encounter an entering vertex swap to left hand (polygon) loop A loop is finished when you arrive back at start Repeat whilst there are entering vertices 8 9 14

Capture clipped polygons Entering Leaving 0 1 2 3 4 5 6 7 i

Capture clipped polygons Entering Leaving 0 1 2 3 4 5 6 7 i a l b k c j d n Loop 1: • L, 4, 5, K n Loop 2: • J, 9, 0, i 8 9 15

Clipping Polygons in 3 D n The Sutherland-Hodgman can easily be extended to 3

Clipping Polygons in 3 D n The Sutherland-Hodgman can easily be extended to 3 D • the clipping boundaries are 6 planes instead of 4 lines • intersection calculation is done by comparing an edge to a plane instead of edge to edge n It can either be done in Projection Space or in Canonical Perspective 16

Clipping in Projection Space n The view volume is defined by: n Testing for

Clipping in Projection Space n The view volume is defined by: n Testing for the 4 cases is fast, for example for the x = 1 (right) clip plane: • • x 0 1 and x 1 1 x 0 1 and x 1 > 1 x 0 > 1 and x 1 > 1 entirely inside leaving entering entirely outside 17

Clipping in Canonical Perspective p When we have an edge that extends from the

Clipping in Canonical Perspective p When we have an edge that extends from the front to behind the COP, then if we clip after projection (which in effect is what the PS does) we might get wrong results V View plane to n +1 p 2 q 1 N O COP q 2 -1 bo tto m 18

Clipping in Homogeneous Coord. The Sutherland-Hodgman can also be used for clipping in 4

Clipping in Homogeneous Coord. The Sutherland-Hodgman can also be used for clipping in 4 D before dividing the points by the w n This can have the advantage that is even more general, it even allows for the front clip plane to be behind the COP n 19

Clipping Recap Sutherland-Hodgman is simple to describe but fails in certain cases n Weiler-Atherton

Clipping Recap Sutherland-Hodgman is simple to describe but fails in certain cases n Weiler-Atherton clipping is more robust but considerably harder n Both extend to 3 D but we need to consider projection and end up clipping in 4 D n 20