cs475m - computer graphics · 2016-08-02 · cs475m - computer graphics lecture 3 : clipping....
TRANSCRIPT
![Page 1: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/1.jpg)
CS475m - Computer Graphics
Lecture 3 : Clipping
![Page 2: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/2.jpg)
CS475m: Lecture 3 Parag Chaudhuri
Image Formation
Camera Model
Image
World
Reflected Ray
Incident Ray
Transmitted Ray
Point Light Source
![Page 3: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/3.jpg)
CS475m: Lecture 3 Parag Chaudhuri
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: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/4.jpg)
CS475m: Lecture 3 Parag Chaudhuri
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: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/5.jpg)
CS475m: Lecture 3 Parag Chaudhuri
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: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/6.jpg)
CS475m: Lecture 3 Parag Chaudhuri
Synthetic Camera ModelY
Z
Eye
Lookat
Up Vector
What if the window is shifted?
![Page 7: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/7.jpg)
CS475m: Lecture 3 Parag Chaudhuri
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: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/8.jpg)
CS475m: Lecture 3 Parag Chaudhuri
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 ∨ OC1 = 0 (TA)
● Trivially reject if OC0 ∧ OC1 = 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: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/9.jpg)
CS475m: Lecture 3 Parag Chaudhuri
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: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/10.jpg)
CS475m: Lecture 3 Parag Chaudhuri
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: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/11.jpg)
CS475m: Lecture 3 Parag Chaudhuri
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: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/12.jpg)
CS475m: Lecture 3 Parag Chaudhuri
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: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/13.jpg)
CS475m: Lecture 3 Parag Chaudhuri
Polygon Clipping
![Page 14: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/14.jpg)
CS475m: Lecture 3 Parag Chaudhuri
Polygon Clipping
Sutherland – Hodgman Algorithm
![Page 15: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/15.jpg)
CS475m: Lecture 3 Parag Chaudhuri
Polygon Clipping
Sutherland – Hodgman Algorithm
![Page 16: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/16.jpg)
CS475m: Lecture 3 Parag Chaudhuri
Polygon Clipping
Sutherland – Hodgman Algorithm
![Page 17: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/17.jpg)
CS475m: Lecture 3 Parag Chaudhuri
Polygon Clipping
Sutherland – Hodgman Algorithm
![Page 18: CS475m - Computer Graphics · 2016-08-02 · CS475m - Computer Graphics Lecture 3 : Clipping. CS475m: Lecture 3 Parag Chaudhuri Image Formation Camera Model Image World Reflected](https://reader034.vdocuments.us/reader034/viewer/2022042316/5f0455817e708231d40d76f6/html5/thumbnails/18.jpg)
CS475m: Lecture 3 Parag Chaudhuri
Polygon Clipping
Sutherland – Hodgman Algorithm