Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai

Similar presentations


Presentation on theme: "CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai"— Presentation transcript:

1 CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai

2 Reminder Homework #2 is due by Friday night
Homework #3 will be posted on Friday night (2/8), due by 2/22

3 Review: 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?

4 Review: Clipping Lines

5 Review: Clipping Lines

6 Review Clipping Simple line clipping algorithm
- compute intersection points - clip the line segment between the outside point and intersection point Cohen-Sutherland - region coding (9 regions, 4bits) - 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

7 Clipping Polygons Clipping polygons is more complex than clipping the individual lines - Input: polygon

8 Clipping Polygons Clipping polygons is more complex than clipping the individual lines - Input: polygon - Output: original polygon, new polygon, or nothing

9 Why Is Polygon Clipping Hard?
What happens to a triangle during clipping? - possible outcomes: triangle->triangle triangle->quad triangle->5-gon

10 Why Is Polygon Clipping Hard?
What happens to a triangle during clipping? - possible outcomes: triangle->triangle triangle->quad triangle->5-gon How many sides a clipped triangle might have? 10 10

11 How Many Sides? Seven

12 Why Is Clipping Hard? A really tough case
Concave polygon -> Multiple polygons

13 Why Is Clipping Hard? A really tough case

14 Outline Sutherland-Hodgman Clipping - convex polygons
Weiler-Atherton Algorithm - general polygons Required readings - HB 8-8

15 Any idea? Clipping polygon edges? 15 15

16 Any idea? Clipping polygon edges?

17 Any idea? Clipping polygon edges? 17 17

18 Any idea? Clipping polygon edges? 18 18

19 Any idea? Clipping polygon edges? Unconnected set of lines!

20 Any idea? Clipping polygon edges?
Wrong even with connected line segments! 20 20

21 Sutherland-Hodgman Clipping
Basic idea: similar to line clipping

22 Sutherland-Hodgman Clipping
Basic idea: similar to line clipping - consider each edge of the view window individually - clip the polygon against the view window edge’s equation 22 22

23 Sutherland-Hodgman Clipping
Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

24 Sutherland-Hodgman Clipping
Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

25 Sutherland-Hodgman Clipping
Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

26 Sutherland-Hodgman Clipping
Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

27 Sutherland-Hodgman Clipping
Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

28 Sutherland-Hodgman Clipping
Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

29 Sutherland-Hodgman Clipping
Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

30 Sutherland-Hodgman Clipping
Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation

31 Sutherland-Hodgman Clipping
Basic idea: - consider each edge of the view window individually - clip the polygon against the view window edge’s equation - after doing all edges, the polygon is fully clipped

32 Sutherland-Hodgman Clipping
Input/output for algorithm: - input: list of polygon vertices in order {abcdef} a f b e d c

33 Sutherland-Hodgman Clipping
Input/output for algorithm: - input: list of polygon vertices in order - output: list of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe)

34 Sutherland-Hodgman Clipping
Input/output for algorithm: - input: list of polygon vertices in order - output: list of clipped polygon vertices consisting of old vertices (maybe) and new vertices (maybe) - exactly what expect from the clipping operation against each edge!

35 Sutherland-Hodgman Clipping
Basic routine: - Go around polygon one vertex at a time - Current vertex has position E - Previous vertex had position S, and it has been added to the output if appropriate a f b e d {abcdef} c

36 Sutherland-Hodgman Clipping
Basic routine: - Go around polygon one vertex (i.e. polygon edge) at a time - Current vertex has position E - Previous vertex had position S, and it has been added to the output if appropriate a f b e d {abcdef} c

37 Sutherland-Hodgman Clipping
Basic routine: - Go around polygon one vertex (i.e. polygon edge) at a time - Current vertex has position E - Previous vertex had position S, and it has been added to the output if appropriate a f b e d {abcdef} c Need to determine output vertices for each polygon line! 37 37

38 Sutherland-Hodgman Clipping
Polygon edge from S to E takes one of four cases: inside outside inside outside inside outside inside outside E S E S E S E S

39 Sutherland-Hodgman Clipping
Polygon edge from S to E takes one of four cases: inside outside inside outside inside outside inside outside E S E S E S E S I output E output E output I output no output 39 39

40 Sutherland-Hodgman Clipping
Four cases: S inside plane and E inside plane Add E to output Note: S has already been added S inside plane and E outside plane Find intersection point I Add I to output S outside plane and E outside plane Add nothing S outside plane and E inside plane Add I to output, followed by E

41 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

42 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E Input vertices after clipping against left edge after clipping against right edge after clipping against bottom edge after clipping all the window edges

43 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

44 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

45 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

46 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

47 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E b

48 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

49 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

50 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

51 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

52 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

53 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

54 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

55 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

56 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

57 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

58 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

59 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

60 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

61 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

62 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

63 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

64 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

65 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

66 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

67 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

68 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

69 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

70 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

71 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

72 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

73 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

74 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

75 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

76 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

77 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

78 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

79 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

80 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

81 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

82 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

83 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E

84 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E Possible error for non-convex polygons

85 Sutherland-Hodgman Algorithm
Out In No output Output E Output I Output I,E Possible error for non-convex polygons S1: split concave polygon into two or more convex polygons (see Section 4-7) S2: Modify Sutherland-Hodgman algorithm S3: use more general polygon clipper. 85 85

86 Sutherland-Hodgman Algorithm
How to deal with more general clipping boundaries (convex clip polygons) 86 86

87 Sutherland-Hodgman Algorithm
How to deal with more general clipping boundaries (convex clip polygons) 87 87

88 Sutherland-Hodgman Algorithm
Work for convex input polygons Work for convex clipping boundaries Easy to pipeline for parallel processing Polygon from one boundary does not have to be completed before next boundary starts Leads to substantial performance gains 88 88

89 Weiler-Atherton Algorithm
+ Work for general input polygons (concave & convex) + Handles a clipping window with any polygon shape (concave & convex) + Can be extended to 3D - Not as efficient as Sutherland-Hodgman - Not easy to parallelize

90 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

91 Weiler-Atherton Algorithm

92 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

93 Weiler-Atherton Algorithm

94 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

95 Weiler-Atherton Algorithm

96 Weiler-Atherton Algorithm

97 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

98 Weiler-Atherton Algorithm

99 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

100 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

101 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

102 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

103 Weiler-Atherton Algorithm

104 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

105 Weiler-Atherton Algorithm

106 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

107 Weiler-Atherton Algorithm

108 Weiler-Atherton Algorithm

109 Weiler-Atherton Algorithm

110 Weiler-Atherton Algorithm

111 Weiler-Atherton Algorithm

112 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

113 Weiler-Atherton Algorithm

114 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

115 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

116 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

117 Weiler-Atherton Algorithm

118 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

119 Weiler-Atherton Algorithm

120 Weiler-Atherton Algorithm
Process the edges of the polygon fill area in a counterclockwise order until an inside-outside pair of vertices is encountered Follow the window boundaries in a counterclockwise direction from the exit-intersection point to another intersection point with the polygon - previously processed? - yes, go to the next step - no, continue processing polygon until a previously processed vertex is encountered Form the vertex list for this section of the clipped fill area Return to the exit-intersection point and continue processing the polygon edges in a counterclockwise order

121 Weiler-Atherton Algorithm

122 Weiler-Atherton Algorithm

123 Nonlinear Clipping-window Boundaries
Approximate the boundaries with straight-line sections. Use the existing polygon clipping algorithms for clipping against a general polygon-shaped clipping window.

124 Next Lecture 2D transformations y y x x y x


Download ppt "CSCE 441 Computer Graphics: Clipping Polygons Jinxiang Chai"

Similar presentations


Ads by Google