clipping

38
1 Clipping

Upload: olinda

Post on 04-Jan-2016

42 views

Category:

Documents


2 download

DESCRIPTION

Clipping. Culling and Clipping. What can’t we see? anything occluded by another object (HSR) anything outside view volume Today: clipping. Clipping Against a Rectangular Region Multiple Cases. B. F. E. C. G. A. D. H. Clip Rectangle. Division of Space. Clip Region. 1. 0. 1. 0. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Clipping

1

Clipping

Page 2: Clipping

3

Culling and Clipping

• What can’t we see?

- anything occluded by another object (HSR)

- anything outside view volume

• Today: clipping

Page 3: Clipping

4

Page 4: Clipping

5

Page 5: Clipping

6

Page 6: Clipping

7

Page 7: Clipping

8

Page 8: Clipping

9

Page 9: Clipping

10

Page 10: Clipping

11

Clipping Against a Rectangular RegionMultiple Cases

A

B

C

D

E

F

Clip Rectangle

G

H

Page 11: Clipping

12

Division of Space

ymin

ymax

xmin xmax

Clip Region

Page 12: Clipping

13

Cohen-Sutherland Clipping:“Outcodes”

1 1 00

minyy

y ymax

minxx

x xmax

min

min1

max

max0

0

1

0

1

:Example

yy

yyb

yy

yyb

0b 1b 2b 3b

Page 13: Clipping

14

Cohen-Sutherland Clipping:Region Outcodes

ymin

ymax

xminxmax

1001 1000 1010

0001

0101 0100 0110

00100000

Page 14: Clipping

15

Cohen-Sutherland Clipping:Trivial Acceptance: O(P0) = O(P1) = 0

ymin

ymax

xmin xmax

1001 1000 1010

0001

0101 0100 0110

00100000

P0

P1

Page 15: Clipping

16

Cohen-Sutherland Clipping:Trivial Rejection: O(P0) & O(P1) 0

ymin

ymax

xmin xmax

1001 1000 1010

0001

0101 0100 0110

00100000

P0

P1

P1P1

P0

P0

Page 16: Clipping

17

Cohen-Sutherland Clipping: O(P0) =0 , O(P1) 0

ymin

ymax

xmin xmax

1001 1000 1010

0001

0101 0100 0110

00100000

P0

P1

P1

P1 P0

P0

Page 17: Clipping

18

Cohen-Sutherland Clipping: The Algorithm

• Compute the outcodes for the two vertices

• Test for trivial acceptance or rejection

• Select a vertex for which outcode is not zero- There will always be one

• Select the first nonzero bit in the outcode to define the boundary against which the line segment will be clipped

• Compute the intersection and replace the vertex with the intersection point

• Compute the outcode for the new point and iterate

Page 18: Clipping

19

Cohen-Sutherland Clipping:Example 1

ymin

ymax

xmin xmax

1001 1000 1010

0001

0101 0100 0110

00100000

A

B

C

Page 19: Clipping

20

Cohen-Sutherland Clipping:Example 1

ymin

ymax

xmin xmax

1001 1000 1010

0001

0101 0100 0110

00100000

B

C

Page 20: Clipping

21

Chopping at each boundary

Page 21: Clipping

22

Cohen-Sutherland Clipping:Example 2

ymin

ymax

xmin xmax

1001 1000 1010

0001

0101 0100 0110

00100000

B

C

A

D

E

Page 22: Clipping

23

Cohen-Sutherland Clipping:Example 2

ymin

ymax

xmin xmax

1001 1000 1010

0001

0101 0100 0110

00100000

B

C

D

E

Page 23: Clipping

24

Cohen-Sutherland Clipping:Example 2

ymin

ymax

xmin xmax

1001 1000 1010

0001

0101 0100 0110

00100000

B

C

D

Page 24: Clipping

25

Cohen-Sutherland Clipping:Example 2

ymin

ymax

xmin xmax

1001 1000 1010

0001

0101 0100 0110

00100000

B

C

Page 25: Clipping

26

Cohen-Sutherland Clipping:Advantages/Extension

• Easily extended to 3 dimensions by adding two bits to the outcode for the z axis.

• Calculations then reduce to intersection of line with plane

• Algorithm most efficient when most segments can either be trivially accepted or trivially rejected

Page 26: Clipping

27

Cohen Sutherland in 3D

• Use 6-bit outcodes

• When needed, clip line segment against planes

Page 27: Clipping

28

Other Clipping Algorithm

• Cyrus–Beck, Liang–Barsky

- generally, these try to be more clever about intersections

- represent lines parametrically, solve for intersection t values

P(t) = P0 + t(P1-P0)

- can clip in fewer steps than Cohen–Sutherland

- try to increase number of trivial rejection cases

Page 28: Clipping

29

Parametric Representation of Lines

)0(0 pp

)1(1 pp

)(p

10)1()( ppp

Page 29: Clipping

30

Liang-Barsky Clipping

• Consider the parametric form of a line segment

• We can distinguish between the cases by looking at the ordering of the values of where

the line determined by the line segment crosses the lines that determine the window

p() = (1-)p1+ p2 1 0

p1

p2

Page 30: Clipping

31

Liang-Barsky Parametric Clipping

)()( 010 pppp

0)( iEi ppN

0)( iEi ppN

Edge Ei

0p

1piE

p

N i

InsideOutside

0)( iEi ppN

Page 31: Clipping

32

Potentially Entering (PE) and Potentially Leaving (PL) Points

001 ppN i

Edge Ei

0p

1p

N i

InsideOutside

Edge Ei

N i

Inside Outside

001 ppN i

Potentially Entering(PE) Point

Potentially Leaving(PL) Point

0p

1p

Page 32: Clipping

33

Liang-Barsky Clipping:Computing the Intersection

0)( iEi ppN

)()( 010 pppp

0010 ppNppN iEi i

:for solve and )(Let 01 ppD

DN

ppN

i

Ei i0=

Page 33: Clipping

34

Liang-Barsky Clipping:Potentially Leaving vs. Potentially Entering

ymin

ymax

xmin xmax

= “Inside”

0p

1pPE

PE

PE

PE

PL

PL

PL

PL

0p

0p

1p1p

Page 34: Clipping

35

Liang-Barsky Clipping:Algorithm Strategy

• Find the largest PE greater than zero.• Find the smallest PL less than one.• Reject the segment if PE > PL.

Page 35: Clipping

36

Liang-Barsky Clipping:Pseudocode of Algorithm

for (each line segment to be clipped)

alpha_E=0; alpha_L=1;

for (each candidate intersection with a clip edge) {

if (Ni•D!=0) { /*edges not parallel to line*/

calculate alpha;

use sign of Ni•D to class alpha as PE or PL;

if (PE) alpha_E = max(alpha_E,alpha);

if (PL) alpha_L = min(alpha_L,alpha);

}

}

if (alpha_E > alpha_L)

return NULL;

else

return P(alpha_E) and P(alpha_L) as clip intersections

Page 36: Clipping

37

Polygon Clipping:Convex Polygons

Line segment clipping is done in order. New verticesare generated at clip point. External vertices areeliminated.

1

2

3

45

1

2

3

4’5’

Page 37: Clipping

38

Polygon Clipping:The Convexity Problem

Single object becomes multiple objects.

Page 38: Clipping

39

Sutherland-Hodgeman Polygon Clipping

Top Bottom Right Left