Presentation is loading. Please wait.

Presentation is loading. Please wait.

Clipping Computer Graphics Cohen Sutherland Algorithm (Line)

Similar presentations


Presentation on theme: "Clipping Computer Graphics Cohen Sutherland Algorithm (Line)"— Presentation transcript:

1 Clipping Computer Graphics Cohen Sutherland Algorithm (Line)
Cyrus-Back Algorithm (Line) Midpoint Subdivision Algorithm

2 Point Clipping For a point (x,y) to be inside the clip rectangle:

3 Point Clipping For a point (x,y) to be inside the clip rectangle:

4 Cases for clipping lines
Line Clipping Cases for clipping lines

5 Cases for clipping lines
Line Clipping Cases for clipping lines

6 Cases for clipping lines
Line Clipping Cases for clipping lines

7 Cases for clipping lines
Line Clipping Cases for clipping lines

8 Cases for clipping lines
Line Clipping Cases for clipping lines

9 Cases for clipping lines
Line Clipping Cases for clipping lines

10 Clipping Lines by Solving Simultaneous Equations
Line Clipping Clipping Lines by Solving Simultaneous Equations

11 Cohen-Sutherland Algorithm
The Cohen-Sutherland Line-Clipping Algorithm performs initial tests on a line to determine whether intersection calculations can be avoided. First, end-point pairs are checked for Trivial Acceptance. If the line cannot be trivially accepted, region checks are done for Trivial Rejection. If the line segment can be neither trivially accepted or rejected, it is divided into two segments at a clip edge, so that one segment can be trivially rejected. These three steps are performed iteratively until what remains can be trivially accepted or rejected.

12 Cohen-Sutherland Algorithm
Region outcodes

13 The rightmost bit is the first bit
The rightmost bit is the first bit. The bits are set to 1 based on the following scheme. 1) First bit Set- If the end point is to the left of the window. 2) Second bit Set- If the end point is to the right of the window. 3) Third bit Set- If the end point is to the below the window. 4) Fourth bit Set- If the end point is to the above the window. Otherwise the bit is set to Zero.

14 The intersection with the window edges are given by
Left XL Y=m(XL-X1)+Y1 Right XR Y=m(XR-X1)+Y1 Top YT X=X1+1/m(YT-Y1) Bottom YB X=X1+1/m(YB-Y1)

15 Cohen-Sutherland Algorithm
A line segment can be trivially accepted if the outcodes of both the endpoints are zero. A line segment can be trivially rejected if the logical AND of the outcodes of the endpoints is not zero. A key property of the outcode is that bits that are set in nonzero outcode correspond to edges crossed.

16 Cohen-Sutherland Algorithm
An Example

17 Cohen-Sutherland Algorithm
An Example

18 Cohen-Sutherland Algorithm
An Example

19 Cohen-Sutherland Algorithm
An Example

20 Parametric Line-Clipping
(1) This fundamentally different (from Cohen-Sutherland algorithm) and generally more efficient algorithm was originally published by Cyrus and Beck. (2) Liang and Barsky later independently developed a more efficient algorithm that is especially fast in the special cases of upright 2D and 3D clipping regions.They also introduced more efficient trivial rejection tests for general clip regions.

21 The Cyrus-Back Algorithm

22 The Cyrus-Back Algorithm

23 The Cyrus-Back Algorithm
PE = Potentially Entering PL = Potentially Leaving

24 The Cyrus-Back Algorithm
Precalculate Ni and PEi for each edge for (each line segment to be clipped) { if (P1 == P0) line is degenerated, so clip as a point; else { tE = 0; tL = 1; for (each candidate intersection with a clip edge) { if (Ni • D != 0) { /* Ignore edges parallel to line */ calculate t; use sign of Ni • D to categorize as PE or PL; if (PE) tE = max(tE , t); if (PL) tL = min(tL , t); } } if (tE > tL) return NULL; else return P(tE) and P(tL) as true clip intersection;

25 Mid Point Subdivision Algorithm
The Cohen-Sutherland algorithm requires the calculation of the intersection of the line with window edge. This direct calculation can be avoided by performing a binary search for the intersection by always dividing the line at its mid point. This algorithm is implemented in hardware.

26 Mid Point Subdivision Algorithm
Implementation in hardware is fast & efficient because a parallel architecture can be used and hardware addition & division by 2 are very fast. In hardware, division by 2 can be accomplished by shifting each bit to the right. The algorithm uses the line end point codes & associated test to immediately identify totally visible lines, & trivially invisible lines.

27 Mid Point Subdivision Algorithm
Lines which can not be immediately identified using there test are subdivided into 2 equal parts. The test are then applied to each half until the intersection with the window edge is found or the length of the divided segment is infinitesimal i.e. 0 point. The visibility of the point is then determined. The result is to perform a logarithmic search for the intersection point.

28 Mid Point Subdivision Algorithm
Pm2 Pm1 P2 P1 Pm2 Pm1 Pm2 P2

29 Thank You


Download ppt "Clipping Computer Graphics Cohen Sutherland Algorithm (Line)"

Similar presentations


Ads by Google