2D Viewing
2D Viewing
Two Dimensional
Viewing
Chapter 6
Intro. to Computer Graphics
Spring 2008, Y. G. Shin
Viewing
e g Pipeline
pe e
Two-Dimensional
o e s o a Viewing
e g
Two dimensional viewing transformation
From world coordinate scene description to
d i (screen)
device ( ) coordinates
di t
Normalization and Viewport
Transformation
World coordinate clipping window
Normalization square: usually [-1,1]x[-1,1]
D i coordinate
Device di t viewport
i t
C pp g
Clipping
Remove portion of line outside viewport or
screen boundaries
Two approaches:
Clip during scan conversion: per-pixel
per pixel bounds check,
or span endpoint tests.
Clip analytically,
analytically then scan-convert the modified
primitive.
Two-Dimensional
o e so a C Clipping
pp g
Point clipping – trivial
Line clipping
Cohen-Sutherland
Cohen Sutherland
Cyrus-beck
Liang Barsky
Liang-Barsky
Fill-area clipping
Sutherland-Hodgeman
S th l d H d
Weiler-Atherton
Curve clipping
C li i
Text clipping
Line
eCClipping
pp g
Basic calculations:
Is an endpoint inside or outside the clip rectangle?
Fi d the
Find th point
i t off intersection,
i t ti if any, b
between
t a liline
segment and an edge of the clip rectangle.
9Both endpoints inside:
trivial accept
9One inside: find
p
intersection and clip
9Both outside: either
clip or reject
Cohen-Sutherland
Line-Clipping
Line Clipping Algorithm
Reduce
educe tthe
e number
u be oof ca
calculating
cu at g
intersections by simple comparisons of
parameter t.
Parametric Line Clipping
(Cyrus-beck
(Cyrus beck Technique)
Algorithm
g
For each edge Ei of the clip region
N i : outward normal of Ei
Parametric Line Clipping
(Cyrus-beck
(Cyrus beck Technique)
Choose an arbitrary point PEi on edge Ei and
consider three vectors P(t ) − PEi
⇒
N i • ( P (t ) − PEi ) < 0 ⇔ a point in the side halfplane
N i • ( P (t ) − PEi ) = 0 ⇔ a point on the line containing the edge
N i • ( P (t ) − PEi ) > 0 ⇔ a point in the outside halfplane
Parametric Line Clipping
(Cyrus-beck
(Cyrus beck Technique)
Solve for the value of t at the intersection
of P0P1 with the edge:
Ni · [P(t) - PEi] = 0.
P(t)
( ) = P0 + t(P
( 1 - P0) and let D = ((P1 - P0),
Then
N i ⋅ [ P0 − PEi ]
t=
− Ni ⋅ D
Ni ≠ 0,
0
D ≠ 0 (that is P0 ≠ P1),
Ni · D ≠ 0 (if not, no intersection)
Parametric Line Clipping
(Cyrus-beck
(Cyrus beck Technique)
Given the four values of t for a line segment,
segment
determine which pair of t's are internal
intersections.
If t ∉ [0,1] then discard
else choose a (PE,
(PE PL) pair
that defines the
clipped line.
line
PE(potentially
(p y entering)
g) intersection:
if moving from P0 to P1 causes us to cross an edge to
enter the edge
edge'ss inside half plane;
Parametric Line Clipping
(Cyrus-beck
(Cyrus beck Technique)
PL(potentially leaving) intersection:
if moving from P0 to P1 causes us to leave the
edge's
g inside half plane.
p
i.e., N i • P0 P1 < 0 ⇒ PE
N i • P0 P1 > 0 ⇒ PL
This is
Thi i an efficient
ffi i t algorithm
l ith when h many line
li
segments need to be clipped
C be
Can b extended
d d easily
il to convex polygon
l windows
i d
Liang-Barsky
a g a s y line
e clipping
pp g
The ideas for clipping line of Liang
Liang-Barsky
Barsky and
Cyrus-Beck are the same. The only difference is
Liang-Barsky
Liang Barsky algorithm has been optimized for
an upright rectangular clip window.
Finds the appropriate end points with more
efficient computations.
Liang-Barsky
a g a s y line
e clipping
pp g
Let PQ
Q be the line
which we want to study
tB
t = 0 ⇒ P( x1, y1)
t = 1 ⇒ Q( x 2, y 2)
Liang-Barsky
Liang Barsky Line Clipping
1. Set tmin = 0 and tmax = 1
2. Calculate the values of tT, tB, tL, tR,
L R
tT T
B
tB
Liang-Barsky
Liang Barsky Line Clipping
If t < tmin or t > tmax, ignore
g it and go
g to the
next edge. N
Otherwise classify the t value as entering or
exiting value (using the inner product to tT
classify)
Let PQ be the line and N is normal vector tR
If N • (Q − P ) ≤ 0, the parameter t is entering
If N • (Q − P) > 0 , the parameter t is exiting
If t is entering value, set tmin = t, if t is exiting
value set tmax = t
Liang-Barsky
a g a s y Line
eCClipping
pp g
3 If tmin < tmax then draw a line
3.
from ( x1 + dx × t min , y1 + dy × t min )
to ( x1 + dx
d × t max , y1 + dy
d × t max )
Q(x2,y2) t
R
tT
P(x1,y1) tL
tB
C pp g
Clipping
Clipping rotated windows,
windows circles
trivial acceptance/rejection test with respect to
bo nding rectangle
bounding ectangle of the window
indo
Line clipping using nonrectangular clip
windows
extend Cyrus
Cyrus-Beck
Beck algorithm
Polygon
o ygo clipping
pp g
Sutherland-Hodgeman
Sutherland Hodgeman Algorithm
clip against 4 infinite clip edge in succession
Sutherland-Hodgeman
Sutherland Hodgeman Algorithm
Accept a series of vertices (polygon) and outputs
another series of vertices
Fo possible outputs
Four o tp ts
Sutherland-Hodgeman
Sutherland Hodgeman Algorithm
The algorithm correctly clips convex polygons,
polygons
but may display extraneous lines for concave
polygons.
polygons
How clip?
How
o to
o correctly
o e y clip
p
[Way I] Split the concave polygon into two
or more convex polygons and process each
convex polygon separately.
[Way II] Modify the algorithm to check the
final vertex list for multiple vertex points
along any clip window boundary and
correctly join pairs of vertices.
[Way III] Use a more general polygon
clipper
Clipping
C pp g concave
o a e polygons
po ygo s
Split
p the concave polygon
p yg into two or more
convex polygons and process each convex
polygon separately.
separately
vector method for splitting concave polygons
⇒ calculate edge-vector
edge vector cross products in a
counterclockwise order. If any z component turns out to
be negative, the polygon is concave.
Weiler-Atherton
Weiler Atherton Polygon Clipping
For an outside-to-inside p
pair of vertices,, follow the
polygon boundary.
For an inside
inside-to-outside
to outside pair of vertices, follow the
window boundary in a clockwise direction.
Weiler-Atherton
Weiler Atherton Polygon Clipping
Polygon clipping using nonrectangular
polygon clip windows
Texture Clipping
1. all-or-none text clipping
pp g : Using
g boundaryy box
for the entire text
2. all-or-none character clipping : Using boundary
box for each individual
3. clip individual characters
vector : clip line segments
bitmap : clip individual pixels
What we have got!
g