0% found this document useful (0 votes)
55 views55 pages

Viewing

The document discusses computer graphics viewing and clipping techniques. It describes how a clipping window maps world coordinates to a viewport. It also explains the 2D viewing transformation pipeline and normalization and viewport transformations. Different clipping algorithms like Cohen-Sutherland line clipping and Liang-Barsky line clipping are described.

Uploaded by

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

Viewing

The document discusses computer graphics viewing and clipping techniques. It describes how a clipping window maps world coordinates to a viewport. It also explains the 2D viewing transformation pipeline and normalization and viewport transformations. Different clipping algorithms like Cohen-Sutherland line clipping and Liang-Barsky line clipping are described.

Uploaded by

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

Computer Graphics Viewing

1
Clipping Window
ywmax
World Coordinates

ywmin The clipping window is


mapped into a viewport.

xwmin xwmax
Viewing world has its own
Viewport
yvmax coordinates, which may be
a non-uniform scaling of
world coordinates.

yvmin
Viewport Coordinates

xvmin xvmax
2
2D viewing transformation pipeline

Construct World-
Modeling World Convert World-
Coordinates Coordinate Scene Coordinates Coordinates to
From Modeling-
Viewing-
Coordinate
Coordinates
Transformations

Viewing Coordinates

Transform Viewing- Normalized Device


Coordinates Map Normalized- Coordinates
Coordinates to
Coordinates to
Normalized-
Device-Coordinates
Coordinates

3
Normalization and Viewport Transformations

• First approach:
– Normalization and window-to-viewport transformations are
combined into one operation.
– Viewport range can be in [0,1] x [0,1].
– Clipping takes place in [0,1] x [0,1].
– Viewport is then mapped to display device.
• Second approach:
– Normalization and clipping take place before viewport
transformation.
– Viewport coordinates are specified in screen coordinates.

4
1
Clipping Window
ywmax Normalized Viewport
yvmax
 xw, yw 
 xv, yv 
ywmin yvmin

0
xwmin xwmax xvmin xvmax1

Maintain relative size and position between clipping window and viewport.

xv  xvmin xw  xwmin yv  yvmin yw  ywmin


 
xvmax  xvmin xwmax  xwmin yvmax  yvmin ywmax  ywmin

5
Solving for  xv, yv  obtains:

xv  sx xw  t x , yv  s y yw  t y , where
xvmax  xvmin yvmax  yvmin
Scaling factors: sx  , sy 
xwmax  xwmin ywmax  ywmin
Translation factors:
xwmax xvmin  xwmin xvmax ywmax yvmin  ywmin yvmax
tx  , ty 
xwmax  xwmin ywmax  ywmin
This can also be obtained by composing transformations:
M window, 
norm_viewport

 sx 0 tx 
T  xvmin , yvmin   S  sx , s y   T   xwmin ,  ywmin    0 sy t y 
 0 0 1 
6
World clipping window can first be mapped to normalized square between -1
and +1, where clipping algorithm takes place, and then transform the scene
into viewport given in display coordinates.

 2 xwmax  xwmin 
 xw  xw 0 
xwmax  xwmin 
 max min

 2 yw  ywmin 
M window,  0  max
norm_square
 ywmax  ywmin ywmax  ywmin 
 0 0 1 
 
 

 xvmax  xvmin  2 0  xvmax  xvmin  2 


 
M norm_square,   0  yvmax  yvmin  2  max min  
yv  yv 2
viewport
 0 0 1 

7
Clipping Algorithms
p9
Before Clipping After Clipping

p4 p10
p2 p2
p1 p1
p8
p6 p6 p8
p3 p5 p5

p7 p7

Parametric equations of line segment from  x0 , y0  to  xend , yend 

x  x0  u  xend  x0  , y  y0  u  yend  y0  , 0  u  1.

Used to determine the parts contained in clipping window.


8
Cohen-Sutherland Line Clipping Algorithm

• Intersection calculations are expensive. Find first lines

completely inside or certainly outside clipping window.

Apply intersection only to undecided lines.

• Perform cheaper tests before proceeding to expensive

intersection calculations.

9
Cohen-Sutherland Line Clipping Algorithm

• Assign code to every endpoint of line segment.


– Borderlines of clipping window divide the plane into two halves.

– A point can be characterized by a 4-bit code according to its


location in half planes.
– Location bit is 0 if the point is in the positive half plane, 1
otherwise.
– Code assignment involves comparisons or subtractions.

• Completely inside / certainly outside tests involve only


logic operations of bits.
10
Top bit Bottom bit Right bit Left bit

x  xwmin xwmax  x

1 0 0 1 1 0 0 0 1 0 1 0

ywmax  y

0 0 0 1 0 0 0 0 0 0 1 0

y  ywmin

0 1 0 1 0 1 0 0 0 1 1 0

Endpoint codes are 0000 for both iff line is completely inside.
If endpoint codes has 1 in same bit, line is certainly outside.
11
Lines that cannot be decided are intersected with window
border lines.

Each test clips the line and the remaining is tested again
for full inclusion or certain exclusion, until remaining is
either empty or fully contained.

Endpoints of lines are examined against left, right, bottom


and top borders (can be any order).

12
p2

1 0 0 1 1 0 0 0
p2
p2

0 0 0 1 0 0 0 0

p3
p1
p3
0 1 0 1 p4 0 1 0 0 p1

13
Liang-Barsky Line Clipping Algorithm
Treat undecided lines in Cohen-Sutherland more efficiently.

Define clipping window by intersections of four half-planes.

 xend , yend 
xwmin  xwmax

ywmax

 
 x0 , y0  ywmin


14
Parametric presentation:
x  x0  u  xend  x0  , y  y0  u  yend  y0  , 0  u  1.

A point on the line is cotained in the clipping window iff:


xwmin  x0  u  xend  x0   xwmax ,
ywmin  y0  u  yend  y0   ywmax .
It can be expressed by: upk  qk , k  1, 2,3, 4, where
p1  x0  xend , q1  x0  xwmin ;
p2  xend  x0 , q2  xwmax  x0 .
p3  y0  yend , q3  y0  ywmin ;
p4  yend  y0 , q4  ywmax  y0 .
15
In the inequality upk  qk if pk  0 (pk  0), the

traversal from  x0 , y0  to  xend , yend  by increasing

u from   to + proceeds the line from the  ( )

half-plane to  () one (with respect to the k -th

border).

Intersection of  ,   extension with k -th border

occurs at u  qk pk .

16
We calculate and update u0 and uend progressively for

k  1, 2,3, 4 borders (left, right, bottom, top).

If pk  0 u0 is calculated since progression is from 

to  half planes. Similarly, if pk  0 uend is calculated.

u0 is the maximum among 0 and all qk pk . uend is the

minimum among 1 and all qk pk . The feasibility

condition uend  u0 is progressively checked. The line

is completely outside if uend  u0 .


17
Notice that qk pk doesn't need actual division since

comparison of q p with q p can be done by

comparison of qp with qp, and the quotient q p

can be stored as a pair  q, p 

Only if uend  u0 , given by  q0 , p0  and  qend , pend  ,

the actual ends of the clipped portion are calculated.

18
This is more efficient than Cohen-Sutherland Alg,
which computes intersection with clipping window
borders for each undecided line, as a part of the
feasibility tests.

19
Sutherland-Hodgman Polygon Clipping
1
1’’ 1’’
1’ 3’’ 1’ 3’’
Clipping
Clipping Window 3

3’ 3’
2’ 2’’ 2’ 2’’
2
Efficient algorithm for clipping convex polygons.

Edges are clipped against every border line of clipping window. Edges
are processed successively.

Allows pipelining of edge clipping of polygons, as well as pipelining of


different polygons.

20
The four possible outputs generated by the left clipper, depending on
the relative position of pair of edge endpoints.

out in in in
v2
output: v1 v 2 output: v 2

v2 v1
v1
v1
out out
v1
v1 output: none
v2 v1
in out
output: v1
v2
21
2
2’

3 2”

1’
3’
1
Input Left Clipper Right Clipper Bottom Clipper Top Clipper

[1,2]: (in-in)>{2}

[2,3]: (in-out)>{2’} [2,2’]:(in-in)>{2’}


[3,1]: (out-in)>{3’,1} [2’,3’]:(in-in)>{3’} [2’,3’]:(in-out)>{2”}
[3’,1]:(in-in)>{1} [3’,1]:(out-out)>{}
[1,2]:(in-in)>{2} [1,2]:(out-in)>{1’,2} [2”,1’]:(in-in)>1’}
[2,2’]:(in-in)>{2’} [1’,2]:(in-in)>{2}
[2,2’]:(in-in)>{2’}
[2’,2”]:(in-in)>{2”}

22
• The four clippers can work in parallel.
– Once a pair of endpoints it output by the first clipper,
the second clipper can start working.
– The more edges in a polygon, the more effective
parallelism is.

• Processing of a new polygon can start once first


clipper finished processing.
– No need to wait for polygon completion.

23
3D Viewing Concepts

World Coordinate System Viewing Coordinate


System

24
2D Reminder
Choose viewing position, direction and orientation of the
camera in the world.

A clipping window is defined by the size of the aperture


and the lens.

Viewing by computing offers many more options which


camera cannot, e.g., parallel or perspective projections,
hiding parts of the scene, viewing behind obstacles, etc.

25
Clipping window: Selects what we want to see.
Viewport: Indicates where it is to be viewed on the output
device (still in world coordinates).
Display window: Setting into screen coordinates.

In 3D the clipping is displayed on the view plane, but


clipping of the scene takes place in the space by a clipping
volume.

3D transformation pipeline is similar to 2D with addition of


projection transformation.
26
3D Viewing Transformation Pipeline
Modeling World Viewing
Coordinates Coordinates Coordinates

Construct World-
Coordinate Scene Convert World-
Coordinates to Projection
From Modeling-
Coordinate Viewing- Transformation
Transformations Coordinates

Projection Coordinates

Transform Projection- Normalized Device


Coordinates Map Normalized- Coordinates
Coordinates to
Coordinates to
Normalized-
Device-Coordinates
Coordinates

27
Model is given in model (self) coordinates.
Conversion to world coordinates takes place.

Viewing coordinate system which defines the position and


orientation of the projection plane (film plane in camera) is
selected, to which scene is converted.

2D clipping window (lens of camera) is defined on the


projection plane (film plane) and a 3D clipping, called view
volume, is established.
28
The shape and size of view volume is defined by the
dimensions of clipping window, the type of projection and
the limiting positions along the viewing direction.

Objects are mapped to normalized coordinated and all


parts of the scene out of the view volume are clipped off.
The clipping is applied after all device independent
transformation are completed, so efficient transformation
concatenation is possible.

Few other tasks such as hidden surface removal and


surface rendering take place along the pipeline.
29
World to Viewing 3D Transformation

yworld
yview
view point
v
p0 view-up vector
xworld u
n
zworld zview xview

30
n : viewing directionon yview
u  v : viewing plane view point
v
u  u x , u y , u z 
p0 view-up vector
u
v   vx , v y , vz  n
n   nx , n y , nz 
zview xview

p 0   x0 , y0 , z0 

u x uy uz 0  1 0 0  x0 
v vy vz 0  0 1 0  y0 
world to viewing M WC,VC  x 
transformation  nx ny nz 0  0 0 1  z0 
   
0 0 0 1  0 0 0 1 
rotation translation
31
Projection Transformations
Next step in 3D viewing pipeline is projection of object to
viewing plane
Parallel Projection

Coordinate are transferred


to viewing plane along
parallel lines.

View Plane

Preserves relative size of object’s portions.

Projection can be perpendicular or oblique to viewing plane.

32
Perspective Projection

Projection lines converge


in a point behind viewing
plane.

Doesn’t preserve relative size but looks more realistic.

33
Orthogonal (orthographic) projections

Projection lines are parallel to normal.

Plane View

Front
Elevation Side
View Elevation
View

Used in engineering and architecture. Length and angles can be


measured directly from drawings.
34
Clipping Window and View Volume
View
Orthogonal Projection
Plane
View Volume

Far
Clipping
Plane
Near
Clipping yview
Plane
Clipping window

xview
zview
35
Normalizing Orthogonal Projection
Orthogonal Projection View Volume ynorm

 xwmax , ywmax , zwfar 


znorm 1,1,1
xnorm
 xwmin , ywmin , znear 

yview

zview xview  1, 1, 1


Normalized View Volume

Display coordinate system is usually left-handed.


36
M ortho,norm 

 2 xwmax  xwmin 
 xw  xw 0 0 
xwmax  xwmin 
 max min

 2 yw  ywmin 
 0 0  max
 ywmax  ywmin ywmax  ywmin 
 2 znear  zfar 
 0 0 
 znear  zfar znear  zfar 
 0 0 0 1 

The complete transformation from world coordinated


to normalized orthogonal-projection coordinates is
obtained by M ortho,norm  M WC,VC .
37
Oblique Parallel Projections
Projection is defined by a viewing vector Vp .

x , y
p p , zvp 

L Projection lines are


parallel to vector Vp .

Vp  x, y , z 
vp

 x, y , z 

38
xp  x

V px x , y
p p , zvp 
zvp  z V pz
L
Not orthogonal
yp  y V py as viewed

zvp  z V pz
Vp  x, y , z 
vp

 x, y , z 

x p  x   zvp  z V px V pz  , y p  y   z vp  z V py V pz 

The above is called shear transformation, where the


displacement in x and y linearly increases with z.
39
View Volume of Parallel Oblique Projection
View Plane

Clipping
Window View
Volume
(Side)

Near Vp
Plane
View
Volume Vp
(Top) Far
Plane

40
 V px V px 
1 0  zvp 
 V pz V pz  This is a 3D shear
 V py V py  transformation.
M oblique  0 1  zvp 
 V pz V pz  x and y are displaced by
 
0 0 1 0  amount proportional to z.
0 0 0 1 

Normalization oblique projection is similar to orthogonal projection.


The composite transformation is obtained by the product of the two.

M oblique,norm  M ortho,norm  M oblique

41
Perspective Projections
View Plane
Closer objects look larger.
Projection
Reference
Point

Projection Point
p   x, y , z  x , y , zvp 
p p yview
p prp   x prp , y prp , z prp 

View Plane xview


zview
42
Parametric representation of a point on the line
connecting P   x, y, z  with Pprp   x prp , y prp , z prp  :
x  x   x  x prp  u , y   y   y  y prp  u ,
z   z   z  z prp  u , 0  u  1.

At viewing plane: u   zvp  z   z prp  z .

Substitution for the point on viewing plane:


x p  x  z prp  zvp   z prp  z   x prp  zvp  z   z prp  z 
y p  y  z prp  zvp   z prp  z   y prp  zvp  z   z prp  z 

43
The problem with the above representation is that Z appears in
denominator, so matrix multiplication representation of X and Y
on view plane as a function of Z is not straight forward.

Z is point specific, hence division will be computation killer.

Different representation is in order, so transformations can


be concatenated

44
Vanishing Points
Vanishing points occur when the viewing plane intersects with the
axes of viewing coordinate system.

y Vanishing
Point

z
Principle axes for cube One-Point perspective Projection

Parallel to Z lines of XZ plane and parallel lines to Z in YZ plane will


vanish. Vanishing point on viewing plane correspond to infinity in
world.
May 2010 45
Viewing plane is parallel to y-axis, z-axis vanishing point
intersecting both x-axis and z-axis

x-axis vanishing point

Vanishing points of all three axes occur when viewing plane


intersects all three axes.
May 2010 46
Perspective-Projection View Volume

View
Rectangular Frustum
Plane
View Volume

Far Clipping Window


Clipping
Plane

Near yview
Clipping
Plane 
xview
Field-of-view Angle Projection
zview Reference Point

May 2010 47
Symmetric Frustum Parallel Piped
View Volume View Volume
Far Plane

Perspective
Mapping

Near Plane
View Plane

Clipping Window

Projection
Reference Point

May 2010 48
Oblique Frustum Parallel Piped
View Volume View Volume

Perspective
Mapping

xwmin xwmax

Projection
Reference Point

May 2010 49
3D Viewport Transformation
The normalized view volume cube extending from  1, 1, 1 to

1,1,1 is mapped to a screen viewport, extending from  xvmin , yvmin 


to  xvmax , yvmax  . z information is stored for depth calculations. z is

often renormalized to the range from 0 to 1.0, yielding:

 xvmax  xvmin xvmax  xvmin 


 0 0 
2 2
 
 yvmax  yvmin yvmax  yvmin 
0 0
M normviewvol,  2 2 
 
3D screen
 1 1 
0 0
 2 2 
 0 0 0 1 
 

May 2010 50
Settings of Perspective Projection
• Perspective projection point
– Where the viewer (camera, eye) is positioned in the world.
• Positioning viewing plane with respect to viewing
coordinates
– Results vanishing points, one, two or three.
• Clipping window on viewing plane
– Defines the infinite pyramid view volume.
• Near and far clipping planes (parallel to view plane)
– Define the rectangular frustum view volume.
• Scale and translation parameters of perspective matrix
– Define the normalization range.
May 2010 51
3D Clipping
Clipping can take place on normalized cube:

xwmin  1, ywmin  1, zwmin  1, xwmax  1, ywmax  1, zwmax  1.

Similar to 2D, we add two bits to code the far and near planes.

Far bit Near bit Top bit Bottom bit Right bit Left bit

Recall that in 3D point is represented in homogeneous form. Hence

P   xh , yh , zh , h  is inside the normalized cube iff

 h  xh  h,  h  yh  h,  h  z h  h if h  0

h  xh   h, h  yh   h, h  zh   h if h  0

52
Top
y
Far
Near
Bottom

Left
x
Right
z

011001 011000 011010 001001 001000 001010 101001 101000 101010

010001 010000 010010 000001 000000 000010 100001 100000 100010

010101 010100 010110 000101 000100 000110 100101 100100 100110

53
A line is completely accepted if the codes of its ends are both 000000, or
equivalently, if the logical OR between codes is zero.

A line is rejected if the codes of its ends has at least one 1 in same bit, or
equivalently, if the logical AND between codes is nonzero.

Otherwise, the line is tested against each of the planes and the 2D Liang-
Barsky algorithm can be extended to 3D.


A point P of a line segment P1P2 extending from P1  xh1 , yh1 , zh1 , h1 
 
to P2  xh2 , yh2 , zh2 , h2 is given by P  P1   P2  P1  u, 0  u  1.

54
If for instance the codes of the two end points of P1P2 w.r.t the right

clipping plane xmax  1 are different, the intersection point is derived

 
from x p  xh h   xh1  xh2  xh1 u   h1   h2  h1  u   1.
 

  
Solving for u yields u   xh1  h1   xh1  h1  xh2  h2  .
  
Such calculation proceeds for each upk  qk , 1  k  6, while

updating u0 and u1. If at some iteration u1  u0 , line segment is

completely clipped. If upon termination u1  u0 , the end points

of the clipped line segment are obtained.

55

You might also like