Computer Graphics Chapter 4 2 D Viewing Algorithms

  • Slides: 22
Download presentation
Computer Graphics Chapter 4 2 D Viewing Algorithms 1

Computer Graphics Chapter 4 2 D Viewing Algorithms 1

Coordinate Systems y v (u, v) (x, y) 0 x World Coordinates: • User-Defined

Coordinate Systems y v (u, v) (x, y) 0 x World Coordinates: • User-Defined Limits • Floating point values RM 0 u Device Coordinates: • Device dependent Limits • Positive Integer values 2

Window: A rectangular region in World Coordinate System. Viewport: A rectangular region in Device

Window: A rectangular region in World Coordinate System. Viewport: A rectangular region in Device Coordinate System. (0, 300) (0, 0) RM (360, 0) 3

Window to Viewport Transformation We denote the boundaries of the world window by four

Window to Viewport Transformation We denote the boundaries of the world window by four real values xmin, ymin, xmax, ymax denoting its left, bottom, right, top margins respectively. Similary the boundaries of the viewport on the screen are defined by four integer values umin, vmin, umax, vmax. When a graphics display is generated using arbitrary coordinates on the world window, the important problem encountered in viewing this display on the actual viewport on the screen is to have a function which maps every point (x, y) on the window to a corresponding point (u, v) on the viewport. The following window to viewport transformation achieves this relationship. RM 4

Window to Viewport Transformation (xmax, ymax) (x, y) (umax, vmax) (u, v) (xmin, ymin)

Window to Viewport Transformation (xmax, ymax) (x, y) (umax, vmax) (u, v) (xmin, ymin) (umin, vmin) RM (x, y) (u, v) 5

Window to Viewport Transformation u = c 1 x + c 2 v =

Window to Viewport Transformation u = c 1 x + c 2 v = d 1 y + d 2 RM 6

Window to Viewport Transformation 400 0. 2 0. 1 -0. 05 +0. 05 100

Window to Viewport Transformation 400 0. 2 0. 1 -0. 05 +0. 05 100 250 550 u = 3000 x + 400 v = 3000 y 200 RM 7

Aspect Ratio = Width/Height. • Aspect ratio of a world window = (xmax-xmin) /

Aspect Ratio = Width/Height. • Aspect ratio of a world window = (xmax-xmin) / (ymax-ymin). • Aspect ratio of the viewport = (umax-umin) / (vmax-vmin). The transformation from the window to viewport is said to preserve the aspect ratio, if both the above quantities are same. In such a case, we have c 1 = d 1. When this condition is satisfied, the mapping from the window to the viewport is distortion-free. RM 8

Window to Viewport Transformation For distortion-free mapping from the window to the viewport, we

Window to Viewport Transformation For distortion-free mapping from the window to the viewport, we must have c 1 = d 1 (in magnitude) 400 0. 2 0. 1 RM 100 -0. 05 +0. 05 250 u = 1000 x + 300 v = 3000 y 200 350 9

W-V Transform (Open. GL) RM 10

W-V Transform (Open. GL) RM 10

Line Clipping A line is required to be clipped against a rectangular clipping window

Line Clipping A line is required to be clipped against a rectangular clipping window such that the portion of the line that falls outside the window is not displayed. There are many possible arrangements of a segment with respect to the window. We therefore need an organized approach to identify the correct situation and to compute the new end points of each clipped segment. Efficiency is important because a typical picture contains thousands of line segments, each of which must be clipped against a window. RM 11

Line Clipping Window RM Clipping Window 12

Line Clipping Window RM Clipping Window 12

Cohen-Sutherland Algorithm A rapid divide-and-conquer approach to the line clipping Clipping window Trivial Accept:

Cohen-Sutherland Algorithm A rapid divide-and-conquer approach to the line clipping Clipping window Trivial Accept: When both end points are inside the window, and therefore the line is completely visible. RM Trivial Reject: When both end points are outside the window and on the same side of the window. Then the line is completely outside, and hence can be rejected. 13

Region Codes A point is assigned a unique region code depending on the location

Region Codes A point is assigned a unique region code depending on the location of the point with respect to the window. A B R L 1001 1000 1010 0001 0000 0010 Clipping window 0101 RM 0100 0110 14

Region Codes Trivial Accept 0000 r 1 == 0000 and r 2 == 0000

Region Codes Trivial Accept 0000 r 1 == 0000 and r 2 == 0000 (r 1 OR r 2) == 0000 RM (OR: Bitwise) 15

Region Codes Trivial Reject 1010 0010 r 1 and r 2 have a common

Region Codes Trivial Reject 1010 0010 r 1 and r 2 have a common bit set to 1 (r 1 AND r 2) 0000 RM (AND: Bitwise) 16

Region Codes “Other Cases” 1001 1010 0000 0100 RM 17

Region Codes “Other Cases” 1001 1010 0000 0100 RM 17

Region Codes “Other Cases” i. The point that lies outside the window is considered.

Region Codes “Other Cases” i. The point that lies outside the window is considered. (This is the point whose region code is non-zero). ii. For the above point, an edge outside which the point lies is identified. (If a particular bit is non-zero, the corresponding edge of the window is considered). iii. The intersection of the line with the edge is computed. The initial point in (i) is now replaced by the new intersection point. Its region code is computed. iv. The conditions for the “trivial accept” or “trivial reject” or “other case” is again checked for the new line segment. RM 18

Region Codes 1010 0000 RM Trivial Accept 19

Region Codes 1010 0000 RM Trivial Accept 19

Computing Intersection Point (Eg. ) Q P A x=xmin The equation of the line

Computing Intersection Point (Eg. ) Q P A x=xmin The equation of the line PQ is The intersection point A lies on the left edge and therefore its x-coordinate is x = xmin. To get the y-coordinate of A, we substitute for x in the above equation of PQ: y= RM 20

Computing Intersection Point (Eg. ) Q P A x=xmin Now P is replaced by

Computing Intersection Point (Eg. ) Q P A x=xmin Now P is replaced by the point A (effectively discarding the segment PA), and the whole process of checking is repeated for the segment AQ. Now both A, Q will have region codes 0000, and hence will satisfy the condition “trivial accept”. RM 21

Line Clipping (Open. GL) RM 22

Line Clipping (Open. GL) RM 22