Professional Documents
Culture Documents
CG (Line Clipping: Cohen Sutherland Line Clipping) : BITS Pilani
CG (Line Clipping: Cohen Sutherland Line Clipping) : BITS Pilani
2
BITS Pilani, Hyderabad Campus
Cohen-Sutherland: World
Division
• World space is divided into regions based on the window
boundaries
– Each region has a unique four bit region code
– Region codes indicate the position of the regions with
respect to the window
3
BITS Pilani, Hyderabad Campus
Cohen-Sutherland: Labelling
P11 [1010]
P4 [1000]
Window
wymax P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7
[0001 P9 [0000] P8 [0010]
wymin ]
P10 [0100]
P13 [0101] P2 [0110]
wxmin wxmax
P11 [1010]
P4 [1000]
Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P2 [0110]
wxmin wxmax 5
BITS Pilani, Hyderabad Campus
Cohen-Sutherland: Lines
Outside The Window
•Any lines with a common set bit in the region codes of
both end-points can be clipped
– The logical AND of codes can efficiently check this. A
non-zero result would mean it is outside.
P11 [1010]
P4 [1000]
Window
wymax
P6 [0000]
P3 [0001]
P5 [0000] P12 [0010]
P7 [0001]
P9 [0000] P8 [0010]
wymin
P10 [0100]
P13 [0101] P2 [0110]
wxmin wxmax 6
BITS Pilani, Hyderabad Campus
Cohen-Sutherland: Other
Lines
• Lines that cannot be identified as completely inside or outside
the window may or may not cross the window interior.
• These lines are processed as follows:
– We find an end point that lies outside the clipping window.
– Then use the outcode bit that is set to determine a clip
edge; the edge chosen is the first in the above-to-below,
right-to-left order i.e. it is the leftmost bit that is set in the
outcode.
– Determine the corresponding intersection point.
– Clip off the line segment from the outside endpoint to the
intersection point.
– Replace the outside endpoint with the intersection point.
– Compute the outcode of this new endpoint to prepare for
the next iteration.
7
BITS Pilani, Hyderabad Campus
Non-trivial Examples
10
BITS Pilani, Hyderabad Campus
• Start with the outside
point P2 (either end point P2 [1000]
11
BITS Pilani, Hyderabad Campus
• Trivially accept the
remaining clipped portion
XY. Window
wymax
X [0000] Y [0000]
wymin
wxmin wxmax
12
BITS Pilani, Hyderabad Campus
Cohen-Sutherland: Overview
13
BITS Pilani, Hyderabad Campus
Pros and Cons
• Cohen-Sutherland
– Repeated clipping is expensive
– Best used when trivial acceptance and rejection is
possible for most lines
14
BITS Pilani, Hyderabad Campus