Extraction of data/primitives inside a region of interest “ window ” => Discard (parts of ) primitives outside window. Point Clipping: Remove points outside window. • A point is either entirely inside the window or not (x R , y T ) Q x L <= x <= x R P y B <= y <= y T Q is inside P is outside (x L , y B )
Line Clipping: Remove portion of line segment outside window • Can we use point clipping for the end points? 1 2 Point clipping works
Line Clipping: Remove portion of line segment outside window • How about these lines? 3 5 4 Point clipping does not work
Cohen and Sutherland
Cohen and Sutherland 4 bit code to indicate the zone of end points of line with respect to window 1xxx xx1x xxx1 0000 x1xx
Cohen and Sutherland 4 bit code to indicate the zone of end points of line with respect to window 1001 1000 1010 0001 0000 0010 0101 0110 0100
Cohen and Sutherland Trivially accept case • line is totally visible • if both ends of the line have outcode as 0000 Trivially accept
Cohen and Sutherland Trivially reject case • line is totally invisible • logical AND of the two end points outcodes Trivially reject
Cohen and Sutherland If not trivially reject and accept case • line is potentially visible Potentially visible
Cohen and Sutherland If potentially visible • subdivide into segments and apply trivial acceptance and rejection test • segments by intersection with window edges • edges in any order but consistent (e.g., top-bottom, right-left) D B B A A Result
Cohen and Sutherland • simple, still popular • limited to rectangular region • extension to 3D clipping using 3D orthographic view volume is straightforward
Cyrus Beck Line Clipping (Liang and Barsky) • any convex region B Parametric line (input line AB): L ( t ) A ( B A ) t ; t ( 0 , 1 ) = + − ∈ A
Cyrus Beck Line Clipping (Liang and Barsky) P Implicit line (window edge): n l ( Q ) ( Q P ). n = − • Q Tells us on which side of the line the point Q is.
Cyrus Beck Line Clipping (Liang and Barsky) Evaluate l ( Q ) ( Q P ). n = − If > 0 inside halfspace of line (plane) P If < 0 outside halfspace of line (plane) n If = 0 on the line Outside • Q Should give indications for trivial accept and reject cases. Inside
Cyrus Beck Line Clipping (Liang and Barsky) l ( Q ) ( Q P ). n Window edge = − Line segment L ( t ) A t ( B A ) = + − P n Trivial Reject l ( A ) 0 AND l ( B ) 0 Outside < < • Q Trivial Accept l ( A ) 0 AND l ( B ) 0 > > Inside
Cyrus Beck Line Clipping (Liang and Barsky) P n
Cyrus Beck Line Clipping (Liang and Barsky) L ( t ) A ( B A ) t = + − l ( Q ) ( Q P ). n = − B A l ( L ( t )) 0 ; solve for t = P ( L ( t ) P ). n 0 n − = ( A t ( B A ) P ). n 0 + − − = ( A P ). n t ( B A ). n 0 − + − =
Cyrus Beck Line Clipping (Liang and Barsky) ( A P ). n − t = B A ( B A ). n − ( A P ). n − t = P n ( A P ). n ( B P ). n − − −
Cyrus Beck Line Clipping (Liang and Barsky) B (t=1) n Which ‘ t ’ to select ? A (t=0)
Cyrus Beck Line Clipping (Liang and Barsky) B (t=1) ( A P ). n − t = ( B A ). n − n D ( B A ). n = − D > 0 label t as t E Entering (t=0) A
Cyrus Beck Line Clipping (Liang and Barsky) B (t=1) ( A P ). n − t = ( B A ). n − D ( B A ). n = − n D < 0 label t as t L Leaving (t=0) A
Cyrus Beck Line Clipping (Liang and Barsky) B (t=1) t of interest: max t largest t E E min smallest t L t n L (t=0) A
Cyrus Beck Line Clipping (Liang and Barsky) max min t t If > E L Reject
Cyrus Beck Line Clipping (Liang and Barsky) Arbitrary Convex Window V 6 V 5 P 2 E 5 E 6 V 7 V 4 E 4 E 3 E 7 V 3 P 1 V 8 E 8 E 2 E 1 V 1 V 2
Cyrus Beck Line Clipping (Liang and Barsky) Arbitrary Convex Window E xE : positive 1 2 V 6 V 5 P 2 E xE : positive E 5 2 3 E 6 . V 7 V 4 E 4 . E 3 . E 7 V 3 P 1 V 8 E 8 E 2 E 1 Polygon is convex if for all V 1 V 2 adjacent edges the sign of cross product is same.
Cyrus Beck Line Clipping (Liang and Barsky) Arbitrary Window E xE : positive 1 2 E xE : positive V 5 V 6 2 3 E 4 E xE : negative V 4 3 4 . V 3 . E 3 . E 2 E 1 V 1 V 2 Polygon is non-convex
Cyrus Beck Line Clipping (Liang and Barsky) Arbitrary Window Make the polygon convex by adding the edge V 3 V 5 V 5 V 6 P 2 P 4 E 4 V 4 Clip against the convex polygon V 3 => P 3 P 4 E 3 P 3 E 2 E 1 P 1 V 1 V 2
Cyrus Beck Line Clipping (Liang and Barsky) Arbitrary Window Clip against the triangle V 5 => P 5 P 4 P 4 V 4 Subtract P 5 P 4 from P 3 P 4 V 3 P 5 => P 3 P 5 P 3
Recommend
More recommend