1 / 120

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.

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. Review: Drawing General Polygons • How to draw every interior pixels? ? Scanline conversion of polygons!

  4. Review: Curved Boundaries • How to deal with curved boundaries? Boundary fill algorithm!

  5. Review: How to deal with this? • Multiple color boundaries? Flood fill algorithm!

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

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

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

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

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

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

  12. Clipping Lines

  13. Clipping Lines

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

  15. Clipping Lines

  16. Outline • Simple line clipping algorithm • Cohen-Sutherland • Liang-Barsky

  17. Clipping Lines

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

  19. Clipping Lines – Simple Algorithm

  20. Clipping Lines – Simple Algorithm

  21. Intersecting Two Lines

  22. Intersecting Two Lines

  23. Intersecting Two Lines

  24. Intersecting Two Lines

  25. Intersecting Two Lines

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

  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

  40. Clipping Lines – Simple Algorithm

  41. Clipping Lines – Simple Algorithm

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

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

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

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

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

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

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

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

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

More Related