cs475/cs675 - lecture 2 · 2019-08-12 · cohen – sutherland algorithm 0000 1001 1000 1010 0001...

17
CS475/CS675 - Computer Graphics Clipping

Upload: others

Post on 24-May-2020

13 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Computer Graphics

Clipping

Page 2: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 2

Image Formation

Camera Model

Image

World

Reflected Ray

Incident Ray

Transmitted Ray

Point Light Source

Page 3: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 3

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 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 4

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 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 5

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 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 6

Synthetic Camera ModelY

Z

Eye

Lookat

Up Vector

What if the window is shifted?

Page 7: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 7

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 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 8

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: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 9

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 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 10

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 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 11

Line Clipping if (x0, y0) was the outer point then

x0= x, y0 = yComputeOutcode(x0, y0, OC0)

elsex1= x, y1 = yComputeOutcode(x1, y1, OC1)

until (done)}

Read notes on Cyrus-Beck Parametric Line Clipping Algorithm.

0000

1001 1000 1010

0001 0010

011001000101

Cohen – Sutherland Algorithm

Page 12: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 12

Polygon Clipping

Page 13: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 13

Polygon Clipping

Sutherland – Hodgman Algorithm

Page 14: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 14

Polygon Clipping

Sutherland – Hodgman Algorithm

Page 15: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 15

Polygon Clipping

Sutherland – Hodgman Algorithm

Page 16: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 16

Polygon Clipping

Sutherland – Hodgman Algorithm

Page 17: CS475/CS675 - Lecture 2 · 2019-08-12 · Cohen – Sutherland Algorithm 0000 1001 1000 1010 0001 0010 0101 0100 0110. CS475/CS675 - Lecture 2 9 Line Clipping Cohen – Sutherland

CS475/CS675 - Lecture 2 17

Polygon Clipping

Sutherland – Hodgman Algorithm