clipping - princeton university computer science · polygon clipping • find the part of a polygon...

28
1 C l i p p i n g Thomas Funkhouser Princeton University C0S 426, Fall 2000 3 D R e n d e r i n g P i p e l i n e (for direct illumination) 3D Primitives Modeling Transformation Modeling Transformation Projection Transformation Projection Transformation Clipping Clipping Lighting Lighting Image Viewport Transformation Viewport Transformation Scan Conversion Scan Conversion 2D Image Coordinates 3D Modeling Coordinates 3D World Coordinates 3D Camera Coordinates 2D Screen Coordinates 2D Screen Coordinates Viewing Transformation Viewing Transformation 3D World Coordinates 2D Image Coordinates

Upload: others

Post on 17-Jun-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

1

Clipping

Thomas Funkhouser

Princeton University

C0S 426, Fall 2000

3D Rendering Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ModelingTransformation

ProjectionTransformation

ProjectionTransformation

ClippingClipping

LightingLighting

Image

ViewportTransformation

ViewportTransformation

ScanConversion

ScanConversion

2D Image Coordinates

3D Modeling Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

2D Screen Coordinates

ViewingTransformation

ViewingTransformation

3D World Coordinates

2D Image Coordinates

Page 2: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

2

3D Rendering Pipeline (for direct illumination)

3D Primitives

ModelingTransformation

ModelingTransformation

ProjectionTransformation

ProjectionTransformation

ClippingClipping

LightingLighting

Image

ViewportTransformation

ViewportTransformation

ScanConversion

ScanConversion

2D Image Coordinates

3D Modeling Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

2D Screen Coordinates

ViewingTransformation

ViewingTransformation

3D World Coordinates

2D Image Coordinates

2D Rendering Pipeline

ViewportTransformation

ViewportTransformation

ScanConversion

ScanConversion

ClippingClipping

2D Primitives

Image

Clip portions of geometric primitivesresiding outside the window

Fill pixels representing primitives in screen coordinates

Transform the clipped primitivesfrom screen to image coordinates

3D Primitives

Page 3: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

3

2D Rendering Pipeline

ViewportTransformation

ViewportTransformation

ScanConversion

ScanConversion

ClippingClipping

2D Primitives

Image

Clip portions of geometric primitivesresiding outside the window

Fill pixels representing primitives in screen coordinates

Transform the clipped primitivesfrom screen to image coordinates

3D Primitives

Clipping

• Avoid drawing parts of primitives outside window� Window defines part of scene being viewed� Must draw geometric primitives only inside window

Screen Coordinates

Window

Page 4: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

4

Clipping

• Avoid drawing parts of primitives outside window� Window defines part of scene being viewed� Must draw geometric primitives only inside window

ViewingWindow

Clipping

• Avoid drawing parts of primitives outside window� Points� Lines� Polygons� Circles� etc.

ViewingWindow

Page 5: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

5

Point Clipping

Windowwx1 wx2

wy2

wy1

(x,y)

• Is point (x,y) inside the clip window?

inside = (x >= wx1) && (x <= wx2) && (y >= wy1) && (y <= wy2);

inside = (x >= wx1) && (x <= wx2) && (y >= wy1) && (y <= wy2);

Line Clipping

• Find the part of a line inside the clip window

P1

P10

P9

P8

P7

P4P3

P6

P5

P2

Before Clipping

Page 6: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

6

P’8

P’7

P4P3

P6

P’5

After Clipping

Line Clipping

• Find the part of a line inside the clip window

Cohen Sutherland Line Clipping

• Use simple tests to classify easy cases first

P1

P10

P9

P8

P7

P4P3

P6

P5

P2

Page 7: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

7

Cohen Sutherland Line Clipping

• Classify some lines quickly by AND of bit codesrepresenting regions of two endpoints (must be 0)

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P1

P10

P9

P8

P7

P4P3

P6

P5

P2

Cohen Sutherland Line Clipping

• Classify some lines quickly by AND of bit codesrepresenting regions of two endpoints (must be 0)

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P1

P10

P9

P8

P7

P4P3

P6

P5

P2

Page 8: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

8

Cohen Sutherland Line Clipping

• Classify some lines quickly by AND of bit codesrepresenting regions of two endpoints (must be 0)

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P7

P4P3

P6

P5

Cohen Sutherland Line Clipping

• Classify some lines quickly by AND of bit codesrepresenting regions of two endpoints (must be 0)

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P7

P4P3

P6

P5

Page 9: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

9

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P7

P4P3

P6

P5

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P7

P4P3

P6

P5

Page 10: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

10

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P7

P4P3

P6

P’5

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P7

P4P3

P6

P’5

Page 11: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

11

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P7

P4P3

P6

P’5

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P7

P4P3

P6

P’5

Page 12: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

12

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P’7

P4P3

P6

P’5

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P8

P’7

P4P3

P6

P’5

Page 13: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

13

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P’8

P’7

P4P3

P6

P’5

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P’8

P’7

P4P3

P6

P’5

Page 14: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

14

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P’8

P’7

P4P3

P6

P’5

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P’8

P’7

P4P3

P6

P’5

Page 15: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

15

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P’8

P’7

P4P3

P6

P’5

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P10

P9

P’8

P’7

P4P3

P6

P’5

Page 16: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

16

Cohen-Sutherland Line Clipping

• Compute interesections with window boundary forlines that can’t be classified quickly

Bit 1 Bit 2

Bit 3

Bit 4

0000 01001000

0001 01011001

0010 01101010

P’8

P’7

P4P3

P6

P’5

Clipping

• Avoid drawing parts of primitives outside window Points Lines� Polygons� Circles etc.

2D Screen Coordinates

Window

Page 17: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

17

Polygon Clipping

• Find the part of a polygon inside the clip window?

Before Clipping

Polygon Clipping

• Find the part of a polygon inside the clip window?

After Clipping

Page 18: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

18

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

Page 19: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

19

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

Page 20: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

20

Sutherland Hodgeman Clipping

• Clip to each window boundary one at a time

Clipping to a Boundary

• Do inside test for each point in sequence,Insert new points when cross window boundary,Remove points outside window boundary

Outside

InsideWindow

Boundary

P1

P2

P5

P4

P3

Page 21: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

21

Clipping to a Boundary

• Do inside test for each point in sequence,Insert new points when cross window boundary,Remove points outside window boundary

Outside

InsideWindow

Boundary

P1

P2

P5

P4

P3

Clipping to a Boundary

• Do inside test for each point in sequence,Insert new points when cross window boundary,Remove points outside window boundary

Outside

InsideWindow

Boundary

P1

P2

P5

P4

P3

Page 22: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

22

Clipping to a Boundary

• Do inside test for each point in sequence,Insert new points when cross window boundary,Remove points outside window boundary

Outside

InsideWindow

Boundary

P1

P2

P5

P4

P3

Clipping to a Boundary

• Do inside test for each point in sequence,Insert new points when cross window boundary,Remove points outside window boundary

Outside

InsideWindow

Boundary

P1

P2

P5

P4

P3

P’

Page 23: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

23

Clipping to a Boundary

• Do inside test for each point in sequence,Insert new points when cross window boundary,Remove points outside window boundary

Outside

InsideWindow

Boundary

P1

P2

P5

P4

P3

P’

Clipping to a Boundary

• Do inside test for each point in sequence,Insert new points when cross window boundary,Remove points outside window boundary

Outside

InsideWindow

Boundary

P1

P2

P5

P4

P3

P’

Page 24: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

24

Clipping to a Boundary

• Do inside test for each point in sequence,Insert new points when cross window boundary,Remove points outside window boundary

Outside

InsideWindow

Boundary

P1

P2

P5

P4

P3

P’ P’’

Clipping to a Boundary

• Do inside test for each point in sequence,Insert new points when cross window boundary,Remove points outside window boundary

Outside

InsideWindow

Boundary

P1

P2

P’ P’’

Page 25: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

25

2D Rendering Pipeline

ViewportTransformation

ViewportTransformation

ScanConversion

ScanConversion

ClippingClipping

2D Primitives

Image

Clip portions of geometric primitivesresiding outside the window

Fill pixels representing primitives in screen coordinates

Transform the clipped primitivesfrom screen to image coordinates

3D Primitives

Viewport Transformation

• Transform 2D geometric primitives fromscreen coordinate system (normalized devicecoordinates) to image coordinate system (pixels)

ImageScreen

Viewport

Window

Page 26: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

26

Viewport Transformation

vx1 vx2vy1

vy2

wx1 wx2wy1

wy2Window Viewport

Screen Coordinates Image Coordinates

(wx,wy) (vx,vy)

vx = vx1 + (wx - wx1) * (vx2 - vx1) / (wx2 - wx1);vy = vy1 + (wy - wy1) * (vy2 - vy1) / (wy2 - wy1);vx = vx1 + (wx - wx1) * (vx2 - vx1) / (wx2 - wx1);vy = vy1 + (wy - wy1) * (vy2 - vy1) / (wy2 - wy1);

• Window-to-viewport mapping

Summary of Transformations

ModelingTransformation

ModelingTransformation

ViewingTransformation

ViewingTransformation

2D Image Coordinates

ProjectionTransformation

ProjectionTransformation

Window-to-ViewportTransformation

Window-to-ViewportTransformation

3D Object Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

p(x,y,z)

p’(x’,y’)

}Viewing transformations

}Modeling transformation

}Viewport transformation

Page 27: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

27

Summary

ViewportTransformation

ViewportTransformation

ScanConversion

ScanConversion

ClippingClipping

2D Primitives

Image

Clip portions of geometric primitivesresiding outside the window

Fill pixels representing primitives in screen coordinates

Transform the clipped primitivesfrom screen to image coordinates

3D Primitives

Summary3D Primitives

ModelingTransformation

ModelingTransformation

ProjectionTransformation

ProjectionTransformation

ClippingClipping

LightingLighting

Image

ViewportTransformation

ViewportTransformation

ScanConversion

ScanConversion

2D Image Coordinates

3D Modeling Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

2D Screen Coordinates

ViewingTransformation

ViewingTransformation

3D World Coordinates

2D Image Coordinates

ViewingWindow

Page 28: Clipping - Princeton University Computer Science · Polygon Clipping • Find the part of a polygon inside the clip window? After Clipping. 18 Sutherland Hodgeman Clipping • Clip

28

Next Time3D Primitives

ModelingTransformation

ModelingTransformation

ProjectionTransformation

ProjectionTransformation

ClippingClipping

LightingLighting

Image

ViewportTransformation

ViewportTransformation

ScanConversion

ScanConversion

2D Image Coordinates

3D Modeling Coordinates

3D World Coordinates

3D Camera Coordinates

2D Screen Coordinates

2D Screen Coordinates

ViewingTransformation

ViewingTransformation

3D World Coordinates

2D Image Coordinates

Scan Conversion!

P1

P2

P3