Lecture15-2d-viewing - 2D Viewing Part II Clipping Algorithms Why would we clip • Clip objects before rasterization • To avoid unnecessary work

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 2D Viewing Part II Clipping Algorithms Why would we clip? • Clip objects before rasterization. • To avoid unnecessary work: – pixel coordinate calculations – parameter interpolation Type of Clipping • • • • • Point Clipping Line Clipping Fill-Area Clipping Curve Clipping Text Clipping Line Clipping (xwmin, ywmax) Clipping window (xwmax, ywmax) (xwmin, ywmin) (xwmax, ywmin) Line Clipping Algorithms • Simple Line Clipping • Cohen-Sutherland Algorithm • Liang-Barsky Algorithm Simple Line Clipping • Using point-clipping test to determine completely INSIDE or OUTSIDE line. xwmin ≤ x ≤ xwmax ywmin ≤ y ≤ ywmax • Using parametric equations to determine partially INSIDE or OUTSIDE line. x = x0 + u ( xend − x0 ) y = y0 + u ( yend − y0 ) 0 ≤ u ≤ 1 Cohen­Sutherland Algorithm Top-Left Top Top-Right Left Inside Right Bottom-Left Bottom TBRL Bottom-Right Region Codes Cohen­Sutherland Algorithm (cont.) 1001 1000 TBRL Bit 1 2 3 4 1010 0001 0000 0010 0101 0100 0110 Cohen­Sutherland Algorithm (cont.) 1. Assign a region code for each endpoints. 2. If both endpoints have a region code 0000 trivially accept these line. 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 of the line that is outside the window. 3.2.2. Find the intersection point at the window boundary (base on 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. How to check for intersection? if bit 1 = 1 there is intersection on TOP boundary. if bit 2 = 1 .. .. .. .. BOTTOM .. if bit 3 = 1 .. .. .. .. RIGHT .. if bit 4 = 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 Trivial accept & reject B1 1001 D1 C1 0001 A1 C2 0101 0100 0110 D2 0000 1000 A2 0010 1010 B2 Example 1001 1000 1010 1. algorithm A1=0000,A2=0000 2. (both 0000) – Yes Yes -> accept & draw 3. 3.1 3.2 3.2.1 3.2.2 3.2.3 3.2.4 A2 0001 A1 0000 0010 0101 0100 0110 Example Example B1 1001 1000 1010 1. B1=1001,B2=1010 B2 2. (both 0000) – No A2 0001 A1 0000 3. AND Operation B1 1001 B2 1010 Result 1000 0010 3.1 (not 0000) – Yes reject 3.2 3.2.1 3.2.2 3.2.3 0110 3.2.4 algorithm 0101 0100 Example Example 1001 C1 A2 0001 A1 C1’ C2 0101 0100 0000 1000 1. 1010 1. algorithm C1=0001,C2=0000 C1=0001,C2=0000 2. (both 0000) ––No 2. (both 0000) Yes 3-.>AND Operation AND & accept draw 0001 3. 0000 0010 3.1result 0000 33.2 .1(not 0000) - No 3.2. .2.1 3 (0000)-Yes 33.2.2 choose C1 .2.1. 33.2.3 .2.2. Intersection 3.2.4 0110 point, C1’ at LEFT 3.2.3 C1 <- C1’ C1 = 0000 3.2.4 repeat 2 Example Example D1 1001 D1’ 1000 D1’’ A2 0001 A1 C1’ C2 0101 0100 0000 0010 1010 algorithm D2’’ 0110 D2’ D2 Advantage & Disadvantage of Cohen­Sutherland Algorithm • Easy to implement • Early accept/reject tests • Slow for many clipped lines Exercise • (xwmin, xwmax) = (10, 150) • (ywmin, ywmax) = (10, 100) • P0 = (0, 120) • P1 = (130, 5) ...
View Full Document

This note was uploaded on 04/05/2010 for the course COMPUTER S 876 taught by Professor Ch during the Spring '10 term at Amirkabir University of Technology.

Ask a homework question - tutors are online