You are on page 1of 15

Cohen-Sutherland Example

How many logical ANDs do we have to perform? B

Cohen-Sutherland Example
Remember, outcodes are: above | below | right | left 1000 B

A = 0101 0001 0000 A 0100 0010 B = 1010

Cohen-Sutherland Example
1000 B

1. A&B = 0 0001 0000 A 0100 0010 So we need to do something further. Neither point has zero outcode, so we choose either, well start with A. We find first nonzero bit and split at implied edge (bottom).

Cohen-Sutherland Example
1000 B

1. A&B = 0 0001 C We can throw away A-C, new line is C-B. A 0100 0000 0010 So we need to do something further. Neither point has zero outcode, so we choose either, well start with A. We find first nonzero bit and split at implied edge (bottom).

Cohen-Sutherland Example
1000 B We now have this situation: 0001 C 0000 0010 C = 0001 B = 1010 2. C&B = 0 Both are nonzero so well pick C arbitrarily.

0100

Cohen-Sutherland Example
1000 B First non-zero bit in C implies left edge is crossed, split at intersection to get D.

0001 C D 0000

0010

0100

Cohen-Sutherland Example
1000 B First non-zero bit in C implies left edge is crossed, split at intersection to get D.

0001 D 0000

0010

Throw away C-D, new line is D-B.

0100

Cohen-Sutherland Example
1000 B Finally, we have a point with a zero outcode: D = 0000 B = 1010 0001 D 0000 0010 But B is nonzero. We dont need to perform an AND we definitely have more work to do. So we turn our attention to point B

0100

Cohen-Sutherland Example
1000 B E First non-zero bit of B implies crossing of upper boundary. So we split at intersection with upper boundary to get E.

0001 D 0000

0010

0100

Cohen-Sutherland Example
1000 We can throw away E-B, so new line is D-E. E First non-zero bit of B implies crossing of upper boundary. So we split at intersection with upper boundary to get E.

0001 D 0000

0010

0100

Cohen-Sutherland Example
1000 E We are left with: D = 0000 0001 D 0000 0010 E = 0010 Again, we have one non-zero outcode. Dont need to perform AND, but still cant do a trivial accept.

0100

Cohen-Sutherland Example
1000 E F 0001 D 0000 0010 First non-zero bit of E implies right edge crossing. Compute intersection, giving F.

0100

Cohen-Sutherland Example
1000

F 0001 D 0000 0010

Throw away E-F. Both outcodes equal zero, so we trivially accept the line.

0100

ANSWER: 2 AND operations

Intersections for Cohen-Sutherland


Example where outcode implies point 2 is above the upper boundary (x2,y2) Outside (above) Inside m = (y2-y1)/(x2-x1) dy = ymax-y1 (x1,y1) Giving: x = x1 + dy/m y = ymax

y = ymax

Clipping Summary (ref: Angel chap. 7.3-7.7)


We perform clipping to avoid rendering polygons that lie outside the view volume i.e. it is a speed up Quicker to perform clipping than to just render everything Clipping: operates with primitives, expensive to perform but speeds up later stages, happens before rasterization Scissoring: operates with pixels, allows arbitrary regions to be masked, happens after rasterization Cohen-Sutherland algorithm:

1. 2D or 3D method for clipping line segments. 2. Assigns outcodes to start and end points, can decide what to do based on whether outcodes and their logical AND are non-zero. 3. Sometimes performs redundant clipping. Fast when there are lots of trivial accepts/rejects (i.e. lots of line segments totally outside or totally inside). Parametric clipping algorithms (Ling-Barsky) Try to avoid explicit intersection calculations, can order parameter values and make inferences works in 3D Sutherland-Hodgman algorithm Clipping polygons, divide and conquer algorith. For each edge of view volume, traverse list of vertices

You might also like