Professional Documents
Culture Documents
Sim Clipping Final
Sim Clipping Final
Sim Clipping Final
Clipping Basics
Goal:only render what will be visible in the drawing window; eliminate
from the rendering pipeline all those primitives which will not appear
in the final viewport
Clipping Approaches
Individual Pixel Tests:
Render at the pixel level
Check pixel for containment in the target region
Maintain Large Drawing Area:
Render the entire set of primitives in the WCS
Display only the portion of the set which overlaps the viewport
Analytical Methods:
Compute the intersections of primitives with the clip region
Eliminate outlying portions of the primitives
Clipping
General criteria for a good clipping algorithm:
Quickly identify lines (or polygon edges) that need not be
drawn at all
- These can be skipped and discarded
Quickly identify lines (or polygon edges) that are completely
3
Trivial Accepts & Rejects
Big optimization: trivial accept/rejects
How can we quickly determine whether a line segment is entirely
ymax
ymin
Clipping Primitives
Different primitives can be handled in different
ways
Points
Lines
Polygons
Point Clipping
This one is easy
Determine if a point (x,y) is in the clip
Lets do 2D first
Clip a line against 1 edge (x1,y1)
of the viewport C
(x,y)???
What do we know?
A D
Similar triangles
A/B=C/D
B = (x2 - x1) (x2,y2)
A = (y2 - y1) B
C = (y1 - ymax)
D = BC / A
B = ymin
P2 = 0 0 0 0
b. Bitwise OR= 0 0 0 0
=>accept segment P1P2
(trivial accept since both end
points are inside the
window)
ifc0|c1=0000
accept(draw)
elseifc0&c10000
reject(dontdraw)
elseclipandretest
Example-Cohen-Sutherland
Case 2: Line segment P3P4
a. Calculate clip codes
P = 1 0 0 1
3
P4 = 1 0 0 0
b. Bitwise AND = 1 0 0 0
=> reject segment P3P4
( trivial reject since both end
points are out of the window)
Example-Cohen-Sutherland
Case 3: Line segments P5P6 , P7P8
a.Calculate clip codes
P5 = 0 0 0 1
P6 = 1 0 0 0
b. Bitwise AND = 0 0 0 0
P7 = 0 0 0 1
P8 = 1 0 0 0
b. Bitwise AND = 0 0 0 0
Example-Cohen-Sutherland
c. Clip against left
P'5 = ( xwmin, y5 + m( xwmin - x5))
P6 = 1 0 0 0
e. Bitwise AND = 1 0 0 0
=> reject P'5P6
P'7 = 0 0 0 0
P8 = 1 0 0 0
e. Bitwise AND = 0 0 0 0
Example-Cohen-Sutherland
Line segment P'7 P8
f. Clip against right
g. Clip against bottom
h. Clip against top
P'8 = (x7 + (ywmax - y7) / m, ywmax)
P'8 = 0 0 0 0
j. Bitwise OR = 0 0 0 0
=> accept P'7 P'8
Cohen-Sutherland Summary
Advantages:
Simple to implement
21
Cohen-Sutherland Summary
Disadvantages:
Fixed-order decision can do needless work
volumes
Liang-Barsky Line Clipping
Consider the parametric definition of a line:
x = x1 + ux y = y1 + uy
x = (x2 - x1) y = (y2 - y1) 0 (u) 1
Substituting in point clipping condition in parametric form:
p1 = -x q1 = (x1 - xmin)
p2 = x q2 = (xmax - x1)
p3 = -y q3 (y1 - ymin)
p4 = y q4 (ymax - y1)
Liang-Barsky Line Clipping Algorithm
1. Input endpoint coordinates of line (x1, y1) and (x2, y2)
2. For each boundary k=(1,2,3,4) for (L,R,B,T) calculate pk, qk
p
1 = -x q1 = (x1 - xmin)
p2 = x q2 = (xmax - x1)
p3 = -y q3 (y1 - ymin)
p4 = y q4 (ymax - y1)
3. Check the following cases:
a. pk = 0 (Line is parallel to boundary k)
If for the same k, qk < 0, reject
Else if qk 0 line is inside boundary, accept
2 more ps and qs
In most cases, Liang-Barsky is slightly more efficient
Avoids unnecessary intersection calculations
30
Why Is Clipping Hard?
A really tough case:
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
33
Sutherland-Hodgeman Polygon Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
34
Sutherland-Hodgeman Polygon Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
35
Sutherland-Hodgeman Polygon Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
36
Sutherland-Hodgeman Polygon Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
37
Sutherland-Hodgeman Polygon Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
38
Sutherland-Hodgeman Polygon Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
39
Sutherland-Hodgeman Polygon Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
40
Sutherland-Hodgeman Polygon Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
41
Sutherland-Hodgeman Polygon Clipping
Basic idea:
Consider each edge of the viewport individually
Clip the polygon against the edge equation
After doing all planes, the polygon is fully clipped
Will this work for non-rectangular clip regions?
What would
3-D clipping
involve?
42
Sutherland-Hodgeman Polygon Clipping
Input/output for algorithm:
Input: list of polygon vertices in order
Output: list of clipped polygon vertices consisting of old
vertices (maybe) and new vertices (maybe)
Note: clipping operation done against each edge
Sutherland-Hodgeman basic routine:
43
Sutherland-Hodgeman Clipping
Edge from s to p takes one of four cases:
(Purple line can be a line or a plane)
p s
p s
45
Example: Sutherland - Hodgeman
Input Vertices
in ->
P1
P2
P3
P4
Example: Sutherland - Hodgeman
Left Clipping
in -> [clip left] ->
P1 - in to in -> P1
P2 - in to out -> P'2
P3 - out to out -> x
P4 - out to in -> P'4
-> P4
Example: Sutherland - Hodgeman
Right Clipping
-> [clip right] ->
P1 - in to in -> P1
P'2 - in to in -> P'2
x
P'4 - in to in -> P'4
P4 - in to in -> P4
Example: Sutherland - Hodgeman
Bottom Clipping
-> [clip bottom]->
P1 - in to in -> P1
P'2 - in to out -> P''2
P'4 - out to in -> P''4
-> P'4
P4 - in to in -> P4
Example: Sutherland - Hodgeman
Top Clipping
-> [clip top] -> out
P1 - in to in -> P1
P''2 - in to in -> P''2
P''4 - in to in -> P''4
P'4 - in to in -> P'4
P4 - in to in -> P4
Sutherland-Hodgeman Summary
Coded recursively - efficient hardware implementation.
Quite general -
51