CG Into ch1

Download as pdf or txt
Download as pdf or txt
You are on page 1of 83

Computer Graphics

Basic of Computer Graphics


Applications of computer graphics
Display devices -construction of CRT
Random and Raster scan systems Random and Raster scan systems
Graphics input devices
Graphics software and standards
Introduction
Graphics
Refers to any computer device or program that
makes a computer capable of displaying and
manipulating pictures. manipulating pictures.
Computer Graphics
graphics created using computers and, more
generally, the representation and manipulation
of image data by a computer
Applications of C. G.
Computer-aided Design(CAD)
Presentation Graphics
Computer Art (Animation)
Entertainment Entertainment
Education & Training
Visulization (scientific or business)
Presentation Graphics:
CT scan
CAD-CAM
CAD/CAM
CAD/CAM
Entertainment
Graphics/Animation for Entertainment Graphics/Animation for Entertainment
Entertainment
Edutainment
Graphics/Animation for Edutainment Graphics/Animation for Edutainment
Edutainment
Simulators for Training
BASIC TERMS
PIXEL
RESOLUTION
ASPECT RATIO ASPECT RATIO
REFREC RATE
FRAME BUFFER(Refrace Buffer)
Pixel: Smallest addressable element on the screen.
Resolution:
The maximum number of points that can be displayed
without overlap on a CRT. without overlap on a CRT.
or
The number of pixels plotted in x-direction multiply
by in y-direction.
Eg: 640 x 480
No. of Pixels in x-direction: 640 (0-639)
No. of Pixels in y-direction:480 (0-479)
Minimum (0,0) to maximum (639,479)
Aspect Ratio:
Ratio of No. of pixels in y-direction divide by No. of
pixels in x-direction.
It is used to produce equal length lines in both the It is used to produce equal length lines in both the
direction in the screen.
Eg. Resolution : 640 x 480
Aspect Ratio : 480/640=
NOTE:
A.R =3/4 means vertical line plotted with 3 points has
the same length as horizontal line plotted with 4 points.
Frame buffer(Refrace Buffer):
Picture defination is stored in a memory area called the
Frame buffer.
This memory area holds the set of intensity values for all This memory area holds the set of intensity values for all
the screen points(pixels).
Refrace Rate:
Refresh rate on a computer is used to describe how often a
monitor draws the current data to the screen.
Refresh rate effects visual quality for CRT, LCD.
Unit: hertz (60 or 80) or fames per second or cycles per
second.
Depends on picture complexity(no. of lines, points,
characters)
Display Devices/output
Devices
Types of Display systems:
1 Raster Scan Displays
2 Random scan displays
3 Direct view storage tube 3 Direct view storage tube
4 Flat panel displays
Parts of display system:
1. Display adapter : creates & holds the image information
2. Monitor
3. Cable
CRT(Cathod Ray Tube)
Fig 2.2 :Basic Operation of CRT:
The operation of CRT is based on the concept of
energizing an electron beam that strikes the
phosphor coated screen at very high speed.
A Beam of Electrons (Cathode Rays) emitted by the A Beam of Electrons (Cathode Rays) emitted by the
electron gun passes through focusing and deflection
systems.
Focusing system direct the beam toward specified
positions on the phosphor-coated screen.
The Phosphor emits visible light when the electrons
hit the screen.
The entire picture must be refreshed(redraw) by
quickly directing the electron beam back over the
same points repeatedly.
Heat supplied to the cathod by directing current Heat supplied to the cathod by directing current
through filament.
Intensity of the electron beam is controlled by
setting voltage levels on the control grid.
Focusing system is needed to force the electron
beam to coverage into a small spot as it strikes
the phosphor o/w electrons repel each other.
CRT(Cathod Ray Tube)
Fig 2.4: Electrostatic deflection of the electron
beam in CRT
Two pairs of parallel plates are mounted
inside the CRT envelope.
Horizontal plate is used to control vertical
deflection.
Horizontal plate is used to control vertical
deflection.
Vertical plate is used to control horizontal
deflection.
Random and Raster Scan Systems:
There are two types of display, random scan and
raster scan.
These are based on the scan technology that is
used to control the electron beam while generating used to control the electron beam while generating
graphics on the screen.
In random scan, graphic can be generated
randomly on the screen according to the choices of
input made by the user.
In raster scan system, the screen is scanned in
particular order, from left to right, top to bottom,
all the time to generate graphics.
Description of Raster scan:
The electron beam is swept across the screen ,
one row at a time from top to bottom.
Electron beam moves across each row, the
beam intensity is turned on and off to create a beam intensity is turned on and off to create a
pattern of illuminated spots.
Intensity values retrieved from frame buffer one
line at a time(scanline) according fig.
Intensity range for pixel positions depends on
the capability of the raster system.
Direct view storage tube(DVST)
DVST was introduced in 1960 as an alternative and
inexpensive solution to refresh display, which was
very expensive because of refresh buffer memory
and fast display process. and fast display process.
DVST eliminates the refresh processor completely
and use special type of phosphor embedded in a
storage tube that has a long lasting glowing effect.
An old picture has to be erased completely for a new
one to be drawn.
Due to lack of selective erasure, the DVST cannot
provide colours and animation.
Liquid Crystal Displays
Light passing
through the liquid
crystal is twisted so it
gets through the
polarizer
A voltage is applied A voltage is applied
using the
crisscrossing
conductors to stop
the twisting and turn
pixels off
Raster display, based on standard television
technology, was adopted in 1970 as a viable
alternative of DVST.
A typical resolution of a raster display is 1280 x
1024 and can reach upto 4096 x4096 as in DVST,
Raster Display
1024 and can reach upto 4096 x4096 as in DVST,
but at a comparatively much lower price. So it
became popular.
The most common method of implementing a
raster CRT graphics device is by using a frame
buffer.
As a minimum, there is one memory bit for each
pixel in the raster. This amount of memory is
called a bit plane.
A 512 x 512, that is, 2
9
x 2
9
elements square raster
requires 2
18
or 262144 memory bits in single bit
plane.
The picture is built up in the frame buffer one bit at a The picture is built up in the frame buffer one bit at a
time (either 0 or 1) causing black or white display.
Now, this bit information of frame buffer has to be
transformed to raster CRT which is an analog device.
So, DAC is required.
For more intensity levels, N bit plane frame buffer is used in
place of the one bit plane.
The intensity of each pixel on the CRT is controlled by a
corresponding pixel location in each of the N bit planes.
The binary value (0 or 1) for each of the N bit planes for grey The binary value (0 or 1) for each of the N bit planes for grey
levels is loaded into the corresponding position in a register.
The total of 8 (2
n=3
) intensity levels is possible with three bit
planes.
Each bit plane requires the full coplement of memory for given
raster resolution, e.g. 3 bit plane frame buffer for a 512 x 512
requires 3 x 512 x 512=786432 memory bits.
For colour display, a simple colour frame buffer
contains three bit planes for each primary colour, i.e.
red (R), green(G) and blue(B).
Each bit plane drives an individual colour gun for Each bit plane drives an individual colour gun for
each of the primary colours used in the colour video.
These three primary colours, RGB may be combined
at the CRT to yield eight colours.
More shades of RGB can be achieved by using
multiple bit plane colour frrame buffer with 8 bit
planes per colour, that is 24 bit plane frame buffer
which generates 2
8
=256 shades of RGB. These are
combined into (2
8
)
3
=16,777,216 possible colours.
Black and white system:
Each screen point is either on or off.
One bit per pixel is needed to control One bit per pixel is needed to control
the intensity of screen positions.
bit 1: electron beam turned on
bit 0 : electron beam turned off
For high-quality system: upto 24 bits/pixel
(additional bits for color and intensity
variations)
Contd
A system with 24 bits per pixel & screen
resolution of 1024 x 1024 require 3
megabytes of storage for frame buffer.
Bitmap: on black & white system with Bitmap: on black & white system with
one bit per pixel, the frame buffer called
bitmap.
Pixmap: For the systems with multiple
bits per pixel , the frame buffer called
pixmap.
Horizontal Retrace:
At the end of each scan line, the
electron beam returns to the left of the
screen to begin displaying the next scan
electron beam returns to the left of the
screen to begin displaying the next scan
line.
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.
Output Primitives
DDA Line Drawing algorithm
Bresenhams Line Drawing Algorithm
(for all cases) (for all cases)
Bresenhams Cirlcle (Midpoint) Drawing
Algorithm
Bresenhams Ellipse (Midpoint) Drawing
Algorithm
WHERE TO DRAW A LINE??
Line drawing is accomplished by calculating
intermediate positions along the line path between
specified end points.
The Cartesian slope-intercept equation for a straight The Cartesian slope-intercept equation for a straight
line is
y= m. x + b
m is the slope of the line and b is the y intercept.
Given the endpoints of a line segment.
m = y2-y1 / x2-x1
b= y1-m.x1
Line Drawing (cont)
Also for any given interval x along a line, we can
compute the corresponding y interval y from
y= m. x
Similarly we can obtain the x interval x Similarly we can obtain the x interval x
corresponding to a specified y as
x= y / m
These equations form the basis for determining
deflection voltages in analog devices.
Line Drawing (cont)
On Raster systems, lines are plotted with pixels,
and step sizes in the horizontal and vertical
directions are constrained by pixel separations.
Hence we ought to sample a line at discrete
positions and determine the nearest pixel to the positions and determine the nearest pixel to the
line at each sampled position.
DDA ALGORITHM
The digital differential analyzer (DDA) samples the line at unit
intervals in one coordinate corresponding integer values nearest
the line path of the other coordinate.
The following is thus the basic incremental scan- The following is thus the basic incremental scan-
conversion(DDA) algorithm for line drawing
for x from x0 to x1
Compute y=mx+b
Draw_fn(x, round(y))
Major deficiency in the above approach :
Uses floats
Has rounding operations
Consider first a line with positive slope, if slope is less
than 1, we sample at unit x intervals (x=1) and
compute each successive y value as
y
k+1
=y
k
+m y
k+1
=y
k
+m
Where k takes integer values starting from 1, for the
first point, and increases by 1 until final endpoint is
reached.
For lines with a positive slope greater than 1, we
sample at unit y intervals (y=1) and calculate each
succeeding x value as
X
k+1
= x
k
+ 1/m
Both the previous equation are to be processed from
the left end point to the right endpoint.
If this processing is reversed, so that the starting
endpoint is at the right, then we have x=-1 endpoint is at the right, then we have x=-1
y
k+1
=y
k
- m
for y=-1
X
k+1
= x
k
- 1/m
DDA Illustration
(x , y )
(x
i
+1, Round(y
j
+m))
Desired Line
(x
i
, Round(y
j
))
(x
i
+1, y
j
+m)
(x
i
, y
j
)
x1 x2
y2
y1
DDA Algorithm
Procedure lineDDA (xa , ya, xb, yb : integer);
Var
dx , dy , steps , k : integer;
xIncrement , yIncrement , x, y : real;
Begin Begin
Dx := xb-xa;
Dy := yb-ya;
If abs(dx ) > abs( dy) then
Steps :=abs( dx);
Else
Steps:=abs( dy);
xIncrement := dx/steps;
yIncrement := dy/steps;
X := xa;
Y := ya;
Setpixel (round(x),round(y),1);
For k:=1 to steps do For k:=1 to steps do
begin
x:=x + xIncrement;
Y:=y + yIncrement;
Setpixel (round(x),round(y),1)
End
End; (lineDDA)
Advantages:
A. DDA Algorithm is faster than other because it calculates points
on the line w/o any floating point multiplication.
B. It is a simplest algorithm & does not require Skills for
implementation. implementation.
Disadvantages:
A. It is orientation dependent, due to this the end point accuracy
is poor.
B. Floating Point arithmetic in DDA Algorithm is still time
consuming.
Bresenhams Line drawing algorithm:
Accurate & Efficient line generating algorithm.
Scan converts lines using only incremental integer
calculations.
First approcach for ( slop is positive but <1): First approcach for ( slop is positive but <1):
I. Pixel positions along a line path determined by
sampling at unit x intervals .
II. Starting from the left end point (x
0
,y
0
) of given line ,
step to each successive column ( x position) and
plot the pixel whose scan-line y value is closet to
the line path.
Assuming that the pixel at (x
k
, y
k
) is to be
displayed, next need to decide which pixel to plot in
column x
k+1.
Our choices are the pixels at positions (x
k
+ 1, y
k
) Our choices are the pixels at positions (x
k
+ 1, y
k
)
and (x
k
+ 1, y
k+1
)
At sampling position x
k
+ 1, we label vertical pixel
separations from the mathematical line path as d1
and d2.
For slope(m) >0
(positive)
Find (11,11) or
(11,12) near to
Y axis- scan line conversion
X axis- pixel columns
(11,12) near to
(10,11)
For slope(m) < 0
(Negative)
Find (51,49) or
(51,50) near to
(50,50)
Find the nearest pixel of x
K+1
(k
th
step process)
Two possibility (x
k
+ 1 , y
k
) OR (x
k
+ 1 , y
k
+1 )
y = m (x
k
+ 1) + b
Vertical pixel separations from the
mathematical path as d1 & d2:
d1 = y - y
k
d2 = (y
k
+1) - y
A decision parameter p
k
for the kth step in the line algorithm
canbe obtained by rearranging equation of d1-d2, so it involves
only integer calculations.
By substituting m=y/ x, where y and x are the vertical
and horizontal separations of the endpoint positions, and and horizontal separations of the endpoint positions, and
defining:
P
k
= x(d1-d2)
=2y*x
k
-2x*y
k
+c
Where c is constant and has value 2y+x(2b-1)
If the pixel at y
k
is closer to the lline path than the pixel at y
k
+1
i.e. d1<d2 then decision parameter p
k
is negative.
In that case, we plot the lower pixel, otherwise we plot the
upper pixel.
N
o
w, at step k+1, the decision parameter is
evaluated from equation of p
k
as,
p
k+1
= 2y*x
k+1
-2x*y
k+1
+c
Subtracting the equation, Subtracting the equation,
p
k+1
p
k
= 2y*(x
k+1
- x
k
) -2x*(y
k+1
-y
k
)
But x
k+1
= x
k
+1 so that
p
k+1
= p
k
+ 2y - 2x*(y
k+1
-y
k
)
The first parameter, p
0
is evaluated from equation of p
k
at the starting pixel (x
0
,y
0
) and with m evaluated as
y/ x:
P
0
=2 y- x
Bresenhams Line-Drawing Algo(for |m|<1
1. Input the Two Line Endpoints and store the Left Endpoint in (x
0,
y
0
).
2. Load (x
0,
y
0
) into the Frame Buffer ; means plot the first point.
3. Calculate Constant x, y , 2 y and 2 y 2 x , and obtain the starting
value for the decision parameter as value for the decision parameter as
p0 = 2 y - x
4. At each x
k
along the line , starting at k=0 , Perform the following test : IF p
k
<
0 , the next point to plot is (x
K
+1,y
k
) and
p
K
+1=p
K
+ 2 y
Otherwise , the next point to plot is (x
K
+1, y
K
+1) and
p
K
+1=p
K
+ 2 y - 2 x
5. Repeat step 4 x times.
Procedure lineBre ( x
a
, y
a
, x
b
,y
b
: integer)
Var
dx, dy, x, y, xEnd, p : integer;
Begin
dx := abs(x
a
- x
b
);
a b
dy := abs(y
a
- y
b
);
[determine which point to use as start , which as end]
If x
a
> x
b
then
begin
x := x
b
;
y := y
b
;
xEnd := x
a
;
End { if x
a
> x
b
)
Else
Begin
x := x
a
;
y := y
a
;
xEnd := x
b
;
End;
Setpixel (x,y,1);
while x < xEnd do
begin
x := x+1;
if p< 0 then p := p+2 *dy
else
begin
y := y+1;
p := p+2 * (dy-dx)
end;
setpixel (x,y,1)
end;
End; {linebre}
Example on bresenham line drawing
The line with endpoints (20,10) and
(30,18).
Calculate slope and x and y .
Start with the initial decision parameter has the value p
0.
Determine increments for calculating successive decision
parameters p
k+1.
k p
k
(x
k+1
, y
k+1
)
0 6 (21,11)
1 2 (22,12)
2 -2 (23,12) 2 -2 (23,12)
3 14 (24,13)
4 10 (25,14)
5 6 (26,15)
6 2 (27,16)
7 -2 (28,16)
8 14 (29,17)
9 10 (30,18)
Where do we draw a circle???
Properties of a circle:
A circle is defined as a set of points that are all the given
distance (x
c
,y
c
). This distance relationship is expressed by the
pythagorean theorem in Cartesian coordinates as
(x x
c
)
2
+ (y y
c
)
2
= r
2
(x x
c
) + (y y
c
) = r
We could use this equation to calculate the points on the circle
circumference by stepping along x-axis in unit steps from x
c
-r to
x
c
+r and calculate the corresponding y values at each position
as
y = y
c
+(- ) (r
2
(xc x )
2
)
1/2
This is not the best method:
Considerable amount of computation
Spacing between plotted pixels is not uniform
Polar co-ordinates for a circle
We could use polar coordinates r and ,
x = x
c
+ r cos y = y
c
+ r sin
A fixed angular step size can be used to plot equally spaced
points along the circumference
A step size of 1/r can be used to set pixel positions to
approximately 1 unit apart for a continuous boundary
But, note that circle sections in adjacent octants within one
quadrant are symmetric with respect to the 45 deg line dividing
the to octants
Thus we can generate all pixel positions around a circle by
calculating just the points within the sector from x=0 to x=y
This method is still computationally expensive
Bresenham to Midpoint
Bresenham requires explicit equation
Not always convenient (many equations
are implicit) are implicit)
Based on implicit equations: Midpoint
Algorithm (circle, ellipse, etc.)
Implicit equations have the form F(x,y)=0.
Midpoint Circle Algorithm
We will first calculate pixel positions for a circle centered around
the origin (0,0). Then, each calculated position (x,y) is moved to
its proper screen position by adding xc to x and yc to y
Note that along the circle section from x=0 to x=y in the first Note that along the circle section from x=0 to x=y in the first
octant, the slope of the curve varies from 0 to -1
Circle function around the origin is given by
fcircle(x,y) = x
2
+ y
2
r
2
Any point (x,y) on the boundary of the circle satisfies the
equation and circle function is zero
Midpoint Circle Algorithm
For a point in the interior of the circle, the circle function is negative
and for a point outside the circle, the function is positive
Thus,
f
circle
(x,y) < 0 if (x,y) is inside the circle boundary
circle
f
circle
(x,y) = 0 if (x,y) is on the circle boundary
f
circle
(x,y) > 0 if (x,y) is outside the circle boundary
yk
Yk-1
xk xk+1
Xk+3 Midpoint
X
2
+y
2
-r
2
=0
Midpoint between candidate
pixels at sampling position
x
k
+1 along a circular path
Midpoint Circle Algorithm
Assuming we have just plotted the pixel at (x
k
,y
k
) , we next
need to determine whether the pixel at position (x
k
+ 1, y
k
-1) is
closer to the circle
Our decision parameter is the circle function evaluated at the
midpoint between these two pixels midpoint between these two pixels
p
k
= f
circle
(x
k
+1, y
k
-1/2) = (x
k
+1)
2
+ (y
k
-1/2)
2
r
2
If p
k
< 0 , this midpoint is inside the circle and the pixel on the
scan line y
k
is closer to the circle boundary. Otherwise, the
mid position is outside or on the circle boundary, and we select
the pixel on the scan line y
k
-1
Midpoint Circle Algorithm
Successive decision parameters are obtained using incremental
calculations
P
k+1
= f
circle
(x
k+1
+1, y
k+1
-1/2)
= [(x
k+1
)+1]
2
+ (y
k+1
-1/2)
2
r
2
k+1 k+1
OR
P
k+1
= P
k
+2(x
K
+1) + (y
K+1
2
y
k
2
) (y
k
+1- y
k
)+1
Where y
k+1
is either y
k
or y
k-1
, depending on the sign of p
k
Increments for obtaining P
k+1
:
2x
k+1
+1 if p
k
is negative
2x
k+1
+1-2y
k+1
otherwise
Midpoint circle algorithm
Note that following can also be done incrementally:
2x
k+1
= 2x
k
+2
2 y
k+1
= 2y
k
2
At the start position (0,r) , these two terms have the values 2 At the start position (0,r) , these two terms have the values 2
and 2r-2 respectively
Initial decision parameter is obtained by evaluating the circle
function at the start position (x0,y0) = (0,r)
p
0
= f
circle
(1, r-1/2) = 1+ (r-1/2)
2
-r
2
OR
P
0
= 5/4 -r
If radius r is specified as an integer, we can round p
0
to
p
0
= 1-r
The actual algorithm
1: Input radius r and circle center (x
c
,y
c
) and obtain the first
point on the circumference of the circle centered on the origin
as
(x
0
,y
0
) = (0,r)
2: Calculate the initial value of the decision parameter as 2: Calculate the initial value of the decision parameter as
P
0
= 5/4 - r
3: At each x
k
position starting at k = 0 , perform the
following test:
If p
k
< 0 , the next point along the circle centered on (0,0) is
(x
k+1
, y
k
) and
p
k+1
= p
k
+ 2x
k+1
+ 1
The algorithm
Otherwise the next point along the circle is (x
k+1
, y
k-1
) and
p
k+1
= p
k
+ 2x
k+1
+1 -2y
k+1
Where 2x
k+1
= 2x
k+2
and 2y
k+1
= 2y
k
-2 Where 2x
k+1
= 2x
k+2
and 2y
k+1
= 2y
k
-2
4: Determine symmetry points in the other seven octants
5: Move each calculated pixel position (x,y) onto the
circular path centered on (x,yc) and plot the coordinate
values
x = x+ x
c
, y= y+ y
c
6: Repeat steps 3 through 5 until x >= y
Midpoint Ellipse
Derivation
Midpoint Ellipse Algorithm
Input and ellipse center and obtain the
first point on an ellipse centered on the origin as
y x
r r , ( )
c c
y x ,
( ) ( )
y
r y x , 0 ,
0 0
=
Calculate the initial value of the decision parameter in
region 1 as
2 2 2
0
4
1
1
x y x y
r r r r p + =
y 0 0
Midpoint Ellipse..
At each position in region 1, starting at k =
0, perform the following test. if , the
next point along the ellipse centered on (0,0)
is and
k
x
0 1 <
k
p
( )
k k
y x ,
1 +
is and
Otherwise, the next point along the ellipse is
and
with
and continue until
( )
k k
y x ,
1 +
2
1
2
1
2 1 1
y k y k k
r x r p p + + =
+ +
( ) 1 , 1 +
k k
y x
2
1
2
1
2
1
2 2 1 1
y k x k y k k
r y r x r p p + + =
+ + +
2 2
1
2 2 2
1
2
2 2 2 , 2 2 2
x k x k x y k y k y
r y r y r r x r x r = + =
+ +
y r x r
x y
2 2
2 2 >
Midpoint Ellipse Contd.
Calculate the initial value of the decision parameter in
region 2 as
where is the last position calculated in region 1
At each position in region 2, starting at k=0,
( )
2 2
2
0
2
2
0
2
0
1
2
1
2
y x x y
r r y r x r p +
|
.
|

\
|
+ =
( )
0 0
, y x
y
At each position in region 2, starting at k=0,
perform the following test. if , the next point
along the ellipse centered on (0,0) is and
Otherwise, the next point along the ellipse is
and
Using the same incremental calculations for x and y
as in region 1. Continue until y=0
k
y
0 2 >
k
p
( ) 1 ,
k k
y x
2
1
2
1
2 2 2
x k x k k
r y r p p + =
+ +
( ) 1 , 1 +
k k
y x
2
1
2
1
2
1
2 2 2 2
x k x k y k k
r y r x r p p + + =
+ + +
Midpoint Ellipse
For both regions, determine symmetry
points in the other three quadrants
Move each calculated pixel position (x, Move each calculated pixel position (x,
y) onto the elliptical path that is
centered on and plot the
coordinate values
( )
c c
y x ,
c c
y y y x x x + = + = ,

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy