Computer Graphics

advertisement
Clipping Algorithms; §8-5 (contd.)
Computer Graphics
Spring 2015-2016
CS4815
Clipping Algorithms; §8-5 (contd.)
Outline
1
Clipping Algorithms; §8-5 (contd.)
CS4815
Clipping Algorithms; §8-5 (contd.)
Announcements
Mid-term: Tues, 10.00, Week07
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper
Liang-Barsky algorithm is a better approach by avoiding
repeated shortening of segment s − e; like C-S also works
for 3-D clipping regions
Idea is to return to parametric form of line (see prev.
lecture)
x = xs + u∆x
y = ys + u∆y ,
0≤u≤1
where
∆x = xe − xs ,
∆y = ye − ys
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper
Liang-Barsky algorithm is a better approach by avoiding
repeated shortening of segment s − e; like C-S also works
for 3-D clipping regions
Idea is to return to parametric form of line (see prev.
lecture)
x = xs + u∆x
y = ys + u∆y ,
0≤u≤1
where
∆x = xe − xs ,
∆y = ye − ys
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper
Applying “window” test
xbl ≤xs + u∆x ≤ xur
ybl ≤ys + u∆y ≤ yur
We break this in to four inequalities of the form uk pk ≤ qk
p1 = −∆x,
q1 = xs − xbl (left border)
p2 = ∆x,
q2 = xur − xs (right border)
p3 = −∆y ,
q3 = ys − ybl (bot border)
p4 = ∆y ,
q4 = yur − ys (top border)
We can now evaluate the four uk s with uk = qk /pk
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper
We want to find the points where line segment crosses
borders
We do this by working with the uk s
Extension of line segment will cross all four borders –
somewhere!
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper
We want to find the points where line segment crosses
borders
We do this by working with the uk s
Extension of line segment will cross all four borders –
somewhere!
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper
We want to find the points where line segment crosses
borders
We do this by working with the uk s
Extension of line segment will cross all four borders –
somewhere!
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
If line is parallel to window border then ∆x = 0 or ∆y = 0;
so, two of pi s will be 0, also (either p1 , p2 or p3 , p4 )
For each pi that is 0, if qi < 0 then line is entirely outside
that clipping boundary; o/w, qi ≥ 0 and line is inside
The infinite extension of every non-parallel (to borders)
line will cut 2 borders from outside to inside and 2 borders
from inside to out
If pk < 0, with respect to that border, the infinite extension
of the line moves from outside to inside; pk > 0 means the
line proceeds from inside to outside
So two pi s will be positive and two negative
The value of uk = qk /pk tells us critical information about
the line
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
Instead of maintaining four ui s, we only maintain 2:
t1 for the “outside to inside cases” (pk < 0)
t2 for the “inside to outside cases” (pk > 0)
t1 is initialised to 0 (corresponds to s) and is taken to be
the larger of the two cases where pk < 0
t2 is initialised to 1 (corresponds to e) and is taken to be
the smaller of the two cases where pk > 0
ui : out-in
uj : in-out
u2
e e
t2 = 1
t1
s
u3
u1
CS4815
u4
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
Instead of maintaining four ui s, we only maintain 2:
t1 for the “outside to inside cases” (pk < 0)
t2 for the “inside to outside cases” (pk > 0)
t1 is initialised to 0 (corresponds to s) and is taken to be
the larger of the two cases where pk < 0
t2 is initialised to 1 (corresponds to e) and is taken to be
the smaller of the two cases where pk > 0
ui : out-in
uj : in-out
u2
e e
t2 = 1
t1
s
u3
u1
CS4815
u4
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
Instead of maintaining four ui s, we only maintain 2:
t1 for the “outside to inside cases” (pk < 0)
t2 for the “inside to outside cases” (pk > 0)
t1 is initialised to 0 (corresponds to s) and is taken to be
the larger of the two cases where pk < 0
t2 is initialised to 1 (corresponds to e) and is taken to be
the smaller of the two cases where pk > 0
ui : out-in
uj : in-out
u2
e e
t2 = 1
t1
s
u3
u1
CS4815
u4
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
Instead of maintaining four ui s, we only maintain 2:
t1 for the “outside to inside cases” (pk < 0)
t2 for the “inside to outside cases” (pk > 0)
t1 is initialised to 0 (corresponds to s) and is taken to be
the larger of the two cases where pk < 0
t2 is initialised to 1 (corresponds to e) and is taken to be
the smaller of the two cases where pk > 0
ui : out-in
uj : in-out
u2
e e
t2 = 1
t1
s
u3
u1
CS4815
u4
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
Instead of maintaining four ui s, we only maintain 2:
t1 for the “outside to inside cases” (pk < 0)
t2 for the “inside to outside cases” (pk > 0)
t1 is initialised to 0 (corresponds to s) and is taken to be
the larger of the two cases where pk < 0
t2 is initialised to 1 (corresponds to e) and is taken to be
the smaller of the two cases where pk > 0
ui : out-in
uj : in-out
u2
e e
t2 = 1
t1
s
u3
u1
CS4815
u4
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
u1
s
e
t2=1
u2
t1> 1
u4
ui : out-in
uj : in-out
if t1 > t2 line is completely outside the clipping region and it
can be discarded
Over Cohen-Sutherland, Liang-Barsky has been found to
run 36% faster for 2-D lines and 40% faster for 3-D lines
Note: alg doesn’t depend on any “ordering” of start and
end points of line
See tutorial here
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
u1
s
e
t2=1
u2
t1> 1
u4
ui : out-in
uj : in-out
if t1 > t2 line is completely outside the clipping region and it
can be discarded
Over Cohen-Sutherland, Liang-Barsky has been found to
run 36% faster for 2-D lines and 40% faster for 3-D lines
Note: alg doesn’t depend on any “ordering” of start and
end points of line
See tutorial here
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
u1
s
e
t2=1
u2
t1> 1
u4
ui : out-in
uj : in-out
if t1 > t2 line is completely outside the clipping region and it
can be discarded
Over Cohen-Sutherland, Liang-Barsky has been found to
run 36% faster for 2-D lines and 40% faster for 3-D lines
Note: alg doesn’t depend on any “ordering” of start and
end points of line
See tutorial here
CS4815
Clipping Algorithms; §8-5 (contd.)
Liang-Barsky Line Clipper (contd.)
u1
s
e
t2=1
u2
t1> 1
u4
ui : out-in
uj : in-out
if t1 > t2 line is completely outside the clipping region and it
can be discarded
Over Cohen-Sutherland, Liang-Barsky has been found to
run 36% faster for 2-D lines and 40% faster for 3-D lines
Note: alg doesn’t depend on any “ordering” of start and
end points of line
See tutorial here
CS4815
Download