Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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

2 Dr. Muhammed Al-Mulhem2 The Rendering Pipeline Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay Model  World World  Camera

3 March 1, 2009Dr. Muhammed Al-Mulhem3 Why clip? We don’t want to waste time rendering objects that are outside the viewing window (or clipping window)

4 March 1, 2009Dr. Muhammed Al-Mulhem4 What is clipping? Analytically calculating the portions of primitives within the view window

5 March 1, 2009Dr. Muhammed Al-Mulhem5 Clip to what? View Window Eye position (focal point) Viewing Frustum

6 March 1, 2009Dr. Muhammed Al-Mulhem6 Why illuminate before clipping? Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay Model  World World  Camera

7 March 1, 2009Dr. Muhammed Al-Mulhem7 Why World  Camera before clipping? Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay Model  World World  Camera

8 March 1, 2009Dr. Muhammed Al-Mulhem8 Why? Why illuminate before clipping? Why World  Camera before clipping? Efficiency Why illuminate before clipping? Why World  Camera before clipping? Efficiency

9 March 1, 2009Dr. Muhammed Al-Mulhem9 Clip to what? View Window Eye position (focal point)

10 March 1, 2009Dr. Muhammed Al-Mulhem10 Why clip before project and rasterize? Transform Illuminate Transform Clip Project Rasterize Model & Camera Parameters Rendering Pipeline FramebufferDisplay Model  World World  Camera

11 March 1, 2009Dr. Muhammed Al-Mulhem11 Why Clip? Bad idea to rasterize outside of framebuffer boundsBad idea to rasterize outside of framebuffer bounds Also, don’t waste time scan converting pixels outside windowAlso, don’t waste time scan converting pixels outside window Bad idea to rasterize outside of framebuffer boundsBad idea to rasterize outside of framebuffer bounds Also, don’t waste time scan converting pixels outside windowAlso, don’t waste time scan converting pixels outside window

12 March 1, 2009Dr. Muhammed Al-Mulhem12 Clipping The naïve approach to clipping lines: for each line segment for each edge of view_window for each edge of view_window find intersection point find intersection point pick “nearest” point pick “nearest” point if anything is left, draw it if anything is left, draw it What do we mean by “nearest”? How can we optimize this? The naïve approach to clipping lines: for each line segment for each edge of view_window for each edge of view_window find intersection point find intersection point pick “nearest” point pick “nearest” point if anything is left, draw it if anything is left, draw it What do we mean by “nearest”? How can we optimize this? A B C D

13 March 1, 2009Dr. Muhammed Al-Mulhem13 Trivial Accepts Big optimization: trivial accept/rejects How can we quickly determine whether a line segment is entirely inside the view window? A: test both endpoints. Big optimization: trivial accept/rejects How can we quickly determine whether a line segment is entirely inside the view window? A: test both endpoints.

14 March 1, 2009Dr. Muhammed Al-Mulhem14 Trivial Rejects How can we know a line is outside view window? A: if both endpoints on wrong side of same edge, can trivially reject line How can we know a line is outside view window? A: if both endpoints on wrong side of same edge, can trivially reject line

15 March 1, 2009Dr. Muhammed Al-Mulhem15 Clipping Lines To View Window Combining trivial accepts/rejects Trivially accept lines with both endpoints inside all edges of the view windowTrivially accept lines with both endpoints inside all edges of the view window Trivially reject lines with both endpoints outside the same edge of the view windowTrivially reject lines with both endpoints outside the same edge of the view window Otherwise, reduce to trivial cases by splitting into two segmentsOtherwise, reduce to trivial cases by splitting into two segments Combining trivial accepts/rejects Trivially accept lines with both endpoints inside all edges of the view windowTrivially accept lines with both endpoints inside all edges of the view window Trivially reject lines with both endpoints outside the same edge of the view windowTrivially reject lines with both endpoints outside the same edge of the view window Otherwise, reduce to trivial cases by splitting into two segmentsOtherwise, reduce to trivial cases by splitting into two segments

16 March 1, 2009Dr. Muhammed Al-Mulhem16 Cohen-Sutherland Line Clipping Divide view window into regions defined by window edgesDivide view window into regions defined by window edges Assign each region a 4-bit outcode: Bit 1 indicates y-value of points are above y maxAssign each region a 4-bit outcode: Bit 1 indicates y-value of points are above y max Divide view window into regions defined by window edgesDivide view window into regions defined by window edges Assign each region a 4-bit outcode: Bit 1 indicates y-value of points are above y maxAssign each region a 4-bit outcode: Bit 1 indicates y-value of points are above y max 000000100001 1001 01010100 10001010 0110 y max x max

17 March 1, 2009Dr. Muhammed Al-Mulhem17 Cohen-Sutherland Line Clipping For each line segment Assign an outcode to each vertexAssign an outcode to each vertex If both outcodes = 0, trivial acceptIf both outcodes = 0, trivial accept –Same as performing if (bitwise OR = 0) ElseElse –bitwise AND vertex outcodes together –if result  0, trivial reject For each line segment Assign an outcode to each vertexAssign an outcode to each vertex If both outcodes = 0, trivial acceptIf both outcodes = 0, trivial accept –Same as performing if (bitwise OR = 0) ElseElse –bitwise AND vertex outcodes together –if result  0, trivial reject

18 March 1, 2009Dr. Muhammed Al-Mulhem18 Cohen-Sutherland Line Clipping If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discardedIf line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded –Pick an edge of view window that the line crosses (how?) –Intersect line with edge (how?) –Discard portion on wrong side of edge and assign new outcode to new vertex –Apply trivial accept/reject tests; repeat if necessary If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discardedIf line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded –Pick an edge of view window that the line crosses (how?) –Intersect line with edge (how?) –Discard portion on wrong side of edge and assign new outcode to new vertex –Apply trivial accept/reject tests; repeat if necessary

19 March 1, 2009Dr. Muhammed Al-Mulhem19 Cohen-Sutherland Line Clipping If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded Pick an edge that the line crosses Check against edges in same order each timeCheck against edges in same order each time (For example: top, bottom, right, left)(For example: top, bottom, right, left) If line cannot be trivially accepted or rejected, subdivide so that one or both segments can be discarded Pick an edge that the line crosses Check against edges in same order each timeCheck against edges in same order each time (For example: top, bottom, right, left)(For example: top, bottom, right, left) A B D E C

20 March 1, 2009Dr. Muhammed Al-Mulhem20 Cohen-Sutherland Line Clipping Intersect line with edge (how?) – Chapter 6. A B D E C

21 March 1, 2009Dr. Muhammed Al-Mulhem21 Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests and repeat if necessary Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests and repeat if necessary Cohen-Sutherland Line Clipping A B D C

22 March 1, 2009Dr. Muhammed Al-Mulhem22 Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests and repeat if necessary Discard portion on wrong side of edge and assign outcode to new vertex Apply trivial accept/reject tests and repeat if necessary Cohen-Sutherland Line Clipping A B C

23 March 1, 2009Dr. Muhammed Al-Mulhem23 View Window Intersection Code (x 1, y 1 ), (x 2, y 2 ) intersect with vertical edge at x right(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 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 ) (x 1, y 1 ), (x 2, y 2 ) intersect with vertical edge at x right(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 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 )

24 March 1, 2009Dr. Muhammed Al-Mulhem24 Cohen-Sutherland Review Use Outodes to quickly eliminate/include linesUse Outodes to quickly eliminate/include lines –Best algorithm when trivial accepts/rejects are common Must compute viewing window clipping of remaining linesMust compute viewing window clipping of remaining lines –Non-trivial clipping cost –Redundant clipping of some lines More efficient algorithms exist Use Outodes to quickly eliminate/include linesUse Outodes to quickly eliminate/include lines –Best algorithm when trivial accepts/rejects are common Must compute viewing window clipping of remaining linesMust compute viewing window clipping of remaining lines –Non-trivial clipping cost –Redundant clipping of some lines More efficient algorithms exist

25 March 1, 2009Dr. Muhammed Al-Mulhem25 Solving Simultaneous Equations Equation of a line Slope-intercept (explicit equation): y = mx + bSlope-intercept (explicit equation): y = mx + b Implicit Equation: Ax + By + C = 0Implicit Equation: Ax + By + C = 0 Parametric Equation: Line defined by two points, P 0 and P 1Parametric Equation: Line defined by two points, P 0 and P 1 –P(t) = P 0 + (P 1 - P 0 ) t, where P is a vector [x, y] T –x(t) = x 0 + (x 1 - x 0 ) t –y(t) = y 0 + (y 1 - y 0 ) t Equation of a line Slope-intercept (explicit equation): y = mx + bSlope-intercept (explicit equation): y = mx + b Implicit Equation: Ax + By + C = 0Implicit Equation: Ax + By + C = 0 Parametric Equation: Line defined by two points, P 0 and P 1Parametric Equation: Line defined by two points, P 0 and P 1 –P(t) = P 0 + (P 1 - P 0 ) t, where P is a vector [x, y] T –x(t) = x 0 + (x 1 - x 0 ) t –y(t) = y 0 + (y 1 - y 0 ) t

26 March 1, 2009Dr. Muhammed Al-Mulhem26 Parametric Line Equation Describes a finite line Works with vertical lines (like the view window edge) 0 <=t <= 10 <=t <= 1 –Defines line between P 0 and P 1 t < 0t < 0 –Defines line before P 0 t > 1t > 1 –Defines line after P 1 Describes a finite line Works with vertical lines (like the view window edge) 0 <=t <= 10 <=t <= 1 –Defines line between P 0 and P 1 t < 0t < 0 –Defines line before P 0 t > 1t > 1 –Defines line after P 1

27 March 1, 2009Dr. Muhammed Al-Mulhem27 Parametric Lines and Clipping Define each line in parametric form: P 0 (t)…P n-1 (t)P 0 (t)…P n-1 (t) Define each edge of view window in parametric form: P L (t), P R (t), P T (t), P B (t)P L (t), P R (t), P T (t), P B (t) Perform Cohen-Sutherland intersection tests using appropriate view window edge and line Define each line in parametric form: P 0 (t)…P n-1 (t)P 0 (t)…P n-1 (t) Define each edge of view window in parametric form: P L (t), P R (t), P T (t), P B (t)P L (t), P R (t), P T (t), P B (t) Perform Cohen-Sutherland intersection tests using appropriate view window edge and line

28 March 1, 2009Dr. Muhammed Al-Mulhem28 Line / Edge Clipping Equations Faster line clippers use parametric equations Line 0: x 0 = x 0 0 + (x 0 1 - x 0 0 ) t 0x 0 = x 0 0 + (x 0 1 - x 0 0 ) t 0 y 0 = y 0 0 + (y 0 1 - y 0 0 ) t 0y 0 = y 0 0 + (y 0 1 - y 0 0 ) t 0 x 0 0 + (x 0 1 - x 0 0 ) t 0 = x L 0 + (x L 1 - x L 0 ) t L y 0 0 + (y 0 1 - y 0 0 ) t 0 = y L 0 + (y L 1 - y L 0 ) t L Solve for t 0 and/or t LSolve for t 0 and/or t L Faster line clippers use parametric equations Line 0: x 0 = x 0 0 + (x 0 1 - x 0 0 ) t 0x 0 = x 0 0 + (x 0 1 - x 0 0 ) t 0 y 0 = y 0 0 + (y 0 1 - y 0 0 ) t 0y 0 = y 0 0 + (y 0 1 - y 0 0 ) t 0 x 0 0 + (x 0 1 - x 0 0 ) t 0 = x L 0 + (x L 1 - x L 0 ) t L y 0 0 + (y 0 1 - y 0 0 ) t 0 = y L 0 + (y L 1 - y L 0 ) t L Solve for t 0 and/or t LSolve for t 0 and/or t L View Window Edge L: x L = x L 0 + (x L 1 - x L 0 ) t Lx L = x L 0 + (x L 1 - x L 0 ) t L y L = y L 0 + (y L 1 - y L 0 ) t Ly L = y L 0 + (y L 1 - y L 0 ) t L View Window Edge L: x L = x L 0 + (x L 1 - x L 0 ) t Lx L = x L 0 + (x L 1 - x L 0 ) t L y L = y L 0 + (y L 1 - y L 0 ) t Ly L = y L 0 + (y L 1 - y L 0 ) t L

29 March 1, 2009Dr. Muhammed Al-Mulhem29 Cyrus-Beck Algorithm We wish to optimize line/line intersection Start with parametric equation of line:Start with parametric equation of line: –P(t) = P 0 + (P 1 - P 0 ) t And a point and normal for each edgeAnd a point and normal for each edge –P L, N L We wish to optimize line/line intersection Start with parametric equation of line:Start with parametric equation of line: –P(t) = P 0 + (P 1 - P 0 ) t And a point and normal for each edgeAnd a point and normal for each edge –P L, N L

30 March 1, 2009Dr. Muhammed Al-Mulhem30 Cyrus-Beck Algorithm Find t such that N L [P(t) - P L ] = 0 Substitute line equation for P(t): N L [ P 0 + (P 1 - P 0 ) t - P L ] = 0N L [ P 0 + (P 1 - P 0 ) t - P L ] = 0 Solve for t t = N L [P L – P 0 ] / -N L [P 1 - P 0 ]t = N L [P L – P 0 ] / -N L [P 1 - P 0 ] Find t such that N L [P(t) - P L ] = 0 Substitute line equation for P(t): N L [ P 0 + (P 1 - P 0 ) t - P L ] = 0N L [ P 0 + (P 1 - P 0 ) t - P L ] = 0 Solve for t t = N L [P L – P 0 ] / -N L [P 1 - P 0 ]t = N L [P L – P 0 ] / -N L [P 1 - P 0 ] PLPL NLNL P(t) Inside P0P0 P1P1

31 March 1, 2009Dr. Muhammed Al-Mulhem31 Cyrus-Beck Algorithm Compute t for line intersection with all four edges Discard all (t 1) Classify each remaining intersection as Potentially Entering (PE)Potentially Entering (PE) Potentially Leaving (PL)Potentially Leaving (PL) N L [P 1 - P 0 ] > 0 implies PL N L [P 1 - P 0 ] < 0 implies PE Compute t for line intersection with all four edges Discard all (t 1) Classify each remaining intersection as Potentially Entering (PE)Potentially Entering (PE) Potentially Leaving (PL)Potentially Leaving (PL) N L [P 1 - P 0 ] > 0 implies PL N L [P 1 - P 0 ] < 0 implies PE

32 March 1, 2009Dr. Muhammed Al-Mulhem32 Compute PE with largest t Compute PL with smallest t Clip to these two points Compute PE with largest t Compute PL with smallest t Clip to these two points Cyrus-Beck Algorithm PE PL P1P1 PE P0P0

33 March 1, 2009Dr. Muhammed Al-Mulhem33 Cyrus-Beck Algorithm Because of horizontal and vertical clip lines: Many computations reduceMany computations reduce Normals: (-1, 0), (1, 0), (0, -1), (0, 1) Pick constant points on edges solution for t: -(x 0 - x left ) / (x 1 - x 0 )-(x 0 - x left ) / (x 1 - x 0 ) (x 0 - x right ) / -(x 1 - x 0 )(x 0 - x right ) / -(x 1 - x 0 ) -(y 0 - y bottom ) / (y 1 - y 0 )-(y 0 - y bottom ) / (y 1 - y 0 ) (y 0 - y top ) / -(y 1 - y 0 )(y 0 - y top ) / -(y 1 - y 0 ) Because of horizontal and vertical clip lines: Many computations reduceMany computations reduce Normals: (-1, 0), (1, 0), (0, -1), (0, 1) Pick constant points on edges solution for t: -(x 0 - x left ) / (x 1 - x 0 )-(x 0 - x left ) / (x 1 - x 0 ) (x 0 - x right ) / -(x 1 - x 0 )(x 0 - x right ) / -(x 1 - x 0 ) -(y 0 - y bottom ) / (y 1 - y 0 )-(y 0 - y bottom ) / (y 1 - y 0 ) (y 0 - y top ) / -(y 1 - y 0 )(y 0 - y top ) / -(y 1 - y 0 )

34 March 1, 2009Dr. Muhammed Al-Mulhem34 Comparison Cohen-Sutherland Repeated clipping is expensiveRepeated clipping is expensive Best used when trivial acceptance and rejection is possible for most linesBest used when trivial acceptance and rejection is possible for most linesCyrus-Beck Computation of t-intersections is cheapComputation of t-intersections is cheap Computation of (x,y) clip points is only done onceComputation of (x,y) clip points is only done once Algorithm doesn’t consider trivial accepts/rejectsAlgorithm doesn’t consider trivial accepts/rejects Best when many lines must be clippedBest when many lines must be clipped Liang-Barsky: Optimized Cyrus-Beck Nicholl et al.: Fastest, but doesn’t do 3D Cohen-Sutherland Repeated clipping is expensiveRepeated clipping is expensive Best used when trivial acceptance and rejection is possible for most linesBest used when trivial acceptance and rejection is possible for most linesCyrus-Beck Computation of t-intersections is cheapComputation of t-intersections is cheap Computation of (x,y) clip points is only done onceComputation of (x,y) clip points is only done once Algorithm doesn’t consider trivial accepts/rejectsAlgorithm doesn’t consider trivial accepts/rejects Best when many lines must be clippedBest when many lines must be clipped Liang-Barsky: Optimized Cyrus-Beck Nicholl et al.: Fastest, but doesn’t do 3D

35 March 1, 2009Dr. Muhammed Al-Mulhem35 Clipping Polygons Clipping polygons is more complex than clipping the individual linesClipping polygons is more complex than clipping the individual lines Input: polygonInput: polygon Output: Original polygon, new polygon, or nothingOutput: Original polygon, new polygon, or nothing OptimizationOptimization The biggest line optimizer we had was trivial accept or reject.The biggest line optimizer we had was trivial accept or reject. When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon?When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon? Clipping polygons is more complex than clipping the individual linesClipping polygons is more complex than clipping the individual lines Input: polygonInput: polygon Output: Original polygon, new polygon, or nothingOutput: Original polygon, new polygon, or nothing OptimizationOptimization The biggest line optimizer we had was trivial accept or reject.The biggest line optimizer we had was trivial accept or reject. When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon?When can we trivially accept/reject a polygon as opposed to the line segments that make up the polygon?

36 March 1, 2009Dr. Muhammed Al-Mulhem36 What happens to a triangle during clipping? Possible outcomes: What happens to a triangle during clipping? Possible outcomes: triangle  triangle Why Is Clipping Hard? triangle  quad triangle  5-gon How many sides can a clipped triangle have?

37 March 1, 2009Dr. Muhammed Al-Mulhem37 How many sides? Seven…

38 March 1, 2009Dr. Muhammed Al-Mulhem38 A really tough case: Why Is Clipping Hard?

39 March 1, 2009Dr. Muhammed Al-Mulhem39 A really tough case: Why Is Clipping Hard? concave polygon  multiple polygons

40 March 1, 2009Dr. Muhammed Al-Mulhem40 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the view window individuallyConsider each edge of the view window individually Clip the polygon against the view window edge’s equationClip the polygon against the view window edge’s equation Basic idea: Consider each edge of the view window individuallyConsider each edge of the view window individually Clip the polygon against the view window edge’s equationClip the polygon against the view window edge’s equation

41 March 1, 2009Dr. Muhammed Al-Mulhem41 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation

42 March 1, 2009Dr. Muhammed Al-Mulhem42 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation

43 March 1, 2009Dr. Muhammed Al-Mulhem43 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation

44 March 1, 2009Dr. Muhammed Al-Mulhem44 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation

45 March 1, 2009Dr. Muhammed Al-Mulhem45 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation

46 March 1, 2009Dr. Muhammed Al-Mulhem46 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation

47 March 1, 2009Dr. Muhammed Al-Mulhem47 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation

48 March 1, 2009Dr. Muhammed Al-Mulhem48 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation

49 March 1, 2009Dr. Muhammed Al-Mulhem49 Sutherland-Hodgman Clipping Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped Basic idea: Consider each edge of the viewport individuallyConsider each edge of the viewport individually Clip the polygon against the edge equationClip the polygon against the edge equation After doing all edges, the polygon is fully clippedAfter doing all edges, the polygon is fully clipped

50 March 1, 2009Dr. Muhammed Al-Mulhem50 Sutherland-Hodgman Clipping Input/output for algorithm:Input/output for algorithm: Input: List of polygon vertices in order.Input: List of polygon vertices in order. Output: List of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe).Output: List of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe). Note: this is exactly what we expect from the clipping operation against each edgeNote: this is exactly what we expect from the clipping operation against each edge Input/output for algorithm:Input/output for algorithm: Input: List of polygon vertices in order.Input: List of polygon vertices in order. Output: List of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe).Output: List of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe). Note: this is exactly what we expect from the clipping operation against each edgeNote: this is exactly what we expect from the clipping operation against each edge

51 March 1, 2009Dr. Muhammed Al-Mulhem51 Sutherland-Hodgman Clipping Sutherland-Hodgman basic routine: Go around polygon one vertex at a timeGo around polygon one vertex at a time Current vertex has position pCurrent vertex has position p Previous vertex had position s, and it has been added to the output if appropriate.Previous vertex had position s, and it has been added to the output if appropriate. Sutherland-Hodgman basic routine: Go around polygon one vertex at a timeGo around polygon one vertex at a time Current vertex has position pCurrent vertex has position p Previous vertex had position s, and it has been added to the output if appropriate.Previous vertex had position s, and it has been added to the output if appropriate.

52 March 1, 2009Dr. Muhammed Al-Mulhem52 Sutherland-Hodgman Clipping Edge from s to p takes one of four cases:Edge from s to p takes one of four cases: (Orange line can be a line or a plane) Edge from s to p takes one of four cases:Edge from s to p takes one of four cases: (Orange line can be a line or a plane) insideoutside s p p output insideoutside s p no output insideoutside s p i output insideoutside s p i output p output

53 March 1, 2009Dr. Muhammed Al-Mulhem53 Sutherland-Hodgman Clipping Four cases: s inside plane and p inside planes inside plane and p inside plane –Add p to output –Note: s has already been added s inside plane and p outside planes inside plane and p outside plane –Find intersection point i –Add i to output s outside plane and p outside planes outside plane and p outside plane –Add nothing s outside plane and p inside planes outside plane and p inside plane –Find intersection point i –Add i to output, followed by p Four cases: s inside plane and p inside planes inside plane and p inside plane –Add p to output –Note: s has already been added s inside plane and p outside planes inside plane and p outside plane –Find intersection point i –Add i to output s outside plane and p outside planes outside plane and p outside plane –Add nothing s outside plane and p inside planes outside plane and p inside plane –Find intersection point i –Add i to output, followed by p


Download ppt "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."

Similar presentations


Ads by Google