2D Viewing
Introduction
Viewing is the process of displaying different
views of a picture on an output device
Which part of picture to be displayed and
where to be displayed?
Transformation from world device
Clipping: Removing parts outside display area
World coordinates to device coordinates
transformations
Introduction
Examples:
Graphics program which draw an entire
building by an architect but we are only
interested on the ground floor
Map of sales for entire country but we only like
to know from certain region of the country.
Window & Viewport
Window, given in world co-ordinates, defines the portion of
the model that is to be drawn
Viewport given in device co-ordinates, defines the portion of
the screen on which the contents of the window will be
displayed
Viewport
2D Viewing
2D viewing transformation is a mapping of world
coordinate scene to device coordinates
window
yvmax
ywmax
viewport
yvmin
ywmin
xvmin
xwmin
xvmax
xwmax
world coordinates
viewing coordinates
Coordinate Representations
Four cartesian co-ordinates systems in
computer graphics
Modeling co-ordinates
World co-ordinates
Normalized device co-ordinates
Device co-ordinates
Modeling co-ordinates
Local coordinates.
where individual object in a scene
within separate coordinate frames
Each object has an origin (0,0)
The part of the objects are placed
with reference to the objects origin.
World co-ordinates
Objects are placed into appropriate positions
within the scene using reference frame called
world coordinate
Scene has an origin (0,0)
Objects in the scene are
placed with reference to
the scenes origin.
Normalized device co-ordinates
World coordinate positions are converted to
normalized device coordinates, in the range 0 to
1.
This makes the system independent of the
output-devices.
Device co-ordinates
Specific co-ordinates used by a device.
Pixels on a monitor
Points on a laser printer
2D Viewing Transformation
1.
2.
3.
4.
Construct the scene in world coordinate using the
output primitives.
To obtain a particular orientation for the window, set
up a two dimensional viewing coordinate system in
the world coordinate, and define a window in the
viewing coordinate system
Define a viewport in normalized coordinate, and map
the viewing coordinate description of the scene to
normalized coordinate
All parts that lie outside the viewport are clipped, and
contents of the viewport are transferred to device
coordinates.
2D Viewing Transformation
Pipeline
Modeling coordinate
Construct world coordinate scene using
modeling coordinate transformation
World Coordinate
Convert world coordinate to viewing coordinate
Viewing Coordinate
Map viewing coordinates to normalized viewing
coordinates using window-viewport specifications
Normalized viewing Coordinate
Map normalized coordinate to device coordinates
Device Coordinate
Viewing Coordinate Ref Frame
This coordinate system provides the reference
frame for specifying the world coordinate window.
Set up the viewing coordinate:
1. Origin is selected at some world position:
2. Established the orientation. Specify a world vector V
that defines the viewing y direction.
3. Obtain the matrix for converting world to viewing
coordinates (Translate and rotate)
Viewing Coordinate Ref Frame
yw
yv
viewing coordinates
(x0, y0) is the viewing
coordinate origin
V is view up
vector(orientation)
v
y0
xv
x0
world coordinates
xw
v = (vx, vy) and
u = (ux, uy) are unit vectors
Viewing Coordinate Ref Frame
yw
yv
xv
xw
yw
Transformation from the
world coordinates to the
viewing coordinates:
1. Translate viewing origin to
world origin
2. Rotate viewing system to
align it with the world frame
yv
xv
xw
MWC,VC = R.T
R->Rotation matrix
T->Translation matrix
Window to viewport coordinate
transformations
Normalized Viewport
1
window
yvmax
ywmax
viewport
(xv, yv)
(xw, yw)
yvmin
ywmin
0
xwmin
xvmin
xvmax
xwmax
world coordinates
viewing coordinates
Window to viewport coordinate
transformations
Point at position (xw,yw) in window is mapped to
position (xv,yv) in viewport
To maintain the same relative placement in the
viewport as in the window:
xv xvmin
xw xwmin
xvmax xvmin
xwmax xwmin
yv yvmin
yw ywmin
yvmax yvmin
ywmax ywmin
Window to viewport coordinate
transformations
sx
xv max xv min
xwmax xwmin
sy
yv max yv min
ywmax ywmin
xv xv min ( xw xwmin ) s x
yv yv min ( yw ywmin ) s y
Window to viewport coordinate
transformations
OR
1. Scale clipping window to the size of viewport
using fixed-point (xwmin, ywmin)
2. Translate (xwmin, ywmin) to (xvmin, yvmin)
Mwindow,normviewp = T . S
Zooming and Panning Effects
Zooming:
By successively mapping different sized windows
on to a fixed size view port.
Zoom in-> windows are made smaller
Zoom out->windows are made larger
Panning:
By moving a fixed size window across various
objects in a scene
2D Clipping
Clipping Algorithm or Clipping: Any procedure
that identifies those portion of a picture that are
either inside or outside of a specified region of
space.
The region against which an object is to clipped is
called a clip window.
2D Clipping Algorithms
Point Clipping
Line Clipping
Area Clipping [Polygons]
Point Clipping
ywmax
P will be displayed if
xwmin x xwmax and
ywmin y ywmax
P=(x,y)
ywmin
xwmin
xwmax
Line Clipping
Before Clipping
After Clipping
Line Clipping
If both endpoints are inside of all 4
clipping boundaries => inside
If both endpoints are outside any
one of the 4 boundaries
=> outside
Otherwise, line intersects at least
one boundary and it may or may
not cross the window ;
intersections needs to be
calculated
Line Clipping
If one or both endpoints is outside
the window, the parametric
representation could be used to
determine values of parameter u
for intersection with the boundary
coordinates.
x = x0 + u(xend x0)
y = y0 + u(yend y0)
if 0 u 1 part of the line is inside
Requires good deal of
computation
(xend,yend)
(x,y)
(x0,y0)
Cohen-Sutherland Line Clipping
The method speeds up the processing of line
segments by performing initial tests that
reduce the number of intersections that must
be calculated.
Every line endpoint is assigned a four digit
binary code, called region code, that
identifies the location of the point relative to
the boundaries of the clipping rectangle.
Cohen-Sutherland Line Clipping
4
top bottom right left
Each bit position in the region
code is used to indicate one of
the four relative coordinate
positions of the point with
respect to the clip window.
1001
1000
1010
0001
0000
0010
0101
0100
0110
Cohen-Sutherland Line Clipping
A region-code 0000 for both endpoints => completely
inside
Region-code 1 in the same bit position for each
endpoint
=> completely outside
If OR of region codes of endpoints is 0000 => inside
If AND of region codes of endpoints is not 0000
=>outside
If not completely outside or inside: check for
intersection
Cohen-Sutherland Line Clipping
Processing order of boundaries:
left, right, bottom, top
Intersection point x or y:
m = (yend y0) / (xend x0)
y = y0 + m(x-x0)
x is xwmin or xwmax
x = x0 + (y-y0)/m
y is ywmin or ywmax
Polygon Clipping
Polygon Clipping
Similar to lines, areas must be clipped to
a window boundary
Consideration must be taken as to which
portions of the area must be clipped
Polygon Clipping
To clip a polygon:
Modify the line clipping procedures
Polygon boundary processed with a line
clipper may be displayed as a series of
unconnected line segments as in following
figure:
Polygon Clipping
A bounded area is really required after
clipping as in the following figure:
Sutherland Hodgeman Polygon Clipping
Sutherland Hodgeman Polygon
Clipping
An algorithm that will generate one or more closed
areas that are then scan converted for the appropriate
area fill is required
The output of a polygon clipper should be a sequence
of vertices that defines the clipped polygon boundaries
Beginning with the initial set of polygon vertices, first
clip the polygon against the left rectangle boundary
to produce a new sequence of vertices.
The new set of vertices could then be successively
passed to a right boundary clipper, a bottom
boundary clipper and a top boundary clipper as
shown in the below sequence:
Various Cases
Following tests are conducted as
each pair of adjacent polygon
vertices are passed to a window
boundary clipper.
1. First vertex is outside the window
border and second vertex is inside
=> send the intersection point and
the second vertex to the next clipper
2. Both vertices are inside
=> send only the second vertex
v1
v2
v1
v2
v1
Various Cases
v1
v2
v1
3. First vertex is inside and the second
vertex is outside
=> send only the intersection point
v1
v2
4. Both vertices are outside
=> no vertices are sent
Example
Example
Left boundary
1,2 (out, out)->clip
2,3 (in, out)->save 1,3
3,4 (in, in)->save 4
4,5 (in, in) ->save 5
5,6 (in, out)->save 5
6,1 (out, out)->clip
Saved points->1,3,4,5,5
Using the saved points, process
is repeated for next boundary
Sutherland-Hodgman Polygon
Clipping
Concave Polygons
Split concave polygon into convex
polygons and then use SutherlandHodgman algorithm
or
Modify the algorithm to check the
vertex list for multiple intersection
points along any boundary. Then
split into separate sections.