Professional Documents
Culture Documents
Chapter 5 Two Dimensional Viewing
Chapter 5 Two Dimensional Viewing
2D Viewing
Compile
1 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
The Viewing Pipeline
CGVR
Window
• A world-coordinate area selected for display.
defines what is to be viewed
Viewport
• An area on a display device to which a window is
mapped.
defines where it is to be displayed
Viewing transformation
• The mapping of a part of a world-coordinate scene
to device coordinates.
A window could be a rectangle to have any
orientation.
Zooming effects
• Successively mapping different-sized windows on
a fixed-sized viewports.
Panning effects
• Moving a fixed-sized window across the various
objects in a scene.
Device independent
• Viewports are typically defined within the unit
square (normalized coordinates)
2D Primitives
Image
Compile
7 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
2D Rendering Pipeline
CGVR
3D Primitives
2D Primitives
Image
Compile
8 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping
CGVR
World
Coordinates
Compile
9 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping
CGVR
Compile
10 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping
CGVR
Compile
11 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Two-Dimensional Clipping
CGVR
Point clipping –trivial
Line clipping
Cohen-Sutherland
Cyrus-beck (Cyrus Beck Line Clipping ( Liang and Barsky))
Nicholl-Lee-Nicholl Line Clipping
Fill-area clipping
Sutherland-Hodgeman
Weiler-Atherton
Curve clipping
Text clipping
Compile
12 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Line Clipping
CGVR
P1
P4 P8
P3
P2
P6
P10
P5 P9
Before Clipping
Compile
13 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Line Clipping: Possible Configurations
CGVR
P4 P’8
P3
P6
P’5
After Clipping
Compile
18 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line Clipping
CGVR
Region code
A four-digit binary code assigned to every line endpoint
in a picture.
Numbering the bit positions in the region code as 1
through 4 from right to left.
P1
P4 P8
P3
P2
P6
P10
P5 P9
Compile
20 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
Compile
23 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
Compile
24 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P5 0010 P9 0110
Bit 1 Bit 2
Compile
25 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
26 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
27 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
28 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
29 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
30 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
31 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
32 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
33 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
34 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 0110
P9
Bit 1 Bit 2
Compile
35 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 P’90110
Bit 1 Bit 2
Compile
36 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P’8
1000 P3 0000 0100
P6
P10
Bit 3
1010 P’5 0010 P’90110
Bit 1 Bit 2
Compile
37 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line
Clipping CGVR
P4 P’8
1000 P3 0000 0100
P6
Bit 3
1010 P’5 0010 0110
Bit 1 Bit 2
Compile
38 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Cohen-Sutherland Line Clip Examples
H CGVR
1001 1000 1010
F
if c0 | c1 = 0000
G D
accept (draw) else if c0 &
c1 0000
reject (don’t draw) 0001 0000 C 0010 J
A
else clip and E
retest
0101 I
0100 0110
B
I 0110
A 0001 C 0000 E 0000 G 0000
B 0100 D 0010 F 0000 H 1010 J 0010
OR 0101 OR 0010 OR 0000 OR 1010 OR 0110
AND 0000 AND 0000 AND 0000 AND 0000 AND 0010
if c0 | c1 = 0000
G D
accept (draw) else if c0 &
c1 0000
reject (don’t draw) 0001 0000 C C’ 0010
else clip and A
retest A
’
0101 0100
B 0110
A 0001 remove C
0000 remove G 0000
Remove
A’ 0001 C’D G’H G’ 0000
A’B C’ 0000
OR OR 0000 OR 0000
0001
AND 0001 AND 0000 AND 0000
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping
CGVR
Before Clipping
Compile
41 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping
CGVR
After Clipping
Compile
42 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR
Compile
43 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR
Compile
44 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR
Compile
45 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR
Compile
46 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Sutherland-Hodgeman Polygon Clipping
CGVR
Compile
47 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR
P2 P1
Window
Boundary Inside
P5 Outside
P3
P4
Compile
48 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR
P2 P1
Window
Boundary Inside
P5 Outside
P3
P4
Compile
49 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR
P2 P1
Window
Boundary Inside
P5 Outside
P3
P4
Compile
50 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR
P2 P1
Window
Boundary Inside
P5 Outside
P3
P4
Compile
51 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR
P2 P1
Window
Boundary P’ Inside
P5 Outside
P3
P4
Compile
52 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR
P2 P1
Window
Boundary P’ Inside
P5 Outside
P3
P4
Compile
53 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR
P2 P1
Window
Boundary P’ Inside
P5 Outside
P3
P4
Compile
54 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR
P2 P1
Window
Boundary P’ P” Inside
P5 Outside
P3
P4
Compile
55 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Clipping to a Boundary
CGVR
P2 P1
Window
Boundary P’ P” Inside
Outside
Compile
56 by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping
CGVR
What about
polygons?
59
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Algorithm
CGVR
• Clip polygon to ymin and ymax:
• Create empty output vertex list
• Process input list (v0, v1, …, vn) where v0 = vn
• For each input vertex (vi where 0 i n–1):
• If vi is inside region Add vi to output list.
• If the line between vi and vi+1 intersects clipping
boundaries Add intersection point(s) to output list.
• Repeat: Clip to xmin and xmax
• Post-process:
• Remove degenerate sections that have collapsed
to region boundary.
60
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v0 ymax p0
Inside region: No
Line intersect boundary: Yes v9
v5
v2 v1
Add p0 to output list
ymin
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex p0
list:
61
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v1 ymax p0
inside region: yes
line intersect boundary: No v9
v5
v2 v1
add v1 to output list
ymin
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list: p0 , v1
62
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v2 ymax p0
inside region: yes
line intersect boundary: yes v9
v5
v2 v1
add v2 , p1 to output list
p1
ymin
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list: p0 , v1 , v2, p1
63
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v3 ymax p0
inside region: no
v9
line intersect
boundary: no v1
v5
v2
p1
ymin
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p0, v1, v2, p1
64
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v4 ymax p0
inside region: no
line intersect v9
boundary: yes
v5
v2 v1
add p2 to output list
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p , v , v , p , p
0 1 2 1 2
65
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v5 p3
ymax p0
inside region: yes
line intersect v9
boundary: yes
v5
v2 v1
add v5, p 3 to output list
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p , v , v , p , p , v , p
0 1 2 1 2 5 3
66
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v6 p3
ymax p0
inside region: no line
intersect boundary: no v9
v5
v2 v1
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex p 0 , v1 , v 2 , p 1 , p 2 , v 5 , p 3
list:
67
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and
ymax v8 v0
p3
vertex: v7 ymax p0
inside region:
v9
no line intersect
boundary: no v1
v5
v2
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8,
v9 )
Output vertex p 0 , v1 , v 2 , p 1 , p 2 , v 5 , p 3
list:
68
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v8 p4 p3
ymax p0
inside region: no
line intersect v9
boundary: yes
v5
v2 v1
add p4 to output list
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p , v , v , p , p , v , p , p
0 1 2 1 2 5 3 4
69
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
v7 v6 CGVR
Clip first to ymin and ymax
v8 v0
vertex: v9 p4 p5 p3
ymax p0
inside region: yes
line intersect v9
boundary: yes
v5
v2 v1
add v9, p 5 to output list
p1
ymin p2
v3
v4
Input vertex list: (v0, v1, v2, v3, v4, v5, v6, v7, v8, v9)
Output vertex list:p , v , v , p , p , v , p , p , v , p
0 1 2 1 2 5 3 4 9 5
70
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example
CGVR
This gives us a new polygon
p4 p5 p3
ymax p0
v9
v5
v2 v1
p1
ymin p2
with vertices: (p0, v1, v2, p1, p2, v5, p3, p4, v9, p5)
71
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example (cont.)
CGVR
Now clip to xmin and xmax
xmin xmax
p4 p5 p3
p0 p9
v9
p6
p7 v v5
v2 1
p1
p8 p2
Input vertex list: = (p0, v1, v2, p1, p2, v5, p3, p4, v9, p5)
Output vertex list: (p0, p6, p7, v2, p1, p8, p9, p3, p4, v9, p5)
72
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University
Polygon Clipping: Example (cont.)
CGVR
Now post-process
xmin xmax
p4 p5 p3
p0 p9
v9
p6
p7
v2
pv
p8
13
Output vertex list: (p0, p6, p7, v2, p1, p8, p9, p3, p4, v9, p5)
Post-process: (p0, p6, p9, p3,) and (p7, v2, p1, p8) and (v4, v9, p5)
73
Compile by : Engr. Syed Atir Iftikhar Graphics Lab @ Korea University