ClippingHardware Sutherland-HodgmanInside-Outside TestingInside/Outside in Screen SpaceFinding Intersection Pts Watt Sect 1.4.3, 1.4.4Additional Clipping PlanesClipping LinesCohen-Sutherland (1)Cohen-Sutherland (2)Cohen-Sutherland (3)Cohen-Sutherland - DetailsLiang-Barsky ClippingLiang-Barsky (2)Liang-Barsky (3)Liang-Barsky (4)Liang-Barsky - AlgorithmNicholl-Lee-Nicholl clippingNicholl-Lee-Nicholl (2)Weiler Atherton Polygon ClippingGeneral ClippingWeiler Algorithm (1)PowerPoint PresentationClipping•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 boxesHardware 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 edgeClip TopVertices inClip RightClip BottomClip LeftClipped vertices outInside-Outside Testing•Edges/Planes store a vector pointing toward the outside of the clip region•Dot products give inside/outside informationOutside Insidensfix000---x)(fnx)(inx)(sns-xInside/Outside in Screen Space•In screen space, clip planes are xs=±1, ys=±1, zs=0, zs=1•Inside/Outside reduces to comparisons before perspective dividesssssssswzwywwxw0Finding Intersection Pts Watt Sect 1.4.3, 1.4.4•Use the parametric form for the line between two points, x1 and x2:•For planes of the form x=a:•Similar forms for y=a, z=a•Solution for general plane in textbook10 )()(121 ttt xxxx))()()(),()()(,(112121112121xaxxzzzxaxxyyyaixAdditional 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)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-NichollCohen-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 continueCohen-Sutherland (2)1 2341 234341 234Cohen-Sutherland (3)•Some cases lead to premature acceptance or rejection–If both endpoints are inside all edges–If both endpoints are outside one edgeCohen-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(x1)&outcode(x2)!=0•Trivial accept:–outcode(x1)|outcode(x2)==0•Which edges to clip against?–outcode(x1)^outcode(x2)1 23400100101Liang-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:12max1min12max1min yyyyytyyxxxxxtxxLiang-Barsky (2)•Infinite line intersects clip region edges when:kkkpqt p1 x q1x1 xminp2x q2xmax x1p3 y q3y1 yminp4y q4 ymax y1whereLiang-Barsky (3)•When pk<0, as t increases line goes from outside to inside - enter•When pk>0, line goes from inside to outside - leave•When pk=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, leaveLiang-Barsky (4)EnterEnterLeaveLeaveEnterLeaveEnterLeaveLiang-Barsky - Algorithm•Compute entering t values, which are qk/pk for each pk<0•Compute leaving t values, which are qk/pk for each pk>0•Parameter value for small t end of line is:tsmall= max(0, entering t’s)•parameter value for large t end of line is: tlarge=min(1, leaving t’s)•if tsmall<tlarge, 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.)Nicholl-Lee-Nicholl clipping•Some edges are irrelevant to clipping, particularly if one vertex lies inside region.•Cases: –x1 in–x1 in corner region–x1 in edge region•For each case, we generate specialized test regions for x2, which use simple tests (slope, >, <), and tell which edges to clip against. aaaNicholl-Lee-Nicholl (2)•Special cases for each endpoint location and slope•Number of cases explodes in 3D, making it unsuitable1 234RejectTopTop, RightTop, BottomLeftLeft, bottomWeiler 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 outsideInside12345678go upgo upGeneral 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 edgesWeiler Algorithm (1)Changes toRearranging pointersmakes it possible to enumerate all componentsof the
View Full Document