CG Notes (Unit I &II)
CG Notes (Unit I &II)
)
Computer Graphics
In a raster-scan system, the electron beam is swept across the screen, one row at a time from top
to bottom. 7
The electron beam moves across each row, the beam intensity is turned on and off to create a
pattern of illuminated spots.
Refresh Buffer or Frame Buffer
Picture definition is stored in a memory area called the refresh buffer or frame buffer.
Scan Line
The frame buffer holds the set of intensity values for all the screen points. Stored intensity values
are then retrieved from the refresh buffer and "painted" on the screen one row at a time is called scan line
(Fig. 1.7).
Pixel
Each screen point is referred to as a pixel or pel or picture element.
Intensity range for pixel positions depends on the capability of the raster system.
In a simple black-and-white system, each screen point is either on or off. So only one bit per pixel
is needed to control the intensity of screen positions.
For a bi-level system, a bit value of 1 indicates that the electron beam is to be turned on at that
position, and a value of 0 indicates that the beam intensity is to be off.
Bitmap
On a black-and-white system with one bit per pixel, the frame buffer is commonly called a
bitmap.
Pixmap
Systems with multiple bits per pixel, the frame buffer is often referred to as a pixmap.
Refreshing on raster scan displays is carried out at the rate of 60 to 80 frames per second. Refresh
rates are described in units of cycles per second or Hertz.
Using these units, we would describe a refresh rate of 60 frames per second as simply 60 Hz.
Horizontal Retrace
At the end of each scan line, the electron beam returns to the left side of the screen to begin
displaying the next scan line.
The return to the left of the screen, after refreshing each scan line, is called the horizontal retrace
of the electron beam.
Vertical Retrace
At the end of each frame the electron beam returns to the top left corner of the screen to begin the
next frame is called vertical retrace.
Computer Graphics
8
Fig 1.8 Interlacing scan lines on a Raster Scan Display
Interlace
Each frame is displayed in two passes using an interlaced refresh procedure.
In the first pass, the beam sweeps across every other scan line from top to bottom.
Then after the vertical retrace, the beam sweeps out the remaining scan lines (Fig 1.8).
Random-Scan Displays
In a random-scan display unit, a CRT has the electron beam directed only to the parts of the
screen where a picture is to be drawn (Fig 1.9).
Random-scan monitors draw a picture one line at a time and for this reason are also referred to as
vector displays or stroke-writing or calligraphic displays.
Refresh rate on a random-scan system depends on the number of lines to be displayed.
Fig 1.12 Architecture of raster system with a fixed portion of the system memory
A fixed area of the system memory is reserved for the frame buffer. So the video controller is
given direct access to the frame-buffer memory (Fig 1.12).
Frame-buffer locations, and the corresponding screen positions, are referenced in Cartesian
coordinates. The coordinate origin is defined at lower left screen corner.
Then the first quadrant of a two dimensional system, positive x values increasing to the right and
positive y values increasing from bottom to top.
Scan lines are labeled from ymax at the top of the screen to 0 at the bottom, each scan line screen
pixel positions are labeled from 0 to xmax.
Computer Graphics
There are two registers are used to store the coordinates of the screen pixels.
Initially, the x register is set to 0 and the y register is set to ymax. 13
The value stored in the frame buffer for this pixel position is then retrieved and used to set the
intensity of the CRT beam.
Then the x register is incremented by 1, and the process repeated for the next pixel on the top
scan line.
In high quality system, two frame buffers are provided, one for refreshing other for filling
intensity values.
Raster-Scan Display Processor
A raster system containing a separate display processor, sometimes referred to as a graphics
controller or a display coprocessor (Fig 1.13).
Scan Conversion
Task of the display processor is digitizing a picture definition given in an application program
into a set of pixel-intensity values for storage in the frame buffer. This digitization process is
called scan conversion.
Display processors are also designed to perform a number of additional operations.
These functions include generating various line styles (dashed, dotted, or solid), displaying color
areas, and performing certain transformations and manipulations on displayed objects.
Fig 1.15 General Purpose Computer System that can be used for Graphics Application
For example, laser printers and plotters are graphics devices because they permit the computer
to output pictures.
Computer Graphics
15
1. Character Printer
2. Line Printer
Character Printer:
It prints only one character at a time.
It has relatively slower speed. Eg. Dot matrix printers.
Dot Matrix Printer:
It prints characters as combination of dots.
Dot matrix printers are the most popular among serial printers.
These have a matrix of pins on the print head of the printer which form the character.
The computer memory sends one character at a time to be printed by the printer. There is a
carbon between the pins & the paper.
The words get printed on the paper when the pin strikes the carbon. There are generally 24 pins.
Non-Impact Printers:
These printers use non-Impact technology such as ink-jet or laser technology.
These printers provide better quality of O/P at higher speed.
There are two types:
1. Ink-Jet Printer
2. Laser Printer
Computer Graphics
Ink-Jet Printer:
It prints characters by spraying patterns of ink on the paper from a nozzle or jet. 19
It prints from nozzles having very fine holes, from which a specially made ink is pumped out to
create various letters and shapes.
Laser Printer:
It is a type of printer that utilizes a laser beam to produce an image on a drum.
This is also the way copy machines work. Because an entire page is transmitted to a drum before
the toner is applied, laser printers are sometimes called page printers.
GRAPHICS SOFTWARE
There are two general classifications for graphics software:
General Programming Packages
A general graphics programming package provides an extensive set of graphics functions that can
be used in a high-level programming language, such as C or FORTRAN.
Example: Generating picture components straight lines, polygons, circles, and other figures.
Special-Purpose Applications Packages
Application graphics packages are designed for nonprogrammers, so that users can generate
displays without worrying about how graphics operations work.
Example: Artist’s painting programs and various business, medical, and CAD systems
Coordinate Representations
Coordinate values for a picture are converted to Cartesian coordinates before they can be input to
the graphics package.
Different Cartesian reference frames are used to construct and display a scene.
Modeling Coordinates
We can construct the shape of individual objects, such as trees or furniture, in a scene within
separate coordinate reference frames called modeling coordinates, or sometimes local coordinates
or master coordinates.
World Coordinates
Once individual object shapes have been specified, we can place the objects into appropriate
positions within the scene using a reference frame called world coordinates.
Graphics Functions
A general-purpose graphics package provides users with a variety of functions for creating and
manipulating pictures.
The basic building blocks for pictures are referred to as output primitives. They include character
strings and geometric entities, such as points, straight lines, curved lines, filled areas (polygons,
circles, etc.).
Computer Graphics
Attributes are the properties of the output primitives. It includes intensity and color
specifications, line styles, text styles, and area-filling patterns. 20
Geometric Transformations
To change the size, position, or orientation of an object within a scene using geometric
transformations.
Modeling Transformations
It is used to construct a scene using object descriptions given in modeling coordinates
Viewing Transformations
Viewing transformations are used to specify the view that is to be presented and the portion of the
output display area that is to be used.
Pictures can be subdivided into component parts, called structures or segments or objects,
depending on the software package in use
Interactive graphics applications use various kinds of input devices, such as a mouse, a tablet, or a
joystick.
Software Standards
The primary goal of standardized graphics software is portability.
When packages are designed with standard graphics functions, software can he moved easily
from one hardware system to another and used in different implementations and applications.
Graphical Kernel System (GKS)
It is the first graphics software standard by the International Standards Organization (ISO).
It is also includes in the American National Standards Institute (ANSI).
PHIGS (Programmer's Hierarchical Interactive Graphics standard)
It is the second software standard to be developed and approved by the standards organizations.It
is an extension of GKS.
PHIGS Workstations
Workstation refers to a computer system with a combination of input and output devices that is
designed for a single user.
In PHIGS and GKS, however, the term workstation is used to identify various combinations of
graphics hardware and software.
A PHIGS workstation can be a single output device, a single input device, a combination of input
and output devices, a file, or even a window displayed on a video monitor.
Computer Graphics
2. OUTPUT PRIMITIVES
Introduction 21
The Primitives are the simple geometric functions that are used to generate various Computer
Graphics required by the User.
Basic Output primitives are point-position (pixel), and a straight line.
Some other output primitives are rectangle, conic section, circle, or may be a surface.
POINT AND LINES
Point Function
A point function is the most basic Output primitive in the graphic package.
A point function contains location using x and y coordinate and the user may also pass other
attributes such as its intensity and color.
The location is stored as two integer tuple, the color is defined using hex codes.
The size of a pixel is equal to the size of pixel on display monitor.
22
To determine pixel positions along a straight-line path from the geometric properties of the line.The
Cartesian slope-intercept equation for a straight line is
y = m · x + b -------------------- 1
where m as the slope of the line and b as the y intercept.
Given that the two endpoints of a line segment are specified at positions (x1, y1) and (x2, y2), as
shown in Fig.2.2.
Fig 2.3 Line path between endpoint positions (x1, y1) and (x2, y2)
To determine values for the slope m and y intercept b with the following calculations:
Algorithms for displaying straight lines are based on the line equation 1 and the calculations
given in Eqs. 2 and 3.
For any given x interval ∆x along a line, we can compute the corresponding y interval ∆y from
Eq.2 as
Computer Graphics
∆y = m · ∆x -------------------- 4
Similarly, we can obtain the x interval ∆x corresponding to a specified ∆y as 23
∆x = ∆y / m------------------------- 5
For lines with slope magnitudes |m| < 1, ∆x can be set proportional to a small horizontal
deflection voltage, and the corresponding vertical deflection is then set proportional to ∆y as calculated
from Eq-4.
For lines whose slopes have magnitudes |m| > 1, ∆y can be set proportional to a small vertical
deflection voltage with the corresponding horizontal deflection voltage set proportional to ∆x, calculated
from Eq.5.
For lines with m = 1, ∆x = ∆y and the horizontal and vertical deflections voltages are equal. In
each case, a smooth line with slope m is generated between the specified endpoints.
On raster system, lines are plotted with pixels, and step sizes in the horizontal and vertical
directions are constrained by pixel separations.
Scan conversion process for straight lines is illustrated in Fig 2.3.
DDA Algorithm
The digital differential analyzer (DDA) is a scan-conversion line algorithm based on calculating
either ∆y or ∆x, using Eq. 4 or Eq. 5.
First consider a line with positive slope, as shown in Fig. If the slope is less than or equal to 1,
sample at unit x intervals (∆x = 1) and compute successive y values as
yk+1 = yk + m 6
Fig 2.4 straight line segment with five sampling positions along the x axis between x1 and x2.
Subscript k takes integer values starting from 0, for the first point, and increases by 1 until the
final endpoint is reached.
Since m can be any real number between 0.0 and 1.0, each calculated y value must be rounded to
the nearest integer corresponding to a screen pixel position in the x column.
For lines with a positive slope greater than 1.0, reverse the roles of x and y. That is, we sample at
unit y intervals (∆y = 1) and calculate consecutive x values as
x k+1 = xk + 1/m --------------------------- 7
Computer Graphics
In this case, each computed x value is rounded to the nearest pixel position along the current y
scan line. 24
Equations 6 and 7 are based on the assumption that lines are to be processed from the left
endpoint to the right endpoint Fig 2.2. If this processing is reversed, so that the starting endpoint is at the
right, then either we have ∆x = −1 and
yk+1 = yk - m 8
xk+1 = xk – 1/ m --------------------------- 9
Negative slopes are calculated using Eq-s 6 through 9. If the absolute value of the slope is less
than 1 and the starting endpoint is at the left, we set ∆x = 1 and calculate y values with Eq-6.
When the starting endpoint is at the right (for the same slope), we set ∆x = −1 and obtain y
positions using Eq. 8.
For a negative slope with absolute value greater than 1, we use ∆y = −1 and Eq. 9 or we use ∆y =
1 and Eq.7.
Algorithm
D.Ananthi.,M.Sc.,M.Phil.,B.Ed.,SET.,
Computer Graphics
Step 5: loop the following process for steps number of times
1. Use a unit of increment or decrement in the x and y direction 25
2. if xa is less than xb the values of increment in the x and y directions are 1 and m
3. if xa is greater than xb then the decrements -1 and – m are used.
Example: Consider the line from (0, 0) to (4, 6)
1. xa = 0, ya = 0 and xb = 4 yb = 6
2. dx = xb - xa = 4-0 = 4 and dy = yb - ya = 6-0 = 6
3. x = 0 and y = 0
4. 4 > 6 (false) so, steps = 6
5. Calculate xIncrement = dx/steps = 4 / 6 = 0.66 and
yIncrement = dy/steps = 6/6 = 1
6. Setpixel(x, y) = Setpixel(0, 0) (Starting Pixel Position)
7. Iterate the calculation for xIncrement and yIncrement for steps (6) number of times
8. Tabulation of the each iteration is given below.
Fig 2.5 Pixel positions along the line path between endpoints (0, 0) and (4, 6) plotted with DDA line
algorithm
Fig 2.6 a straight line segment is to be plotted, starting from the pixel at column 2 on scan line 3.
At sampling position x k + 1, we label vertical pixel separations from the mathematical line path as
dlower and dupper in Fig 2.5.
Then
dlower = y - yk
= m (xk+1) + b - yk
And
2.8 Pixel positions along the line path between endpoints (20, 10) and (30, 18) plotted with
Bresenham’s line algorithm
Advantages
1. Algorithm is fast
2. Uses only integer calculations
Disadvantages
1. It is meant only for basic line drawing.
LOADING THE FRAME BUFFER
After scan converting the straight line segments and other objects in the raster system, frame
buffer positions must be calculated.
Computer Graphics
It is done by set pixel procedure that stores intensity values for the pixels at corresponding
addresses within the frame buffer array. 30
Scan conversion algorithms generate pixel positions at successive intervals.
To calculate frame-buffer addresses, incremental methods are used.
Figure 2.9 Pixel screen positions stored within the frame buffer
For example, in the figure 2.9, the frame buffer array is addressed in row major order. The pixel
positions vary from (0,0) to (xmax, ymax).
The pixel postion (x,y) is calculated as follows:
addr (x,y) = addr (0,0) + y(xmax+1) + x
We can calculate the frame buffer address for the next pixel logo in the scanline by using
incremental method as follows:
addr (x+1,y) = addr (x, y) +1
For calculating the frame buffer address for the pixel position (x+1, y+1).
addr (x+1,y+1) = addr (x,y) + xmax+2
Where the constant xmax +2 is precomputed once for all line segments.
CIRCLE GENERATING ALGORITHMS
PROPERTIES OF CIRCLE
A circle is defined as the set of points that are all at a given distance r from a center position (xc,
yc).
Figure 2.10 Circle with Center Coordinate (xc, yc) and Radius r
Computer Graphics
The distance relationship is expressed by the Pythagorean Theorem in Cartesian coordinates as follows
(x – xc)2+(y – yc)2 = r2 31
y values at each position is calculated as
and the x axis steps from xc – r to xc + r. This method is not a best method for generating a circle.
Problems
(1) It involves considerable computation at each step.
(2) The spacing between each plotted pixel position is not uniform.
Solutions
(1) The spacing can be adjusted by interchanging x and y whenever the absolute value of the
slope of the circle is greater than 1.
It increases the computation and processing of the algorithm.
(2) Another way to adjust the unequal spacing is to calculate points along the circular boundary
using polar coordinates r and θ.
The circle equation in parametric polar form yields the following pair of equations:
x = xc+r cosθ
y = yc+r sinθ
Where θ is a fixed angular step size.
By using the above equation, a circle is plotted with equally spaced points along the
circumference.
Symmetry of a circle
•By considering the symmetry of a circle, computations can be reduced.
•The shape of the circle is similar in all the four quadrants.
The circle function test is performed for the mid positions between pixels near the circle path at
each sampling step. So the circle function is the decision parameter in the midpoint algorithm.
33
Computer Graphics
The start position (0, r) with the value (0, 2r).
Successive values are obtained by adding 2 to the previous value of 2x, and subtracting 2 from 34
the previous value of 2y.
Computer Graphics
35
Computer Graphics
ATTRIBUTES OF OUTPUT PRIMITIVES
Any parameter that affects the way a primitive is to be displayed is referred to as an 36
attribute parameter. Attribute parameters are color, size etc. It is used to determine the
fundamental characteristics of a primitive.
TYPES OF ATTRIBUTES
1. Line Attributes
2. Curve Attributes
3. Color and Grayscale Levels
4. Area Fill Attributes
5. Character Attributes
6. Bundled Attributes
Line Attributes
Basic attributes of a straight line segment are
1. Line Type
2. Line Width
3. Pen and Brush Options
4. Line Color
Line type
Line type attribute includes solid lines, dashed lines and dotted lines.
To set line type attributes in a PHIGS application program, a user invokes the function
setLinetype (lt)
where parameter lt is assigned a positive integer value of 1, 2, 3 or 4 to generate lines that are
solid, dashed, dash dotted respectively. Other values for line type parameter it could be used to display
variations in dot-dash patterns.
Line width
Implementation of line width option depends on the capabilities of the output device to set the
line width attributes.
To set the line-width attributes using the following command
setLinewidthScaleFactor (lw)
Line width parameter lw is assigned a positive number to indicate the relative width of line to be
displayed.
A value of 1 specifies a standard width line.
To set lw to a value of 0.5 to plot a line whose width is half that of the standard line.
Values greater than 1 produce lines thicker than the standard.
Computer Graphics
Line Cap
To adjust the shape of the line ends to give them a better appearance by adding line cap (Fig: 2.8). 37
There are three types of line cap. They are
1. Butt cap
2. Round cap
3. Projecting square cap
40
For fill style pattern, table entries can be created on individual output devices with the following
function
setPatternRepresentation (ws,pi,nx,ny,cp)
Parameter pi sets the pattern index number for workstation code ws, and cp is a two dimensional
array of color codes with nx columns and ny rows. For example the following function could be used to
set the first entry in the pattern table for workstation 1.
cp [1,1 ] = 4; cp [2,2] = 4;
cp [1,2] = 0; cp[2,1] = 0;
setPatternRepresentation (1,1,2,2,cp);
When color array cp is to be applied to fill a region, we need to specify the size of an array with
the following function
setPatternSize( dx,dy)
Where parameters dx and dy give the coordinate width and height of the array mapping. Then a
reference position for starting a pattern fill is assigned with the following statement;
setPatternReferencePoint (position);
Where parameter position is a pointer to coordinates (xp,yp) that fix the lower left corner of the
rectangular pattern.
Tiling:
The process of filling an area with a rectangular pattern is called tiling and it is also referred to as
tiling patterns.
Soft Fill:
Soft fill or tint fill algorithms are applied to repaint areas so that the fill color is combined with
background color. An example of this type of fill is linear soft fill algorithm repaints an area by merging a
fore ground color F with a single background color B, Where F is not equal B.
Character Attributes
The appearance of displayed character is controlled by attributes such as font, size, color and
orientation.
Computer Graphics
Attributes can be set both for entire character strings (text) and for individual characters defined
as marker symbols. 41
Text Attributes
The choice of font or type face is set of characters with a particular design style as courier,
Helvetica, times roman, and various symbol groups.
The characters in a selected font also are displayed with styles (solid, dotted, double) in bold face
in italics and in outline or shadow styles.
A particular font and associated style is selected in a PHIGS program by setting an integer code
for the text font parameter tf in the function
setTextFont (tf)
Control of text color (or intensity) is managed from an application program with
setTextColourIndex (tc)
Where text color parameter tc specifies an allowable color code.
We can adjust text size by scaling the overall dimensions of characters or by scaling only the
character width.
Character size is specified by points, where 1 point is 0.013837 inch. Point measurements specify
the size of the body of a character.
The distance between the bottom-line and the top line of the character body is same for all
characters in particular size and typeface, but width of the body may vary.
Proportionally spaced fonts assign a smaller body width to narrow characters such as i, j, l and f
compared to broad characters such as W or M.
Character height is defined as the distance between the base line and cap line of characters.
Text size can be adjusted without changing the width to height ratio of characters with
setCharacterHeight (ch)
Parameter ch is assigned a real value greater than 0 to set the coordinate height of capital letters.
Width 0.5 42
Width 1.0
Width 2.0
Spacing between characters is controlled separately with
setCharacterSpacing (cs)
Spacing
Spacing
S p ac i n g
Where the character-spacing parameter cs can he assigned any real value.
The orientation for a displayed character string is set according to the direction of the character up
vector
setCharacterUpVector (upvect)
Parameter upvect in this function is assigned two values that specify the x and y vector
components.
Text is displayed so that the orientation of characters from base line to cap line is in the direction
of the up vector. For example, upvect = (1, 1) is displayed the text in 450 as shown in the following
figure.
D.Ananthi.,M.Sc.,M.Phil.,B.Ed.,SET.,
Computer Graphics
To arrange character strings vertically or horizontally
setTextPath (tp) 43
tp can be assigned the value: right, left, up, or down
Another attribute for character strings is alignment. This attribute specifies how text is to be
positioned with respect to the start coordinates. Alignment attributes are set with
SetTextAlignment (h,v)
Where parameters h and v control horizontal and vertical alignment.
ST RING
GNIRTS STRING
STRING
setMarkerSizeScaleFactor (ms)
With parameter marker size ms assigned a positive number. This scaling parameter is applied to
the nominal size for the particular marker symbol.
Values greater than 1 increase the marker size and values less than one reduce the marker size.
D.Ananthi.,M.Sc.,M.Phil.,B.Ed.,SET.,
Computer Graphics
Marker color is specified with
SetPolymarkerColourIndex (mc) 44
Selected color code parameter mc is stored in the current attribute list and used to display
subsequently specified marker primitives
Bundled Attributes
A single attribute that specifies exactly how a primitive is to be displayed with that attribute
setting. These specifications are called individual or unbundled attributes.
A particular set of attributes values for a primitive on each output device is chosen by specifying
appropriate table index. Attributes specified in this manner are called bundled attributes.
The table for each primitive that defines groups of attribute values to be used on particular output
devices is called a bundle table.
The choice between a bundled or an unbundled specification is made by setting a switch called
the aspect source flag for each of these attributes
setIndividualASF( attributeptr, flagptr)
Where parameter attributerptr points to a list of attributes and parameter flagptr points to the
corresponding list of aspect source flags.
Each aspect source flag can be assigned a value of individual or bundled.
Bundled line Attributes
Entries in the bundle table for line attributes on a specified workstation are set with the function
A poly line that is assigned a table index value of 3 would be displayed using dashed lines at half
thickness in a blue color on work station 1; while on workstation 4, this same index generates solid,
standard-sized white lines.
Once the bundled tables have been set up, a group of bundled line attributes is chosen for each
workstation by specifying table index value;
D.Ananthi.,M.Sc.,M.Phil.,B.Ed.,SET.,
Computer Graphics
setPolylineIndex (li);
Bundled Area fills Attributes 45
Table entries for bundled area-fill attributes are set with
setInteriorRepresentation (ws, fi, fs, pi, fc)
Which defines the attributes list corresponding to fill index fi on workstation ws.
Parameter fs, pi and fc are assigned values for the fill style, pattern index and fill color
respectively.
A particular attribute bundle is selected from the table with the function
setInteriorIndex (fi);
Bundled Text Attributes
Table entries for bundled text attributes are set with
setTextRepresentation (ws, ti, tf, tp, te, ts, tc)
Bundles values for text font, precision,expansion factor, size and color in a table position for
work station ws that is specified by value assigned to text index parameter ti.
A particular text index value is chosen with the function
setTextIndex (ti);
Bundled Marker Attributes
Table entries for bundled marker attributes are set with
setPolymarkerRepresentation (ws, mi, mt, ms, mc)
That defines marker type, marker scale factor, marker color for index mi on workstation ws.
Bundle table selections are made with the function
setPolymarkerIndex (mi);
COLOUR AND GRAYSCALE LEVELS
Colour options are numerically coded with values ranging from 0 through the positive integers.
These color codes are converted to intensity level settings for the electron beams in CRT
monitors.
Color Tables
Color information can be stored in the frame buffer in two ways :
o The colour codes can be directly put in the frame buffer (or)
o Colour codes can be maintained in a separate table and pixel values can be used as an
index into this table.
D.Ananthi.,M.Sc.,M.Phil.,B.Ed.,SET.,
Computer Graphics
46
D.Ananthi.,M.Sc.,M.Phil.,B.Ed.,SET.,
Computer Graphics
47
D.Ananthi.,M.Sc.,M.Phil.,B.Ed.,SET.,