Computer Graphics
Lecture 21
Fasih ur Rehman
Last Class
•
Clipping Algorithms
Today’s Agenda
•
Clipping Algorithms
Cohen – Sutherland Line
Clipping
•
Cohen – Sutherland Line
Clipping
The view window
is divided into regions as
shown in the figure
•
Each region is assigned a 4-bit outcode
•
Cohen – Sutherland Line
Most significant bit (MSB)
called bit 1 indicates y-value of
Clipping
points are above ymax
•
Bit 2 indicates y-value of points are below ymin
•
Bit 3 indicates x-value of points are to the right of Xmax
•
Bit 4 indicates x-value of points are to the left of Xmin
•
Cohen – Sutherland Line
Clipping
For each line segment
–
Assign an outcode to each vertex
–
If both outcodes = 0, (by bit – wise OR
operation)
•
–
trivial accept (Line AB of the Figure)
Else
•
AND (bitwise) vertex outcodes
•
if result
0, trivial reject (e. g. EF)
•
Cohen – Sutherland Line
If line cannot beClipping
trivially accepted or
rejected, subdivide the line into the
segments either or both of which can be
rejected
–
Start with an edge of view window that the line
intersects
–
Find intersection of line with the edge
–
Reject the segment on wrong side of edge
(outside the view window) and assign new
outcode to new vertex
–
Apply trivial accept/reject tests
•
Cohen – Sutherland Line
If line can neither Clipping
be trivially accepted nor
rejected, subdivide the line so that o both or either
of the two segments can be discarded
•
Select an edge that the line crosses
–
Keep check order the same order each time
To find intersection point
Parametric Form of Line
Summary
•
Clipping
References
•
•
Fundamentals of Computer Graphics Third
Edition by Peter Shirley and Steve
Marschner
Interactive Computer Graphics, A Topdown Approach with OpenGL (Sixth
Edition) by Edward Angel.