cs475 / cs675 computer graphics · line clipping cohen – sutherland algorithm clipline(x 0, y 0,x...
TRANSCRIPT
![Page 1: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/1.jpg)
CS475 / CS675Computer Graphics
Lecture 2 : Clipping
![Page 2: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/2.jpg)
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Image Formation
Camera Model
Image
World
Reflected Ray
Incident Ray
Transmitted Ray
Point Light Source
![Page 3: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/3.jpg)
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
![Page 4: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/4.jpg)
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?
![Page 5: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/5.jpg)
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).
Ө
![Page 6: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/6.jpg)
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Synthetic Camera ModelY
Z
Eye
Lookat
Up Vector
What if the window is shifted?
![Page 7: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/7.jpg)
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
![Page 8: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/8.jpg)
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
![Page 9: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/9.jpg)
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
![Page 10: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/10.jpg)
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
![Page 11: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/11.jpg)
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
![Page 12: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/12.jpg)
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
![Page 13: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/13.jpg)
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
![Page 14: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/14.jpg)
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm
![Page 15: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/15.jpg)
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm
![Page 16: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/16.jpg)
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm
![Page 17: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/17.jpg)
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm
![Page 18: CS475 / CS675 Computer Graphics · Line Clipping Cohen – Sutherland Algorithm clipline(x 0, y 0,x 1, y 1) { ComputeOutcode(x 0, y 0, OC 0); ComputeOutcode(x 1, y 1, OC 1); repeat](https://reader034.vdocuments.us/reader034/viewer/2022042302/5ecd190bbe20f52d8533854b/html5/thumbnails/18.jpg)
CS 475/CS 675: Lecture 3 Parag Chaudhuri, 2015
Polygon Clipping
Sutherland – Hodgman Algorithm