150 likes | 311 Views
Introduction. Introduction. Abstract. Clipping is an basic oper ation of computer graphics Classical line clipping algorithms 1) Cohen-sutherland algorithm 2)Midpoint-subdivision algorithm 3)liang-Baskey algorithm Some rules of clipping algoritnm
E N D
Introduction Introduction Abstract • Clipping is an basic operation of computer graphics • Classical line clipping algorithms 1)Cohen-sutherland algorithm 2)Midpoint-subdivision algorithm 3)liang-Baskey algorithm • Some rules of clipping algoritnm 1)avoid unnecessary intersection calculation 2)quicken the process of intersection calculaiton 3)deal the special intersection quickly and robustly C-S clip V-window1 V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Abstract of the new algorithm Introduction Abstract C-S clip The new algorithm consists of three steps as follows V-window1 • Firstly reject lines as A by Encoding&code checking technique of Cohen-Sutherland algorithm. • Secondly we construct a diamond enclosing box of original box of the original window (Fig1) called V window to reject another portion of visible lines such as line f. • Lastly we construct a virtual enclosing box of the original window called K window to identify all the remaining lines (line e is rejected ) . V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Cohen-sutherland’s clipping Introduction Abstract C-S clip The traditional Encoding &code technique V-window1 V-window2 • The two-dimensional plane is divided into nine non-overlapping reginons as Shown in fig2 • A four-digit-code is used to indicate the two endpoints of the line are located • If code(p1)|code(p2 )=0 /*line is totally visible*/ else if code(p1)&code(p2)!=0/*line is partially visible*/ else /*line is totally unvisible */ K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Redundant line clipping with v-window1 Introduction Abstract C-S clip New encoding&code by v-window V-window1 V-window2 • Traditional technique can’t Reject lines as line f; • A diamond enclosing box of the original window is constructed as shown in fig 3 • Such window we call it v-window cuts the plane into nine regions • Each of the regions is also indicated by a four-digit-code as shown in fig 3 • Since the v-window is aligned 45°to the X-axis the encoding procedure is simple K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Redundant line clipping with v-window2 Introduction Abstract C-S clip The encoding procedure V-window1 • Let the boundary of the original clipping window be left-(XL),right-(XR),top-(YT),bottom-(YB). • The encoding procedure can be described as follows • #define LEFT 1 If(x+y-YB<XL) code=code|LEFT; • #define RIGHT 2 Else if(x+y-YT>XR) code=code|RIGHT; • #define BOTTOM 4 If(y-x+XR<YB) code=code|BOTTOM; • #define TOP 8Else if(y-x+XL>YT) code=code|TOP; • Code=0; Return code; • model consists of seven layers of services and protocols. V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary How simple the procedure is!
Remaining line clipping with K-window Introduction Abstract C-S clip Rejecting of remaining redundant lines V-window1 • Lines such as line e is still can’t be rejected after the previous steps; • The virtual window(k-window) is consturcted which aligns with direction of the line to be clipped ,as shown in fig4 • Now the line e is easily rejected by this means . • If(b<b1)||(b>b2) return FALSE; b=Ya-kXa; • /*redundant lines such as line e */ b1=YB-kXR; • Else {… …} b2=YT-kXL; • Here b ,b1,b2 are calculated as following : k=(Ya-Yb)/(Xa-Xb); now all the redundant lines have been rejected! V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Fast intersection calculation1 Introduction Abstract C-S clip Two cases of lines that intersect with the V-window1 • Suppose k isthe slop of the line and K_WINDOW is the slop of the original diagonal. If(k<=K_WINDOW) The broken lines In Fig5 constitute the reduced K-Window. Else The Broken lines in Fig6 constitute the reduced K-Window. • By comparing the y_intercept of the line that of V1 an V2 ,two edges of the reduced V-window shown in Fig5 or Fig 6. Clipping window V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Fast intersection calculation 2 Introduction Abstract C-S clip The Exact edges of the original window that intersect V-window1 with the line can be determined as follows V-window2 K-window • If (b<=b4) line can only intersect with right edge and the bottom edge(line E2 in Fig5 and Fig6 ) • Else if (b>=b3) line can only be intersect with left edge and top edge (line E1 in Fig5 And Fig 6) Else {if (k<=K_WINDOW) line can only Intersect with left edge and right edge (line E3 in Fig 5) Else {… …}line can only intersect with top Edge and bottom edge(line E3 in Fig 6) } Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Fast intersection calculation 3 Introduction Abstract Here b3 and b4 are y-intercepts of V1 and V2 They are determined as folllows : C-S clip V-window1 V-window2 If(k>=K_WINDOW )Else { {b3=b1+YT-YB; b4=b1+YT-YB; b4=b2+YT-YB;} b3=b2-YT-YB;} The results of the six cases of intersection Calculation are listed bellow: Line E1 of Fig5 and Fig6: (XL,YT-b2+b),(XL+(b2-b)/k,YT) Line E2 of Fig5 and Fig6: (XR,YB+b-b1),(XR-(b-b1)/k,YB) Line E3 of Fig5: (XL,YB+b-b3),(XR,YT-b4+b) Line E3of Fig6: (XL+(b4-b)/k,YB),(XR-(b-b3)/k,YT) K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Fast intersection calculation4 Introduction Abstract Note that lines perpendicular to X-axis belong to a special subset ,which need separate treating. C-S clip • Implementation of the new clipping algorithm : • We implemented the new algorithm on PC and compared its performance than of Cohen-Sutherland algorithm C-S for short . • Our machine is based on PentiumⅡ 350MHZ ,and the compile is Turbo C 2.0 running on Windows 2000 • Six thousand lines that satisfy the case are clipped by C-S and our algorithm in seconds.(table1) Line types are specified as follows V-window1 V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Line types1 Introduction Abstract C-S clip • A1:can only rejected by C-S algorithm after one time of intersection calculation and it can be rejected by V-WINDOW • A2: can only rejected by C-S algorithm after two time of intersection calculation and it can be rejected by V-WINDOW • B1: can only rejected by C-S algorithm after one time of intersection calculation and it can be rejected by k-WINDOW • B2: can only rejected by C-S algorithm after two time of intersection calculation and it can be rejected by k-WINDOW • C1: can only rejected by C-S algorithm after two time of intersection calculation and it can be rejected by reduced k-WINDOW • C2: can only rejected by C-S algorithm after three time of intersection calculation and it can be rejected by reduced k-WINDOW • C3: can only rejected by C-S algorithm after four time of intersection calculation and it can be rejected by reduced k-WINDOW V-window1 V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Line types2 Introduction Abstract C-S clip • D: combined lines that are made up of such lines 1) One thousand lines which can be accepted by tranditional Encoding&Code checking technique. 2) one thousand lines which can be rejected by tranditional Encoding&Code checking technique. 3) One thousand lines which can be rejected by V-window. 4) One thousand lines which can be rejected by K-window. 5) One thousand lines with one endpoint inside the clipping window and the other outside it. 6) One thousand partially visible lines which can be clipped with reduced k-Window. V-window1 V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary Statistics in Table1 Suggests the potential of our new algorithm!
Discussion of our new algorithm1 Introduction Abstract How much is the chance for lines to be rejectedby the V-window? C-S clip V-window1 • Traditional Encodint&code technique Can reject or accept such lines that totally in the regions of, ABGL,BCIF, CDKH,and DAEJ,MNOP.So the ratio of lines which can be rejected is: • Similarly,V-window rejects lines of four portions trivially ,lines whose two endpoints locate ,respectively ,in the regions of XLM and ESM ,in the regions of QKP and JVP,in the regions of WIO and THO ,and in the regions of RFN and UGN .examples of such lines are a-d in Fig8 .the ratio of lines within each portion to all lines is : V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Discussion of our new algorithm2 Introduction Abstract C-S clip • The ratio of lines rejected by V-Window to lines remaining after the first clipping step can be deduced as follows : • Table 2 list the value of M1 and M2 when t is specified to different values .If t>100,there are nearly a half of lines that can be trivially rejected by V-Window .The greater t is .the larger the ratio M2 will be .Apparently ,V-Window does contribute to the high efficiency of line clipping . V-window1 V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary
Summary Introduction Abstract C-S clip • Line clipping is a fundamental operation of computer graphics . • In this new algorithm ,we pays more attention to the efficiency of rejection. • With adaptively constructed V-Window and K-Window ,our algorithm can quickly reject all invisible lines,which may otherwise incur unnecessary intersection calculation in traditional clipping algorithms • Moreover ,the exact edges of the original clipping windows,which intersect with a partially visible line can be easily identified by our algorithm. V-window1 V-window2 K-window Intersection1 Intersection2 Intersection3 Intersection4 Line types 1 Line types 2 Discussion 1 Discussion 2 Summary