Viewing Pipeline: Window-Viewport Transf. 2D Viewing yw max clipping window: what to display viewport: where to be viewed translation, rotation, scaling, clipping,... Clipping Window yv max Viewport yv min yw min xw min xw max world coordinates Werner Purgathofer / Computergraphik 1 1 xv min xv max viewport coordinates 2-dim. Viewing-Transformation Pipeline Modeling construction of objects and scenes World definition of viewing area and orientation WC VC Transformation setting up a rotated world window in viewing coordinates and the corresponding normalized-coordinate viewport transformation to normalized viewing frame Normalized mapping to device dependent values Device Viewport Werner Purgathofer / Computergraphik 1 2 World Coordinates Werner Purgathofer / Computergraphik 1 3 Viewing Coordinate Reference Frame A viewingcoordinate frame is moved into coincidence with the world frame in two steps: (a) translate the viewing origin to the world origin (b) rotate to align the axes of the two systems. 2-dim. Viewing-Transformation Pipeline Modeling construction of objects and scenes transformation to normalized viewing frame World Normalized definition of viewing area and orientation mapping to device dependent values Device Werner Purgathofer / Computergraphik 1 4 Werner Purgathofer / Computergraphik 1 5 1
Window - Viewport Transform (1) point (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 - Viewport Transform (2) linear in x and y (xw min /yw min ) (xv min /yv min ) (xw max /yw max ) (xv max /yv max ) Werner Purgathofer / Computergraphik 1 6 Werner Purgathofer / Computergraphik 1 7 t x Window - Viewport Transform (3) xw = xw min + λ ( ) where 0 λ 1 xv = xv min + λ (xv max xv min ) xw xw min λ = xw xw xv = xv min + min (xv max xv min ) xw = xv min min (xv max xv min ) + xw window-viewport transformation: xv = s x xw+t x Werner Purgathofer / Computergraphik 1 8 xv max xv min yv = s y.yw+t y s x 2-dim. Viewing-Transformation Pipeline Modeling construction of objects and scenes transformation to normalized viewing frame Werner Purgathofer / Computergraphik 1 9 World Normalized definition of viewing area and orientation mapping to device dependent values Device Workstation Transformation Viewing Window Normalized Space 1 Viewport 0 0 1 Viewport Device 1 Clipping partly visible or completely invisible parts must not be ignored and must not be drawn ignored scrolled [Mapping selected parts of a scene in normalized coordinates to different video monitors with workstation transformations] Viewport Device 2 vertices must be cut off (if possible in world coordinates) edges Werner Purgathofer / Computergraphik 1 10 Werner Purgathofer / Computergraphik 1 11 2
Clipping Operations remove objects outside a clip window clip window: rectangle, polygon, curved boundaries applied in world or viewing coordinates combined with scan conversion objects to clip: points, lines, polygons, curves, text,... 3 Possibilities for Clipping analytically = in world coordinates reduces WC DC transformations during raster conversation = as part of the rasterization algorithm efficient for complex primitives pixel by pixel test biggest effort, very primitive algorithm Werner Purgathofer / Computergraphik 1 12 Werner Purgathofer / Computergraphik 1 13 Line Clipping (1) Line Clipping (2) P 9 P 4 P 3 P 5 P 10 P 1 P 8 P P 8 P 1 6 P 6 P 5 P 7 P 2 P 2 before clipping after clipping [line clipping against a rectangular clip window] P 7 goals eliminate simple cases fast avoid intersection calculations for endpoints (x 0,y 0 ), (x end,y end ) intersect parametric representation x = x 0 + u (x end x 0 ) y = y 0 + u (y end y 0 ) with window borders: intersection 0 < u < 1 Werner Purgathofer / Computergraphik 1 14 Werner Purgathofer / Computergraphik 1 15 assignment of region codes to line endpoints bit1: left bit2: right bit3: below bit4: above binary region codes assigned to line endpoints according to relative position with respect to the clipping rectangle or of codes of both points = 0000 line entirely visible and of codes of both points 0000 line entirely invisible all others intersect! Werner Purgathofer / Computergraphik 1 16 Werner Purgathofer / Computergraphik 1 17 3
Werner Purgathofer / Computergraphik 1 18 [lines extending from one coordinate region to another may pass through the clip window, or they may intersect clipping boundaries without entering the window] remaining lines intersection test with bounding lines of clipping window left, right, bottom, top discard an outside part repeat intersection test up to four times vertical: y = y 0 + m(xw min x 0 ), y = y 0 + m(xw max x 0 ) horiz.: x = x 0 + (yw min y 0 )/m, x = x 0 + (yw max y 0 )/m Werner Purgathofer / Computergraphik 1 19 Polygon Clipping modification of line clipping goal: one or more closed areas intersects boundaries without entering clipping window passes through clipping window vertical: y = y 0 + m(xw min x 0 ), y = y 0 + m(xw max x 0 ) horiz.: x = x 0 + (yw min y 0 )/m, x = x 0 + (yw max y 0 )/m [display of a polygon processed by a lineclipping algorithm] [display of a correctly clipped polygon] Werner Purgathofer / Computergraphik 1 20 Werner Purgathofer / Computergraphik 1 21 processing polygon boundary as a whole against each window edge output: list of vertices four possible edge cases V 1 V 1 V 1 original polygon clip left clip right clipping a polygon against successive window boundaries Werner Purgathofer / Computergraphik 1 22 clip bottom clip top V 1 V V 1 1 out in output: V 1, in in successive processing of pairs of polygon vertices against the left window boundary Werner Purgathofer / Computergraphik 1 23 in out V 1 out out no output 4
for 1 edge: := 1 st vertex Sutherland-Hodgman no no V 1 visible? V 1 := :=next vertex visible? yes no yes V 1 visible? V 1 = clip edge V 1 result list result list yes [clipping a polygon against the left boundary of a window, starting with vertex 1. Primed numbers are used to label the points in the output vertex list for this window boundary] finished! Werner Purgathofer / Computergraphik 1 24 Werner Purgathofer / Computergraphik 1 25 Polygon Clip: Combination of 4 Passes the polygon is clipped against each of the 4 borders separately, that would produce 3 intermediate results. by calling the 4 tests recursively, (or by using a clipping pipeline) every result point is immediately processed on, so that only one result list is produced Werner Purgathofer / Computergraphik 1 26 Sutherland-Hodgman Clipping Example pipeline of boundary clippers to avoid intermediate vertex lists Werner Purgathofer / Computergraphik 1 27 3 1 st clip: left [Processing the polygon vertices through a boundary-clipping pipeline. After all vertices are processed through the pipeline, the vertex list for the clipped polygon is {1, 2, 2, 2 } ] 2 2 3 1 1 2 2 nd clip: bottom extraneous lines for concave polygons: split into separate parts or final check of output vertex list Text Clipping (1) [clipping the concave polygon with the Sutherland- Hodgeman clipper produces two connected areas] Werner Purgathofer / Computergraphik 1 28 1. text clipping using a bounding rectangle about the entire string Werner Purgathofer / Computergraphik 1 29 5
Text Clipping (2) Text Clipping (3) T NO. 1 TEX 2. text clipping using a bounding rectangle about individual characters 3. text clipping performed on the components of individual characters Werner Purgathofer / Computergraphik 1 30 Werner Purgathofer / Computergraphik 1 31 Summary: Clipping Cohen-Sutherland line clipping Hodgman-Sutherland polygon clipping text clipping Werner Purgathofer / Computergraphik 1 32 6