1 / 119

CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai

CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai. GL_LINES. GL_POLYGON. GL_LINE_STRIP. GL_LINE_LOOP. GL_POINTS. GL_TRIANGLES. GL_QUADS. GL_TRIANGLE_FAN. GL_TRIANGLE_STRIP. GL_QUAD_STRIP. OpenGL Geometric Primitives. All geometric primitives are specified by vertices. Why Clip?.

olsonc
Download Presentation

CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai

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. CSCE 441 Computer Graphics:Clipping LinesJinxiang Chai

  2. GL_LINES GL_POLYGON GL_LINE_STRIP GL_LINE_LOOP GL_POINTS GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN GL_TRIANGLE_STRIP GL_QUAD_STRIP OpenGL Geometric Primitives • All geometric primitives are specified by vertices

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

  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,ymin)

  5. 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?

  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=<x<=xmax? (xmin,ymin) ymin=<y<=ymax?

  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=<x1<=xmax Yes (xmin,ymin) ymin=<y1<=ymaxYes

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

  9. Clipping Lines

  10. Clipping Lines

  11. 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)

  12. Clipping Lines

  13. Outline • Simple line clipping algorithm • Cohen-Sutherland • Liang-Barsky • Required readings: HB 8-5, 8-6, 8-7 and 8-9

  14. Clipping Lines

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

  16. Clipping Lines – Simple Algorithm

  17. Clipping Lines – Simple Algorithm

  18. Intersecting Two Lines

  19. Intersecting Two Lines

  20. Intersecting Two Lines

  21. Intersecting Two Lines

  22. Intersecting Two Lines

  23. Intersecting Two Lines Substitute t or s back into equation to find intersection

  24. Clipping Lines – Simple Algorithm

  25. Clipping Lines – Simple Algorithm

  26. Clipping Lines – Simple Algorithm

  27. Clipping Lines – Simple Algorithm

  28. Clipping Lines – Simple Algorithm

  29. Clipping Lines – Simple Algorithm

  30. Clipping Lines – Simple Algorithm

  31. Clipping Lines – Simple Algorithm

  32. Clipping Lines – Simple Algorithm

  33. Clipping Lines – Simple Algorithm

  34. Clipping Lines – Simple Algorithm

  35. Clipping Lines – Simple Algorithm

  36. Clipping Lines – Simple Algorithm

  37. Clipping Lines – Simple Algorithm

  38. Clipping Lines – Simple Algorithm

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

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

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

  42. Trivial Rejects • How can we know a line is outside of the window • Answer:

  43. Trivial Rejects • How can we know a line is outside of the window • Answer: Wrong side

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

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

  46. 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 edges bit 4 bit 3 bit 2 bit 1 top bottom right left If inside, set the corresponding bit to 0; otherwise set it to 1.

  47. Cohen-Sutherland Algorithm bit 4 bit 3 bit 2 bit 1 top bottom right left top right left Region code? bottom

  48. Cohen-Sutherland Algorithm bit 4 bit 3 bit 2 bit 1 top bottom right left top right left 0010 bottom ?

  49. Cohen-Sutherland Algorithm bit 4 bit 3 bit 2 bit 1 top bottom right left top right left 0010 bottom 0100

  50. Cohen-Sutherland Algorithm

More Related