1 / 94

Efficient Clipping Algorithms in Computer Graphics

Learn about clipping objects within a defined window to optimize rendering. Explore point and line clipping algorithms like Cohen-Sutherland for accurate visualization.

Download Presentation

Efficient Clipping Algorithms in Computer Graphics

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 Lines Dr. Scott Schaefer

  2. Why Clip? • We do not want to waste time drawing objects that are outside of viewing window (or clipping window)

  3. Clipping Points • Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn (xmax,ymax) (x,y) (xmin,ymin)

  4. Clipping Points • Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn (xmax,ymax) (x,y) xmin<=x<=xmax? (xmin,ymin) ymin<=y<=ymax?

  5. Clipping Points • Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn (xmax,ymax) (x2,y2) (x1,y1) xmin<=x<=xmax? (xmin,ymin) ymin<=y<=ymax?

  6. Clipping Points • Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn (xmax,ymax) (x2,y2) (x1,y1) xmin<=x1<=xmax Yes (xmin,ymin) ymin<=y1<=ymaxYes

  7. Clipping Points • Given a point (x, y) and clipping window (xmin, ymin), (xmax, ymax), determine if the point should be drawn (xmax,ymax) (x2,y2) (x1,y1) xmin<=x2<=xmaxNo (xmin,ymin) ymin<=y2<=ymax Yes

  8. Clipping Lines

  9. Clipping Lines

  10. Clipping Lines • Given a line with end-points (x0, y0), (x1, y1) and clipping window (xmin, ymin), (xmax, ymax), determine if line should be drawn and clipped end-points of line to draw. (xmax,ymax) (x1, y1) (x0, y0) (xmin,ymin)

  11. Clipping Lines

  12. Clipping Lines – Simple Algorithm • If both end-points inside rectangle, draw line • Otherwise, intersect line with all edges of rectangle clip that point and repeat test

  13. Clipping Lines – Simple Algorithm

  14. Clipping Lines – Simple Algorithm

  15. Clipping Lines – Simple Algorithm

  16. Clipping Lines – Simple Algorithm

  17. Clipping Lines – Simple Algorithm

  18. Clipping Lines – Simple Algorithm

  19. Clipping Lines – Simple Algorithm

  20. Clipping Lines – Simple Algorithm

  21. Clipping Lines – Simple Algorithm

  22. Clipping Lines – Simple Algorithm

  23. Clipping Lines – Simple Algorithm

  24. Window Intersection (x1, y1), (x2, y2) intersect with vertical edge at xright • yintersect = y1 + m(xright – x1) where m=(y2-y1)/(x2-x1) (x1, y1), (x2, y2) intersect with horizontal edge at ybottom • xintersect = x1 + (ybottom – y1)/m where m=(y2-y1)/(x2-x1)

  25. Clipping Lines – Simple Algorithm • Lots of intersection tests makes algorithm expensive • Complicated tests to determine if intersecting rectangle • Is there a better way?

  26. Trivial Accepts • Big Optimization: trivial accepts/rejects • How can we quickly decide whether line segment is entirely inside window • Answer: test both endpoints

  27. Trivial Accepts • Big Optimization: trivial accepts/rejects • How can we quickly decide whether line segment is entirely inside window • Answer: test both endpoints

  28. Trivial Rejects • How can we know a line is outside of the window • Answer: both endpoints on wrong side of same edge, can trivially reject the line

  29. Trivial Rejects • How can we know a line is outside of the window • Answer: both endpoints on wrong side of same edge, can trivially reject the line

  30. Cohen-Sutherland Algorithm • Classify p0, p1 using region codes c0, c1 • If , trivially reject • If , trivially accept • Otherwise reduce to trivial cases by splitting into two segments

  31. Cohen-Sutherland Algorithm • Every end point is assigned to a four-digit binary value, i.e. Region code • Each bit position indicates whether the point is inside or outside of a specific window edge bit 4 bit 3 bit 2 bit 1 top bottom right left

  32. Cohen-Sutherland Algorithm

  33. Cohen-Sutherland Algorithm • Classify p0, p1 using region codes c0, c1 • If , trivially reject • If , trivially accept • Otherwise reduce to trivial cases by splitting into two segments

  34. Cohen-Sutherland Algorithm • Classify p0, p1 using region codes c0, c1 • If , trivially reject • If , trivially accept • Otherwise reduce to trivial cases by splitting into two segments

  35. Cohen-Sutherland Algorithm • Classify p0, p1 using region codes c0, c1 • If , trivially reject • If , trivially accept • Otherwise reduce to trivial cases by splitting into two segments Line is outside the window! reject

  36. Cohen-Sutherland Algorithm • Classify p0, p1 using region codes c0, c1 • If , trivially reject • If , trivially accept • Otherwise reduce to trivial cases by splitting into two segments Line is inside the window! draw

  37. Cohen-Sutherland Algorithm • Classify p0, p1 using region codes c0, c1 • If , trivially reject • If , trivially accept • Otherwise reduce to trivial cases by splitting into two segments

  38. Cohen-Sutherland Algorithm

  39. Cohen-Sutherland Algorithm

  40. Cohen-Sutherland Algorithm

  41. Cohen-Sutherland Algorithm

  42. Cohen-Sutherland Algorithm

  43. Cohen-Sutherland Algorithm

  44. Cohen-Sutherland Algorithm

  45. Cohen-Sutherland Algorithm

  46. Cohen-Sutherland Algorithm

  47. Cohen-Sutherland Algorithm

  48. Cohen-Sutherland Algorithm

  49. Cohen-Sutherland Algorithm

  50. Cohen-Sutherland Algorithm

More Related