Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. ·...

81
MIT EECS 6.837, Teller and Durand 1

Transcript of Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. ·...

Page 1: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 1

Page 2: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 2

Clipping

MIT EECS 6.837Frédo Durand and Seth Teller

Some slides and images courtesy of Leonard McMillan

Page 3: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 3

Administrative• Assignment 2

– Due Friday 27 at 5pm– Model a scene using iv files from assignt 1– Lighting: at least one spot and one other light

Page 4: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 4

Assignment 1 Gallery

Page 5: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 5

Overview of graphics pipeline?

Page 6: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 6

Questions about previous lectures?

Page 7: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 7

Today’s lecture: Clipping• Overview and motivation

• Plane equation & point clipping

• Line & segment clipping

• Acceleration using outcodes

• Polygon clipping

P’

P0

P

H1 H2

H3

H4

0000

1010 0010 0110

1000 0100

00011001 0101

Page 8: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 8

Overview of graphics pipeline?

TraverseGeometric

ModelTransform toWorld space

Apply lightingEquation at

vertices

Transform toEye space

Perspective transformto NDC

Clip

Transform to 3D

Screen spaceRasterize Resolve

visibility

SceneDatabase

Camera+Viewport Parameters

Framebuffer Values

Page 9: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 9

Clipping• Eliminate parts of

primitives outside the viewing frustum

• Shirley p 210• Jim Blinn’s

Corner, A Trip Down The Graphics Pipeline, Morgan Kaufman, chapter 13

Page 10: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 10

Why clipping?• Avoid degeneracy

– Don’t draw outside image– Avoid division by 0 and overflow

• Efficiency– Don’t waste time on object outside the screen

• Other graphics methods(usually more complex cases, non convex)– Hidden-surface removal– Shadows– Picking– Binning– CSG (Boolean) operations (2D & 3D)

Page 11: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 11

Clipping strategies• Don’t clip (and hope for the best)• Clip on –the-fly during rasterization• Analytical clipping: alter input geometry

– This is the subject of today’s lecture

Page 12: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 12

Plan• Overview and motivation

• Plane equation & point clipping

• Line & segment clipping

• Acceleration using outcodes

• Polygon clipping

P’

P0

P

H1 H2

H3

H4

0000

1010 0010 0110

1000 0100

00011001 0101

Page 13: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 13

3D plane equation• Implicit plane equation

H(p) = Ax+By+Cz+D = 0• Gradient of H?

PH

Page 14: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 14

3D plane equation• Implicit plane equation

H(p) = Ax+By+Cz+D = 0• Gradient of H?• Plane defined by

– P0(x,y,z,1)– n(A, B, C, 1)

P0PH

Page 15: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 15

Plane-point distance• Plane Hp=0• If n is normalized

d=HP• Signed distance!

P’

P0

P

H

Page 16: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 16

Homogeneous plane equation• H=(A,B,C,D) p=(x,y,z,1)• Dot product in homogeneous coordinates

H.p=0 ( HTp=0 )• Duality between points and hyperplanes…

P0PH

n

Page 17: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 17

Homogeneous plane equation• H=(A,B,C,D) p=(x,y,z,1)• Infinite number of equivalent plane expressions

sAx+sBy+sCz+sD=0• Infinite number of homogeneous coordinate

(sx, sy, sz, sw)

P0PH

n

Page 18: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 18

Clipping wrt 1 plane• Pass through if Hp≥0• Clip (or cull or reject) if Hp<0

P’

P0

P

Page 19: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 19

Point clipping• Test against each of the 6 planes

– Normals oriented towards the interior• Clip (or cull or reject) if Hp<0

P

Page 20: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 20

Point clipping & transformation• Transform M (e.g. from world space to NDC)• The plane equation is transformed with (M-1)T

P

Page 21: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 21

Plan• Overview and motivation

• Plane equation & point clipping

• Line & segment clipping

• Acceleration using outcodes

• Polygon clipping

P’

P0

P

H1 H2

H3

H4

0000

1010 0010 0110

1000 0100

00011001 0101

Page 22: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 22

Parametric expression of line• ?

P0

P1

Page 23: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 23

Line-plane intersection• Insert explicit equation of line into

implicit equation of plane

• Parameter t can be usedto interpolate attributes(color, etc.)

P0

PP1

Page 24: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 24

Segment clippingIf Hq < 0 and Hp > 0, “clip q to plane”If Hp < 0 and Hq > 0, “clip p to plane”If Hp > 0 and Hq > 0, “pass through”If Hp < 0 and Hq < 0, “clipped out”

p

q

Page 25: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 25

Segment clippingIf Hq < 0 and Hp > 0, “clip q to plane”If Hp < 0 and Hq > 0, “clip p to plane”If Hp > 0 and Hq > 0, “pass through”If Hp < 0 and Hq < 0, “clipped out”

p

q

Page 26: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 26

Segment clippingIf Hq < 0 and Hp > 0, “clip q to plane”If Hp < 0 and Hq > 0, “clip p to plane”If Hp > 0 and Hq > 0, “pass through”If Hp < 0 and Hq < 0, “clipped out”

p

q

Page 27: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 27

Segment clippingIf Hq < 0 and Hp > 0, “clip q to plane”If Hp < 0 and Hq > 0, “clip p to plane”If Hp > 0 and Hq > 0, “pass through”If Hp < 0 and Hq < 0, “clipped out”

p

q

Page 28: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 28

Segment clippingIf Hq < 0 and Hp > 0, “clip q to plane”If Hp < 0 and Hq > 0, “clip p to plane”If Hp > 0 and Hq > 0, “pass through”If Hp < 0 and Hq < 0, “clipped out”

• Note qualitative contrast with point clipping– “Triage"

p

q

Page 29: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 29

Clipping against the frustumFor each frustum plane H

If Hp<0 and Hq<0, clipped out; breakIf Hp>0 and>Hq 0, pass throughIf Hp < 0 and Hq > 0, clip p to HIf Hq < 0 and Hp > 0, clip q to H

Page 30: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 30

Segment clipping• Note: must interpolate associated attributes

– (color, normal, texture, etc.)

Page 31: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 31

Line clipping• Result is a single segment• Why?

Page 32: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 32

Questions?

Page 33: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 33

Plan• Overview and motivation

• Plane equation & point clipping

• Line & segment clipping

• Acceleration using outcodes

• Polygon clipping

P’

P0

P

H1 H2

H3

H4

0000

1010 0010 0110

1000 0100

00011001 0101

Page 34: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 34

Acceleration using outcodes• Avoid many geometric calculations• Eliminate obvious rejects

• We’ll show it in 2D• Same principle in n-D

Page 35: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 35

Is it efficient?For each frustum plane H

If Hp<0 and Hq<0, clipped out; breakIf Hp>0 and>Hq 0, pass throughIf Hp < 0 and Hq > 0, clip p to HIf Hq < 0 and Hp > 0, clip q to H

q

p H1 H2

H3

H4

Page 36: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 36

Is it efficient?For each frustum plane H

If Hp<0 and Hq<0, clipped out; breakIf Hp>0 and>Hq 0, pass throughIf Hp < 0 and Hq > 0, clip p to HIf Hq < 0 and Hp > 0, clip q to H

pH1 H2

H3

H4

q

Page 37: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 37

Is it efficient?For each frustum plane H

If Hp<0 and Hq<0, clipped out; breakIf Hp>0 and>Hq 0, pass throughIf Hp < 0 and Hq > 0, clip p to HIf Hq < 0 and Hp > 0, clip q to H

qpH1 H2

H3

H4

Page 38: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 38

Is it efficient?For each frustum plane H

If Hp<0 and Hq<0, clipped out; breakIf Hp>0 and>Hq 0, pass throughIf Hp < 0 and Hq > 0, clip p to HIf Hq < 0 and Hp > 0, clip q to H

qpH1 H2

H3

H4

What is the problem?

Page 39: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 39

Is it efficient?For each frustum plane H

If Hp<0 and Hq<0, clipped out; breakIf Hp>0 and>Hq 0, pass throughIf Hp < 0 and Hq > 0, clip p to HIf Hq < 0 and Hp > 0, clip q to H

What is the problem?

The computation of the intersections were unnecessary

How can we detect this earlier?

q

p H1 H2

H3

H4

Page 40: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 40

Outcodes• Compute the n plane equations for point p• Combine into an outcode (binary)• 0 means : is valid wrt this plane

pH1 H2

H3

H4

0000

1010 00100110

1000 0100

00011001 0101

Outcode of p : 1010

Page 41: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 41

Outcodes• Compute the n plane equations for point p and q• Combine into an outcode (binary)• Logical AND

q

pH1 H2

H3

H4

0000

1010 00100110

1000 0100

00011001 0101

Outcode of p : 1010

Outcode of q : 0110

Outcode of [pq] : 0010

Rejected because there is a 1

Page 42: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 42

Outcodes• When do we fail to save computation?

H1 H2

H3

H4

0000

1010 0010 0110

1000 0100

00011001 0101

Page 43: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 43

Outcodes• When do we fail to save computation?• Conservative rejection• And we have the info on what to intersect

Outcode of p : 1000

Outcode of q : 0010

Outcode of [pq] : 0000

Not rejected

H1 H2

H3

H4

0000

1010 0010 0110

1000 0100

00011001 0101

Page 44: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 44

Outcodes• It works for arbitrary primitives

Outcode of p : 1010

Rejected

H1 H2

H3

H4

0000

1010 0010 0110

1000 0100

00011001 0101

Outcode of q : 1010Outcode of r : 0110Outcode of s : 0010Outcode of t : 0110

Outcode of u : 0010

Outcode : 0010

Page 45: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 45

When to clip?• Before perspective transform

in 3D space– Use the equation of 6 planes– Advantages? Problems?

• In homogeneous coordinates after perspective transform (NDC)– Before perspective divide– Advantages? Problems

• In the transformed 3D screen space after perspective division– Advantages? Problems?

Page 46: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 46

When to clip?• Before perspective transform

in 3D space– Use the equation of 6 planes– Natural, not too degenerate

• In homogeneous coordinates after perspective transform (Clip space)– Before perspective divide

(4D space, weird w values)– Canonical,independent of camera– The simplest to implement in fact

• In the transformed 3D screen space after perspective division– Problem: objects in the plane of the camera

Page 47: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 47

Plan• Overview and motivation

• Plane equation & point clipping

• Line & segment clipping

• Acceleration using outcodes

• Polygon clipping

P’

P0

P

H1 H2

H3

H4

0000

1010 0010 0110

1000 0100

00011001 0101

Page 48: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 48

Polygon clipping

Page 49: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 49

Polygon clipping

Page 50: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 50

Polygon clipping• Clipping is symmetric

Page 51: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 51

Polygon clipping is complex• Even when the polygons are convex

Page 52: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 52

Polygon clipping is nasty• When the polygons are concave

Page 53: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 53

Weiler-Atherton Clipping• Strategy: “Walk" polygon/window boundary• Polygons are oriented (CCW)

Page 54: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 54

Weiler-Atherton Clipping• Compute intersection points

Page 55: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 55

Weiler-Atherton Clipping• Compute intersection points• Mark points where polygons enters clipping

window (green here)

Page 56: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 56

ClippingWhile there is still an unprocessed entering

intersectionWalk" polygon/window boundary

Page 57: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 57

Walking rules• Out-to-in pair:

– Record clipped point– Follow polygon boundary (ccw)

• In-to-out pair:– Record clipped point– Follow window boundary (ccw)

Page 58: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 58

Walking rules• Out-to-in pair:

– Record clipped point– Follow polygon boundary (ccw)

• In-to-out pair:– Record clipped point– Follow window boundary (ccw)

Page 59: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 59

Walking rules• Out-to-in pair:

– Record clipped point– Follow polygon boundary (ccw)

• In-to-out pair:– Record clipped point– Follow window boundary (ccw)

Page 60: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 60

Walking rules• Out-to-in pair:

– Record clipped point– Follow polygon boundary (ccw)

• In-to-out pair:– Record clipped point– Follow window boundary (ccw)

Page 61: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 61

Walking rulesWhile there is still an unprocessed entering

intersectionWalk" polygon/window boundary

Page 62: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 62

Walking rulesWhile there is still an unprocessed entering

intersectionWalk" polygon/window boundary

Page 63: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 63

Walking rulesWhile there is still an unprocessed entering

intersectionWalk" polygon/window boundary

Page 64: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 64

Walking rulesWhile there is still an unprocessed entering

intersectionWalk" polygon/window boundary

Page 65: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 65

Weiler-Atherton Clipping• Importance of good adjacency data structure

(here simply list of oriented edges)

Page 66: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 66

Robustness, precision, degeneracies• What if a vertex is on the boundary?• What happens if it is “almost” on the boundary?

– Problem with floating point precision• Welcome to the real world of 3D geometry!

Page 67: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 67

Clipping• Many other clipping algorithms:• Parametric, general windows, region-region,

One-Plane-at-a-Time Clipping, etc.

Page 68: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 68

Constructive Solid Geometry (CSG)• Sort of generalized clipping• Boolean operations• Very popular in CAD/CAM• CSG tree

Intersection

Union

DifferenceAri Rappoport, Steven Spitz 97

Page 69: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 69

Constructive Solid Geometry (CSG)• Simple with some rendering algorithms (Ray

Tracing)

Page 70: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 70

Constructive Solid Geometry (CSG)• Simple with some rendering algorithms (Ray

Tracing)

Page 71: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 71

Constructive Solid Geometry (CSG)• Simple with some rendering algorithms (Ray

Tracing)• Very hard with polygonal models• Can also be done with hardware tricks

Page 72: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 72

Questions?

Page 73: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 73

Playtime: The Green Flash• Novel by Jules Verne (19th century)

– Movie by Rohmer, Summer• Visual phenomenon at sunset

Page 74: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 74

Green Flash• http://mintaka.sdsu.edu/GF/• http://www.mtwilson.edu/Tour/Lot/Green_Flash/• http://www.intersoft.it/galaxlux/GreenFlashGallery.htm• http://www.isc.tamu.edu/~astro/research/sandiego.html• http://www.meteores.net/rv.html• http://flzhgn.home.mindspring.com/grnray.htm

Page 75: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 75

Green flash

Page 76: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 76

Green flash

Page 77: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 77

Page 78: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 78

Green flash• Mirage• Refraction

– temperature gradient

• Ω shape• Depends

on wavelength

Page 79: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 79

Green flash• Simulation

Page 80: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 80

Green flash

Page 81: Clipping - MIT CSAILgroups.csail.mit.edu/graphics/classes/6.837/F02/lectures/... · 2005. 5. 4. · Clipping MIT EECS 6.837 Frédo Durand and Seth Teller Some slides and images courtesy

MIT EECS 6.837, Teller and Durand 81

Green flash• Why don’t you see green flash at sunrise?