0% found this document useful (0 votes)
17 views44 pages

CG Chapter1

This document discusses computer graphics primitives. It begins by defining computer graphics as the creation and manipulation of pictures with computers. It then discusses some common applications of computer graphics like CAD, presentations, entertainment, and visualization. Next, it describes the components of interactive graphics systems including the frame buffer, display controller, and monitor. It explains how graphics primitives like points, lines and polygons are stored and displayed on raster scan devices. Finally, it covers color representation methods for graphics like grayscale, primary colors, and true color frame buffers.

Uploaded by

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

CG Chapter1

This document discusses computer graphics primitives. It begins by defining computer graphics as the creation and manipulation of pictures with computers. It then discusses some common applications of computer graphics like CAD, presentations, entertainment, and visualization. Next, it describes the components of interactive graphics systems including the frame buffer, display controller, and monitor. It explains how graphics primitives like points, lines and polygons are stored and displayed on raster scan devices. Finally, it covers color representation methods for graphics like grayscale, primary colors, and true color frame buffers.

Uploaded by

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

Computer Graphics

Chapter 1- Graphics Primitives

Graphics Primitives 1 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Introduction

What is computer graphics?


CG is creation and manipulation of pictures with the help of
computers.
Pictures consists of points and a drawing algorithm stored in a
file to display them.
Most pictures are simple enough that simple data structures like
Linked lists that can be easily accessed are used.
But Complex Pictures requires complex algorithms to access them.
) They contain data organized in complex data structures such as
Trees.

Graphics Primitives 2 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Application of Computer Graphics


Computer-Aided Design (CAD)
Presentation Graphics: To produce illustrations which summarize
various kinds of data.
Computer Art: artists can produce electronic paintings.
Entertainment: Music videos, and TV shows, Computer games.
Education and Training: training of ship captains and pilots.
Visualization: For analyzing scientific, engineering, and medicals.
Graphical User Interface Multiple window, icons, menus.

(Loading)

Graphics Primitives 3 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Interactive Computer Graphics


Interactive: User has control over the image.
Involves a two way communication between computer and user
Interactive graphics display consists of three components.
1 Frame buffer
2 Display controller
3 Monitor/Display device

Block diagram of a CRT graphics system

Graphics Primitives 4 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Frame Buffer
A block of memory dedicated to graphics output, that holds the
contents of what will be displayed on the raster display.
Raster-is a Rectangular array of points or dots or pixels.
It acts as a temporary store of the image
It also acts as a decoupler to allow the graphics processor and the
display controller to operate at different speeds

Display Controller
Reads the buffer contents row by row and display them on the
display device.
It is responsible for generating the timing of video signals such as
the horizontal & vertical synchronization signals and the
blanking interval signal.

Graphics Primitives 5 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Display Devices

Vector(Random scan) Display Raster scan Dispaly


Lines drawn directly, no Image stored in a frame buffer
predefined grid Electron gun(s) continually
commands tell the electron gun scanning in a regular pattern
where to move and when to (line by line across entire
turn on/off screen)
+ Lines are smooth + Constant time to redraw any
+ Close to the ’pure number of elements
mathematics’ of the model + No flicker
-Slower with more elements to -jagged edges in conversion to
be drawn, can start to flicker pixels
-Only lines possible, no filled -discretized version of the
polygons, or bitmaps model

Graphics Primitives 6 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Display Device

Vector Dispaly Raster Display

Graphics Primitives 7 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Raster Display Frame Buffer


Picture definition is stored in a memory area called the frame buffer.
This frame buffer stores the intensity values for all the screen points
called a pixel.
On black and white systems, the frame buffer storing the values of
the pixels is called a bitmap or bit plane.
Each entry in the bitmap is a 1-bit data which determine the on (1)
and off (0) of the intensity of the pixel.
A 1024 by 1024 element square raster requires 220 bits in a single bit
plane. Since a memory bit has only two states 0 and 1.
A sigle bit plane yields a black and white display.
DAC- Convert the digital representation into analog signal.

Graphics Primitives 8 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

A single bit plane (1bit/pixel) Black & White frame buffer raster

Graphics Primitives 9 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Gray Scale Levels


Grayscale is an in which the value of each pixel carries only intensity
information.
The darkest possible shade is black, and the lightest possible shade
is white.
Bit values are loaded from each N planes to a register, the resulting
number is interpretted as intesity level b/n 0 and 2N − 1.
This is converted to analog voltage b/n 0 and tha max. voltage of
the electron gun by the DAC.

Graphics Primitives 10 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

An N bit plane gray level frame buffer

Graphics Primitives 11 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Primary Colors

A simple color frame buffer combined 10 colors at CRT


yields

Graphics Primitives 12 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Shades of intensities of colors

Full color or True color Frame buffer

1.How much memory is needed for a 1024 x 1024 raster display using
true color frame buffer?
2.If each pixel has different color how many colors will be on the
screen?
Graphics Primitives 13 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Solution
1 True color frame buffer(24 bit per pixel)
⇒ 1 pixel = 24 bit of memory and also
⇒ Resolution= 1024 x 1024
Resolution: The maximum number of points that can be displayed
without overlap on a CRT.
Then, the size of frame buffer = Resolution x bits per pixel
= (1024 x 1024) x 24 bits
= 3MB (∵ 1M=1024 x 1024 bits and 3B=24 bits)
2 If each pixel has different color:
∴ #colors on the screen = #pixels of the screen
(i.e. 1024x1024 ≈ 1 million colors).

Graphics Primitives 14 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Color Lookup Table or Palette


It is an excellent compromise b/n lower storage requirment and
reasonably sufficient number of simultanous colors.
Color values are stored in lookup table, where frame-buffer values
are now used as indices into the color table.

Graphics Primitives 15 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

CLUT
As shown in the above figure each 256 entries contains a 24 bit RGB
color value.
Using lookup table would allow a user to select any 256 colors for
simultaneous display from a palette of nearly 17 million colors.
For most applications, 256 or 512 different colors are sufficient for a
single picture.
- This scheme reduces the number of simultaneous colors that can
be displayed.
But table entries can be changed at any time.
+ It reduces the frame buffer storage requirements from 3MB to
1MB + 768 Bytes.

Graphics Primitives 16 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Display Monitor

CRT with Phosphorus Coated Screen


Phosphorus: is coated inside a display screen and emits light for a
period of time when hit by beam of electrons.
Fluorescence: is the light givenoff by the phosphorus during
exposure to the electron beam.
Phosphorescence: is the continuing glow after the beam is
removed.
Persistence: is the duration of phosphorescence.
In general one type of phophorus vary from another by two things.
1 Color of light
2 Persistence

Graphics Primitives 17 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

CRT
Electron gun: heated to send out electron’s.
Electron beam strikes each and every pixel position in a scan line
fashion.
Control grid: control intensity value of electron beams by setting
voltage levels.
Focusing electrod: force electron beam to (narrow) converge
inorder to strike the phosphorus coating at small spot.
Horizontal deflection plates: control the beams to scan from left
to right and retrace from right to left.
Vertical deflection plate: control the beams to go vertically.
The control circuits shut off the electron beam during the
horizontal and vertical retraces.

Graphics Primitives 19 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Analogy of Monochromatic CRT (Raster refresh)

Graphics Primitives 18 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Retracing
Horizontal Retrace: The return to the left of the screen, after
refreshing each scan line.
Vertical Retrace: The return to the top left corner of the screen to
begin the next frame.

Graphics Primitives 20 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Refresh rate
Refresh rate: is the frequancy at which the content of frame buffer
is sent to the display monitor, w/c is normally 60 to 80 frames/sec.
Flicker is a visible fading between cycles displayed on video displays,
especially in the refresh interval on cathode ray tube (CRT)
To avoid flickering some monitors use interlacing technique (double
their refresh rate).
In this case, First the odd numbered lines(pass 1), then the even
numbered lines(pass 2) are refreshed.
This works best when the adjacent scan lines contain similar display
information.
Ex. What is the fraction of the total refresh time per frame spent in
retrace of the electron beam for a noninterlaced raster system with a
resolution of 1280 by 1024, a refresh rate of 60 Hz, a horizontal retrace
time of 5µsec, and a vertical retrace time of 500µsec?
Graphics Primitives 21 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Color Display

Beam penetration method in random scan display


Two layers of phosphor (red and green) are coated onto the inside of
the CRT screen.
The displayed colors depends on how far the electron beam
penetrates into the phosphors layers.
A slow electron beam excites only the outer red layer.
A very fast electron beam penetrates trough the red layer and hence
excites the green layer.
An average electron beam gives the combination of red and green
color(yellow and orange). This technique only provides four colors.

Graphics Primitives 22 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Color Display

Shadow mask method in Raster Scan display


A shadow Mask CRT has three phosphor color dots at each pixel
location. These are Red, Green and Blue phosphoruses.
A shadow mask grid is installed behind the phosphor coated screen.
The three electron beams are deflected and focused as a group onto
the shadow mask, which contains a series of very fine holes aligned
with the phosphor dot patterns.
The tiny holes on the shadew mask constrain each electron beam to
hit its corresponding phosphorus dots.
The light emitted by the 3 types of phosphoruses blends together to
give us a broad range of colors.

Graphics Primitives 23 / 44
OverView of Graphics Systems Output Primitivies Introduction Applications Video Display Devices

Graphics Primitives 24 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Point Plotting
Point: is the unit of a graphical picture.
Picture in raster scan): is the set of intensities of the pixel
positions in display.
How the electron beam is positioned depends on the display
technology.
Point Plotting: with a CRT monitor electron beam turned on to
illuminate the screen phosphorus at the selected point or position.
A Random scan system stores point-plotting instructions in the
display list, and coordinate values in these instructions are converted
to deflection voltages that position the electron beam at the screen
locations to be plotted.

Graphics Primitives 25 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Line drawing in Raster scan display


A line is drawn by plotting discrete points between the two
endpoints.
Discrete coordinate positions along the line path are calculated from
the equation of the line.
Screen locations are referenced with integer values, so plotted
positions may only approximate actual Line positions between two
specified endpoints. eg. (5.4 , 7.6) −→ (5,8)
Stairstep effect (jaggies) produced when a line is generated as a
series of pixel positions.

Graphics Primitives 26 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Line drawing algorithms


Assumptions:
Pixel position: Integer values.
Screen location: At first quadrant
To load a specified color into the frame buffer at a position
corresponding to column x along scan line y, setPixel(x,y)
To retrieve the current framebuffer intensity setting for a specified
location, getPixel(x,y)
The Algorithms:
1 Equation method

2 DDA(Digital Differential Analyzer)


3 Bresenham’s Line Algorithm

Graphics Primitives 27 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Equation Method
Equation of a straight line: y=m.x+b
Algorithm:
1 Read (x1,y1) , (x2,y2)
2 Find the slope: m= yx22−−xy11
3 Fine y-intercept: b=y1 - m.x1
4 x ← x1
5 while ( x ≤ x2 )
y=m.x + b
setPixel(x,y)
x++
end while
The equation method involves floating point multiplication, which
doesn’t make it fact.

Graphics Primitives 28 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

DDA(Digital Differential Analyzer)


It is the simple line generation algorithm.
The characteristic of the DDA algorithm is to take unit steps along
one coordinate and compute the corresponding values along the
other coordinate.
For m ≤ 1 ,
) sample @unit x-interval: xinc = 1, i.e. x k+1 = xk + 1
) Compute each succesive y-values as yk+1 = yk + m and rounded to
the nearest integer value.
For m > 1 ,
) Sample @unit y-interval: yinc = 1, i.e. yk+1 = yk + 1
) Compute xk+1 = xk + m 1

Graphics Primitives 29 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

DDA Algorithm:
DDA( xa , ya , xb , yb )
step 1. Δx ← xb - xa , Δy ← yb - ya
step 2. if (abs(Δx) > abs(Δy) )
steps ← Δx
else steps ← Δy
step 3. xinc ← steps
Δx

yinc ← steps
Δy

step 4. x ← xa and y ← ya
setPixel(x , y)
step 5. for k = 0 to steps
x ← x + xinc
y ← y + yinc
setPixel( Round(x) , Round(y) )

eg. Using DDA algorithm determine the intermidiate points of the line
which has end points at (2,5) and (10,9) .
Graphics Primitives 30 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Pros and Cons of DDA


Faster than the equation method, as no multiplication is involved.
But there is accumulation of round off errors in succesive additions
of the floating point increment.
This can cause pixel positions to drift away from the true line path
for long line segments.
Round off and floating point operations are time consuming.

Graphics Primitives 31 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Bresenham’s Line Drawing Algorithm


Accurate and efficient line drawing algorithm
It uses only incremental integer calculations.
Works by determining the closer pixel to the true line
path(mathematical line path).
Consider lines with +ve slope < 1: Moving across the x axis in unit
intervals and at each step choose between two different y
coordinates.

Graphics Primitives 32 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

A decision parameter P k for the K th step (+ve slope < 1)


y-coordinate on the mathematical line @pixel position xk+1 is
y = m(xk + 1) + b
dlower = y - yk ⇒ m(xk + 1) + b - yk and
dupper = yk + 1 - y ⇒ (yk + 1) - m(xk + 1) - b
dlower - dupper = 2m(xk + 1) - 2yk + 2b - 1
Δy
Reduce this evaluation by finding slope and substituting: m = Δx
So now, (dlower - dupper ) = 2 ΔΔ yx (x k + 1) - 2yk + 2b - 1
Expand 1st term so, (dlower - dupper ) = 2 ΔΔ yx xk + 2 ΔΔ yx - 2yk + 2b - 1
To simplify this expression we will create a new decision variable P k :
P k = Δx (dlower - dupper ) this is will remove the divisions and will
still keep the same sign for the decision. Why?
∵ Δ x is always positive!

∴ If P k is -ve, choose the lower pixel, otherwise choose the upper pixel.

Graphics Primitives 33 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Evaluate Pk as follows:
P k = Δ x (dlower - dupper ) ⇒ Δx( 2 ΔΔ yx xk + 2 ΔΔ yx - 2yk + 2b - 1 )
⇒ 2Δy*xk + 2Δy - 2Δx*yk + 2Δx*b - Δx
Rearrange the terms to get:
P k = 2Δy*xk - 2Δx*yk + C where C = 2Δy + Δx(2b - 1)
This C remains constant regardless of choice of x and y.
Here, It still requires a complete evaluation of P(k) for each point
along the line. so, P k+1 = 2Δy*xk+1 - 2Δx*yk+1 + C
By evaluating an incremental change in pk :
P k+1 - P k = 2Δy(xk+1 - xk ) - 2Δx(yk+1 - yk ), but xk+1 = xk +1
So, P k+1 = P k + 2Δy - 2Δx(yk+1 - yk )
where yk+1 - yk is either 0 or 1 depending on the sign of pk

pk + 2 Δ y, if P k < 0
pk +1 =
pk + 2 Δ y − 2 Δ x, otherwise

Graphics Primitives 34 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Evaluate the initial decision value p0


P k = 2Δy*xk - 2Δx*yk + 2Δy + Δx(2b - 1)
P0 = 2Δy*x0 - 2Δx*y0 + 2Δy + Δx(2b - 1)
Using the point-slope equation of line:
y0 = m*x0 + b so substitute b = y0 - m*x0
P0 = 2Δy*x0 - 2Δx*y0 + 2Δy + Δx(2( y0 - m*x0 ) - 1)
Substitute m = ΔΔyx
Δy
P0 = 2Δy*x0 - 2Δx*y0 + 2Δy + Δx(2( y0 - Δ x *x0 ) - 1)
P0 = 2Δy*x0 - 2Δx*y0 + 2Δy + 2Δx( y0 - ΔΔxy *x0 ) - Δx
P 0 = 2Δy*x0 - 2Δx*y0 + 2Δy + 2Δx*y0 - 2Δy*x0 - Δx
∴ P 0 = 2Δ y - Δ x

Graphics Primitives 35 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Bresenham’s algorithm for +ve slope(m < 1)


Step 1. Input the two end-points of line, storing the left end-point
in (x0 , y0)
Step 2. Plot the point (x0 , y0)
Step 3. Calculate the constants Δx, Δy, 2Δy, (2Δy – 2Δx) and
get the first value for the decision parameter as p0 = 2Δy - Δx
Step 4. At each xk along the line, starting at k = 0, perform the
following test:
If pk < 0, the next point to plot is (xk + 1 , yk ) and
P k+1 = pk + 2Δy
Otherwise, next point to plot is (xk + 1 , yk + 1) and
P k+1 = pk + 2Δy - 2Δx
Step 5. Repeat step 4 (Δx – 1) times

Graphics Primitives 36 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Summary of Bresenham’s algorithm


For a line with +ve slope > 1, interchange the roles of x and y
directions (we step along y-direction in unit step).
If the initial position for a line with positive slope is the right end
point, both x and y decreases as we step from right to left.
If dlower = dupper always choose the upper or lower of the two
candi points.
Special cases that hahdle separately: when

Δx = 0 , Δy = 0 and Δ x = Δy

No need to pass through the line drawing algorithm.

Assignment 1

Graphics Primitives 37 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Circle Generating Algorithm

Properties of Circle
Circle: is set of points @a given distance from central position
( xc = a , yc = b)

(x - xc )2 + (y - yc )2 = r2

Graphics Primitives 38 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Equation method
Calculate position of points on a circle by stepping along the x-axis
in unit steps from xc - r to xc + r and
Calculate the corresponding y value @each position as
q
y = yc ± r 2 − (x − xc )2

Problems:
It involves considerable computation at each step.
Moreover, the spacing between plotted pixel positions is not uniform.
To adjust the spacing, interchange the roles of x and y whenever the
absolute value of the slope of the circle is greater than 1.
But this increases the computation required by the algorithm.

Graphics Primitives 39 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Trignometric Method
Another way to eliminate the unequal spacing by calculate points
along the circular boundary using polar coordinates r and θ.

x = xc + rcosθ and y = yc + rsinθ

Problem: The parametric equation contain multiplications and


trigonometric calculations.

Eight way symmetry

Graphics Primitives 40 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

MidPoint Circle Algorithm


We sample @unit interval and determine the closest pixel position
to the specified circle path @each step.
First set up the algorithm to calculate pixel positions around a circle
path(x = 0 to x = y) centered at the coordinate origin (0,0).
To apply the midpoint method, we define fcircle(x , y) = x2 + y2 - r2

< 0, if (x , y) is inside the circle boundary


fcircle (x,y) = = 0, if (x , y) is on the circle boundary
> 0, if (x , y) is outside the circle boundary

Pixel drawn at (xk , yk ) , What is the next pixel?


(xk + 1 , yk ) or (xk + 1 , yk - 1), we use a decision parameter(circle
function) to decide which point is nearer to the actual circle path.

Graphics Primitives 41 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Decision Parameters pk
pk = fcircle (xk + 1 , yk - 12 ) ⇒ (xk + 1)2 + (yk - 12 )2 - r 2

(xk + 1,y k), if pk < 0


Next pixel =
(xk + 1,yk − 1), otherwise

Graphics Primitives 42 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Successive decision parameter


Successive decision parameters are obtained using incremental
calculations.
pk +1 = fcircle (xk +1 + 1 , yk +1 - 21 )
pk +1 ⇒ [(xk + 1) + 1]2 + (yk +1 - 12 )2 - r 2
pk +1 ⇒ pk + 2(xk + 1) + (y2k +1 - y2k ) - (yk +1 - yk ) + 1

pk + 2x k +1 + 1, if pk < 0
pk +1 =
pk + 2xk +1 − 2yk +1 + 1, otherwise

Where 2xk+1 = 2xk + 2 and 2yk+1 = 2yk - 2


The initial decision parameter is obtained by evaluating the circle
function at the start position (x 0 , y0) = (0 , r) is p0 = 54 - r ≈ 1 - r

Graphics Primitives 43 / 44
OverView of Graphics Systems Output Primitivies Points Lines Circle

Midpoint circle generating algorithm


1 Read the radius r and the center (xc , yc )
2 x←0 , y←r , p0 = 1-r , and k←0
3 At each xk position, starting at k = 0 until x ≥ y, perform
If pk < 0, the next pixel is (xk + 1 , yk ) and pk+1 = pk + 2xk+1 + 1
Otherwise, the nest pixel is (xk + 1 , yk - 1) and
pk+1 = pk + 2xk+1 - 2yk+1 + 1
4 Deterrmine symmetry points in the other seven octants.
5 Move the pixel positions to the circular path centered at (xc , yc ).
x = x + xc and y = y + yc

eg. Given a circle radius r = 10 and (xc , yc ) = (0 , 0) , demonstrate the


midpoint circle algorithm by determining positions along the circle octant
in the first quadrant from x = 0 to x = y.

Graphics Primitives 44 / 44

You might also like