Application of Computer Graphics: 2.1 Cathode-Ray Tubes (CRT) - Still The Most Common Video Display Device Presently
Application of Computer Graphics: 2.1 Cathode-Ray Tubes (CRT) - Still The Most Common Video Display Device Presently
Presentation Graphics
To produce illustrations which summarize various kinds of data. Except 2D, 3D graphics are good
tools for reporting more complex data.
Computer Art
Painting packages are available. With cordless, pressure-sensitive stylus, artists can produce electronic
paintings which simulate different brush strokes, brush widths, and colors. Photorealistic techniques,
morphing and animations are very useful in commercial art. For films, 24 frames per second are
required. For video monitor, 30 frames per second are required.
Entertainment
Motion pictures, Music videos, and TV shows, Computer games
Visualization
For analyzing scientific, engineering, medical and business data or behavior. Converting data to visual
form can help to understand mass volume of data very efficiently.
Image Processing
Image processing is to apply techniques to modify or interpret existing pictures. It is widely used in
medical applications.
2.1 Cathode-Ray Tubes (CRT) - still the most common video display device presently
An electron gun emits a beam of electrons, which passes through focusing and deflection systems and
hits on the phosphor-coated screen. The number of points displayed on a CRT is referred to as the
1
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
resolution (eg. 1024x768). Different phosphors emit small light spots of different colors, which can
combine to form a range of colors. A common methodology for color CRT display is the Shadow-
mask method.
The light emitted by phosphor fades very rapidly, so it needs to redraw the picture repeatedly. There
are 2 kinds of redrawing mechanisms: Raster-Scan and Random-Scan
Raster-Scan
The electron beam is swept across the screen one row at a time from top to bottom. As it moves across
each row, the beam intensity is turned on and off to create a pattern of illuminated spots. This
scanning process is called refreshing. Each complete scanning of a screen is normally called a frame.
The refreshing rate, called the frame rate, is normally 60 to 80 frames per second, or described as 60
Hz to 80 Hz.
Picture definition is stored in a memory area called the frame buffer. This frame buffer stores the
intensity values for all the screen points. Each screen point is called a pixel (picture element).
On black and white systems, the frame buffer storing the values of the pixels is called a bitmap. Each
entry in the bitmap is a 1-bit data which determine the on (1) and off (0) of the intensity of the pixel.
On color systems, the frame buffer storing the values of the pixels is called a pixmap (Though
nowadays many graphics libraries name it as bitmap too). Each entry in the pixmap occupies a
number of bits to represent the color of the pixel. For a true color display, the number of bits for each
entry is 24 (8 bits per red/green/blue channel, each channel 2 8=256 levels of intensity value, ie. 256
voltage settings for each of the red/green/blue electron guns).
2
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
The CRT's electron beam is directed only to the parts of the screen where a picture is to be drawn. The
picture definition is stored as a set of line-drawing commands in a refresh display file or a refresh
buffer in memory.
Random-scan generally have higher resolution than raster systems and can produce smooth line
drawings, however it cannot display realistic shaded scenes.
2.2 Flat-Panel Displays - will be the most common video display device very soon.
- Liquid crystal refers to compounds which are in crystalline arrangement, but can flow like liquid.
- The light source passes through a liquid-crystal material that can be aligned to either block or
transmit the light.
- 2 glass plates, each containing a light polarizer at right angles to the other, sandwich a liquid
crystal material.
- Rows of horizontal transparent conductors are built into one glass page. Columns of vertical
conductors are put into the other plate. The intersection of 2 conductors defines a pixel position. -
- Passive-matrix LCD
- In the "on" state, polarized light passing through the material is twisted so that it will pass through
the opposite polarizer.
- Different materials can display different colors.
- By placing thin-film transistors at pixel locations, voltage at each pixel can be controlled. --
Active-matrix LCD.
3
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
In this context we discuss the graphics systems of raster-scan devices. A graphics processor accepts
graphics commands from the CPU and executes the graphics commands which may involve drawing
into the frame buffer. The frame buffer acts as a temporary store of the image and also as a decoupler
to allow the graphics processor and the display controller to operate at different speeds. The display
controller reads the frame buffer line by line and generates the control signals for the screen.
Graphics commands:
- Draw point
- Draw polygon
- Draw text
- Clear frame buffer
- Change drawing color
2D graphics processors execute commands in 2D coordinates. When objects overlap, the one being
drawn will obscure objects drawn previously in the region. BitBlt operations (Bit Block Transfer) are
usually provided for moving/copying one rectangular region of frame buffer contents to another
region.
Display Controller for a raster display device reads the frame buffer and generates the control signals
for the screen, ie. the signals for horizontal scanning and vertical scanning. Most display controllers
include a colormap (or video look-up table). The major function of a colormap is to provide a
mapping between the input pixel value to the output color.
4
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
A tablet contains a stylus and a drawing surface and it is mainly used for the input of drawings. A
tablet is usually more accurate than a mouse, and is commonly used for large drawings.
Scanners are used to convert drawings or pictures in hardcopy format into digital signal for computer
processing.
Touch panels allow displayed objects or screen positions to be selected with the touch of a finger. In
these devices a touch-sensing mechanism is fitted over the video monitor screen. Touch input can be
recorded using optical, electrical, or acoustical methods.
Directing pictures to a printer or plotter to produce hard-copy output on 35-mm slides, overhead
transparencies, or plain paper. The quality of the pictures depend on dot size and number of dots per
inch (DPI).
Laserjet printers use a laser beam to create a charge distribution on a rotating drum coated with a
photoelectric material. Toner is applied to the drum and then transferred to the paper. To produce
color outputs, the 3 color pigments (cyan, magenta, and yellow) are deposited on separate passes.
Inkjet printers produce output by squirting ink in horizontal rows across a roll of paper wrapped on a
drum. To produce color outputs, the 3 color pigments are shot simultaneously on a single pass along
each print line on the paper.
Inkjet or pen plotters are used to generate drafting layouts and other drawings of normally larger
sizes. A pen plotter has one or more pens of different colors and widths mounted on a carriage which
spans a sheet of paper.
General graphics packages are designed to be used with Cartesian coordinate representations (x,y,z).
Usually several different Cartesian reference frames are used to construct and display a scene:
5
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
3. Output Primitives
Shapes and colors of objects can be described internally with pixel arrays or sets of basic geometric
structures such as straight line segments and polygon color areas. The functions provided by graphics
programming packages to deal with these basic geometric structures are called output primitives.
For example:
Drawing a point: SetPixel(100,200,RGB(255,255,0));
Drawing a line: MoveTo(100,100); LineTo(100,200);
Drawing some text: SetText(100,200,"Hello");
Drawing an ellipse: Ellipse(100,100,200,200);
Painting a picture: BitBlt(100,100,50,50,srcImage,0,0,SRCCOPY);
This is to compute intermediate discrete coordinates along the line path between 2 specified endpoint
positions. The corresponding entry of these discrete coordinates in the frame buffer is then marked
with the line color wanted.
6
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
This algorithm is very efficient since it use only incremental integer calculations. Instead of
calculating the non-integral values of D1 and D2 for decision of pixel location, it computes a value, p,
which is defined as:
7
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
To save time in drawing a circle, we can make use of the symmetrical property of a circle which is to
draw the segment of the circle between 0 and 45 degrees and repeat the segment 8 times as shown in
the diagram to produce a circle. Ths algorithm also employs the incremental method which further
improves the efficiency.
8
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
- Basic idea: For each scan line crossing a polygon, this algorithm locates the intersection points of
the scan line with the polygon edges. These intersection points are shorted from left to right.
Then, we fill the pixels between each intersection pair.
- Some scan-line intersection at polygon vertices require special handling. A scan line passing
through a vertex as intersecting the polygon twice. In this case we may or may not add 2 points to
the list of intersections, instead of adding 1 points. This decision depends on whether the 2 edges
at both sides of the vertex are both above, both below, or one is above and one is below the scan
line. Only for the case if both are above or both are below the scan line, then we will add 2 points.
- Inside-Outside Tests: The above algorithm only works for standard polygon shapes. However, for
the cases which the edges of the polygon intersects, we need to identify whether a point is an
interior or exterior point. Students may find interesting descriptions of 2 methods to solve this
problem in many text books: odd-even rule and nonzero winding number rule.
9
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
- This algorithm starts at a point inside a region and paint the interior outward towards the boundary.
- This is a simple method but not efficient: 1. It is recursive method which may occupy a large stack
size in the main memory.
void BoundaryFill(int x, int y, COLOR fill, COLOR boundary)
{ COLOR current;
current=GetPixel(x,y);
if (current<>boundary) and (current<>fill) then
{ SetPixel(x,y,fill);
BoundaryFill(x+1,y,fill,boundary);
BoundaryFill(x-1,y,fill,boundary);
BoundaryFill(x,y+1,fill,boundary);
BoundaryFill(x,y-1,fill,boundary);
}
}
- More efficient methods fill horizontal pixel spands across scan lines, instead of proceeding to
neighboring points.
- Flood-Fill is similar to Boundary-Fill. The difference is that Flood-Fill is to fill an area which I
not defined by a single boundary color.
10
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
- A character is defined by its outline which is usually comoposed of lines and curves.
- We can use a method similar the one for rendering polygon to render a character
- However, because text is used very oftenly, we usually convert them into bitmaps in advance to
improve the drawing efficiency.
- To draw a character on the screen, all we need to do is to copy the corresponding bitmap to
the specified coordinate.
- The problem with this method is that scaling a character with a bitmap to produce different
character sizes would result in a block-like structures (stair-case, aliasing). Hence we normally
render a few bitmaps for a single character to represent different sizes of the same character.
3.7 Bitmap
- A graphics pattern suh as an icon or a character may be needed frequently, or may need to be
re-used.
- Generating the pattern every time when needed may waste a lot of processing time.
- A bitmap can be used to store a pattern and duplicate it to many places on the image or on
the screen with simple copying operations.
11
CS3162 Introduction to Computer Graphics
Helena Wong,
2000
3.8 Properties
In graphical packages, we can specify such properties, eg. In Powerpoint, we can modify
the properties of objects by a format command.
In programming tools, we may pass the properties as arguments when we call the functions of these
primitives, or we may pre-select the properties before calling the functions.
In many applications, changes in orientations, size, and shape are accomplished with geometric transformations
that alter the coordinate descriptions of objects.
Other transformations:
Reflection
Shear
Basic Transformations
Translation
We translate a 2D point by adding translation distances, tx and ty, to the original coordinate position
(x,y):
x' = x + tx, y' = y + ty
1 0tx
0
1 t y
0 0 1
Then we can rewrite the formula as:
x'1 0 t x x
y' = 0 1 t y
y
0 0 1 1
1
For example, to translate a triangle with vertices at original coordinates (10,20), (10,10), (20,10) by
tx=5, ty=10, we compute as followings:
The resultant coordinates of the triangle vertices are (15,30), (15,20), and (25,20) respectively.
Exercise: translate a triangle with vertices at original coordinates (10,25), (5,10), (20,10) by t x=15,
ty=5. Roughly plot the original and resultant triangles.
To rotate an object about the origin (0,0), we specify the rotation angle ?. Positive and negative values
for the rotation angle define counterclockwise and clockwise rotations respectively. The followings is
the computation of this rotation for a point:
Alternatively, this rotation can also be specified by the following transformation matrix:
cos sin 0
sin cos 0
0 0 1
Then we can rewrite the formula as:
1 0
0 1 1
For example, to rotate a triange about the origin with vertices at original coordinates (10,20), (10,10),
(20,10) by 30 degrees, we compute as followings:
x' 0.866 0.5 010 0.866 *10 (0.5) *10 0 *1 3.66
y' = 0.5 0.866 0 10 = 0.5 *10 0.866 *10 0 *1 = 13.66
1 0 0 1 1 0 *10 0 *10 1*1 1
Rotation of vertex (20,10):
Exercise: Rotate a triange with vertices at original coordinates (10,20), (5,10), (20,10) by 45
degrees. Roughly plot the original and resultant triangles.
We scale a 2D object with respect to the origin by setting the scaling factors s x and sy, which
are multiplied to the original vertex coordinate positions (x,y):
Alternatively, this scaling can also be specified by the following transformation matrix:
sx 0 0
0 sy 0
0 0 1
Then we can rewrite the formula as:
Exercise: Scale a triange with vertices at original coordinates (10,25), (5,10), (20,10) by s x=1.5,
sy=2, with respect to the origin. Roughly plot the original and resultant triangles.
C'=A·(B·C)
C' = (A·B)·C
The advantage of computing it using C' = (A·B)·C instead of C'=A·(B·C) is that, for computing
the 3 vertices of the triangle, C1, C2, C 3, the computation time is shortened:
Using C'=A·(B·C):
- compute B · C1 and put the result into I1
- compute A · I1 and put the result into C1'
- compute B · C2 and put the result into I2
- compute A · I2 and put the result into C2'
- compute B · C3 and put the result into I3
- compute A · I3 and put the result into C3'
4
CS3162 Introduction to Computer Graphics
Helena Wong, 2000
Example: Rotate a triangle with vertices (10,20), (10,10), (20,10) about the origin by 30 degrees
and then translate it by tx=5, ty=10,
0 0 1 0 0 1
And we compute the translation matrix:
1 0 5
A= 0 1 10
0 0 1
1 0 5 0.866 0.5 0
M= 0 1 10 · 0.5 0.866 0
0 0 1 0 0 1
0.866 0.5 5
M= 0.5 0.866 10
0 0 1
x' 0.866 0.5 5 10 0.866 *10 (0.5) *10 5 *1 8.66
y' = 0.5 0.866 10 10 = 0.5 *10 0.866 *10 10 *1 = 23.66
1 0 0 1 1 0 *10 0 *10 1*1 1
Transformation of vertex (20,10):
Exercise: Translate a triangle with vertices (10,20), (10,10), (20,10) by t x=5, ty=10 and then rotate it about
the origin by 30 degrees. Compare the result with the one obtained previously: (3.66,32.32),
(8.66,23.66), and (17.32,28.66) by plotting the original triangle together with these 2 results.
Translations
By common sense, if we translate a shape with 2 successive translation vectors: (t x1, ty1) and (tx2, ty2), it is
equal to a single translation of (tx1+ tx2, ty1+ t y2).
This additive property can be demonstrated by composite transformation matrix:
1 0 t x1 1 0 t x 2 1*1 0 * 0 t x1 * 0 1* 0 0 *1 t x1 * 0 1* t x 2 0 * t y 2 t x1 *1
0 1 t · 0 1 t = 0 *1 1* 0 t * 0 0 * 0 1*1 t * 0 0*t 1* t t *1
y1 y2 y1 y1 x2 y2 y1
0 0 1
This demonstrates that 2 successive translations are additive.
Rotations
By common sense, if we rotate a shape with 2 successive rotation angles: ? and a, about the origin, it
is equal to rotating the shape once by an angle ? + a about the origin.
Similarly, this additive property can be demonstrated by composite transformation matrix:
cos cos = sin
cos
sin sin (cos sin sin cos ) 0
cos sin sin sin cos cos 0
0 0 1
cos() sin() 0
= sin() cos() 0
0 0 1
This demonstrates that 2 successive rotations are additive.
By common sense, if we scale a shape with 2 successive scaling factor: (s x1, sy1) and (sx2, sy2), with
respect to the origin, it is equal to a single scaling of (s x1* sx2, sy1* sy2) with respect to the origin. This
multiplicative property can be demonstrated by composite transformation matrix:
s x1 0 0s x 2 0 0
s
0 y1 0 · 0 s y2 0
0 0 1 0 0 1
s x1 * s x 2 0 * 0 0 * 0 s x1 * 0 0 * s y 2 0 * 0 s x1 * 0 0 * 0 0 *1
= 0 * s x 2 s y1 * 0 0 * 0 0 * 0 s y1 * s y 2 0 * 0 0 * 0 s y1 * 0 0 *1
0 * s x 2 0 * 0 1* 0 0 * 0 0 * s y 2 1* 0 0 * 0 0 * 0 1*1
s x1 * s x 2 0 0
s *s
=
0 y1 y2 0
0 0 1
This demonstrates that 2 successive scalings with respect to the origin are multiplicative.
Rotation about an arbitrary pivot point is not as simple as rotation about the origin. The procedure of
rotation about an arbitrary pivot point is:
- Translate the object so that the pivot-point position is moved to the origin.
- Rotate the object about the origin.
- Translate the object so that the pivot point is returned to its original position.
0 0 1
General Fixed-Point Scaling
Scaling with respect to an arbitrary fixed point is not as simple as scaling with respect to the origin.
The procedure of scaling with respect to an arbitrary fixed point is:
1. Translate the object so that the fixed point coincides with the origin.
2. Scale the object with respect to the origin.
3. Use the inverse translation of step 1 to return the object to its original position.
1 0 x f sx 0 0 1 0xf s x 0 x f (1 s x )
0
1 y 0 s
f y
0 0
1 y
f
=
0 s
yf
y (1 s )
y
0 0 1 0 0 1 0 0 1 0 0 1
Scaling along an arbitrary direction is not as simple as scaling along the x-y axis. The procedure of
scaling along and normal to an arbitrary direction (s 1 and s2), with respect to the origin, is:
1. Rotate the object so that the directions for s1 and s2 coincide with the x and y axes respectively.
2. Scale the object with respect to the origin using (s 1, s2).
3. Use an opposite rotation to return points to their original orientation.
Reflection
Shear
X-direction shear, with a shearing parameter sh x, relative
to the x-axis:
x' 1 sh x 0x
y' = 0 1 0 y
1 001 1
ie. x'=x+y*shx; y'=-x
Exercise: Think of a y-direction shear, with a shearing parameter sh y, relative to the y-axis.
Transformation Between 2 Cartesian Systems
For modelling and design applications, individual objects may be defined in their own
local Cartesian References. The local coordinates must then be transformed to position
the objects within the overall scene coordinate system.
Suppose we want to transform object descriptions from the xy system to the x'y' system:
The composite transformation is:
0 0 10 0 1
Clipping
Line Clipping
This section treats clipping of lines against rectangles. Although there are specialized algorithms
for rectangle and polygon clipping, it is important to note that other graphic primitives can be
clipped by repeated application of the line clipper.
Before we discuss clipping lines, let's look at the simpler problem of clipping individual
points.
If the x coordinate boundaries of the clipping rectangle are Xmin and Xmax, and the y
coordinate boundaries are Ymin and Ymax, then the following inequalities must be
satisfied for a point at (X,Y) to be inside the clipping rectangle:
If any of the four inequalities does not hold, the point is outside the clipping rectangle.
1. End-points pairs are check for trivial acceptance or trivial rejected using the outcode.
2. If not trivial-accepance or trivial-rejected, divided into two segments at a clip edge.
3. Iteratively clipped by testing trivial-acceptance or trivial-rejected, and divided into two
segments until completely inside or trivial-rejected.
To perform trivial accept and reject tests, we extend the edges of the clip rectangle to
divide the plane of the clip rectangle into nine regions. Each region is assigned a 4-bit
code deteermined by where the region lies with respect to the outside halfplanes of the
clip-rectangle edges. Each bit in the outcode is set to either 1 (true) or 0 (false); the 4 bits
in the code correspond to the following conditions:
5.
Note the difference between this strategy for a polygon and the Cohen-Sutherland algorithm for
clipping a line: The polygon clipper clips against four edges in succession, whereas the line
clipper tests the outcode to see which edge is crossed, and clips only when necessary.
Polygons can be clipped against each edge of the window one at a time. Windows/edge
intersections, if any, are easy to find since the X or Y coordinates are already known.
Vertices which are kept after clipping against one window edge are saved for clipping
against the remaining edges.
Note that the number of vertices usually changes and will often increases.
We are using the Divide and Conquer approach.
The clip boundary determines a visible and invisible region. The edges from vertex i to vertex
i+1 can be one of four types:
All information in the user dialogue is then presented in the language of the Mion 6-1
application. In an architectural design package, this means that all interactions The User Dialogue
are described only in architectural terms, without reference to particular data
structures or other concepts that may be unfamiliar to an architect. In the following
sections, we discuss some of the general considerations in structuring a user
dialogue.
Windows and Icons
Figure 8-1 shows examples of common window and icon graphical interfaces. Visual
representations are used both for obpds to be manipulated in an application
and for the actions to be performed on the application objects.
A window system provides a window-manager interface for the user and
functions for handling the display and manipulation of the windows. Common
functions for the window system are opening and closing windows, repositioning
windows, resizing windows, and display routines that provide interior and
exterior clipping and other graphics functions. Typically, windows are displayed
with sliders, buttons, and menu icons for selecting various window options.
Some general systems, such as X Widows and NeWS, are capable of supporting
multiple window managers so that different window styles can be accommodated,
each with its own window manager. The window managers can then be
designed for particular applications. In other cases, a window system is designed
for one specific application and window style.
Icons representing objects such as furniture items and circuit elements are
often referred to as application icons. The icons representing actions, such as 1-0-
tate, magnlfy, scale, clip, and paste, are called control icons, or command icons.