Escolar Documentos
Profissional Documentos
Cultura Documentos
Clipping in 2D
Clipping - Overview
Clipping is the removal or scissoring of primitives against clip-regions Useful to consider rectangular clip-regions Lines - Cohen-Sutherland; Liang-Barsky
Nicholl-Lee-Nicholl refinement
y = ClipYB
8/10 - 3
x = ClipXL
x = ClipXR
y = ClipYB
[Bottom, Left] [Bottom] [Bottom, Right]
x = ClipXL
x = ClipXR
8/10 - 4
IF (y < ClipYB) THEN Code := Code + [Bottom] ELSE IF (y > ClipYT) THEN Code := Code + [Top];
8/10 - 5
8/10 - 6
8/10 - 8
Q
8/10 - 9
8/10 - 10
R c q (X1, Y1) = P b a
X = ClipXL
8/10 - 11
(X1, Y1) = A
B = (X2, Y2)
c a
b q
Y = ClipYB
8/10 - 12
8/10 - 13
Straight Lines
P1 = (x1, y1) Any point (x, y) lying on this line may be expressed as follows: x = x0 + dx.t and y = y0 + dy.t P0 = (x0, y0) where: dx = (x1 - x0) dy = (y1 - y0) and 0 <= t <= 1
8/10 - 14
Liang-Barsky Principals
This algorithm defines the clip region to be such that: xleft and ybottom <= y <= ytop <= x <= xright
(x0, y0)
Clip Region
V0 = (x0, y0)
x = x LEFT x = x RIGHT
y = y BOTTOM
8/10 - 17
Invisible Side
Visible Side
V0 = (x0, y0)
x = x LEFT
y = y BOTTOM
8/10 - 19
Is qi > 0?
(i) If (qi > 0) Then V0 is on the visible side of the corresponding boundary
Eg
==>
If
q1
>
>
0
0
x0 - xleft
and thus
x0
>
xleft
V0 (end point whose x coord is x0) lies on the visible side of the xleft boundary.
8/10 - 22
Is qi < 0?
(ii) If (qi < 0) Then V0 is on the invisible side of the corresponding boundary
Eg
==>
If
q1
<
<
0
0
x0 - xleft
and thus
x0
<
xleft
V0 (end point whose x coord is x0) lies to the invisible side of the xleft boundary
8/10 - 23
Is qi = 0?
(iii) If (qi = 0) Then V0 lies on the corresponding boundary
Eg
==>
If
q1
=
=
0
0
xo - xleft
and thus
x0
x left.
V0 (the end point whose x coordinate is x0) lies on the xleft boundary
8/10 - 24
This tells us whether the direction of the line is: visible side of the boundary to invisible side invisible side of the boundary to visible side parallel to (or indeed ON) the actual boundary
8/10 - 25
Eg
P1 < 0
so x1 > x0
V1 is thus to the right of V0 and hence with respect to the xleft boundary the line from V0 to V1 is from the invisible side to the visible side.
8/10 - 26
A Max/Min Problem
We ignore decreases to t0 and increases to t1
Such t values represent the parts of the extended line segment beyond its natural end-points. Analysis reduces to solving a max/min problem:
A Q
8/10 - 30
Bottom
8/10 - 31
Q2
One Clip A
Two Clips
Q3
8/10 - 32
Q4
P
L L LB Q3
8/10 - 33
LR Q1 Q2
T T L LB TB
TR
8/10 - 34
T TR L L
LB
LR
8/10 - 35
BL
BR
8/10 - 36
8/10 - 37
where Q is the finishing end-point and L, T, B, R is the intercept with the Left, Top, Bottom, Right boundary
8/10 - 40
Q is the finishing end-point L, T, B, R is the intercept with the 8/10 - 41 Left, Top, Bottom, Right boundary
Polygon Clipping
Cohen-Sutherland Approach
p E q
t D B u w C v
8/10 - 44
Clip Region
Small Polygon
8/10 - 45
Head
Tail Head
Invisible Side
Visible Side
8/10 - 47
Methodology
Traverse all of the vertices in turn against a given clip boundary to produce a set of clipped points (orvertices) which define the clipped polygon WRT that clip boundary. We start with a sequence of N vertices and end up with a sequence of vertices (unlikely to be N - may be fewer or more) Repeat this exercise for each of the other clip boundaries in turn. 8/10 - 48
Associated Functions/Procedures
The algorithm uses the following functions and procedures. Details not required A Boolean function Visible which accepts as parameter some vertex and a clip boundary and returns a true value if the vertex is visible WRT that clip boundary and false otherwise.
A procedure Calculate which calculates the intersection of the edge under consideration with the current (appropriate) clip boundary. 8/10 - 50
Text Clipping
Character Clipping
3 methods
Stroke
Highly precise, most accurate, most expensive. Clip unit is the composite strokes of the character Clip Unit is the entire string which is either fully displayed or not displayed at all Clip Unit is the individual character which is either fully displayed or not displayed at all
8/10 - 52
String
Character