0% found this document useful (0 votes)
46 views34 pages

2D Viewing

1. Two-dimensional viewing involves transforming a 3D scene description into 2D device coordinates for display. This involves normalization, viewport transformation, and clipping. 2. Clipping removes portions of primitives that fall outside the viewing region. Common clipping techniques include Cohen-Sutherland line clipping and Sutherland-Hodgeman polygon clipping. 3. Parametric line clipping techniques like Cyrus-Beck and Liang-Barsky find line segment intersections with clip edges more efficiently than Cohen-Sutherland by using parametric line equations.

Uploaded by

kjindal1221
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views34 pages

2D Viewing

1. Two-dimensional viewing involves transforming a 3D scene description into 2D device coordinates for display. This involves normalization, viewport transformation, and clipping. 2. Clipping removes portions of primitives that fall outside the viewing region. Common clipping techniques include Cohen-Sutherland line clipping and Sutherland-Hodgeman polygon clipping. 3. Parametric line clipping techniques like Cyrus-Beck and Liang-Barsky find line segment intersections with clip edges more efficiently than Cohen-Sutherland by using parametric line equations.

Uploaded by

kjindal1221
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 34

Two-Dimensional

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

1001 1000 1010


View port

0001 0000 0010

0101 0100 0110

< Region code for each endpoint >


above below right left
Bit 4 3 2 1
Cohen-Sutherland
Line-Clipping
Line Clipping Algorithm
„ Trivially accepted
if (both region codes = 0000)
„ Trivially
ll rejected
d
if ((AND of region
g codes ≠ 0000))
„ Otherwise, divide line into two segments
„ test intersection edges in a fixed order.
order
(e.g., top-to-bottom, right-to-left)
Cohen-Sutherland
Line-Clipping
Line Clipping Algorithm
* fixed order testing and clipping cause
needless clipping (external intersection)
Cohen-Sutherland
Line-Clipping
Line Clipping Algorithm
„ Midpoint Subdivision for locating
intersections
1. trivial accept/reject test
2. midpoint subdivision:
xm = (x1 + x2)/2, ym = (y1 + y2)/2
(one addition and one shift)
3. repeat step 1 with two halves of line
⇒ good for hardware implementation
Cohen-Sutherland
Line-Clipping
Line Clipping Algorithm
„ When this is good
„ If it can trivially reject most cases
„ Works well if a window is large w.r.t. to data
„ Works
o s well
e if a windowdo iss small
s a w.r.t.
t to data
„ i.e., it works well in extreme cases
„ Good for hardware implementation
Parametric Line Clipping
(Cyrus-beck
(Cyrus beck Technique)
„ Use a parametric line equation
P(t ) = P0 + t ( P1 − P0 ), 0 ≤ t ≤ 1

„ 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

„ Intersections can be categorized!


„ Inside the clipp rectangleg (T( E,,TL)
„ TE: select PE with largest t value ≥ 0

„ TL: select PL with the smallest t value ≤ 1.


1
Parametric Line Clipping
(Cyrus-beck
(Cyrus beck Technique)

„ 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

Q(x2,y2) t Parametric equation of


R
the line segment
tT
x = x1 + ( x 2 − x1)t = x1 + dx × t
P(x1 y1)
P(x1,y1) tL y = y1 + ( y 2 − y1)t = y1 + dy
d ×t

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy