CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x...
Transcript of CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x...
CS475 / CS675Computer Graphics
Lecture 2 : Clipping
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Image Formation
Camera Model
Image
World
Reflected Ray
Incident Ray
Transmitted Ray
Point Light Source
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Camera Model
Pinhole Camera
Y
X
Z
O
P(X, Y, Z)
p(x, y)
f
x = f X/Zy = f Y/Z
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Synthetic Camera ModelY
X
Z
P(X, Y, Z) p(x, y)
f
x = f X/Zy = f Y/Z
Eye
Lookat
Up Vector
Is the Eye, Lookat and Up Vector is enough to define the camera?
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Synthetic Camera ModelY
X
Z
P(X, Y, Z) p(x, y)
w
h
Eye
Lookat
Up Vector
The field of view (Ө) is also needed alongwith the window aspect ratio (w/h).
Ө
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Synthetic Camera ModelY
Z
Eye
Lookat
Up Vector
What if the window is shifted?
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Synthetic Camera ModelY
Z
Eye
Lookat
Up Vector
If the window is shifted the the scene gets clipped at the window edges.
Camera Demo
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Line Clipping● Divide the plane into 9 regions.
● Each region has its own 4 bit outcode.
● Compute the outcodes OC0 and
OC1 for the vertices of the line
segment.
● Trivially accept if OC0 ∨ OC
1 = 0 (TA)
● Trivially reject if OC0 ∧ OC
1 = 1 (TR)
● If cannot TA/TR, subdivide line into two segments at a clip edge and TA/TR one or both segments.
● Repeat until entire line has been processed.
Cohen – Sutherland Algorithm
0000
1001 1000 1010
0001 0010
011001000101
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Line Clipping
Cohen – Sutherland Algorithm
clipline(x0, y0,x1, y1){ ComputeOutcode(x0, y0, OC0);
ComputeOutcode(x1, y1, OC1); repeat Check for TA and TR. If either happens then done.
Choose a vertex that is outside the clip rectangle.
If (vertex lies over TOP edge) then
x = x0 + 1/slope * (ymax – y0)y = ymax
....
0000
1001 1000 1010
0001 0010
011001000101
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Line Clipping
Cohen – Sutherland Algorithm
else if (vertex lies below BOTTOM edge) then
x = x0 + 1/slope * (ymin – y0)y = ymin
else if (vertex lies to right of RIGHT edge) then
y = y0 + slope * (xmax – x0)x = xmax
else if (vertex lies to left of LEFT edge) then
y = y0 + slope * (xmin – x0)x = xmin
0000
1001 1000 1010
0001 0010
011001000101
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Line Clipping
Cohen – Sutherland Algorithm
else if (vertex lies below BOTTOM edge) then
x = x0 + 1/slope * (ymin – y0)y = ymin
else if (vertex lies to right of RIGHT edge) then
y = y0 + slope * (xmax – x0)x = xmax
else if (vertex lies to left of LEFT edge) then
y = y0 + slope * (xmin – x0)x = xmin
0000
1001 1000 1010
0001 0010
011001000101
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Line Clipping
Cohen – Sutherland Algorithm
if (x0, y0) was the outer point then
x0= x, y0 = yComputeOutcode(x0, y0, OC0)
elsex1= x, y1 = yComputeOutcode(x1, y1, OC1)
until (done)
}Issues in Clipping Scan Conversion and Clipping
Read notes on CyrusBeck Parametric Line Clipping Algorithm.
0000
1001 1000 1010
0001 0010
011001000101
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm