he capability that show some part of object internal a specify window is called windowing and a rectangular region in a world coordinate system is called window. ... Points and lines which are outside the window are "cut off" from view. This process of "cutting off" parts of the image of the world is called Clipping.
4. • World Coordinate System (Object Space) -
Representation of an object measured in some
physical units.
• Window - The rectangle defining the part of the
world we wish to display.
• Image Coordinate System (Image Space) - The
space within the image is displayed.
• Viewport - The rectangle area in image space
where the image from the window will appear.
• Viewing Transformation - The process of going
from a window in world coordinates to a
viewport in image coordinates.
4
5. 5
• In 2D, a ‘world’ consists of an infinite plane,
defined in ‘world’ coordinates, i.e metres,
angstroms etc.
• We need to pick an area of the 2D plane to view,
referred to as the ‘window’.
• On our display device, need to allocate an area for
display, referred to as the ‘viewport’ in device
specific coordinates.
– Clip objects outside of window.
– Translate to fit viewport.
– Scale to device coordinates.
6. 6
Choose Window in
World Coordinates
Clip to size
of Window
Translate to
origin
Scale to size of Viewport Translate to proper position in
image
7. Any procedure that identifies those portions of a
picture that are either inside or outside of a
specified region is referred to as a clipping
algorithm or clipping.
7
World Coordinates
8. 8
• When we display a scene only those objects
within a particular window are displayed.
wymax
wymin
wxmin wxmax
Window or Clipping Region
World Coordinates
9. 9
Because drawing things to a display takes time
we clip everything outside the window.
wymax
wymin
wxmin wxmax
Window or Clipping Region
World Coordinates
10. For the image below consider which lines and
points should be kept and which ones should be
clipped.
10
wymax
wymin
wxmin wxmax
Window
P1
P2
P3
P6
P5
P7
P10
P9
P4
P8
11. Easy - a point (x,y) is not clipped if:
wxmin ≤ x ≤ wxmax AND wymin ≤ y ≤ wymax
11
wymax
wymin
wxmin wxmax
Window
P1
P2
P5
P7
P10
P9
P4
P8
Clipped
Points Within the
Window are Not Clipped
Clipped
Clipped
Clipped
12. Harder - examine the end-points of each line to
see if they are in the window or not.
12
Situation Solution Example
Both end-points inside
the window
Don’t clip
One end-point inside
the window, one
outside
Must clip
Both end-points
outside the window
Don’t know!
13. Brute force line clipping can be performed as follows:
Don’t clip lines with both
end-points within the
window.
For lines with one end-
point inside the window
and one end-point
outside, calculate the
intersection point (using the equation of the line) and
clip from this point out.
13
14. 14
– For lines with both end-
points outside the
window test the line for
intersection with all of
the window boundaries,
and clip appropriately.
However, calculating line intersections is
computationally expensive.
Because a scene can contain so many lines,
the brute force approach to clipping is much
too slow.
15. 15
An efficient line clipping
algorithm.
The key advantage of the
algorithm is that it vastly
reduces the number of line
intersections that must be
calculated.
Dr. Ivan E. Sutherland
c o - d e v e l o p e d t h e
C o h e n - S u t h e r l a n d
clipping algorithm.
Sutherland is a graphics
giant and includes
a m o n g s t h i s
a c h i e v e m e n t s t h e
invention of the head
Cohen is something of a mystery – can
anybody find out who he was?
16. Algorithm
Step 1 − Assign a region code for each endpoints.
Step 2 − If both endpoints have a region code 0000 then accept this line.
Step 3 − Else, perform the logical AND operation for both region codes.
Step 3.1 − If the result is not 0000, then reject the line.
Step 3.2 − Else you need clipping.
Step 3.2.1 − Choose an endpoint of the line that is outside the
window.
Step 3.2.2 − Find the intersection point at the window boundary
(base on region code).
Step 3.2.3 − Replace endpoint with the intersection point and
update the region code.
Step 3.2.4 − Repeat step 2 until we find a clipped line either
trivially accepted or trivially rejected.
Step 4 − Repeat step 1 for other lines.
16
17. 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.
17
above below right left
3 2 1 0
Region Code Legend
1001 1000 1010
0001
0000
Window
0010
0101 0100 0110
18. 18
• Every end-point is labelled with the
appropriate region code.
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
19. 19
Lines completely contained within the window
boundaries have region code [0000] for both end-
points so are not clipped. The OR operation can
efficiently check this.
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
20. 20
Any lines with a common set bit in the region
codes of both end-points can be clipped.
– The AND operation can efficiently check this.
wymax
wymin
wxmin wxmax
Window
P3 [0001]
P6 [0000]
P5 [0000]
P7 [0001]
P10 [0100]
P9 [0000]
P4 [1000]
P8 [0010]
P12 [0010]
P11 [1010]
P13 [0101] P14 [0110]
21. 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:
Compare an end-point outside the window to a
boundary (choose any order in which to consider
boundaries e.g. left, right, bottom, top) and
determine how much can be discarded.
If the remainder of the line is entirely inside or
outside the window, retain it or clip it respectively.
21
22. Otherwise, compare the remainder of the line against the
other window boundaries.
Continue until the line is either discarded or a segment
inside the window is found.
We can use the region codes to determine which
window boundaries should be considered for
intersection.
To check if a line crosses a particular boundary we
compare the appropriate bits in the region codes of its
end-points.
If one of these is a 1 and the other is a 0 then the line
crosses the boundary.
22
23. Intersection points with the window boundaries are
calculated using the line-equation parameters.
Consider a line with the end-points (x1, y1) and (x2, y2)
The y-coordinate of an intersection with a vertical
window boundary can be calculated using:
y = y1 + m (xboundary - x1)
where xboundary can be set to either wxmin or wxmax
23
24. The x-coordinate of an intersection with a
horizontal window boundary can be calculated
using:
x = x1 + (yboundary - y1) / m
where yboundary can be set to either wymin or wymax
m is the slope of the line in question and can be
calculated as
m = (y2 - y1) / (x2 - x1)
24
25. Polygons can be clipped against each edge of the
window one edge at a time. Window/edge
intersections, if any, are easy to find since the X or
Y coordinates are already known.
Vertices which are kept after clipping against one
window edge are saved for clipping against the
remaining edges. Note that the number of vertices
usually changes and will often increase.
25
26. A technique for clipping areas
developed by Sutherland &
Hodgman.
Put simply the polygon is clipped
by comparing it against each
boundary in turn.
26
Sutherland
turns up
again. This
time with
Gary Hodgman
with whom he
worked at the first
ever graphics
company Evans &
Sutherland
Original Area Clip Left Clip Right Clip Top Clip Bottom
27. To clip an area against an individual boundary:
Consider each vertex in turn against the boundary.
Vertices inside the boundary are saved for clipping
against the next boundary.
Vertices outside the boundary are clipped.
If we proceed from a point inside the boundary to one
outside, the intersection of the line with the boundary is
saved.
If we cross from the outside to the inside intersection
point and the vertex are saved.
27
28. Each example shows
the point being
processed (P) and the
previous point (S).
Saved points define
area clipped to the
boundary in question.
28
S
P
Save Point P
S
P
Save Point I
I
P
S
No Points Saved
S
P
Save Points I & P
I
29. Instead of always
proceeding around the
polygon edges as vertices are
processed, we sometime
want to follow window
boundary.
This algorithm is used for
clipping concave polygons.
V1, V2, V3, V4, V5 are the
vertices of the polygon.
C1, C2, C3, C4 are the
vertices of the clip polygon
I1, I2, I3, I4 are the
intersection points of 29