Computer Graphics
Dr.S.Sivakumar,Principal
C.P.A College, Bodinayakanur
*
1
2D Clipping
2D Clipping
1. Introduction:
A scene is made up of a collection of objects specified in world coordinates
*
Computer Graphics
3
World Coordinates
2D Clipping
When we display a scene only those objects within a particular window are displayed
*
Computer Graphics
4
wymax
wymin
wxmin
wxmax
Window
World Coordinates
2D Clipping
Because drawing things to a display takes time we clip everything outside the window
*
Computer Graphics
5
wymax
wymin
wxmin
wxmax
World Coordinates
Window
2D Clipping
1.1 Definition:
*
Computer Graphics
6
2D Clipping
1.2 Shielding:
*
Computer Graphics
7
2D Clipping
*
Computer Graphics
8
wymax
wymin
wxmin
wxmax
Window
World Coordinates
2D Clipping
1.3 Example:
For the image below consider which lines and points should be kept and which ones should be clipped against the clipping window
*
Computer Graphics
9
wymax
wymin
wxmin
wxmax
Window
P1
P2
P3
P6
P5
P7
P10
P9
P4
P8
2D Clipping
1.4 Applications:
*
Computer Graphics
10
2D Clipping
1.5 Types of clipping:
a. Analytical clipping
*
Computer Graphics
11
2D Clipping
b. Scissoring
*
Computer Graphics
12
2D Clipping
c. Raster Clipping
*
Computer Graphics
13
2D Clipping
Foley and van Dam suggest the following:
*
Computer Graphics
14
2D Clipping
1.6 Levels of clipping:
*
Computer Graphics
15
2D Clipping
Point Clipping
wxmin ≤ x ≤ wxmax
&
wymin ≤ y ≤ wymax
*
Computer Graphics
17
wymax
wymin
wxmin
wxmax
Window
P1
P2
P5
P7
P10
P9
P4
P8
Clipped
Points Within the Window are Not Clipped
Clipped
Clipped
Clipped
2D Clipping
Line Clipping
*
Computer Graphics
19
ymin
ymax
xmin
xmax
Line Clipping
*
Computer Graphics
20
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! | |
2D Line Clipping Algorithms
Cohen-Sutherland Line Clipping
*
Computer Graphics
22
Dr. Ivan E. Sutherland co-developed the Cohen-Sutherland clipping algorithm. Sutherland is a graphics giant and includes amongst his achievements the invention of the head mounted display.
Cohen is something of a mystery – can anybody find out who he was?
Cohen-Sutherland Line Clipping
Phase I: Identification Phase
All line segments fall into one of the following categories
Phase II: Perform Clipping
Compute intersection for all lines that are candidate for clipping.
*
Computer Graphics
23
Cohen-Sutherland Line Clipping
Phase I: Identification Phase: World space is divided into regions based on the window boundaries
*
Computer Graphics
24
1001 | 1000 | 1010 |
0001 | 0000 Window | 0010 |
0101 | 0100 | 0110 |
above
below
right
left
3
2
1
0
Region Code Legend
Cohen-Sutherland Line Clipping
Every end-point is labelled with the appropriate region code
*
Computer Graphics
25
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]
Cohen-Sutherland Line Clipping
*
Computer Graphics
26
Visible Lines: Lines completely contained within the window boundaries have region code [0000] for both end-points so are not clipped
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]
Cohen-Sutherland Line Clipping
*
Computer Graphics
27
Invisible Lines: Any line with a common set bit in the region codes of both end-points can be clipped completely
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]
Cohen-Sutherland Line Clipping
Clipping Candidates: Lines that cannot be identified as completely inside or outside the window may or may not cross the window interior. These lines are processed in Phase II.
*
Computer Graphics
28
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]
Cohen-Sutherland Line Clipping
Assigning Codes
bit 3 = 1 if wymax - y ≤0
bit 2 = 1 if y - wymin ≤ 0
bit 1 = 1 if wxmax - x ≤0
bit 0 = 1 if x - wxmin ≤ 0
*
Computer Graphics
29
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]
Cohen-Sutherland Clipping Algorithm
Phase II: Clipping Phase: Lines that are in category 3 are now processed as follows:
*
Computer Graphics
30
Cohen-Sutherland Line Clipping
y = y1 + m (xboundary - x1)
where xboundary can be set to either wxmin or wxmax
x = x1 + (yboundary - y1) / m
where yboundary can be set to either wymin or wymax
*
Computer Graphics
31
Cohen-Sutherland Line Clipping
*
Computer Graphics
32
Cohen-Sutherland Line Clipping
Example1: Consider the line P9 to P10 below
to generate point P10’
*
Computer Graphics
33
wymax
wymin
wxmin
wxmax
Window
P10 [0100]
P9 [0000]
P10’ [0000]
P9 [0000]
Cohen-Sutherland Line Clipping
Example 2: Consider the line P3 to P4 below
*
Computer Graphics
34
wymax
wymin
wxmin
wxmax
Window
P4’ [1001]
P3 [0001]
P4 [1000]
P3 [0001]
Cohen-Sutherland Line Clipping
Example 3: Consider the line P7 to P8 below
*
Computer Graphics
35
wymax
wymin
wxmin
wxmax
Window
P7’ [0000]
P7 [0001]
P8 [0010]
P8’ [0000]
Cohen-Sutherland Line Clipping
Example 4: Consider the line P7’ to P8
*
Computer Graphics
36
wymax
wymin
wxmin
wxmax
Window
P7’ [0000]
P7 [0001]
P8 [0010]
P8’ [0000]
Cohen-Sutherland Line Clipping
Mid-Point Subdivision Method
*
Computer Graphics
37
Cohen-Sutherland Line Clipping
*
Computer Graphics
38
wymax
wymin
wxmin
wxmax
Window
Cohen-Sutherland Line Clipping
*
Computer Graphics
39
wymax
wymin
wxmin
wxmax
Window
Cohen-Sutherland Line Clipping
Mid-Point Subdivision Method
*
Computer Graphics
40
2D Clipping
Polygon Clipping
*
Computer Graphics
42
Polygon Clipping
*
Computer Graphics
43
NOTE!
Polygon Clipping
correctly
*
Computer Graphics
44
Sutherland-Hodgman Area Clipping
*
Computer Graphics
45
Original Area
Clip Left
Clip Right
Clip Top
Clip Bottom
Sutherland �turns up �again. This �time with �Gary Hodgman with whom he worked at the first ever graphics company Evans & Sutherland
Sutherland-Hodgeman Polygon Clipping
1. Basic Concept:
*
Computer Graphics
46
Sutherland-Hodgeman Polygon Clipping
*
Computer Graphics
47
Start
Left
Right
Bottom
Top
Note that the point one of the points added when clipping
on the right gets removed when we clip with bottom
Sutherland-Hodgeman Polygon Clipping
2. Algorithm:
Let (P1, P2,…. PN) be the vertex list of the Polygon to be clipped and E be the edge of +vely oriented, convex clipping window.
We clip each edge of the polygon in turn against each window edge E, forming a new polygon whose vertices are determined as follows:
*
Computer Graphics
48
Sutherland-Hodgeman Polygon Clipping
Four cases
*
Computer Graphics
49
Sutherland-Hodgeman Polygon Clipping
Creating New Vertex List
*
Computer Graphics
50
out 🡪 out
save nothing
Outside
(0 output)
Pi-1
Pi
in 🡪 in
save ending vert
Inside
(1 output)
Pi-1
Pi
out 🡪 in
save new clip vert
and ending vert
Entering
(2 outputs)
Pi
Pi-1
Pi
in 🡪 out
save new clip vert
Leaving
(1 output)
Pi-1
Sutherland-Hodgman Polygon Clipping
*
Computer Graphics
51
S
P
Save Point P
S
P
Save Point I
I
P
S
No Points Saved
S
P
Save Points I & P
I
Flow Chart
*
Computer Graphics
52
START
INPUT VERTEX LIST
(P1, P2........, PN)
IF PiPi+1 INTERSECT E ?
FOR i =1 TO (N-1) DO
COMPUTE I
OUTPUT I IN VERTEX LIST
IF Pi TO LEFT OF E ?
YES
NO
YES
OUTPUT Pi IN VERTEX LIST
NO
i = i+1
Special case for first Vertex
Flow Chart
*
Computer Graphics
53
Special case for first Vertex
IF PNP0 INTERSECT E ?
COMPUTE I
OUTPUT I IN VERTEX LIST
YES
NO
END
YOU CAN ALSO APPEND AN ADDITIONAL VERTEX PN+1 = P1 AND AVOID SPECIAL CASE FOR FIRST VERTEX
Sutherland-Hodgeman Polygon Clipping
Inside/Outside Test:
Let P(x,y) be the polygon vertex which is to be tested against edge E defined form A(x1, y1) to B(x2, y2). Point P is to be said to the left (inside) of E or AB iff
or C = (x2 – x1) (y – y1) – (y2 – y1)(x – x1) > 0
otherwise it is said to be the right/Outside of edge E
*
Computer Graphics
54
Weiler-Atherton Polygon Clipping
*
Computer Graphics
55
Remember
me?
Weiler-Atherton Polygon Clipping
*
Computer Graphics
56
add clip pt.
and end pt.
add end pt.
add clip pt.
cache old dir.
follow clip edge until
found
b) reach pt. already
added
Weiler-Atherton Polygon Clipping
*
Computer Graphics
57
continue from
cached location
add clip pt.
and end pt.
add clip pt.
cache dir.
follow clip edge until
a) new crossing
found
b) reach pt. already
added
Weiler-Atherton Polygon Clipping
*
Computer Graphics
58
continue from
cached location
nothing added
finished
Final result:
Two unconnected
polygons
Weiler-Atherton Polygon Clipping
*
Computer Graphics
59
Other Area Clipping Concerns
*
Computer Graphics
60
Window
Window
Window
Window
2D Clipping
Text Clipping
Text clipping relies on the concept of bounding rectangle
TYPES
*
Computer Graphics
62
Text Clipping
1. All or None String Clipping
*
Computer Graphics
63
STRI NG 1
STRING 2
STRING 3
STRING 4
STRING 5
STRING 4
Text Clipping
2. All or None Character Clipping
*
Computer Graphics
64
STRI NG 1
STRING 2
STRING 3
STRING 4
STRING 5
NG 1
STRI
TRING 3
STRING 4
Text Clipping
3. Component Character Clipping
*
Computer Graphics
65
STRI NG 1
STRING 2
STRING 3
STRING 4
STRING 5
NG 1
STRING 4
STRIN
STRING 3
2D Clipping
Curve Clipping
*
Computer Graphics
67
Curve Clipping
*
Computer Graphics
68
Curve Clipping
*
Computer Graphics
69
Any Question !