Two-Dimensional Viewing Chapter 6
Viewing Pipeline
Two-Dimensional Viewing Two dimensional viewing transformation From world coordinate scene description to device (screen) coordinates
Normalization and Viewport Transformation World coordinate clipping window Normalization square: usually [-1,1]x[-1,1] Device coordinate viewport
Normalization and Viewport Normalization and Viewport Normalization and Viewport Normalization and Viewport Transformation Transformation + 2 i min max i xw xw xw xw xw xw + = 1 2 min max min max min max min max min max, yw yw yw yw yw yw xw xw xw xw M normsquare window 1 + 2 2 min max min max xv xv xv xv + = 1 2 2 min max min max, yv yv yv yv M viewport normsquare
Clipping Remove portions of a picture outside viewport or screen boundaries Two approaches: Clip during scan conversion: per-pixel bounds check, or span endpoint tests. Clip analytically, then scan-convert the modified primitive.
Two-Dimensional Clipping Point clipping trivial xw yw min min x y xw yw max max Line clipping (straight-line segments) Cohen-Sutherland Cyrus-Beck Liang-Barsky Fill-area clipping (polygons) Sutherland-Hodgeman Weiler-Atherton Ah Curve clipping Text clipping i
Line Clipping Basic calculations Is an endpoint inside or outside the clip rectangle? Find the point of intersection, if any, between a line segment and an edge of the clip rectangle. Both endpoints inside trivial accept One inside find intersection ti and clip Both outside either x = y = x y + u( x + u( y end end x y ) ) u 1 clip or reject
Cohen-Sutherland Line-Clipping Algorithm 11 1 11 1 View port 1 11 1 11 < Region code for each endpoint > Bit 4 3 2 1 above below right left
Cohen-Sutherland Line-Clipping Algorithm Trivially accepted if ( rc1 rc2 == ) // completely inside Trivially rejected if ( rc1 rc2 ) // completely outside Otherwise, divide line into two segments test intersection edges in a fixed order. (e.g., in the order of left, right, bottom, top)
Cohen-Sutherland Line-Clipping Algorithm y = x = y x + m ( x ) x ( y y + m ) m = ( y end y ) /( x end x ) Fixed order testing ti and clipping i cause needless clipping (external intersections)
Cohen-Sutherland Line-Clipping Algorithm When this is good If it can trivially reject or accept most cases Works well if a window is large w.r.t. data Works well if a window is small w.r.t. data i.e., it works well in extreme cases
Parametric Line Clipping (Cyrus-Beck Technique) Use a parametric line equation P ( t) = P + t( P1 P ), t 1 Reduce the number of calculating intersections by simple comparisons of parameter t.
Parametric Line Clipping (Cyrus-Beck Technique) Algorithm For each edge E i of the clip region N i : outward normal of E i
Parametric Line Clipping (Cyrus-Beck Technique) Choose an arbitrary point PE i on edge Ei and consider three vectors P( t) N N N i ( P( t) ) < i P E i ( E i a P E i point in the outside halfplane ( P( t) ) = an intersection point ( P ( t ) ) > a point in the inside halfplane i P E i P E
Parametric Line Clipping (Cyrus-Beck Technique) Solve for the value of t at the intersection of P P 1 with the edge: N i [P(t)-P Ei ]=. P(t) = P + t(p 1 - P ) and let D = (P 1 - P ), Then N i, t = N i [ P P N i D D (h (that is P P 1 ), N i D (if not, no intersection) Ei ] (edge and line are parallel )
Parametric Line Clipping (Cyrus-Beck Technique) Given the four values of t for a line segment, determine which pair of t's s are internal intersections. If t [,1] then discard else choose a (PE, PL) pair that defines the clipped line.
Parametric Line Clipping (Cyrus-Beck Technique) PE(potentially entering) intersection if moving from P to P 1 causes us to cross an edge to enter the edge's inside half plane PL(potentially ti leaving) intersection: ti if moving from P to P 1 causes us to leave the edge's inside half plane. N i N i P P 1 < P P > 1 PE PL Intersections can be categorized! Inside the clip rectangle (t E, t L ) t E : select PE with largest t value t L : select PL with the smallest t value 1.
Parametric Line Clipping (Cyrus-Beck Technique) This is an efficient algorithm when many line segments need to be clipped Can be extended easily to convex polygon windows
Liang-Barsky line clipping The ideas for clipping line of Liang-Barsky and Cyrus-Beck are the same. The only difference is Liang-Barsky algorithm has been optimized for an upright rectangular clip window. Finds the appropriate end points with more efficient computations.
Liang-Barsky line clipping Let PQ be the line which we want to study Q(x2,y2) Parametric equation of t R the line segment P(x1,y1) t B t L t T x= x + ( x x ) t = x + dx t 1 2 1 1 y = y + ( y y ) t = y + dy t t 1 2 1 1 = P( x, y ) 1 1 t = 1 Q ( x, y ) 2 2
Liang-Barsky Line Clipping 1. Set t min = and t max = 1 2. Calculate the values of t T, t B, t L, t R, L R t T T t B B
Liang-Barsky Line Clipping If t < t min or t > t max, ignore it and go to the next edge. Otherwise classify the t value as entering or exiting value (using the inner product to classify) Let PQ be the line and N is normal vector If N ( Q P), the parameter t is entering If N ( Q P ) >, the parameter t is exiting(leaving) If t is entering value, set t min = t If t is exiting value set t max =t N t R t T
Liang-Barsky Line Clipping 3. If t min < t max then draw a line from ( x + dx t, y + dy t ) 1 min 1 min to ( x + dx t, y + dy t ) 1 max 1 max Q(x2,y2) t R t T P(x1,y1) t L t B
Clipping Line clipping using nonrectangular polygon clip windows extend Cyrus-Beck algorithm (parametric clipping procedure) Line clipping using nonlinear clipping-window boundary Circles or other curved-boundary clipping regions More processing for non-linear intersection calculations
Polygon Fill-Area Clipping To clip a polygon fill area, can not directly apply a line-clipping method Line-clipping methods would not produce a closed polyline We need one or more closed polylines
Polygon Fill-Area Clipping Process a polygon fill area against successive clipping-window clip against 4 infinite clip edges in succession
Sutherland-Hodgeman Algorithm An efficient method for clipping a convex-polygon fill area Accept a series of vertices (polygon) and outputs a list of vertices Send a pair of endpoints for each successive polygon line segment through the series of clippers Left, right, bottom, and top clippers As soon as a clipper completes the processing of one vertex pair, the clipped coordinate values, if any, are sent to the next clipper.
Sutherland-Hodgeman Algorithm Four possible cases
Sutherland-Hodgeman Algorithm
Sutherland-Hodgeman Algorithm When applied to a concave polygon, it may display extraneous lines.
Sutherland-Hodgeman Algorithm How to correctly clip a concave polygon [Way I] Split the concave polygon into two or more convex polygons and process each convex polygon separately. [Way II] Modify the algorithm to check the final vertex list for multiple vertex points along any clip window boundary and correctly join pairs of vertices. [Way III] Use a more general polygon clipper
Splitting Concave Polygons Split the concave polygon into two or more convex polygons and process each convex polygon separately. vector method for splitting concave polygons Calculate edge-vector cross products in a counterclockwise order. If any z component turns out to be negative, the polygon is concave.
Weiler-Atherton Polygon Clipping For an inside-to-outside pair of vertices, follow the window boundary in a counterclockwise direction. For an outside-to-inside pair of vertices, follow the polygon boundary.
Weiler-Atherton Polygon Clipping 1. Process the polygon edges in a counterclockwise order until an inside-outside pair of vertices is encountered for one of clipping boundaries 2. Follow the window boundaries in a counterclockwise order from the exit-intersection pt. to another intersection point. If this is a previously processed pt., proceed to the next step If this is a new intersection pt., follow the polygon edges until a previously processed vertex is encountered 3. Form the vertex list 4. Return to the exit-intersection pt. and dfollow the polygon edges
Weiler-Atherton Polygon Clipping Polygon clipping using nonrectangular polygon clip windows
Texture Clipping 1. all-or-none text clipping : Using boundary box for the entire text 2. all-or-none character clipping : Using boundary box for each individual 3. clip individual id characters vector : clip line segments bitmap : clip individual pixels