Title: Clipping
1 Clipping
2Transformation Sequence
Normalized Device Coords.
Screen Coords.
Clip Coords.
Object Coords.
Eye Coords.
Implementation 4 x 4 matrix multiplication in
homogeneous coords.
3Culling and Clipping
- What cant we see?
- anything occluded by another object (HSR)
- anything outside view volume
- Today clipping
4(No Transcript)
5(No Transcript)
6(No Transcript)
7(No Transcript)
8(No Transcript)
9(No Transcript)
10(No Transcript)
11Clipping Against a Rectangular RegionMultiple
Cases
B
F
E
C
G
A
D
H
Clip Rectangle
12Division of Space
Clip Region
13Cohen-Sutherland ClippingOutcodes
14Cohen-Sutherland ClippingRegion Outcodes
1001
1000
1010
0001
0010
0000
0100
0110
0101
15Cohen-Sutherland ClippingTrivial Acceptance
O(P0) O(P1) 0
1001
1000
1010
P1
0001
0010
0000
P0
0100
0110
0101
16Cohen-Sutherland ClippingTrivial Rejection
O(P0) O(P1) ? 0
P0
1001
1000
1010
P1
P0
0001
0010
0000
P0
P1
P1
0100
0110
0101
17Cohen-Sutherland Clipping O(P0) 0 , O(P1) ? 0
1001
1000
1010
P0
0001
0010
0000
P1
P1
P0
P0
0100
0110
0101
P1
18Cohen-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
19Cohen-Sutherland ClippingExample 1
A
1001
1000
1010
B
C
0001
0010
0000
0100
0110
0101
20Cohen-Sutherland ClippingExample 1
1001
1000
1010
B
C
0001
0010
0000
0100
0110
0101
21Chopping at each boundary
22Cohen-Sutherland ClippingExample 2
1001
1000
1010
E
D
0001
0010
0000
C
B
A
0100
0110
0101
23Cohen-Sutherland ClippingExample 2
1001
1000
1010
E
D
0001
0010
0000
C
B
0100
0110
0101
24Cohen-Sutherland ClippingExample 2
1001
1000
1010
D
0001
0010
0000
C
B
0100
0110
0101
25Cohen-Sutherland ClippingExample 2
1001
1000
1010
0001
0010
0000
C
B
0100
0110
0101
26Cohen-Sutherland ClippingAdvantages/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
27Cohen Sutherland in 3D
- Use 6-bit outcodes
- When needed, clip line segment against planes
28Other Clipping Algorithm
- CyrusBeck, LiangBarsky
- 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 CohenSutherland
- try to increase number of trivial rejection cases
29Parametric Representation of Lines
30Liang-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 a where the line
determined by the line segment crosses the lines
that determine the window
p(a) (1-a)p1 ap2 1 ? a ? 0
p2
p1
31Liang-Barsky Parametric Clipping
Edge Ei
Inside
Outside
32Potentially Entering (PE) and Potentially Leaving
(PL) Points
Edge Ei
Edge Ei
Inside
Outside
Inside
Outside
Potentially Entering (PE) Point
Potentially Leaving (PL) Point
33Liang-Barsky ClippingComputing the Intersection
34Liang-Barsky ClippingPotentially Leaving vs.
Potentially Entering
PE
PL
PL
PL
PE
PL
PE
PE
Inside
35Liang-Barsky ClippingAlgorithm Strategy
- Find the largest PE greater than zero.
- Find the smallest PL less than one.
- Reject the segment if PE gt PL.
36Liang-Barsky ClippingPseudocode of Algorithm
for (each line segment to be clipped) alpha_E0
alpha_L1 for (each candidate intersection with
a clip edge) if (NiD!0) /edges not
parallel to line/ calculate alpha use
sign of NiD 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
gt alpha_L) return NULL else return
P(alpha_E) and P(alpha_L) as clip intersections
37Polygon ClippingConvex Polygons
5
4
4
5
1
3
1
3
2
2
Line segment clipping is done in order. New
vertices are generated at clip point. External
vertices are eliminated.
38Polygon ClippingThe Convexity Problem
Single object becomes multiple objects.
39Sutherland-Hodgeman Polygon Clipping