1 / 15

4.1 Window-to-viewport Mapping

4.1 Window-to-viewport Mapping. We can define a window as a rectangular region of the world coordinate space, and the viewport as a rectangular region of the device coordinate system. (1,1). (1,1). (0,1/2). VIEWPORT. (Normalize). WINDOW. (0,0). (-1,1). (1,1).

kendis
Download Presentation

4.1 Window-to-viewport Mapping

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 4.1 Window-to-viewport Mapping We can define a window as a rectangular region of the world coordinate space, and the viewport as a rectangular region of the device coordinate system. (1,1) (1,1) (0,1/2) VIEWPORT (Normalize) WINDOW (0,0) (-1,1) (1,1) (3/4,1) (0,1/2) (Distortion) WINDOW (-1,1) (1/4,0)

  2. The problem is to "map" coordinates from the window units into the viewport units. Derive the mapping from (xw,yw) , a coordinate in the window, to (xv, yv), the corresponding point in the viewport: * Remove window coordinate system x1 = y1 = sxv sxw (xv,yv) syv syw (xw,yw) (cxw,cyw) (cxv,cyv) window viewport sxw syw (x1,y1) (cxw,cyw) window

  3. * Convert units x2 = y2 = * Remove to viewport center xv = yv = so xv = yv = (1) What happens if the ratios sxv/sxw and syv/syw are not equal? (2) If you want a set of data in the window, how do you decide the size of the window? sxv (x2,y2) syv (cxv,cyv) viewport

  4. (3) Can the window-to-viewport mappintg represented in matrix form?

  5. Homework: Find the transformation matrix that will map points contained in a window whose lower left corner is at (2,2) and upper right corner is at (6,5) onto a viewport that has a lower left corner at (1/2, 1/2) and upper right corner at (1,1).

  6. (80,80) * * (4) Derive the window to viewport mapping for viewports defined on devices which have the origin at the upper left of the screen, with the horizontal coordinate increasing right, and the vertical coordinate increasing down. y (100,100) h x v (100,100) (0,0) viewport window

  7. 4.2 2D Clipping The process of clipping decides which part, if any, of a primitive lies inside the window. The algorithms used for line clipping can be divided into two parts: (1) Check all the line segments and separate those that intersect the window boundary. (The curve is represented by a sequence of line segment) (2) Clip the line segments obtained from step 1 by calculating their intersections with the window boundaries. Clipping

  8. E G F Ymax A D Ymin B C Xmin Xmax (1) How can we sure that a line segment is totally inside the window (such as A) ? Both endpoints of the segment fall within the boundaries. (2) How can we sure that a line segment is totally outside the window (such as E,F,G)? Let two endpoints are (x1,y1),(x2,y2) If ( max{x1,x2} < xmin or min{x1,x2} > xmax or max{y1,y2} < ymin or min{y1,y2} > ymax) then the line segment is totally outside the window. We introduce an efficient procedure, the Cohen-Sutherland algorithm, to check the intersection property and further clip the line segment if necessary.

  9. Ymax Ymin Xmin Xmax Cohen-Sutherland Algorithm The 2D plane is divided into 9 regions. Each region is designated by a 4-bit (base 2) integer code. Each bit of the code is set to 1 (true) or 0 (false), starting with the left most one. The bits are assigned by the follow rule: bit 1 = 1 if the region is above the window. bit 2 = 1 if the region is below the window. bit 3 = 1 if the region is on the right of the window. bit 4 = 1 if the region is on the left of the window. (1001) (1000) (1010) (0001) (0000) (0010) (0001) (0100) (0110)

  10. (1) Given a point (x,y), we would like to assign a "region code" to it by using Cohen-Suterlandalgorithm. In C this can be coded: code = 0 if (x < xmin) code = 1 if (x > xmax) code = 2 if (y < ymin) code += 4 if (y > ymax) code += 8 (2) According to the C code in (1), what code will be assigned if the point is on the boundary of the window? (0000) * 0 (3) How about the point on the line Xmax and not on the boundary of the window? (0100) or (1000) depending on y

  11. (4) Draw precise picture for the partition of 2D plane according to the C code in (1). (Using solid line and dotted line) Let's consider the line clipping now. At first, the visibility of the line segment is determined as follows: (1) Visible -> Both endoint codes are (0000).

  12. (2) Invisible -> Bitwise logical AND of the endpoint codes is not (0000). (3) Indeterminate -> Bitwise logical AND of the endpoint codes is (0000), but at least one of the endpoint does not have a (0000) code. On the third situation, the line endpoints are "pushed" towards the boundary line until the first or the second situation occurs. Ymax (0001) (0010) (0000) Ymin Xmin Xmax

  13. The algorithm steps: 1. Calculate IC1 and IC2, the code of the two endpoints. 2. If (IC1 + IC2 .eq. 0) then "Visible". 3. If ( (IC1 .AND. IC2) .NE. 0) then "Invisible". 4. If ( IC1 .EQ. 0) then { Swap(IC1, IC2); Swap(X1,X2); Swap(Y1,Y2); } // At lease one point is outside the // viewport. Insure that point #1 is // one of the outside point. 5. Push endpoint #1 towards Xmin, Xmax, Ymin, or Ymax, depending on which region endpoint #1 occupies (via IC1). bit 1 = 1 toward Ymax bit 2 = 1 toward Ymin bit 3 = 1 toward Xmax bit 4 = 1 toward Xmin If endpoint #1 towards Ymax , then { Ymax = Y = X1 + t(Y2 - Y1), find t and calculate X = X1 + t(X2 - X1) } 6. Go To Step #1 above.

  14. Example: Let Xmin = 2, Xmax = 8, Ymin = 2 and Ymax = 8, check the visibility of the following segments using the Cohen-Sutherland Algorithm and, if necessary, clip them against the appropriate window boundaries. Line AB: A(3,10) B(6,12) Line CD: C(4,1) D(10,6) Example: Let Xmin = 2, Xmax = 8, Ymin = 2 and Ymax = 8, check the visibility of the following segments using the Cohen-Sutherland Algorithm. Line AB: A(3,10) B(6,12) Line CD: C(4,1) D(10,6) B(6,12) A(3,10) Ymax =8 D(10,6) Ymin=2 C(4,1) Xmin=2 Xmax=8

  15. How will the algorithm handle these examples? (A) (B) (C) (D)

More Related