Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.

Clipping 22

1.527 visualizaciones

Publicado el


  • Sé el primero en comentar

Clipping 22

  1. 1. Drawing with Thick Primitives<br />Drawing with Thick Primitives<br />• How do we thicken<br />the line stroke width?<br />• Ideas:<br />– Place the center of<br />the circular “brush” on<br />the pixel<br />– Place the upper<br />corner of the square<br />“marker” on the pixel<br />(issues of orientation)<br />– Then do scan<br />conversion algorithm<br />
  2. 2. Why Clip?<br />Rasterization is very expensive<br />Approximately linear with number of fragments created<br />Math and logic per pixel<br />If we only rasterize what is actually viewable, we can save a lot<br />A few operations now can save many later<br />
  3. 3. Clipping Primitives<br />Different primitives can be handled in different ways<br />Points<br />Lines<br />Polygons<br />
  4. 4. 159.235<br />Graphics<br />4<br />Viewing & Clipping - Outline<br />Viewing in 2D<br />Clipping in 2D<br />Cohen-Sutherland Algorithm<br />Cyrus & Beck Algorithm<br />Clipping Polygons<br />Sutherland-Hodgman Algorithm<br />
  5. 5. 159.235<br />Graphics<br />5<br />Viewing in 2D - Viewport<br />250<br />45<br />Window in world coordinates.<br />250 x 250<br />Pixels.<br />Viewport in<br />Device coords<br />
  6. 6. 159.235<br />Graphics<br />6<br />Clipping in 2D<br />Need to clip primitives (eg lines) against the sides of the viewing window<br />e.g lines or polygons<br />We only see what is inside the window<br />
  7. 7. 159.235<br />Graphics<br />7<br />Trivial Clipping Acceptance<br />If all a line’s vertices lie inside box we “accept” it<br />
  8. 8. 159.235<br />Graphics<br />8<br />Trivial Vertex Rejection<br />All line vertices lie outside and on same side  reject.<br />
  9. 9. 159.235<br />Graphics<br />9<br />This is an efficient method of accepting or rejecting lines that do not intersect the window edges.<br />Assign a binary 4 bit code to each vertex :<br />First bit : above top of window, y > ymax<br />Second bit : below bottom, y < ymin<br />Third bit : to right of right edge, x > xmax<br />Fourth bit : to left of left edge, x < xmin<br />4-bit code called: Outcode<br />Cohen-Sutherland Clipping Algorithm<br />
  10. 10. Cohen-Sutherland Line Clipping<br />Divide 2D space into 3x3 regions.<br />Middle region is the clipping window.<br />Each region is assigned a 4-bit code.<br />Bit 1 is set to 1 if the region is to the left of the clipping window, 0 otherwise. Similarly for bits 2, 3 and 4.<br />4<br />3<br />2<br />1<br />Top Bottom Right Left<br />
  11. 11. Cohen-Sutherland Line Clipping<br />1010<br />1000<br />1001<br />0000<br />0010<br />0001<br />0100<br />0110<br />0101<br />
  12. 12. 159.235<br />Graphics<br />12<br />Cohen-Sutherland Algorithm<br />1001<br />1000<br />1010<br />0000<br />0001<br />0010<br />0100<br />0110<br />0101<br /> Both endpoint codes 0000, trivial acceptance, else:<br /> Do logical AND of Outcodes (reject if non-zero)<br />
  13. 13. Cohen-Sutherland Line Clipping<br />For those lines that we cannot immediately determine, we successively clip against each boundary.<br />Then check the new endpoint for its region code.<br />How to find boundary intersection: To find y coordinate at vertical intersection, substitute x value at the boundary into the line equation of the line to be clipped.<br />Other algorithms:<br />Faster: Cyrus-Beck<br />Even faster: Liang-Barsky<br />Even faster: Nichol-Lee-Nichol<br />
  14. 14. 159.235<br />Graphics<br />14<br />Clipping Polygons<br />Clip polygons by clipping successively against 4 sides.<br />
  15. 15. 159.235<br />Graphics<br />15<br />Clipping Polygons<br />Clip polygons by clipping successively against all 4 sides<br />Can implement as pipelined algorithm (ie special hardware can do the work)<br />Recursively test each edge.<br />Form new edge with next vertex<br />Call with new edge<br />
  16. 16. 159.235<br />Graphics<br />16<br />Four cases of polygon clipping:<br />Inside<br />Outside<br />Inside<br />Outside<br />Inside<br />Outside<br />Inside<br />Outside<br />Output<br />Intersection<br />Second<br />Output<br />Case 3<br />No output.<br />Case 1<br />Case 2.<br />Case 4<br />Sutherland-Hodgman Clipping Algorithm<br />First<br />Output<br />Output<br />Vertex<br />
  17. 17. 159.235<br />Graphics<br />17<br />Sutherland-Hodgman Algorithm<br />Loop round vertices, test each against all 4 clipping planes in sequence<br />Call algorithm again with new edge formed by next vertex -re-entrant<br />No storage requirement between stages<br />Easy to implement in hardware<br />
  18. 18. 18<br />Viewing & Clipping - Summary<br />Window and Viewport<br />Clipping cuts out what we do not “see”<br />Also reduces unnecessary computation<br />Can be done at various levels<br />Java 2D system does a lot of the clipping for us if we use that rendering pipeline<br />