1 / 38

Clipping

Clipping. Culling and Clipping. What can’t we see? anything occluded by another object (HSR) anything outside view volume Today: clipping. Clipping Against a Rectangular Region Multiple Cases. B. F. E. C. G. A. D. H. Clip Rectangle. Division of Space. Clip Region. 1. 0. 1. 0.

olinda
Download Presentation

Clipping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Clipping

  2. Culling and Clipping • What can’t we see? • anything occluded by another object (HSR) • anything outside view volume • Today: clipping

  3. Clipping Against a Rectangular RegionMultiple Cases B F E C G A D H Clip Rectangle

  4. Division of Space Clip Region

  5. 1 0 1 0 Cohen-Sutherland Clipping:“Outcodes”

  6. Cohen-Sutherland Clipping:Region Outcodes 1001 1000 1010 0001 0000 0010 0100 0110 0101

  7. Cohen-Sutherland Clipping:Trivial Acceptance: O(P0) = O(P1) = 0 1001 1000 1010 P1 0001 0000 0010 P0 0100 0110 0101

  8. Cohen-Sutherland Clipping:Trivial Rejection: O(P0) & O(P1)  0 P0 1001 1000 1010 P1 P0 0001 0000 0010 P0 P1 P1 0100 0110 0101

  9. Cohen-Sutherland Clipping:O(P0) =0 , O(P1)  0 1001 1000 1010 P0 0001 0000 0010 P1 P1 P0 P0 0100 0110 0101 P1

  10. 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

  11. Cohen-Sutherland Clipping:Example 1 A 1001 1000 1010 B C 0001 0000 0010 0100 0110 0101

  12. Cohen-Sutherland Clipping:Example 1 1001 1000 1010 B C 0001 0000 0010 0100 0110 0101

  13. Chopping at each boundary

  14. Cohen-Sutherland Clipping:Example 2 1001 1000 1010 E D 0001 0000 0010 C B A 0100 0110 0101

  15. Cohen-Sutherland Clipping:Example 2 1001 1000 1010 E D 0001 0000 0010 C B 0100 0110 0101

  16. Cohen-Sutherland Clipping:Example 2 1001 1000 1010 D 0001 0000 0010 C B 0100 0110 0101

  17. Cohen-Sutherland Clipping:Example 2 1001 1000 1010 0001 0000 0010 C B 0100 0110 0101

  18. 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

  19. Cohen Sutherland in 3D • Use 6-bit outcodes • When needed, clip line segment against planes

  20. 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

  21. Parametric Representation of Lines

  22. 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 a where the line determined by the line segment crosses the lines that determine the window p(a) = (1-a)p1+ ap2 1  a  0 p2 p1

  23. Liang-Barsky Parametric Clipping Edge Ei Outside Inside

  24. Potentially Entering (PE) and Potentially Leaving (PL) Points Edge Ei Edge Ei Outside Inside Inside Outside Potentially Entering (PE) Point Potentially Leaving (PL) Point

  25. Liang-Barsky Clipping:Computing the Intersection

  26. Liang-Barsky Clipping:Potentially Leaving vs. Potentially Entering PE PL PL PL PE PL PE PE = “Inside”

  27. 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.

  28. 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 (Ni•D!=0) { /*edges not parallel to line*/ calculate alpha; use sign of Ni•D 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

  29. Polygon Clipping:Convex Polygons 5 4 5’ 4’ 1 3 1 3 2 2 Line segment clipping is done in order. New vertices are generated at clip point. External vertices are eliminated.

  30. Polygon Clipping:The Convexity Problem Single object becomes multiple objects.

  31. Top Bottom Right Left Sutherland-Hodgeman Polygon Clipping

More Related