# 2 D viewing Prepared by Elizabeth Isaac DCS, RSET.

## Presentation on theme: "2 D viewing Prepared by Elizabeth Isaac DCS, RSET."— Presentation transcript:

2 D viewing Prepared by Elizabeth Isaac DCS, RSET

The Viewing Pipeline Viewing transformations in several steps Window to Viewport. Window: A region of the scene selected for viewing (also called clipping window) Viewport: A region on display device for mapping to window 2-D viewing transformation referred to as Window –to-Viewport Transformation or windowing transformation

World Coordinates Viewing Coordinates Window Viewport The Viewing Pipeline

A viewing transformation using standard rectangles for the window and viewport World Coordinates xv min xv max yw max yw min Device Coordinate xv min xv max yv max yv min

The two-dimensional viewing- transformation pipeline Construct World Coordinate Scene Using Modeling-Coordinate Transformation Convert World-Coordinates to Viewing Coordinates Map Viewing Coordinates to Normalized Viewing Coordinates using Window-Viewport Specifications Map Normalized Viewport to Device Coordinates

Setting up a rotated world window in viewing coordinates and the corresponding normalized- coordinate viewport Normalized Device Coordinates Viewpoint 0 1 1 World Coordinates y view x view y world y0y0 x0x0 x world

Viewing Coordinate Reference Frame The steps in this coordinate transformation – A viewing coordinate frame is moved into coincidence with the world frame in two steps a)Translate the viewing origin to the world origin, then b)Rotate to align the axes of the two systems

Viewing Coordinate Reference Frame

Matrix for converting world-coordinate positions to viewing coordinate R: rotation matrix T: translation matrix

Window-To-Viewport Coordinate Transformation A point at position (xw, yw) in a designated window is mapped to viewport coordinates (xv, yv) so that relative positions in the two areas are the same

Window-To-Viewport Coordinate Transformation To maintain the same relative placement

Window-To-Viewport Coordinate Transformation Solving these expressions The scaling factors

Window-To-Viewport Coordinate Transformation Conversion sequence of transformation 1.Perform a scaling transformation using a fixed- point position of (xw min, yw min ) that scales the window area to the size of the viewport 2.Translate the scaled window area to the position of the viewport

Window-To-Viewport Coordinate Transformation Workstation transformation – Opening any number of output devices in a particular application – Performing another window-to-viewport transformation for each open output device

Window-To-Viewport Coordinate Transformation

Two-Dimensional Viewing Functions Setting up the elements of a window-to- viewport mapping matrix evaluateViewMappingMatrix (xwmin, xwmax, ywmin, ywmax, xvmin, xvmax, yvmin, yvmax, error, viewMappingMatrix)

Two-Dimensional Viewing Functions Selection of a workstation window-viewport pair – setWorkstationWindow (ws, xwsWindmin, xwsWindmax, ywsWindmin, ywsWindmax) – setWorkstationViewport (ws, xwsVPortmin, xwsVPortmax, ywsVPortmin, ywsVPortmax)

Clipping Any procedure that identifies those portions of a picture that are either inside or outside of a specified region of space is referred to as a clipping algorithm or clipping Clip window

Clipping – Point – Line – Area (or Polygons) – Curve – Text

Clipping Point Clipping Assuming that the clip window is a rectangle in standard position Saving a point P=(x, y) for display

Line Clipping Line clipping against a rectangular clip window

Line Clipping

Cohen-Sutherland Line Clipping Four digit binary code - Region Code Identifies the location of the point relative to the boundaries of the clipping rectangle Bit 1: left Bit 2: right Bit 3: below Bit 4: above 4321

Cohen-Sutherland Line Clipping

– Calculate differences between endpoint coordinates and clipping boundaries – Use the resultant sign bit of each difference calculation to set the corresponding value in the region code

Region code divide space into 9 regions Computation of region code requires at most 4 subtractions b 0 = 1 if y > y max, 0 otherwise b 1 = 1 if y < y min, 0 otherwise b 2 = 1 if x > x max, 0 otherwise b 3 = 1 if x < x min, 0 otherwise

Cohen-Sutherland Line Clipping Outside Line Removal Test – A method that can be used to test lines total clipping is to perform the logical and operation with both region codes – Not 0000 Completely outside the clipping region!! Lines that cannot be identified as completely inside or outside a clip window by this test

Cohen-Sutherland Line Clipping

Intersection Point Calculate Intersection Point – Using the slope-intercept form – Vertical Boundary – Horizontal Boundary

1. Start 2. Read two end points of a line P1,P2 (x1,y1) and (x2,y2) 3. Read two corners of window(wx1,wy1) and(wx2,wy2) 4. Assign the region codes for two end points using following steps – a. Set bit 1 if x < wx1 – b. Set bit 2 if x>wx2 – c. Set bit 3 if y<wy2 – d. Set bit 4 if y> wy1

5. Check for the visibility of the line – a. If region codes for both end points are 0 then the line is completely visible. Draw the line. Go to 10 – b. If the region codes are not zero and the logical AND ing of them is also non zero then the line is completely invisible. Go to 10 – c. If the region codes for two end points do not satisfy the conditions in 5 a and 5 b the line is partially visible

6. Determine the intersecting edge of the clipping window by inspecting the region codes of two end points – a. If the region codes foe both end points are non zero find the intersection point P1’ and P2’ with boundary edges of clipping window with respect to P1 and P2 respectively – b. If the region code for any one end point is non zero then find intersection point P1’ or P2’ with the boundary edge of the clipping window with respect to it.

7. Divide the line segments considering the intersection points 8. Reject the line segment if any one end point of it appears outside the clipping window 9. Draw the remaining line segments 10. Stop.

Polygon Clipping

36 Sutherland-Hodgman Clipping

37 Sutherland-Hodgman Clipping

38 Sutherland-Hodgman Clipping

39 Sutherland-Hodgman Clipping

40 Sutherland-Hodgman Clipping

41 Sutherland-Hodgman Clipping

42 Sutherland-Hodgman Clipping

43 Sutherland-Hodgman Clipping

Sutherland-Hodgeman Polygon Clipping

4 possible cases

Sutherland-Hodgeman Polygon Clipping

Weiler-Atherton Polygon Clipping Rules – For an outside-to-inside pair of vertices, follow the polygon boundary – For an inside-to-outside pair of vertices, follow the window boundary in clockwise direction

Other Polygon-Clipping Algorithm Clipping a polygon by determining the intersection of two polygon areas

Text clipping

All-or-none string clipping – No text is retained after clipping since part of text is outside clip window

Text clipping All-or-none character clipping – Only “ B ” and “ C ” are retained after clipping since part of “ A ” is outside clip window

Text clipping Character component clipping – All of “ B ” and “ C ” are retained, and those parts of “ A ” inside clip window are also retained

interior clipping – what is to be saved is inside the clip window exterior clipping – what is to be saved is outside clip window Interior clipping - keep point P2 P2 (x2, y2)

Exterior Clipping Exterior clipping - keep point P1 Clip window P1 (x1, y1)