clipping
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 PresentationTRANSCRIPT
1
Clipping
3
Culling and Clipping
• What can’t we see?
- anything occluded by another object (HSR)
- anything outside view volume
• Today: clipping
4
5
6
7
8
9
10
11
Clipping Against a Rectangular RegionMultiple Cases
A
B
C
D
E
F
Clip Rectangle
G
H
12
Division of Space
ymin
ymax
xmin xmax
Clip Region
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
14
Cohen-Sutherland Clipping:Region Outcodes
ymin
ymax
xminxmax
1001 1000 1010
0001
0101 0100 0110
00100000
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
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
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
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
19
Cohen-Sutherland Clipping:Example 1
ymin
ymax
xmin xmax
1001 1000 1010
0001
0101 0100 0110
00100000
A
B
C
20
Cohen-Sutherland Clipping:Example 1
ymin
ymax
xmin xmax
1001 1000 1010
0001
0101 0100 0110
00100000
B
C
21
Chopping at each boundary
22
Cohen-Sutherland Clipping:Example 2
ymin
ymax
xmin xmax
1001 1000 1010
0001
0101 0100 0110
00100000
B
C
A
D
E
23
Cohen-Sutherland Clipping:Example 2
ymin
ymax
xmin xmax
1001 1000 1010
0001
0101 0100 0110
00100000
B
C
D
E
24
Cohen-Sutherland Clipping:Example 2
ymin
ymax
xmin xmax
1001 1000 1010
0001
0101 0100 0110
00100000
B
C
D
25
Cohen-Sutherland Clipping:Example 2
ymin
ymax
xmin xmax
1001 1000 1010
0001
0101 0100 0110
00100000
B
C
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
27
Cohen Sutherland in 3D
• Use 6-bit outcodes
• When needed, clip line segment against planes
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
29
Parametric Representation of Lines
)0(0 pp
)1(1 pp
)(p
10)1()( ppp
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
31
Liang-Barsky Parametric Clipping
)()( 010 pppp
0)( iEi ppN
0)( iEi ppN
Edge Ei
0p
1piE
p
N i
InsideOutside
0)( iEi ppN
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
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=
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
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.
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
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’
38
Polygon Clipping:The Convexity Problem
Single object becomes multiple objects.
39
Sutherland-Hodgeman Polygon Clipping
Top Bottom Right Left