Lecture 11
Lecture 11
2
Window & Viewport
3
Why Do We Need Clipping?
❑ The viewing window (or viewport) often has a limited display area.
❑ Moreover, when rendering complex scenes, it’s essential to optimize performance
by discarding objects or parts of objects that viewers can’t see.
❑ Clipping helps eliminate unnecessary calculations and improves the efficiency of
rendering algorithms.
❑ Furthermore, it guarantees the display of only the visible portions of objects,
resulting in faster rendering times and a more realistic representation of a scene.
4
Clipping Rectangular Window
❑ When we want to display a scene with only those objects within a particular
rectangular window, we should first specify the window’s coordinates (Y_Max,
Y_Min, X_Max, X_Min):
5
❑ Then, we clip the objects to show only their parts in the specified window:
6
Clipping
❑ There are several clipping techniques:
❖ Cohen-Sutherland Algorithm for Line Clipping
❖ Point Clipping
❖ Polygon Clipping
❖ Curve, Exterior, and Text Clipping
7
Cohen-Sutherland Algorithm for Line Clipping
❑ The Cohen-Sutherland algorithm uses a region code to clip a portion of a line not
present in the visible region. It divides a region into 9 cells based on (Y_Max,
Y_Min, X_Max, X_Min):
8
Cohen-Sutherland Algorithm for Line Clipping
❑ The central part is the viewing window, and all lines which lie within this region are
completely visible.
❑ A region code is always assigned to the endpoints of the line based on the cells they’re in.
❑ A line segment is:
➢ Visible if both endpoints have the 0000 code
➢ Invisible if no endpoint has the 0000 code
➢ To be clipped if one endpoint has the 0000 code and the other doesn’t.
9
Cohen-Sutherland Algorithm (Example)
10
Point Clipping
❑ This type involves determining whether a point (X, Y)
is inside or outside a specific region.
❑ If any of these inequalities is false, it means that the
point lies outside the window, and therefore, it won’t
be visible:
11
Polygon Clipping
❑ We can use polygon clipping to determine which portions of the polygon are visible
to the viewer and to discard any parts of the polygon that are outside of the
viewing area:
12
Text Clipping
❑ There are additional clipping techniques that allow us to control and confine visual
elements within defined regions; for example, text clipping.
❑ We use text clipping to ensure that text is displayed only within a defined region.
❑ Text clipping is commonly used in graphic design software, web design tools, and
document processing software.
13
Exterior Clipping
❑ We can use the exterior clipping to show only the elements outside of the clipping
window.
14
Curve Clipping
❑ Curve clipping involves determining which parts of a curve lie within the viewing
window. It involves non-linear calculations.
15
Applications
Clipping in computer graphics finds applications in various contexts:
16
Questions
1- Write a pseudo code for Cohen Sutherland Line Clipping Algorithm.
2- In Cohen Sutherland Line Clipping Algorithm, the viewing window
has a region code of ………
(a) 0000 (b) 0100 (c) 0000 (d) 010
3- Write a pseudo code for the Point Clipping Algorithm.