Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and.

Similar presentations


Presentation on theme: "Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and."— Presentation transcript:

1 Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and windowing –Modelling May require more complex geometry than rectangular boxes

2 Hardware Sutherland-Hodgman Suitable for hardware implementation –Only need the clip edge, the endpoints of the current edge, and the last output point –Polygon edges are output as they are found, and passed right on to the next clip region edge Clip Top Vertices in Clip Right Clip Bottom Clip Left Clipped vertices out

3 Inside-Outside Testing Edges/Planes store a vector pointing toward the outside of the clip region Dot products give inside/outside information OutsideInside n s f i x s-x

4 Inside/Outside in Screen Space In screen space, clip planes are x s =±1, y s =±1, z s =0, z s =1 Inside/Outside reduces to comparisons before perspective divide

5 Finding Intersection Pts Watt Sect 1.4.3, 1.4.4 Use the parametric form for the line between two points, x 1 and x 2 : For planes of the form x=a: Similar forms for y=a, z=a Solution for general plane in textbook

6 Additional Clipping Planes Useful for doing things like cut-away views –Use a clip plane to cut off part of the object –Only works if piece to be left behind is convex OpenGL allows you to do it Also one way to use OpenGL to identify objects in a region of space (uses the selection mechanism)

7 Clipping Lines Lines can also be clipped by Sutherland-Hodgman –Slow, unless you already have hardware Better algorithms exist –Cohen-Sutherland –Liang-Barsky –Nicholl-Lee-Nicholl

8 Cohen-Sutherland (1) Works basically the same as Sutherland-Hodgman –Was developed earlier Clip line against each edge of clip region in turn –If both endpoints outside, discard line and stop –If both endpoints in, continue to next edge (or finish) –If one in, one out, chop line at crossing pt and continue

9 Cohen-Sutherland (2) 12 3 4 12 3 4 3 4 12 3 4

10 Cohen-Sutherland (3) Some cases lead to premature acceptance or rejection –If both endpoints are inside all edges –If both endpoints are outside one edge

11 Cohen-Sutherland - Details Only need to clip line against edges where one endpoint is out Use outcode to record endpoint in/out wrt each edge. One bit per edge, 1 if out, 0 if in. Trivial reject: –outcode(x 1 )&outcode(x 2 )!=0 Trivial accept: –outcode(x 1 )|outcode(x 2 )==0 Which edges to clip against? –outcode(x 1 )^outcode(x 2 ) 12 3 4 0010 0101

12 Liang-Barsky Clipping Parametric clipping - view line in parametric form and reason about the parameter values More efficient, as not computing the coordinate values at irrelevant vertices Clipping conditions on parameter: Line is inside clip region for values of t such that:

13 Liang-Barsky (2) Infinite line intersects clip region edges when: where

14 Liang-Barsky (3) When p k <0, as t increases line goes from outside to inside - enter When p k >0, line goes from inside to outside - leave When p k =0, line is parallel to an edge (clipping is easy) If there is a segment of the line inside the clip region, sequence of infinite line intersections must go: enter, enter, leave, leave

15 Liang-Barsky (4) Enter Leave Enter Leave Enter Leave

16 Liang-Barsky - Algorithm Compute entering t values, which are q k /p k for each p k <0 Compute leaving t values, which are q k /p k for each p k >0 Parameter value for small t end of line is:t small = max(0, entering t’s) parameter value for large t end of line is: t large =min(1, leaving t’s) if t small <t large, there is a line segment - compute endpoints by substituting t values Improvement (and actual Liang-Barsky): –compute t’s for each edge in turn (some rejects occur earlier like this.)

17 Nicholl-Lee-Nicholl clipping Some edges are irrelevant to clipping, particularly if one vertex lies inside region. Cases: –x 1 in –x 1 in corner region –x 1 in edge region For each case, we generate specialized test regions for x 2, which use simple tests (slope, >, <), and tell which edges to clip against.

18 Nicholl-Lee-Nicholl (2) Special cases for each endpoint location and slope Number of cases explodes in 3D, making it unsuitable 12 3 4 Reject Top Top, Right Top, Bottom Left Left, bottom

19 Weiler Atherton Polygon Clipping For clockwise polygon: –for out-to-in pair, follow usual rule –for in-to-out pair, follow clip edge Easiest to start outside

20 General Clipping Clipping general against general polygons is quite hard Outline of Weiler algorithm: –Replace crossing points with vertices –Double all edges and form linked lists of edges –Change links at vertices –Enumerate polygon patches Can use clipping to break concave polygon into convex pieces; main issue is inside-outside for edges

21 Weiler Algorithm (1)

22 Changes to Rearranging pointers makes it possible to enumerate all components of the intersection


Download ppt "Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and."

Similar presentations


Ads by Google