1 / 30

Computer Graphics

This chapter discusses the concepts of window and viewport in 2D viewing, including their definitions, transformations, and effects such as zooming and panning. It also covers clipping algorithms for point and line objects.

Download Presentation

Computer Graphics

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. Computer Graphics Chapter 8 Two-Dimensional Viewing

  2. 1. The 2D viewing World (2D) Window in the world Display device (2D) Viewportin the display device Computer Vision & Pattern Recognition Lab.

  3. 1. The 2D viewing • (Clipping) Window : What area in the world is to be viewed? • Todefine what we want to see • a world-coordinate area selected for display • Viewport: Which area on the display device is it to be displayed? • To define where it is to be displayed on the output device • a device-coordinate area on a display device • Windows & viewport • Rectangles in standard position, with the rectangle edges parallel to the coordinate axes • Other geometries : take longer to process Computer Vision & Pattern Recognition Lab.

  4. 1. The 2D viewing • Viewing transformation • Mapping of a part of a world-coordinate scene to device coordinates • 2D viewing transformation = window-to-viewport transformation = windowing transformation Computer Vision & Pattern Recognition Lab.

  5. 1. The 2D viewing • Viewing-transformation • By changing the position and size of the viewport • We can view objects at different positions and size/proportion on the display area of an output device • Zooming effect • By successively mapping smaller clipping windows onto a fixed-size viewport • Panning effect • By successively moving a fixed-size clipping window across various objects in a scene viewport Computer Vision & Pattern Recognition Lab.

  6. 2. The Clipping Window (skip!) • Viewport • Defined within the unit square • Device-independent ⇒ Separating the viewing & other transformations from specific output-device requirements • The unit square is mapped to the display area for the particular output device in use at that time • Viewport clipping • Performed in normalized coordinates or in device coordinates • To reduce computations by concatenating the various transformation matrices Computer Vision & Pattern Recognition Lab.

  7. The window-to-viewport transform: 1. Translate the window’s lower-left corner to the origin. 2. Scale width and height of window to match viewport’s. 3. Translate corner at origin to lower-left corner in viewport. 3. Window-to-Viewport Transformations Computer Vision & Pattern Recognition Lab.

  8. 3. Window-to-Viewport Transformations 10 20 30 40 50 60 70 80 0 3 2 1 0 -4 -3 -2 -1 1 2 3 4 -1 -2 -3 Viewport (screen) Window (“world”) v y (xmax, ymax) (umax, vmax) 60 50 40 x 30 20 10 (umin, vmin) (xmin, ymin) u 0 Computer Vision & Pattern Recognition Lab.

  9. The final window-to-viewport transform is: 3. Window-to-Viewport Transformations Computer Vision & Pattern Recognition Lab.

  10. Multiplying the matrix Mwv by the point p gives: 3. Window-to-Viewport Transformations Computer Vision & Pattern Recognition Lab.

  11. Example: Window: (xmin, ymin) = (-3, -3) Viewport: (umin, vmin) = (30, 10) (xmax, ymax) = (2 , 1) (umax, vmax) = (80, 30) 10 20 30 40 50 60 70 80 0 3 2 1 0 -4 -3 -2 -1 1 2 3 4 -1 -2 -3 3. Window-to-Viewport Transformations Window (“world”) Viewport (“screen”) v y 60 (xmax, ymax) 50 40 (umax, vmax) x 30 20 10 (umin, vmin) (xmin, ymin) u 0 Computer Vision & Pattern Recognition Lab.

  12. Plugging the values into the equation: 3. Window-to-Viewport Transformations Computer Vision & Pattern Recognition Lab.

  13. Verifying some points: 10 20 30 40 50 60 70 80 0 3 2 1 0 -4 -3 -2 -1 1 2 3 4 -1 -2 -3 3. Window-to-Viewport Transformations (xmin, ymin) = (-3, -3) -> (30, 10) (xmax, ymax) = (2, 1) -> (80, 30) Left eye = (-1, -.8) -> (50, 21) Top of head = (-0.5, 0.5) -> (55, 27.5) Window (“world”) Viewport (“screen”) v y 60 50 40 x 30 20 10 u 0 Computer Vision & Pattern Recognition Lab.

  14. 5. Clipping Algorithms • Clipping algorithm • Identify those portions of 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 • Clipping application (skip!) • extracting part of a defined scene for viewing • identifying visible surfaces in 3D views • antialiasing line segments or object boundaries • creating objects using solid-modeling procedures • displaying a multiwindow environment • drawing & painting operations that allow parts of a picture to be selected for copying, moving, erasing, or duplicating Computer Vision & Pattern Recognition Lab.

  15. 6. Two-Dimensional Point Clipping • For a clipping rectangle in standard position, • A point P=(x, y) is displayed if • Otherwise, the point is clipped Computer Vision & Pattern Recognition Lab.

  16. 7. Two-Dimensional Line Clipping • Line clipping procedure (1) Test a given line segment whether it lies completely inside the clipping window (2) If it doesn’t, we try to determine whether it lies completely outside the window (3) If we can’t identify a line as completely inside or completely outside, we must perform intersection calculations with one or more clipping boundaries Computer Vision & Pattern Recognition Lab.

  17. 7. Two-Dimensional Line Clipping • Checking the line endpoints • Line clipping • Cohen-Sutherland line clipping • Liang-Barsky line clipping (skip!) Computer Vision & Pattern Recognition Lab.

  18. 7. Two-Dimensional Line Clipping • Cohen-Sutherland line clipping • one of the oldest and most popular line-clipping procedures • speed up the processing of line segments by performing initial tests that reduce the number of intersections that must be calculated • Region code : four-digit binary code (outside test) ⇒ bit 1:left, bit 2:right, bit 3:below, bit 4:above • bit 1 is set if x < xwmin bit 2 is set if x > xwmax bit 3 is set if y < ywmin bit 4 is set if y > ywmax Computer Vision & Pattern Recognition Lab.

  19. 7. Two-Dimensional Line Clipping TBRL Bit 4 3 2 1 1000 1010 Top Top-Right Top-Left 1001 Inside 0010 Left Right 0001 0000 Region Codes : Bottom-Left Bottom-Right Bottom 0110 0101 0100 Computer Vision & Pattern Recognition Lab.

  20. 7. Two-Dimensional Line Clipping 1. Assign a region code for each endpoints. 2. If both endpoints have a region code 0000  trivially accept 3. Else, perform the logical AND operation for both region codes. 3.1 if the result is not 0000  trivially reject the line. 3.2 else – (result = 0000, need clipping) 3.2.1 Choose an endpoint that is outside the window 3.2.2 Find the intersection point at the window boundary (Using region code). 3.2.3 Replace endpoint with the intersection point and update the region code. 3.2.4 Repeat step 2 until we find a clipped line either trivially accepted or trivially rejected. 4. Repeat step 1 for other lines. Computer Vision & Pattern Recognition Lab.

  21. 7. Two-Dimensional Line Clipping How to check for intersection? if bit 4 = 1  there is intersection on TOP boundary. if bit 3 = 1  .. .. .. .. BOTTOM .. if bit 2 = 1  .. .. .. .. RIGHT .. if bit 1 = 1  .. .. .. .. LEFT .. How to find intersection point? - use line equation intersection with LEFT or RIGHT boundary. x = xwmin (LEFT) x = xwmax (RIGHT) y = y0 + m(x –x0) intersection with BOTTOM or TOP boundary. y = ywmin (BOTTOM) y = ywmax (TOP) x = x0 + (y –y0)/m Computer Vision & Pattern Recognition Lab.

  22. 7. Two-Dimensional Line Clipping TBRL • Example Bit 4 3 2 1 B1 1000 1010 B2 1001 D1 A2 C1 A1 0010 0001 0000 C2 D2 0110 0101 0100 Computer Vision & Pattern Recognition Lab.

  23. 7. Two-Dimensional Line Clipping algorithm 1. A1=0000,A2=0000 1000 1010 1001 2. Both A1 and A2 are 0000 - Yes A2 0010 0001 0000 A1 0110 0101 0100 Computer Vision & Pattern Recognition Lab.

  24. 7. Two-Dimensional Line Clipping algorithm 1. B1=1001,B2=1010 1000 1010 1001 2. (both 0000) – No B1 B2 3. AND Operation B1  1001 B2  1010 Result 1000 A2 0010 0001 0000 3.1 Result is not 0000  rejected A1 0110 0101 0100 Computer Vision & Pattern Recognition Lab.

  25. 7. Two-Dimensional Line Clipping TBRL algorithm Bit 4 3 2 1 1. C1=0001,C2=0000 1. C1=0000,C2=0000 2. (both 0000) – Yes -> accept & draw 2. (both 0000) – No 3. AND Operation C1  0001 C2  0000 Result 0000 1000 1010 1001 A2 C1 3.2 Result is 0000 3.2.1. choose C1 3.2.2. Intersection point, C1’ at LEFT A1 0010 0001 0000 C1’ C2 3.2.3 C1 <- C1’ C1 = 0000 3.2.4 repeat 2 0110 0101 0100 Computer Vision & Pattern Recognition Lab.

  26. 7. Two-Dimensional Line Clipping TBRL algorithm Bit 4 3 2 1 1. D1=0000,D2=0000 2. (both 0000) – Yes -> accept & draw 1. D1=1001,D2=0110 2. (both 0000) – No 3. AND Operation D1  1001 D2  0110 Result 0000 D1 1000 1010 1001 A2 C1 D1’ 3.2 Result is 0000 3.2.1. choose D1 3.2.2. Intersection point, D1’ at LEFT A1 0010 0001 0000 C1’ C2 D2’ 3.2.3 D1 <- D1’ D1 = 0000 3.2.4 repeat 2 0110 0101 0100 D2 Computer Vision & Pattern Recognition Lab.

  27. 8 Polygon Fill-Area Clipping • Sutherland-Hodgman Algorithm • Given: polygon vertices V1, V2, ..., Vn Input Vertex List: 1-2-3 Output Vertex List: 1’-2’-2’’-3’-3’’-1’’ • Approach: “Divide and conquer” Computer Vision & Pattern Recognition Lab.

  28. 8 Polygon Fill-Area Clipping • Sutherland-Hodgman Algorithm • Algorithm: 1. Clip against one clip edge.             For each polygon edge from S to P              if S, P are inside, add P to the list                if S is inside and P is outside, add intersection point to the list if S is outside and P is inside, add inter. pt. and P to the list if S, P are outside, no action 2. Repeat Step 1 for the other 3 clip edges.            • Inside-outside tests (slide 29 of Chap 6) • Odd-even rule • If # of crossings is odd, interior. • If # of crossings is even, exterior. (Make sure there is no crossing at vertex) A B Computer Vision & Pattern Recognition Lab.

  29. Out -> In Save new clip vertexand ending vertex In -> Out Save new clip vertex In -> In Save ending vertex Out -> Out Save nothing Sutherland-Hodgman algorithm Computer Vision & Pattern Recognition Lab.

  30. Sutherland-Hodgman algorithm C’ C’’ A C A’ B’’ A’’ B’ B Left Clipper Right Clipper Bottom Clipper Top Clipper { } BB’ B”C’’ C’’ A’B B A’B AB C’ B’’C’’ BC B’ B’C’’ C’’C’ C BC A’ C’ CC’ C’’C’ C’’C’ C’ C’A’ CA A” C’A’ A’ C’A’ A’A” A’ A’’ A’’B” B” A’B Edges Output Edges Output Edges Output Edges Output Final Computer Vision & Pattern Recognition Lab.

More Related