Download presentation
Presentation is loading. Please wait.
Published byChristina Lamb Modified over 9 years ago
1
1 Clipping
2
2 Transformation Sequence X Y Z X Y Z X Y Z X Y Z Object Coords. Eye Coords. Clip Coords. Normalized Device Coords. Screen Coords. Implementation: 4 x 4 matrix multiplication in homogeneous coords.
3
3 Culling and Clipping What can’t we see? -anything occluded by another object (HSR) -anything outside view volume Today: clipping
4
4
5
5
6
6
7
7
8
8
9
9
10
10
11
11 Clipping Against a Rectangular Region Multiple Cases A B C D E F Clip Rectangle G H
12
12 Division of Space Clip Region
13
13 Cohen-Sutherland Clipping: “Outcodes” 1100
14
14 Cohen-Sutherland Clipping: Region Outcodes 100110001010 0001 0101 01000110 00100000
15
15 Cohen-Sutherland Clipping: Trivial Acceptance: O(P0) = O(P1) = 0 100110001010 0001 0101 01000110 00100000 P0 P1
16
16 Cohen-Sutherland Clipping: Trivial Rejection: O(P0) & O(P1) 0 100110001010 0001 0101 01000110 00100000 P0 P1 P0
17
17 Cohen-Sutherland Clipping: O(P0) =0, O(P1) 0 100110001010 0001 0101 01000110 00100000 P0 P1 P0
18
18 Cohen-Sutherland Clipping: The Algorithm Compute the outcodes for the two vertices Test for trivial acceptance or rejection Select a vertex for which outcode is not zero -There will always be one Select the first nonzero bit in the outcode to define the boundary against which the line segment will be clipped Compute the intersection and replace the vertex with the intersection point Compute the outcode for the new point and iterate
19
19 Cohen-Sutherland Clipping: Example 1 100110001010 0001 0101 01000110 00100000 A B C
20
20 Cohen-Sutherland Clipping: Example 1 100110001010 0001 0101 01000110 00100000 B C
21
21 Chopping at each boundary
22
22 Cohen-Sutherland Clipping: Example 2 100110001010 0001 0101 01000110 00100000 B C A D E
23
23 Cohen-Sutherland Clipping: Example 2 100110001010 0001 0101 01000110 00100000 B C D E
24
24 Cohen-Sutherland Clipping: Example 2 100110001010 0001 0101 01000110 00100000 B C D
25
25 Cohen-Sutherland Clipping: Example 2 100110001010 0001 0101 01000110 00100000 B C
26
26 Cohen-Sutherland Clipping: Advantages/Extension Easily extended to 3 dimensions by adding two bits to the outcode for the z axis. Calculations then reduce to intersection of line with plane Algorithm most efficient when most segments can either be trivially accepted or trivially rejected
27
27 Cohen Sutherland in 3D Use 6-bit outcodes When needed, clip line segment against planes
28
28 Other Clipping Algorithm Cyrus–Beck, Liang–Barsky - generally, these try to be more clever about intersections -represent lines parametrically, solve for intersection t values P(t) = P0 + t(P1-P0) -can clip in fewer steps than Cohen–Sutherland -try to increase number of trivial rejection cases
29
29 Parametric Representation of Lines
30
30 Liang-Barsky Clipping Consider the parametric form of a line segment We can distinguish between the cases by looking at the ordering of the values of where the line determined by the line segment crosses the lines that determine the window p( ) = (1- )p 1 + p 2 1 0 p1p1 p2p2
31
31 Liang-Barsky Parametric Clipping Edge Ei InsideOutside
32
32 Potentially Entering (PE) and Potentially Leaving (PL) Points Edge Ei InsideOutside Edge Ei InsideOutside Potentially Entering (PE) Point Potentially Leaving (PL) Point
33
33 Liang-Barsky Clipping: Computing the Intersection
34
34 Liang-Barsky Clipping: Potentially Leaving vs. Potentially Entering = “Inside” PE PL
35
35 Liang-Barsky Clipping: Algorithm Strategy Find the largest PE greater than zero. Find the smallest PL less than one. Reject the segment if PE > PL.
36
36 Liang-Barsky Clipping: Pseudocode of Algorithm for (each line segment to be clipped) alpha_E=0; alpha_L=1; for (each candidate intersection with a clip edge) { if (NiD!=0) { /*edges not parallel to line*/ calculate alpha; use sign of NiD to class alpha as PE or PL; if (PE) alpha_E = max(alpha_E,alpha); if (PL) alpha_L = min(alpha_L,alpha); } if (alpha_E > alpha_L) return NULL; else return P(alpha_E) and P(alpha_L) as clip intersections
37
37 Polygon Clipping: Convex Polygons Line segment clipping is done in order. New vertices are generated at clip point. External vertices are eliminated. 1 2 3 4 5 1 2 3 4’5’
38
38 Polygon Clipping: The Convexity Problem Single object becomes multiple objects.
39
39 Sutherland-Hodgeman Polygon Clipping TopBottomRight Left
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.