1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai.

Slides:



Advertisements
Similar presentations
Computer Graphics Inf4/MSc 1 Computer Graphics Lecture 7 Scanline algorithm and polygon clipping Taku Komura.
Advertisements

Rezanje črt in poligonov. World window & viewport window viewport screen window world window.
I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam September 30, D Clipping 1/14 Clipping (pages , )
Computer Graphics CLIPPING.
Objectives Define Clipping Various clipping methods. Line clipping methods.
Line clipping: Line clipping algorithm is method of eliminate lines of outside area of the object,so outside of object viewing is Removed. Typically, any.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
CS 551 / 645: Introductory Computer Graphics Clipping Lines and Polygons.
CS 445 / 645 Introduction to Computer Graphics Lecture 9 Clipping Clipping.
3/2/04© University of Wisconsin, CS559 Spring 2004 Last Time General Perspective –Methods for specifying the view volume As a set of clip planes As a field.
David Breen, William Regli and Maxim Peysakhov
Dr. Scott Schaefer Clipping Lines. 2/94 Why Clip? We do not want to waste time drawing objects that are outside of viewing window (or clipping window)
Course Website: Computer Graphics 4: Viewing In 2D.
1 Clipping. 2 Transformation Sequence X Y Z X Y Z X Y Z X Y Z Object Coords. Eye Coords. Clip Coords. Normalized Device Coords. Screen Coords. Implementation:
Two-Dimensional Viewing Jehee Lee Seoul National University.
Computer Graphics : Clipping
Computer Graphics Viewing.
Clipping CSE 403 Computer Graphics Cohen Sutherland Algorithm (Line)
Viewing & Clipping In 2D. 2 of 44 Contents Windowing Concepts Clipping –Introduction –Brute Force –Cohen-Sutherland Clipping Algorithm Area Clipping –Sutherland-Hodgman.
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
Introduction to Computer Graphics Chapter 6 – 2D Viewing Pt 2 1.
March 1, 2009Dr. Muhammed Al-Mulhem1 ICS 415 Computer Graphics Clipping Dr. Muhammed Al-Mulhem March 1, 2009 Dr. Muhammed Al-Mulhem March 1, 2009.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2007 Tamara Munzner Clipping Week 8, Wed Mar.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2005 Tamara Munzner Interpolation Clipping.
Informationsteknologi Thursday, November 22, 2007Computer Graphics - Class 111 Today’s class Clipping Parametric and point-normal form of lines Intersecting.
Vertices and Fragments I CS4395: Computer Graphics 1 Mohan Sridharan Based on slides created by Edward Angel.
CSCE 441: Computer Graphics Scan Conversion of Polygons
Computer Graphics Clipping Cohen Sutherland Algorithm (Line) Cyrus-Back Algorithm (Line) Sutherland-Hodgeman Algorithm (Polygon) Cohen Sutherland Algorithm.
1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Clipping.
1 Angel: Interactive Computer Graphics 4E © Addison-Wesley 2005 Implementation I Ed Angel Professor of Computer Science, Electrical and Computer Engineering,
Graphics Pipeline Clipping CMSC 435/634. Graphics Pipeline Object-order approach to rendering Sequence of operations – Vertex processing – Transforms.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
2-Dimension Viewing and Clipping
Clipping Apart from clipping to the view volume, clipping is a basic operation in many other algorithms –Breaking space up into chunks –2D drawing and.
CGMB 314 Intro to Computer Graphics Fill Area Primitives.
CS 376 Introduction to Computer Graphics 02 / 12 / 2007 Instructor: Michael Eckmann.
Clipping: Clipping is a process of dividing an object into visible and invisible positions and displaying the visible portion and discarding the invisible.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Objectives Introduce basic implementation strategies Clipping Scan conversion.
Clipping Aaron Bloomfield CS 445: Introduction to Graphics Fall 2006 (Slide set originally by David Luebke)
CS 480/680 Computer Graphics Shading in OpenGL Dr. Frederick C Harris, Jr. Fall 2013.
CSE Real Time Rendering Week 9. Post Geometry Shaders Courtesy: E. Angel and D. Shreiner – Interactive Computer Graphics 6E © Addison-Wesley 2012.
Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
EEL Introduction to Computer Graphics
1 Computer Graphics Clipping Fall FCC Line Clipping What happens when one or both endpoints of a line segment are not inside the specified drawing.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
Computer Graphics Lecture 20 Fasih ur Rehman. Last Class Clipping – What is clipping – Why we do clipping – How clipping is done.
1Computer Graphics Implementation 1 Lecture 15 John Shearer Culture Lab – space 2
Clipping Primitives. Clipping line Clipping rectangle: – x min to x max – y min to y max A point (x,y) lies within a clip rectangle and thus displayed.
Graphics Graphics & Graphical Programming Lecture 23 - Viewing & Clipping.
1 CSCE 441: Computer Graphics Scan Conversion of Polygons Jinxiang Chai.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics Lecture 14 CLIPPING I Taqdees A. Siddiqi
Computer Graphics Clipping.
Computer Graphics CC416 Week 13 Clipping.
CS 551 / 645: Introductory Computer Graphics
Computer Graphics Shading in OpenGL
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Concepts, algorithms for clipping
Graphics Pipeline Clipping
CSCE 441 Lecture 2: Scan Conversion of Lines
Computer Graphics : Viewing In 2D
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai
Lecture 13 Clipping & Scan Conversion
CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai
Segment Clipping Simple algorithm. For each segment compute the intersection with the four sides of the rectangle, and then determine which sub-segment.
Clipping University of British Columbia CPSC 314 Computer Graphics
Presentation transcript:

1 CSCE 441 Computer Graphics: Clipping Lines Jinxiang Chai

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

3/135 Review: Drawing General Polygons How to draw every interior pixels? ? Scanline conversion of polygons!

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

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

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

7/135 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn (x min, y min ) (x max, y max ) (x,y)

8/135 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn (x min, y min ) (x max, y max ) (x,y) x min =<x<=x max ? y min =<y<=y max ?

9/135 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn ( x 1, y 1) ( x 2, y 2) (x min, y min ) (x max, y max ) x min =<x<=x max ? y min =<y<=y max ?

10/135 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn ( x 1, y 1) ( x 2, y 2) (x min, y min ) (x max, y max ) x min =<x 1 <=x max Yes y min =<y 1 <=y max Yes

11/135 Clipping Points Given a point (x, y)and clipping window (x min, y min ), (x max, y max ), determine if the point should be drawn ( x 1, y 1) ( x 2, y 2) (x min, y min ) (x max, y max ) x min =<x 2 <=x max No y min =<y 2 <=y max No

12/135 Clipping Lines

13/135 Clipping Lines

14/135 Clipping Lines Given a line with end-points (x 0, y 0 ), (x 1, y 1 ) and clipping window (x min, y min ), (x max, y max ), determine if line should be drawn and clipped end-points of line to draw. (x 0, y 0 ) (x 1, y 1 ) (x min, y min ) (x max, y max )

15/135 Clipping Lines

16/135 Outline Simple line clipping algorithm Cohen-Sutherland Liang-Barsky

17/135 Clipping Lines

18/135 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/135 Clipping Lines – Simple Algorithm

20/135 Clipping Lines – Simple Algorithm

21/135 Intersecting Two Lines

22/135 Intersecting Two Lines

23/135 Intersecting Two Lines

24/135 Intersecting Two Lines

25/135 Intersecting Two Lines

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

27/135 Clipping Lines – Simple Algorithm

28/135 Clipping Lines – Simple Algorithm

29/135 Clipping Lines – Simple Algorithm

30/135 Clipping Lines – Simple Algorithm

31/135 Clipping Lines – Simple Algorithm

32/135 Clipping Lines – Simple Algorithm

33/135 Clipping Lines – Simple Algorithm

34/135 Clipping Lines – Simple Algorithm

35/135 Clipping Lines – Simple Algorithm

36/135 Clipping Lines – Simple Algorithm

37/135 Clipping Lines – Simple Algorithm

38/135 Clipping Lines – Simple Algorithm

39/135 Clipping Lines – Simple Algorithm

40/135 Clipping Lines – Simple Algorithm

41/135 Clipping Lines – Simple Algorithm

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

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

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

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

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

47/135 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/135 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments

49/135 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 4bit 3bit 2bit 1 leftrightbottomtop

50/135 Cohen-Sutherland Algorithm bit 4bit 3bit 2bit 1 leftrightbottomtop right left bottom Region code?

51/135 Cohen-Sutherland Algorithm bit 4bit 3bit 2bit 1 leftrightbottomtop right left bottom 0010 ?

52/135 Cohen-Sutherland Algorithm bit 4bit 3bit 2bit 1 leftrightbottomtop right left bottom

53/135 Cohen-Sutherland Algorithm

54/135 Cohen-Sutherland Algorithm

55/135 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments

56/135 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments

57/135 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments Line is outside the window! reject

58/135 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments Line is outside the window! reject

59/135 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments Line is inside the window! draw

60/135 Cohen-Sutherland Algorithm Classify p 0, p 1 using region codes c 0, c 1 If, trivially reject If, trivially accept Otherwise reduce to trivial cases by splitting into two segments

61/135 Window Intersection (x 1, y 1 ), (x 2, y 2 ) intersect with vertical edge at x right  y intersect = y 1 + m(x right – x1) where m=(y 2 -y 1 )/(x 2 -x 1 ) (x 1, y 1 ), (x 2, y 2 ) intersect with horizontal edge at y bottom  x intersect = x 1 + (y bottom – y1)/m where m=(y 2 -y 1 )/(x 2 -x 1 )

62/135 Example 1

63/135 Example 1

64/135 Example 1

65/135 Example 1

66/135 Example 2

67/135 Example 2

68/135 Example 2

69/135 Example 2

70/135 Example 2

71/135 Example 2

72/135 Example 2

73/135 Example 3

74/135 Example 3

75/135 Example 3

76/135 Example 3

77/135 Cohen Sutherland Java applet: click herehere

78/135 Cohen-Sutherland Algorithm Extends easily to 3D line clipping  27 regions  6 bits

79/135 Cohen-Sutherland Algorithm Use region codes to quickly eliminate/include lines  Best algorithm when trivial accepts/rejects are common Must compute viewing window clipping of remaining lines  Non-trivial clipping cost More efficient algorithms exist

80/135 Liang-Barsky Algorithm Parametric definition of a line:  x = x 1 + u Δ x  y = y 1 + u Δ y  Δ x = (x 2 -x 1 ), Δ y = (y 2 -y 1 ), 0<=u<=1 Lines are oriented: classify lines as moving inside to out or outside to in Goal: find range of u for which x and y both inside the viewing window

81/135 Liang-Barsky Algorithm Current clipped line (u 1 =0,u 2 =1) (-.5,-.5) (2,1)

82/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.333,u 2 =0.6) (-.5,-.5) (2,1)

83/135 Liang-Barsky Algorithm For lines starting outside of boundary, update its starting point (u 1 ) For lines starting inside of boundary, update end point (u 2 ) For lines paralleling the boundaries and outside window, reject it.

84/135 Liang-Barsky Algorithm For lines starting outside of boundary, update its starting point (u 1 ) For lines starting inside of boundary, update end point (u 2 ) For lines paralleling the boundaries and outside window, reject it.

85/135 Liang-Barsky Algorithm Mathematically:  x min <= x 1 + u Δ x <= x max  y min <= y 1 + u Δ y <= y max Rearranged  1:u*(- Δ x) <= (x 1 – x min )  2:u*( Δ x) <= (x max – x 1 )  3:u*(- Δ y) <= (y 1 – y min )  4:u*( Δ y) <= (y max – y 1 )  gen:u*(p k ) <= (q k ), k=1,2,3,4

86/135 Liang-Barsky Algorithm Rules: 1) p k = 0: the line is parallel to boundaries  If for that same k, q k < 0, it’s outside  Otherwise it’s inside 2) p k < 0: the line starts outside this boundary  r k = q k /p k  u 1 = max(0, r k, u 1 ) /**update starting point**/  p k > 0: the line starts inside the boundary  r k = q k /p k  u 2 = min(1, r k, u 2 ) /** update end point**/  If u 1 > u 2, the line is completely outside

87/135 Liang-Barsky Algorithm Current clipped line (u 1 =0,u 2 =1) (-.5,-.5) (2,1)

88/135 Liang-Barsky Algorithm Current clipped line (u 1 =0,u 2 =1) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 1 = -Δx =-2.5<0 q 1 = (x 1 -x min )=-.5 r 1 = q 1 /p 1 =0.2

89/135 Liang-Barsky Algorithm Current clipped line (u 1 =0,u 2 =1) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 1 = -Δx =-2.5<0 q 1 = (x 1 -x min )=-.5 r 1 = q 1 /p 1 =0.2 line starts outside this boundary

90/135 Liang-Barsky Algorithm Current clipped line (u 1 =0,u 2 =1) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 1 = -Δx =-2.5<0 q 1 = (x 1 -x min )=-.5 r 1 = q 1 /p 1 =0.2

91/135 Liang-Barsky Algorithm Current clipped line (u 1 =0,u 2 =1) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 1 = -Δx =-2.5<0 q 1 = (x 1 -x min )=-.5 r 1 = q 1 /p 1 =0.2

92/135 Liang-Barsky Algorithm Current clipped line (u 1 =0,u 2 =1) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 1 = -Δx =-2.5<0 q 1 = (x 1 -x min )=-.5 r 1 = q 1 /p 1 =0.2u 1 = max(0, r 1, u 1 )

93/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.2,u 2 =1) (-.5,-.5) (2,1) u 1 <u2? - yes: continue - no: the line is completely outside window

94/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.2,u 2 =1) (-.5,-.5) (2,1)

95/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.2,u 2 =1) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 2 = Δx =2.5>0 q 2 = (x max -x 1 )=1.5 r 2 = q 2 /p 2 =0.6

96/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.2,u 2 =1) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 2 = Δx =2.5>0 q 2 = (x max -x 1 )=1.5 r 2 = q 2 /p 2 =0.6u 2 = min(1, r 2, u 2 )

97/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.2,u 2 =0.6) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 2 = Δx =2.5>0 q 2 = (x max -x 1 )=1.5 r 2 = q 2 /p 2 =0.6

98/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.2,u 2 =0.6) (-.5,-.5) (2,1) u 1 <u2? - yes: continue - no: the line is completely outside window

99/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.2,u 2 =0.6) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 3 = -Δy =-1.5<0 q 3 = (y 1 -y min )=0.5 r 3 = q 3 /p 3 =0.333

100/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.2,u 2 =0.6) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 3 = -Δy =-1.5<0 q 3 = (y 1 -y min )=0.5 r 3 = q 3 /p 3 =0.333u 1 = max(0, r 3, u 1 )

101/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.333,u 2 =0.6) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 3 = -Δy =-1.5<0 q 3 = (y 1 -y min )=0.5 r 3 = q 3 /p 3 =0.333

102/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.333,u 2 =0.6) (-.5,-.5) (2,1)

103/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.333,u 2 =0.6) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 3 = -Δy =-1.5<0 q 3 = (y 1 -y min )=0.5 r 3 = q 3 /p 3 =0.333

104/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.333,u 2 =0.6) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 4 = Δy =1.5>0 q 4 = (y max -y 1 )=1.5 r 4 = q 4 /p 4 =1

105/135 Liang-Barsky Algorithm Current clipped line (u 1 =0.333,u 2 =0.6) (-.5,-.5) (2,1) Δx = (x2-x1)=2.5 Δy = (y2-y1)=1.5 p 4 = Δy =1.5>0 q 4 = (y max -y 1 )=1.5 r 4 = q 4 /p 4 =1u 2 = min(1, r 4, u 2 )

106/135 Liang-Barsky Algorithm Check the left edge (u 1 =0.333,u 2 =0.6) (-.5,-.5) (2,1) u 1 <u 2 x new1 =x 1 +Δx*u 1 y new1 =y 1 +Δy*u 1 x new2 =x 2 +Δx*u 2 y new2 =y 2 +Δy*u 2

107/135 Liang-Barsky Algorithm Faster than Cohen-Sutherland Extension to 3D is easy - Parametric representation for 3D lines - Compute u1,u2 based on the intersection between line and plane

108/135 Comparison Cohen-Sutherland  Repeated clipping is expensive  Best used when trivial acceptance and rejection is possible for most lines Liang-Barsky  Computation of t-intersections is cheap (only one division)  Computation of (x,y) clip points is only done once  Algorithm doesn’t consider trivial accepts/rejects  Best when many lines must be clipped

109/135 Curve Clipping

110/135 Curve Clipping

111/135 Curve Clipping Approximate a curve using a set of straight- line segments Apply line clipping for curve clipping

112/135 Next Lecture Polygon fill-area clipping

113/135 Next Lecture Polygon fill-area clipping