Presentation is loading. Please wait.

Presentation is loading. Please wait.

Unit – IV 2D Viewing. 2 of 30 Contents Windowing Concepts The viewing pipeline viewing coordinate reference frame, window to view-port coordinate transformation,

Similar presentations


Presentation on theme: "Unit – IV 2D Viewing. 2 of 30 Contents Windowing Concepts The viewing pipeline viewing coordinate reference frame, window to view-port coordinate transformation,"— Presentation transcript:

1

2 Unit – IV 2D Viewing.

3 2 of 30 Contents Windowing Concepts The viewing pipeline viewing coordinate reference frame, window to view-port coordinate transformation, viewing functions Line Clipping –Introduction –Cohen-Sutherland Clipping Algorithm –Cyrus-beck line clipping algorithms Polygon Clipping –Sutherland-Hodgman Area Clipping Algorithm

4 3 of 30 Where we require clipping? An architect may have a graphics program to draw an entire building but be interested in only the swimming pool.

5 4 of 30 Viewing in 2D - Viewport Window in world coordinates. 45  250  Viewport in Device coords 250 x 250 Pixels. Display Device

6 5 of 30 The computer is used in design applications because it can easily and accurately create, store and modify very complex drawings. When drawings are too complex, however, they become difficult to read. In such situations it is useful to display only those portions of the drawing that are of immediate interest. Sometimes, it is desirable to enlarge these portions to take full advantage of the available display surface. The method for selecting and enlarging portions of a drawing is called windowing. The technique for not showing the part of the drawing which one is not interested is called a clipping.

7 6 of 30 Windowing I A scene is made up of a collection of objects specified in world coordinates World Coordinates

8 7 of 30 Window A world coordinate area selected for display is called a window. wy max wy min wx min wx max Window World Coordinates

9 8 of 30 View port An area on a display device to which a window is mapped is called a view port. Vy max Vy min Vx min Vx max Device Coordinates View port

10 9 of 30 VIDEOCON Display Screen View Port

11 10 of 30 The window defines what is to be viewed. And the view port defines where it is to be displayed. Window and view ports are rectangles in standard positions, with rectangle edges parallel to the coordinate axes.

12 11 of 30 Window to viewport mapping or windowing transformation. The mapping of a part of a world coordinate scene to device coordinates is referred to as a viewing transformation. 2-d viewing transformation is also referred as window to view port or windowing transformation. Y w max Y w min X w min X w max window Y v max Y v min X v min X v max View port

13 12 of 30 The Viewing Pipeline Window A world-coordinate area selected for display. defines what is to be viewed Viewport An area on a display device to which a window is mapped. defines where it is to be displayed Viewing transformation The mapping of a part of a world-coordinate scene to device coordinates. A window could be a rectangle to have any orientation.

14 13 of 30

15 14 of 30

16 15 of 30 2D Viewing Pipeline To make the viewing process independent of the requirements of any output device, graphics systems convert object descriptions to normalized coordinates range from 0 to 1

17 16 of 30 Window to viewing coordinate transformation  First, we construct the scene in world coordinates using the output primitives and attributes.  Next, to obtain a particular orientation for the window, we can set up a 2-dimenstional viewing coordinate system in the world coordinate plane and define a window in the viewing coordinate system.  The viewing coordinate reference frame is used to provide a method for setting up arbitrary orientation of rectangular windows.  Once the viewing reference frame is established, we can transform descriptions in world coordinates to viewing coordinates( in the range from 0 to 1) and map viewing coordinate description of the scene to normalized coordinates.  At the final step, all parts of the picture that lie outside the view port are clipped and the contents of the view port are transferred to device coordinates.

18 17 of 30 Cntd.. By changing the position of the view port, we can view objects at different positions on the display area of an output device. Also, by varying the size of view port, we can change the size and proportions of displayed objects. We achieve zooming effects by successively mapping different sized windows on a fixed size view port. As the windows are made smaller, we zoom in on some part of a scene to view details that are not shown with larger windows. Similarly, more overview is obtained by zooming out from a section of a scene with successively larger windows.

19 18 of 30 The Viewing Pipeline M wc,vc = R. T

20 19 of 30

21 20 of 30

22 21 of 30 (0,0) (100,50) (0,25) (50,50) So S x = 50/100 = ½ And S y = 25/50 = ½ XW min,YW min XW max,YW max XV min,YV min XV max,YV max XV max -XV min XW max -XW min Sx=Sx= YV max -YV min YW max -YW min Sy=Sy=

23 22 of 30 Window to View port coordinate Transformation

24 23 of 30

25 24 of 30 Window-to-Viewport Coordinate Transformation To map a point in the window at world position (xw, yw ) in the associated view port (xv, yv ) we use the concept of relative distance.

26 25 of 30 Workstation transformation Mapping selected parts of a scene in normalized coordinates to different video monitors with workstation transformations

27 26 of 30 Clipping Operations Clipping Identify those portions of a picture that are either inside or outside of a specified region of space. Clip window The region against which an object is to be clipped. The shape of clip window Applications of clipping World-coordinate clipping

28 27 of 30 Clipping Operations Viewport clipping It can reduce calculations by allowing concatenation of viewing and geometric transformation matrices. Types of clipping Point clipping Line clipping Area (Polygon) clipping Curve clipping Text clipping Point clipping (Rectangular clip window)

29 28 of 30 Point clipping Point clipping: Remove points outside window. –A point is either entirely inside the region or not Assuming that the clip window is a rectangle in standard position, we save a point p=(x,y) for display if the following inequalities are satisfied: Where the edges of the clip window ( xw min, xw max, yw min, yw max ) can be either world coordinate window boundaries or viewport boundaries. If any one of these four inequalities is not satisfied, the point is clipped (not saved for display)

30 29 of 30 For a point (x,y) to be inside the clip rectangle: Point Clipping

31 30 of 30 Line Clipping Basic calculations: –Is an endpoint inside or outside the clipping window? –Find the point of intersection, if any, between a line segment and an edge of the clipping window. Both endpoints inside: trivial accept One inside: find intersection and clip Both outside: either clip or reject

32 31 of 30 Line Clipping For the image below consider which lines and points should be kept and which ones should be clipped wy max wy min wx min wx max Window P1P1 P2P2 P3P3 P6P6 P5P5 P7P7 P 10 P9P9 P4P4 P8P8

33 32 of 30 Point Clipping Easy - a point ( x,y ) is not clipped if: wx min ≤ x ≤ wx max AND wy min ≤ y ≤ wy max otherwise it is clipped wy max wy min wx min wx max Window P1P1 P2P2 P5P5 P7P7 P 10 P9P9 P4P4 P8P8 Clipped Points Within the Window are Not Clipped Clipped

34 33 of 30 Line Clipping Harder - examine the end-points of each line to see if they are in the window or not SituationSolutionExample Both end-points inside the window Don’t clip One end-point inside the window, one outside Must clip Both end-points outside the window Must clip

35 34 of 30 Cohen-Sutherland Clipping Algorithm An efficient line clipping algorithm The key advantage of the algorithm is that it vastly reduces the number of line intersections that must be calculated Dr. Ivan E. Sutherland co-developed the Cohen- Sutherland clipping algorithm. Sutherland is a graphics giant and includes amongst his achievements the invention of the head mounted display.

36 35 of 30 Cases for clipping lines Line Clipping

37 36 of 30 Cases for clipping lines Line Clipping

38 37 of 30 Cases for clipping lines Line Clipping

39 38 of 30 Cases for clipping lines Line Clipping

40 39 of 30 Cases for clipping lines Line Clipping

41 40 of 30 Cases for clipping lines Line Clipping

42 41 of 30 Cohen-Sutherland: World Division World space is divided into regions based on the window boundaries –Each region has a unique four bit region code –Region codes indicate the position of the regions with respect to the window 100110001010 0001 0000 Window 0010 010101000110

43 42 of 30 1.End-points pairs are checked for trivial acceptance or rejection using outcode; 2.If not trivially accepted or rejected, divide the line segment into two at a clip edge; 3.Iteratively clipped by test trivial-acceptance or trivial-rejection, and divided into two segments until completely inside or trivial-rejection. A B C D E F G H I 1001 0001 0101 0100 0000 10001010 0010 0110 Steps for Cohen-Sutherland alg.

44 43 of 30 Cohen-Sutherland: Labelling Every end-point is labelled with the appropriate region code wy max wy min wx min wx max Window P 3 [0001] P 6 [0000] P 5 [0000] P 7 [0001] P 10 [0100] P 9 [0000] P 4 [1000] P 8 [0010] P 12 [0010] P 11 [1010] P 13 [0101] P 14 [0110]

45 44 of 30 Cohen-Sutherland: Lines In The Window Lines completely contained within the window boundaries have region code [0000] for both end-points so are not clipped wy max wy min wx min wx max Window P 3 [0001] P 6 [0000] P 5 [0000] P 7 [0001] P 10 [0100] P 9 [0000] P 4 [1000] P 8 [0010] P 12 [0010] P 11 [1010] P 13 [0101] P 14 [0110]

46 45 of 30 Cohen-Sutherland: Lines Outside The Window Any lines with a common set bit in the region codes of both end-points can be clipped –The AND operation can efficiently check this wy max wy min wx min wx max Window P 3 [0001] P 6 [0000] P 5 [0000] P 7 [0001] P 10 [0100] P 9 [0000] P 4 [1000] P 8 [0010] P 12 [0010] P 11 [1010] P 13 [0101] P 14 [0110]

47 46 of 30 Cohen-Sutherland: Other Lines Lines that cannot be identified as completely inside or outside the window may or may not cross the window interior These lines are processed as follows: –Compare an end-point outside the window to a boundary (choose any order in which to consider boundaries e.g. left, right, bottom, top) and determine how much can be discarded –If the remainder of the line is entirely inside or outside the window, retain it or clip it respectively

48 47 of 30 Cohen-Sutherland: Other Lines (cont…) –Otherwise, compare the remainder of the line against the other window boundaries –Continue until the line is either discarded or a segment inside the window is found We can use the region codes to determine which window boundaries should be considered for intersection –To check if a line crosses a particular boundary we compare the appropriate bits in the region codes of its end-points –If one of these is a 1 and the other is a 0 then the line crosses the boundary

49 48 of 30 Cohen-Sutherland Examples Consider the line P 9 to P 10 below –Start at P 10 –From the region codes of the two end-points we know the line doesn’t cross the left or right boundary –Calculate the intersection of the line with the bottom boundary to generate point P 10 ’ –The line P 9 to P 10 ’ is completely inside the window so is retained wy max wy min wx min wx max Window P 10 [0100] P 9 [0000] P 10 ’ [0000] P 9 [0000]

50 49 of 30 Cohen-Sutherland Examples (cont…) Consider the line P 3 to P 4 below –Start at P 4 –From the region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P 4 ’ –The line P 3 to P 4 ’ is completely outside the window so is clipped wy max wy min wx min wx max Window P 4 ’ [1001] P 3 [0001] P 4 [1000] P 3 [0001]

51 50 of 30 Cohen-Sutherland Examples (cont…) Consider the line P 7 to P 8 below –Start at P 7 –From the two region codes of the two end-points we know the line crosses the left boundary so calculate the intersection point to generate P 7 ’ wy max wy min wx min wx max Window P 7 ’ [0001] P 7 [0001] P 8 [0010] P 8 ’ [0010]

52 51 of 30 Cohen-Sutherland Examples (cont…) Consider the line P 7 ’ to P 8 –Start at P 8 –Calculate the intersection with the right boundary to generate P 8 ’ –P 7 ’ to P 8 ’ is inside the window so is retained wy max wy min wx min wx max Window P 7 ’ [0001] P 7 [0001] P 8 [0010] P 8 ’ [0010]

53 52 of 30 Cohen-Sutherland Worked Example wy max wy min wx min wx max Window

54 53 of 30 Calculating Line Intersections Intersection points with the window boundaries are calculated using the line- equation parameters –Consider a line with the end-points ( x 1, y 1 ) and ( x 2, y 2 ) –The y-coordinate of an intersection with a vertical window boundary can be calculated using: y = y 1 + m (x boundary - x 1 ) where x boundary can be set to either wx min or wx max

55 54 of 30 Calculating Line Intersections (cont…) –The x-coordinate of an intersection with a horizontal window boundary can be calculated using: x = x 1 + (y boundary - y 1 ) / m where y boundary can be set to either wy min or wy max –m is the slope of the line in question and can be calculated as m = (y 2 - y 1 ) / (x 2 - x 1 )

56 55 of 30 Initial Condition Sutherland-Hodgeman Algo. Clip Against Right Clipping Boundary Clip Against Top Clipping Boundary The Clipped Polygon Clip Against Bottom Clipping Boundary Clip Against Left Clipping Boundary

57 56 of 30 Polygon Clipping v1 v2 v1’ out in Output: v1’ and v2 v1 v2 in Output: v2 v1v2 v1’ in out Output: v1’ v1 v2 out Output: none outside inside Sutherland-Hodgeman Polygon Clipping against a rectangle (or a window) For each stage, the boundary clipper divides the plane into an inside half-plane And outside half-plane Inside half-plane contains the clipping window; Outside half-plane doesn’t. Given an edge going from vertex V[i] to vertex V[i+1], during the transversal, there are four cases (assuming the V[i] has been checked in the previous edge):

58 57 of 30 Case 1 4 Cases of Polygon Clipping Case 2 Case 3 Case 4

59 58 of 30 Cohen-Sutherland – polygons s p InsideOutside s p InsideOutside s p InsideOutside s p InsideOutside 1 st Output i OutputNo Output i 2 nd Output Output

60 59 of 30 Area Clipping Similarly to lines, areas must be clipped to a window boundary Consideration must be taken as to which portions of the area must be clipped

61 60 of 30 Sutherland-Hodgman Area Clipping Algorithm A technique for clipping areas developed by Sutherland & Hodgman Put simply the polygon is clipped by comparing it against each boundary in turn Original AreaClip LeftClip RightClip BottomClip Top Sutherland turns up again. This time with Gary Hodgman with whom he worked at the first ever graphics company Evans & Sutherland

62 61 of 30 Sutherland-Hodgman Area Clipping Algorithm (cont…) To clip an area against an individual boundary: –Consider each vertex in turn against the boundary –Vertices inside the boundary are saved for clipping against the next boundary –Vertices outside the boundary are clipped –If we proceed from a point inside the boundary to one outside, the intersection of the line with the boundary is saved –If we cross from the outside to the inside intersection point and the vertex are saved

63 62 of 30 Sutherland-Hodgman Example Each example shows the point being processed (P) and the previous point (S) Saved points define area clipped to the boundary in question S P Save Point P S P Save Point I I P S No Points Saved S P Save Points I & P I

64 63 of 30 Other Area Clipping Concerns Clipping concave areas can be a little more tricky as often superfluous lines must be removed Clipping curves requires more work –For circles we must find the two intersection points on the window boundary Window

65 64 of 30 Summary Objects within a scene must be clipped to display the scene in a window Because there are can be so many objects clipping must be extremely efficient The Cohen-Sutherland algorithm can be used for line clipping The Sutherland-Hodgman algorithm can be used for area clipping

66 65 of 30

67 66 of 30 Cohen-Sutherland Clipping Algorithm VI Let’s consider the lines remaining below wy max wy min wx min wx max Window P 3 [0001] P 6 [0000] P 5 [0000] P 7 [0001] P 10 [0100] P 9 [0000] P 4 [1000] P 8 [0010] P 12 [0010] P 11 [1010] P 13 [0101] P 14 [0110]

68 67 of 30 Cohen-Sutherland Clipping Algorithm Easy - a point ( x,y ) is not clipped if: wx min ≤ x ≤ wx max AND wy min ≤ y ≤ wy max otherwise it is clipped wy max wy min wx min wx max Window P1P1 P2P2 P5P5 P7P7 P 10 P9P9 P4P4 P8P8 Clipped Points Within the Window are Not Clipped Clipped

69 68 of 30 Clipping Point clipping is easy: –For point ( x,y ) the point is not clipped if wx min ≤ x ≤ wx max AND wy min ≤ y ≤ wy max wy max wy min wx min wx max Before Clipping Window P1P1 P2P2 P3P3 P6P6 P5P5 P7P7 P 10 P9P9 P4P4 P8P8

70 69 of 30 Cohen-Sutherland – polygons s p InsideOutside s p InsideOutside s p InsideOutside s p InsideOutside 1 st Output i OutputNo Output i 2 nd Output Output

71 Polygon Clipping.

72 71 of 30 Ex: Simple Convex

73 72 of 30 Ex: Multiple Components

74 73 of 30 Nonconvex with Many Edges

75 74 of 30 Polygons : Before Clipping

76 75 of 30 Polygons: Clip on Top Top Clip Boundary

77 76 of 30 Polygons: Clip on Right Right Clip Boundary

78 77 of 30 Polygons: Clip on Bottom Bottom Clip Boundary

79 78 of 30 Polygons: Clip on Left Left Clip Boundary

80 79 of 30 Polygons: Clipped Polygon

81 80 of 30 Begin Animated Recap

82 81 of 30 Polygons: Before Clipping

83 82 of 30 Polygons: Clip on Top Top Clip Boundary

84 83 of 30 Polygons: Clip on Top Top Clip Boundary

85 84 of 30 Polygons: Clip on Right Right Clip Boundary

86 85 of 30 Polygons: Clip on Right Right Clip Boundary

87 86 of 30 Polygons: Clip on Bottom Bottom Clip Boundary

88 87 of 30 Polygons: Clip on Bottom Bottom Clip Boundary

89 88 of 30 Polygons: Clip on left Left Clip Boundary

90 89 of 30 Polygons: Clip on left Left Clip Boundary

91 90 of 30 Polygons: Fully Clipped

92 91 of 30 Polygons: Clip on Left Left Clip Boundary

93 92 of 30 Polygons: Clipped Polygon

94 93 of 30 End Animated Recap

95 Hodgeman-Sutherland

96 95 of 30 Polygons: Case 1 INOUT S i output P

97 Case 1: S out; P in Action: Output i and P

98 97 of 30 Polygons: Case 2 (no output) P S IN OUT

99 Case 2: S & P both in Action: output p

100 99 of 30 Polygons: Case 3 P : second output i: first output S IN OUT

101 Case 3: S IN ; P OUT Action: Output i

102 101 of 30 Polygons: Case 4 Polygon being clipped P: output Clip boundary S IN OUT

103 Case 4: S & P both out Action: None

104 103 of 30 Case 2 : S & P both IN Action: Output P Case 3: S IN ; P OUT Action: Output i ( S already output under Case 1) Case 4: S & P both OUT Action: None Case 1: S OUT ; P IN Action: Output i and P

105 104 of 30 Hodgeman-Sutherland

106 105 of 30 Hodgeman-Sutherland

107 106 of 30 Hodgeman-Sutherland: Top

108 107 of 30 Hodgeman-Sutherland: Top

109 108 of 30 Hodgeman-Sutherland: Bottom

110 109 of 30 Hodgeman-Sutherland: Bottom

111 110 of 30 Hodgeman-Sutherland: Bottom

112 111 of 30 Hodgeman-Sutherland: Right

113 112 of 30 This case is trivial: do nothing Hodgeman-Sutherland: Right

114 113 of 30 Hodgeman-Sutherland: Left

115 114 of 30 Hodgeman-Sutherland: Left

116 115 of 30 Hodgeman-Sutherland: Left

117 116 of 30 Hodgeman-Sutherland: Done

118 117 of 30 Begin Animated Recap

119 118 of 30

120 119 of 30 Done Top

121 120 of 30

122 121 of 30 Done Bottom

123 122 of 30 Nothing needs to be clipped against Right

124 123 of 30

125 124 of 30 End Animated Recap

126 125 of 30 Hodgeman-Sutherland: Done

127 126 of 30 Hodgeman-Sutherland Problem Extra Lines

128 127 of 30 Correct Result How to Fix Up?

129 128 of 30 Distinguish Between Case 2 S i output P INOUT

130 129 of 30 And, Case 4 P : second output i : first output S INOUT

131 130 of 30 Distingish Between Case 2 S P INOUT

132 131 of 30 And, Case 4 P : second output S INOUT

133 132 of 30 Extended H-S Algorithm Tag the different new vertices Call the one generated on transition from IN to OUT Call the one generated on transition from OUT to IN Starting from OUT, connect as soon as is generated

134 133 of 30 Example of Extended Algo INOUT

135 134 of 30 Result INOUT

136 135 of 30 Extended H-S Algorithm Connect and as soon as the. is generated Generate next polygon beginning with next, i.e.,

137 Another Polygon Clipping Algorithm Weiler-Atherton Clipping

138 137 of 30 Another approach to polygon clipping No extra clipping outside window Works for arbitrary shapes Avoids degenerate polygons Weiler-Atherton Polygon Clipping

139 138 of 30 Weiler-Atherton Clipping 13 11 12 6 5 4 14 3 2 7 9 8 10 1 Clip Polygon (ep) Subject Polygon (sp)

140 139 of 30 Gives “Right” Answer

141 140 of 30 Start at first (inside) vertex Traverse polygon until hitting a window boundary Output intersection point i Turn right Follow window boundary until next intersection Weiler-Atherton Clipping

142 141 of 30 Output second intersection Turn right, again, and follow subject polygon until closed Continue on subject polygon from first intersection point. Repeat processing until complete Weiler-Atherton Clipping

143 142 of 30 Approximate description Can be improved Weiler-Atherton Clipping

144 143 of 30 Generalizations of W-A Can be extended to complex situations, arbitrary windows Stability issues can arise for such cases

145 General Boolean Operations via Boundary Representations (B-reps)

146 General Clipping with abitrary polygons

147 146 of 30 General Boolean Operations A B

148 147 of 30 A B

149 148 of 30 B

150 149 of 30 A B

151 150 of 30

152 151 of 30 A B A

153 152 of 30 A

154 153 of 30

155 154 of 30 A B

156 155 of 30 A B

157 156 of 30

158 157 of 30 A B

159 158 of 30

160 159 of 30 B on

161 160 of 30

162 161 of 30 A B on

163 162 of 30

164 163 of 30 ((anti-)shared ) anti-sharedshared

165 164 of 30 A B

166 165 of 30

167 166 of 30 A B

168 167 of 30

169 168 of 30 A B

170 169 of 30

171 The End Polygon Clipping Lecture Set 5


Download ppt "Unit – IV 2D Viewing. 2 of 30 Contents Windowing Concepts The viewing pipeline viewing coordinate reference frame, window to view-port coordinate transformation,"

Similar presentations


Ads by Google