1 / 27

CS U540 Computer Graphics

CS U540 Computer Graphics. Prof. Harriet Fell Spring 2007 Lectures 16 – February 14, 2007 17 – February 15, 2007 18 – February 21, 2007. Clipping Lines. G. D. C. F. A. F’. G’. E. B. K. H’. J. H. Intersections. We know how to find the intersections of a line segment

richardsonj
Download Presentation

CS U540 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. CS U540Computer Graphics Prof. Harriet Fell Spring 2007 Lectures 16 – February 14, 2007 17 – February 15, 2007 18 – February 21, 2007

  2. Clipping Lines G D C F A F’ G’ E B K H’ J H

  3. Intersections We know how to find the intersections of a line segment P + t(Q-P) with the 4 boundaries x = xmin x = xmax y = ymin y = ymax Q P

  4. 1100 1000 1001 0001 0000 0100 0010 0011 0110 above left below right Cohen-Sutherland Clipping • Assign a 4 bit outcode to each endpoint. //above left below right int outcode(x,y,xmin,xmax,ymin,ymax) { int code=0; if(x > xmax) code |= 1; //right if(y < ymin) code |= 2; //below if(x < xmin) code |= 4; //left if(y > ymax) code |= 8; //above return(code); }

  5. 1100 1000 1001 0001 0000 0100 0010 0011 0110 above left below right Cohen-Sutherland Clipping • Identify lines that are trivially accepted or trivially rejected. • if(outcode(P)|outcode(Q)==0) accept • else if(outcode(P)&outcode(Q))!=0) • reject • else test further

  6. Cohen-Sutherland continued Clip against one boundary at a time, top, left, bottom, right. Check for trivial accept or reject. If a line segment PQ falls into the “test further” category then if (outcode(P) & 1000  0) replace P with PQ intersect y = top else if (outcode(Q) & 1000  0) replace Q with PQ intersect y = top go on to next boundary

  7. G G’ ACCEPT G’’ H’ H

  8. Cohen-Sutherland Applet • Cohen-Sutherland Applet • By Patrick Min, CS Department, Princeton University

  9. Liang-Barsky Clipping Clip window interior is defined by: xleft  x xright ybottom  y ytop

  10. Liang-Barsky continued V1 = (x1, y1) x = x0 + tx x = x1 - x0 y = y0 + ty y = y1 - y0 t = 0 at V0 t = 1 at V1 V0 = (x0, y0)

  11. Liang-Barsky continued Put the parametric equations into the inequalities: xleft  x0 + tx xright ybottom  y0 + ty ytop -tx x0 - xleft tx xright - x0 -ty y0 - ybottom ty ytop - y0 These decribe the interior of the clip window in terms of t.

  12. Liang-Barsky continued -tx x0 - xleft tx xright - x0 -ty y0 - ybottom ty ytop - y0 • These are all of the form tp  q • For each boundary, we decide whether to accept, reject, or which point to change depending on the sign of p and the value of t at the intersection of the line with the boundary.

  13. t  (x0 – xleft)/(-x) = q/p t = (x0 – xleft)/(x0 – x1 ) is between 0 and 1. x = x1 – x0 > 0 so p < 0  replace V0 x = xleft p = - x V1 t  V0 V1 t = (x0 – xleft)/(x0 – x1 ) is between 0 and 1. x = x1 – x0 < 0 so p > 0  replace V1  t V0

  14. V0 p > 0 t > 1 V1 p < 0 so might replace V0 but t = (x0 – xleft)/(x0 – x1 ) > 1 so reject. V1 V0 t  p > 0 so might replace V1 but t = (x0 – xleft)/(x0 – x1 ) < 0 so reject. V0  t V1 p = - x x = tleft V1 p < 0 so might replace V0 but t = (x0 – xleft)/(x0 – x1 ) < 0 so no change. V0 t 

  15. Liang-Barsky Rules • 0 < t < 1, p < 0 replace V0 • 0 < t < 1, p > 0 replace V1 • t < 0, p < 0 no change • t < 0, p > 0 reject • t > 1, p > 0 no change • t > 1, p < 0 reject

  16. Polygon Clipping

  17. Sutherland-Hodgeman Polygon Clipping Algorithm • Clip one boundary at a time: left, top, right, bottom. • Check each adjacent pair of vertices (P,Q), in order to make a new vertex list. • If P is out and Q is in, add intersection point with boundary and Q. • If P and Q are in, add Q. • If P is in and Q is out, add the intersection point with boundary only. • If P and Q are both out, add nothing.

  18. Clip Left L2 L1 Sutherland-HodgemanClipping Example V1 New Vertex List V2 V2 V3 If P is in and Q is out, add the intersection point with boundary only. If P is out and Q is in, add intersection point with boundary and Q. V4 If P and Q are in, add Q. V6 V5 L1 V5 L2 V3 V1 V4

  19. Clip Left L2 Clip Top Sutherland-HodgemanClipping Example V1 New Vertex List V2 V2 V3 V4 V5 L1 L1 V5 L2 V3 V1 V4

  20. L2 Clip Top T2 T1 Sutherland-HodgemanClipping Example V1 New Vertex List V2 T1 V3 If P is out and Q is in, add intersection point with boundary and Q. V4 If P is in and Q is out, add the intersection point with boundary only. If P and Q are both out, add nothing. If P and Q are in, add Q. V5 L1 L1 V5 L2 V3 T2 V4

  21. L2 Clip Top T2 T1 Clip Right Sutherland-HodgemanClipping Example New Vertex List T1 V3 V4 V5 L1 L1 V5 L2 V3 T2 V4

  22. L2 R1 T2 T1 R2 Clip Right Sutherland-HodgemanClipping Example New Vertex List R1 R2 V4 V5 L1 L1 V5 L2 V3 T2 T1 V4

  23. L2 T2 T1 R1 B2 R2 B1 Clip Bottom Sutherland-HodgemanClipping Example New Vertex List R2 B1 B2 V5 L1 L1 V5 L2 T2 T1 R1 V4

  24. L2 T1 T2 R1 B2 B1 R2 Sutherland-HodgemanClipping Example New Vertex List R2 B1 B2 V5 L1 L1 V5 L2 T2 T1 R1

  25. Sutherland-Hodgeman Exercise 1 Vertex List initial after after after after left top right bottom A B C D A D B C

  26. Sutherland-Hodgeman Exercise 2 Vertex List initial after after after after left top right bottom H I I A A A B B B C C C D D D E E E F F F G G G H H I A G R1 I B R4 D F R3 E R2 H C

  27. Sutherland-Hodgeman Exercise 2 Vertex List initial after after after after left top right bottom H I I A A A R1 K B B B R2 B1 C C C D D D D D R3 B2 E E E R4 K F F F G R4 G G G H G H H I B3 I A B4 I A R1 A G R1 I B R4 D F B4 B2 B3 K R3 B1 E R2 H C

More Related