This document discusses 2D viewing transformations and clipping techniques in computer graphics. It describes how 2D viewing transformations map 3D world coordinates to 2D device coordinates for display by defining a window and viewport. Clipping techniques like point, line, and polygon clipping are used to remove hidden portions outside the viewing window. Common clipping algorithms like Cohen-Sutherland line clipping and Sutherland-Hodgman polygon clipping are also summarized.
This document discusses 2D viewing transformations and clipping techniques in computer graphics. It describes how 2D viewing transformations map 3D world coordinates to 2D device coordinates for display by defining a window and viewport. Clipping techniques like point, line, and polygon clipping are used to remove hidden portions outside the viewing window. Common clipping algorithms like Cohen-Sutherland line clipping and Sutherland-Hodgman polygon clipping are also summarized.
This document discusses 2D viewing transformations and clipping techniques in computer graphics. It describes how 2D viewing transformations map 3D world coordinates to 2D device coordinates for display by defining a window and viewport. Clipping techniques like point, line, and polygon clipping are used to remove hidden portions outside the viewing window. Common clipping algorithms like Cohen-Sutherland line clipping and Sutherland-Hodgman polygon clipping are also summarized.
This document discusses 2D viewing transformations and clipping techniques in computer graphics. It describes how 2D viewing transformations map 3D world coordinates to 2D device coordinates for display by defining a window and viewport. Clipping techniques like point, line, and polygon clipping are used to remove hidden portions outside the viewing window. Common clipping algorithms like Cohen-Sutherland line clipping and Sutherland-Hodgman polygon clipping are also summarized.
Download as PPT, PDF, TXT or read online from Scribd
Download as ppt, pdf, or txt
You are on page 1of 34
2D Viewing and Clipping
2D viewing transformation or Viewing
Transformation is a mapping of world coordinate scene to device coordinates Viewing means transforming the objects from the world coordinates to device coordinates. To display a picture on the screen, we must determine: What part of the world coordinate is to be displayed (window) The term window refers to a world area selected for display. It defines what is to be viewed. Where it should be displayed on the screen (viewport) Viewport is an area on a display device to which a window is mapped. It defines where it is to be displayed
Window and viewports are usually rectangles in standard position with rectangle edges parallel to the coordinate axes. xw min xw max yw min yw max xv min xv max yv min yv max clipping window world coordinates viewport viewing coordinates Viewing transformation is the process of mapping a part of a world coordinate scene to device coordinate.
It defines the location and size of the image to be displayed.
The two dimensional viewing transformation is sometimes referred to as the window-to- viewport transformation or the windowing transformation. Two-dimensional viewing transformation pipeline
Construct world coordinate scene using modeling coordinate transformation Convert world coordinate to viewing coordinate Transform viewing coordinate to normalized coordinate Map normalized coordinate to device coordinates MC WC VC NC DC
(x 0 , y 0 ) is the viewing coordinate origin
V is view up vector
v = (v x , v y ) and u = (u x , u y ) are unit vectors x 0 xw
y 0 yw
world coordinates viewing coordinates yv
xv
V v u A rotated viewing coordinate reference frame is illustrated Viewing Coordinate Reference Frame
The origin of the 2D viewing coordinate frame is defined in the world coordinates as P0(X0,Y0) The orientation of the 2D viewing coordinate frame is defined in the world coordinates using a vector V(y-view) that defines the 2D view up vector. Steps in 2D viewing transformation: Translate the viewing origin to the world coordinate origin. Rotate the viewing coordinate system to align with the world coordinate system. Viewing Coordinate Reference Frame
The matrix for converting world-coordinate positions to viewing coordinates can be obtained by: translating the viewing origin to the world origin rotating to align the two coordinate reference frame Transformation from the world coordinates to the viewing coordinates: 1. Translate viewing origin to world origin 2. Rotate viewing system to align it with the world frame
M WC,VC = R.T xw
yw
yv
xv xw
yw
yv
xv
2D Viewing xw min xw max yw min yw max xv min xv max yv min yv max clipping window world coordinates viewport viewing coordinates Window-to-Viewport Coordinate Mapping it is the process that converts object coordinates in the world coordinate system to normalized device coordinates. It is also called normalization transformation. Normalized Viewport xw min xw max yw min yw max xv min xv max yv min yv max clipping window world coordinates viewport viewing coordinates 0 1 1 (x w , y w ) (x v , y v ) 2D Viewing Normalized Viewport
1. Scale clipping window to the size of viewport using fixed-point (xw min , yw min ) 2. Translate (xw min , yw min ) to (xv min , yv min )
M window,normviewp = T . S Point Clipping slightly checks whether a single point is within the clip window Line Clipping eliminates lines entirely outside the clip window and calculates new endpoints for lines only partially within the clip window. Polygon Clipping calculates the boundary for the part of a polygon which overlaps the clip window.
2D Clipping Algorithm Clipping algorithms identify portions of the picture that lie inside or outside of a specified region (clip window) Point Clipping
P will be displayed if xw min x xw max and
yw min y yw max
P=(x,y) yw min yw max xw min xw max A point P = (x,y) is considered inside the window if the following inequalities are satisfied: Line Clipping Procedure for line clipping is summarized as follows: Test a given line segment to determine whether it lies completely inside the clipping window. If it does not, determine whether if lies completely outside the window. If the line is not completely inside nor completely outside the window, perform intersection calculations with one or more clipping boundaries. Lines that cross one or more clipping boundaries require calculations of multiple intersection points. To minimize calculations, clipping algorithms that can be efficiently identity outside lines and reduce intersection calculations can be devised. If both endpoints are inside of all 4 clipping boundaries => inside If both endpoints are outside any one of the 4 boundaries => outside Otherwise, line intersects at least one boundary and it may or may not cross the window
Line Clipping x = x 0 + u(x end x 0 ) y = y 0 + u(y end y 0 )
if 0 u 1 part of the line is inside
(x 0 ,y 0 ) (x,y) (x end ,y end ) Line Clipping Cohen-Sutherland Line Clipping Line Clipping Process: Identify those lines which intersect the clipping windows (which are to be clipped) Perform clipping All lines fall into one of the following clipping categories: 1. Visible both endpoints of the line is within the window 2. Not Visible the line definitely lies outside the window. This will occur if the line from (x1, y1) to x2, y2) satisfies any one of the following four inequalities X1, X2 > X max Y1, Y2 > Y max X1, X2 < X min Y1, Y2 < Y min 3. Clipping Candidate the line is in neither category 1 nor 2. Cohen-Sutherland Line Clipping 1 - endpoint is outside of that window border 0 - inside or on the border top bottom right left 1 2 3 4 1 0 0 1 1 0 0 0 1 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 0 1 1 0 Cohen-Sutherland Line Clipping A region-code 0000 for both endpoints => completely inside Region-code 1 in the same bit position for each endpoint => completely outside If OR of region codes of endpoints is 0000 => inside If AND of region codes of endpoints is not 0000 =>outside Other cases: check for intersection sign of (x-xw min ) 1 2 3 4 sign of (xw max -x) sign of (y-yw min ) sign of (yw max -y) Cohen-Sutherland Line Clipping Processing order of boundaries: left, right, bottom, top
Intersection point:
m = (y end y 0 ) / (x end x 0 )
y = y 0 + m(x-x 0 ) x is xw min or xw max
x = x 0 + (y-y 0 )/m y is yw min or yw max
Cohen-Sutherland Line Clipping Polygon Clipping Clip polygons by successively clipping against 4 sides. Sutherland-Hodgman Polygon Clipping In this algorithm, all polygon vertices will be process against each clip rectangle boundary to produce an output vertex list for the clipped polygon. Sutherland-Hodgman Polygon Clipping There are four possible cases of polygon clipping. As each pair of adjacent polygon vertices is passed to a window boundary clipper, the following tests are performed: 1. If the first vertex is outside the window boundary and the second vertex is inside, the intersection point added to the output vertex list. 2. If both input vertices are inside the window boundary, only the second vertex is added to the output vertex list. 3. If the first vertex is inside the window boundary and the second vertex is outside, only the edge intersection with the window boundary is added to the output vertex list. 4. If both input vertices are outside the window boundary, nothing is added to the output list. Sutherland-Hodgman Polygon Clipping 1. First vertex is outside the window border and second vertex is inside => send the intersection point and the second vertex to the next clipper 2. Both vertices are inside => send only the second vertex 3. First vertex is inside and the second vertex is outside => send only the intersection point 4. Both vertices are outside => no vertices are sent v1 v2 v1 v1 v2 v1 v2 v1 v1 v2 Sutherland-Hodgman Polygon Clipping Concave Polygons
Split concave polygon into convex polygons and then use Sutherland- Hodgman algorithm or Modify the algorithm to check the vertex list for multiple intersection points along any boundary. Then split into separate sections. Curve Clipping Curve-clipping procedures involve nonlinear equations and requires more processing than for objects with linear boundaries. Curve clipping procedures are described below: 1. If the bounding rectangle for the object is completely inside the window, save the object. 2. If the rectangle is determined to be completely outside the window, discard the object. There is no further computation necessary in each case. 3. If the object is neither inside nor outside the window, look for other computation-saving approaches. For a circle, use the coordinate extents of individual quadrants and then octants for preliminary testing before calculating curve-window intersections. For an ellipse, test the coordinate extents of individual quadrants. Curve Clipping Illustrates circle clipping against a rectangular window. Text Clipping Text clipping The simplest and fastest text clipping method is the all-or-none string-clipping strategy. In this method, if all of the string is inside a clip window, it is kept; otherwise, it is discarded, This procedure is implemented by considering a bounding rectangle around the text pattern. The boundary positions of the rectangle are then compared to the window boundaries, and the string is rejected if there is any overlap Text Clipping The all-or-non character-clipping strategy discards only those character that are not completely inside the window. In this case, the boundary limits of the individual characters are compared to the window. Any character that either overlaps or is outside a window is clipped. Text Clipping Another text clipping method is to clip the components of individual characters. Characters are treated the same way as lines were treated. If an individual character overlaps a clip window boundary, we clip off the parts of the character that are outside the window.