Clipping - PowerPoint PPT Presentation

1 / 38
About This Presentation
Title:

Clipping

Description:

External vertices are eliminated. 1 2 3 4 5 1 2 3 4 5 Polygon Clipping: The Convexity Problem Single object becomes multiple objects. – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 39
Provided by: HughMas7
Category:
Tags: clipping | polygon

less

Transcript and Presenter's Notes

Title: Clipping


1
Clipping
2
Transformation Sequence
Normalized Device Coords.
Screen Coords.
Clip Coords.
Object Coords.
Eye Coords.
Implementation 4 x 4 matrix multiplication in
homogeneous coords.
3
Culling 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)
11
Clipping Against a Rectangular RegionMultiple
Cases
B
F
E
C
G
A
D
H
Clip Rectangle
12
Division of Space
Clip Region
13
Cohen-Sutherland ClippingOutcodes
14
Cohen-Sutherland ClippingRegion Outcodes
1001
1000
1010
0001
0010
0000
0100
0110
0101
15
Cohen-Sutherland ClippingTrivial Acceptance
O(P0) O(P1) 0
1001
1000
1010
P1
0001
0010
0000
P0
0100
0110
0101
16
Cohen-Sutherland ClippingTrivial Rejection
O(P0) O(P1) ? 0
P0
1001
1000
1010
P1
P0
0001
0010
0000
P0
P1
P1
0100
0110
0101
17
Cohen-Sutherland Clipping O(P0) 0 , O(P1) ? 0
1001
1000
1010
P0
0001
0010
0000
P1
P1
P0
P0
0100
0110
0101
P1
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 ClippingExample 1
A
1001
1000
1010
B
C
0001
0010
0000
0100
0110
0101
20
Cohen-Sutherland ClippingExample 1
1001
1000
1010
B
C
0001
0010
0000
0100
0110
0101
21
Chopping at each boundary
22
Cohen-Sutherland ClippingExample 2
1001
1000
1010
E
D
0001
0010
0000
C
B
A
0100
0110
0101
23
Cohen-Sutherland ClippingExample 2
1001
1000
1010
E
D
0001
0010
0000
C
B
0100
0110
0101
24
Cohen-Sutherland ClippingExample 2
1001
1000
1010
D
0001
0010
0000
C
B
0100
0110
0101
25
Cohen-Sutherland ClippingExample 2
1001
1000
1010
0001
0010
0000
C
B
0100
0110
0101
26
Cohen-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

27
Cohen Sutherland in 3D
  • Use 6-bit outcodes
  • When needed, clip line segment against planes

28
Other 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

29
Parametric Representation of Lines
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 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
31
Liang-Barsky Parametric Clipping
Edge Ei
Inside
Outside
32
Potentially Entering (PE) and Potentially Leaving
(PL) Points
Edge Ei
Edge Ei
Inside
Outside
Inside
Outside
Potentially Entering (PE) Point
Potentially Leaving (PL) Point
33
Liang-Barsky ClippingComputing the Intersection
34
Liang-Barsky ClippingPotentially Leaving vs.
Potentially Entering
PE
PL
PL
PL
PE
PL
PE
PE
Inside
35
Liang-Barsky ClippingAlgorithm Strategy
  • Find the largest PE greater than zero.
  • Find the smallest PL less than one.
  • Reject the segment if PE gt PL.

36
Liang-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
37
Polygon 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.
38
Polygon ClippingThe Convexity Problem
Single object becomes multiple objects.
39
Sutherland-Hodgeman Polygon Clipping
Write a Comment
User Comments (0)
About PowerShow.com