You are on page 1of 10

Introduction

References:
1. Andy Johnson's CS 488 Course Notes, Lecture 1
2. Foley, Van Dam, Feiner, and Hughes, "Computer Graphics - Principles and
Practice", Chapter 1
What is Computer Graphics (CG)
The generation of graphical images using a computer, as opposed to "image
processing" which manipulates images that are already in the computer. Creating a
frame of "Toy Story" or "Jurassic Park" is computer graphics; Comparing an image of
a face from an ATM camera against a database of known criminal mugshots is
image processing. Note that the line between the two can sometimes be hazy, and
a given task may require both sets of skills.
A.J.:
mathematics + computer science + art = computer graphics
rendering of images on a device.
rendering - creating images from models
models - objects constructed from geometric primitives (points, lines, polygons)
specified by their vertices
models exist in n-dimensional 'mathematically pure' space
o

n typically 2 or 3

n can be > 3 with scientific data

Rendered version typically created on physical 2D media (e.g. a video screen.)


Rendered version can be simple or complex (lighting, shadows, colours, texture)
Rendering a single image can take from a small fraction of a second (say, a frame
from 'Unreal') to hours or days (say, a frame from 'Toy Story') depending on the
complexity of the scene, the amount of processing power available, and the needs
of the user.

Common Uses

Movies, such as Toy Story, Who Framed Roger Rabbit, The Hollow Man, Shrek,
Monsters Inc, Jurassic Park, & The Perfect Storm

Advertisements

Football game annotations.

scientific/medical visualization

CAD/CAM

multimedia

computer interfaces (Windows, X, Aqua)

virtual reality

special effects

artistic expression

way cool video games

Software
Many application programs available to produce computer graphics, either as 2D
images, 3D models, or animated sequences (Corel Draw, Photoshop, AutoCAD,
Maya, SoftImage, etc.)
We will deal with the lower level routines which do the work of converting models
into a displayable form on the display device.
Several 'common' graphics languages/libaries/APIs (Application Programming
Interfaces.)

GKS

DirectX

Postscript

OpenGL

Clipping

Since we have a separation between the models and the image created from
those models, there can be parts of the model that do not appear in the

current view when they are rendered.


pixels outside the clip rectangle are clipped, and are not displayed.

can clip analytically - knowing where the clip rectangle is clipping can be
done before scan-line converting a graphics primitive (point, line, polygon) by
altering the graphics primitive so the new version lies entirely within the clip
rectangle

can clip by brute force (scissoring) - scan convert the entire primitive but only
display those pixels within the clip rectangle by checking each pixel to see if
it is visible.

clipping a point against a rectangle -> nothing or single point

clipping a line against a rectangle -> nothing or single line segment

clipping a rectangle against a rectangle -> nothing or single rectangle

( Assuming the rectangle is aligned. Otherwise treat as convex polygon. )

clipping a convex polygon against a rectangle -> nothing or single single


convex polygon

clipping a concave polygon against a rectangle -> nothing or 1 or more


concave polygons

as with scan conversion, this must be done as quickly as possible as it is a


very common operation.

Point Clipping

point (X,Y)
clipping rectangle with corners (Xmin,Ymin) (Xmax,Ymax)

point is within the clip rectangle if:

Xmin <= X<= Xmax


Ymin <= Y<= Ymax

Cohen-Sutherland Line Clipping ( Foley 3.12.3 )

given a line segment, repeatedly:

check for trivial acceptance

both endpoints within clip rectangle

check for trivial rejection

both endpoints outside clip rectangle IS NOT ENOUGH


both endpoints off the same side of clip rectangle IS ENOUGH

divide segment in two where one part can be trivially rejected

Clip rectangle extended into a plane divided into 9 regions


each region is defined by a unique 4-bit string

left bit = 1: above top edge (Y > Ymax)

left bit = sign bit of (Ymax - Y)

2nd bit = 1: below bottom edge (Y < Ymin)

2nd bit = sign bit of (Y - Ymin)

3rd bit = 1: right of right edge (X > Xmax)

3rd bit = sign bit of (Xmax - X)

right bit = 1: left of left edge (X < Xmin)

right bit = sign bit of (X - Xmin)

(the sign bit being the most significant bit in the binary representation of the
value. This bit is '1' if the number is negative, and '0' if the number is
positive.)

The frame buffer itself, in the center, has code 0000.

1001 | 1000 | 1010

-----+------+-----

0001 | 0000 | 0010

-----+------+-----

0101 | 0100 | 0110

For each line segment:

each end point is given the 4-bit code of its region

repeat until acceptance or rejection

if both codes are 0000 -> trivial acceptance

if bitwise logical AND of codes is not 0000 -> trivial rejection

divide line into 2 segments using edge of clip rectangle

find an endpoint with code not equal to 0000

move left to right across the code to find a 1 bit -> the crossed edge

break the line segment into 2 line segments at the crossed edge

forget about the new line segment lying completely outside the clip rectangle

The full algorithm ( was? ) given (in C) in the red book ( ??? Edition ) as
program 3.7 on p.105.
The full algorithm is given (in C) in the white book as figure 3.41 on p.116.

Sutherland-Hodgman Polygon Clipping ( Foley 3.14.1 )

Unlike line-clipping where we selectively clipped against each edge, here we


sucessively clip a polygon against all four edges of the clip rectangle

given a polygon with vertices V1, V2, ... Vn


and edges between vertices Vi and Vi+1, and from Vn to V1

for each of the four clipping edges

repeatedly for each vertex V = Vn, V1, V2, ... Vn

given an edge from vertex s to vertex p


assume s has already been dealt with

if s and p are both inside the clip rectangle -> output p

if s is inside and p is outside the clip rectangle -> output i (the intersection of
edge sp with the clip edge)

if s and p are both outside the clip rectangle -> output nothing

if s is outside and p is inside the clip rectangle -> output i (the intersection of
edge sp with the clip edge) and then p

output edges become new set of polygon edges

This algorithm can break a single polygon into multiple polygons connected
by edges on the boundary of the clipping rectangle for display.

The full algorithm ( was? ) given (in C) in the red book ( ??? Ediiton ) as
program 3.9 on p.114.

The full algorithm is given (in Pascal) in the white book as program 3.49 on
p.128.

Example of Polygon Clipping

Clipping on Ymax edge:

9-1 : both inside -> add 1

1-2 : both inside -> add 2

2-3 : keep 2-3' and clip 3'-3 -> add 3'

3-4 : both outside -> add nothing

4-5 : keep 5'-5 and clip 4-5' -> add 5' and 5

5-6 : both inside -> add 6

6-7 : keep 6-7' and clip 7'-7 -> add 7'

7-8 : both outside -> add nothing

8-9 : keep 9'-9 and clip 8-9' -> add 9' and 9

9-1 : both inside -> add 1

returning 1,2,3',5',5,6,7',9',9 as the new vertex sequence

the new vertex sequence is then checked against the Ymin edge and so on
through the Xmax edge and the Xmin edge

2 More Examples

Rasterisation (or rasterization) is the task of taking an image described in a vector graphics format
(shapes) and converting it into a raster image (pixels or dots) for output on avideo display or printer, or
for storage in a bitmap file format.

In normal usage, the term refers to the popular rendering algorithm for displaying three-dimensional
shapes on a computer.[citation needed] Rasterisation is currently the most popular technique for producing
real-time 3D computer graphics. Real-time applications need to respond immediately to user input, and
generally need to produce frame rates of at least 24 frames per second to achieve smooth animation.

Compared with other rendering techniques such as ray tracing, rasterization is extremely fast.
However, rasterization is simply the process of computing the mapping from scene geometry to pixels
and does not prescribe a particular way to compute the color of those pixels. Shading,
including programmable shading, may be based on physical light transport, or artistic intent.

Transformations[edit]
Transformations are usually performed by matrix multiplication. Quaternion math may also be used but that is
outside the scope of this article. The main transformations aretranslation, scaling, rotation, and projection. A
three-dimensional vertex may be transformed by augmenting an extra variable (known as a "homogeneous
variable") and left multiplying the resulting 4-component vertex by a 4 x 4 transformation matrix.
A translation is simply the movement of a point from its original location to another location in 3-space by a
constant offset. Translations can be represented by the following matrix:

X, Y, and Z are the offsets in the 3 dimensions, respectively.


A scaling transformation is performed by multiplying the position of a vertex by a scalar value. This has
the effect of scaling a vertex with respect to the origin. Scaling can be represented by the following matrix:

X, Y, and Z are the values by which each of the 3-dimensions are multiplied. Asymmetric scaling can
be accomplished by varying the values of X, Y, and Z.
Rotation matrices depend on the axis around which a point is to be rotated.
Rotation about the X-axis:

Rotation about the Y-axis:

Rotation about the Z-axis:

in all each of these cases represent the angle of rotation.


A series of translation, scaling, and rotation matrices can logically describe most
transformations. Rasterization systems generally use a transformation stack to move
the stream of input vertices into place. The transformation stack is a
standard stack which stores matrices. Incoming vertices are multiplied by the matrix
stack.
As an illustrative example of how the transformation stack is used, imagine a simple
scene with a single model of a person. The person is standing upright, facing an
arbitrary direction while his head is turned in another direction. The person is also
located at a certain offset from the origin. A stream of vertices, the model, would be
loaded to represent the person. First, a translation matrix would be pushed onto the
stack to move the model to the correct location. A scaling matrix would be pushed onto
the stack to size the model correctly. A rotation about the y-axis would be pushed onto
the stack to orient the model properly. Then, the stream of vertices representing the
body would be sent through the rasterizer. Since the head is facing a different direction,
the rotation matrix would be popped off the top of the stack and a different rotation
matrix about the y-axis with a different angle would be pushed. Finally the stream of
vertices representing the head would be sent to the rasterizer.
After all points have been transformed to their desired locations in 3-space with respect
to the viewer, they must be transformed to the 2-D image plane. The simplest projection,
the orthographic projection, simply involves removing the z component from transformed
3d vertices. Orthographic projections have the property that all parallel lines in 3-space
will remain parallel in the 2-D representation. However, real world images are
perspective images, with distant objects appearing smaller than objects close to the
viewer. Aperspective projection transformation needs to be applied to these points.
Conceptually, the idea is to transform the perspective viewing volume into the
orthogonal viewing volume. The perspective viewing volume is a frustum, that is, a
truncated pyramid. The orthographic viewing volume is a rectangular box, where both
the near and far viewing planes are parallel to the image plane.
A perspective projection transformation can be represented by the following matrix:

F and N here are the distances of the far and near viewing planes, respectively. The
resulting four vector will be a vector where the homogeneous variable is not 1.
Homogenizing the vector, or multiplying it by the inverse of the homogeneous
variable such that the homogeneous variable becomes unitary, gives us our
resulting 2-D location in the x and y coordinates.

You might also like