cg_into_ch1
-
Upload
nilesh-rana -
Category
Documents
-
view
217 -
download
0
Transcript of cg_into_ch1
-
8/13/2019 cg_into_ch1
1/83
Computer Graphics
-
8/13/2019 cg_into_ch1
2/83
Basic of Computer Graphics Applications of computer graphics
Display devices -construction of CRT Random and Raster scan systems
Graphics input devices
Graphics software and standards
-
8/13/2019 cg_into_ch1
3/83
Introduction
GraphicsRefers to any computer device or program thatmakes a computer capable of displaying andmanipulating pictures .
Computer Graphics
graphics created using computers and, moregenerally, the representation and manipulationof image data by a computer
-
8/13/2019 cg_into_ch1
4/83
Applications of C. G.Computer-aided Design(CAD)Presentation GraphicsComputer Art (Animation)EntertainmentEducation & Training
Visulization (scientific or business)
-
8/13/2019 cg_into_ch1
5/83
Presentation Graphics:
-
8/13/2019 cg_into_ch1
6/83
CT scan
-
8/13/2019 cg_into_ch1
7/83
CAD-CAM
-
8/13/2019 cg_into_ch1
8/83
CAD/CAM
-
8/13/2019 cg_into_ch1
9/83
CAD/CAM
-
8/13/2019 cg_into_ch1
10/83
Entertainment
Gra hics/Animation or Entertainment
-
8/13/2019 cg_into_ch1
11/83
Entertainment
-
8/13/2019 cg_into_ch1
12/83
Edutainment
Gra hics/Animation or Edutainment
-
8/13/2019 cg_into_ch1
13/83
Edutainment
-
8/13/2019 cg_into_ch1
14/83
Simulators for Training
-
8/13/2019 cg_into_ch1
15/83
BASIC TERMSPIXELRESOLUTION
ASPECT RATIOREFREC RATEFRAME BUFFER(Refrace Buffer)
-
8/13/2019 cg_into_ch1
16/83
Pixel: Smallest addressable element on the screen.
Resolution:
The maximum number of points that can be displayed.
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)
-
8/13/2019 cg_into_ch1
17/83
Aspect Ratio:Ratio of No. of pixels in y-direction divide by No. of
pixels in x-direction. direction in the screen.
Eg. Resolution : 640 x 480Aspect Ratio : 480/640=
NOTE:A.R =3/4 means vertical line plotted with 3 points hasthe same length as horizontal line plotted with 4 points .
-
8/13/2019 cg_into_ch1
18/83
Frame buffer(Refrace Buffer):Picture defination is stored in a memory area called theFrame buffer.This memor area holds the set of intensit values for all
the screen points(pixels).Refrace Rate:Refresh rate on a computer is used to describe how often amonitor 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 persecond.
Depends on picture complexity(no. of lines, points,characters)
-
8/13/2019 cg_into_ch1
19/83
Display Devices/output
DevicesTypes of Display systems:
1 Raster Scan Displays2 Random scan displays3 Direct view stora e tube 4 Flat panel displays
Parts of display system:1. Display adapter : creates & holds the image information
2. Monitor3. Cable
-
8/13/2019 cg_into_ch1
20/83
CRT(Cathod Ray Tube)
-
8/13/2019 cg_into_ch1
21/83
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.
electron gun passes through focusing and deflectionsystems.
Focusing system direct the beam toward specifiedpositions on the phosphor-coated screen.The Phosphor emits visible light when the electronshit the screen.
-
8/13/2019 cg_into_ch1
22/83
The entire picture must be refreshed(redraw) byquickly directing the electron beam back over the
same points repeatedly.
through filament.Intensity of the electron beam is controlled by
setting voltage levels on the control grid.Focusing system is needed to force the electronbeam to coverage into a small spot as it strikesthe phosphor o/w electrons repel each other.
-
8/13/2019 cg_into_ch1
23/83
CRT(Cathod Ray Tube)
-
8/13/2019 cg_into_ch1
24/83
Fig 2.4: Electrostatic deflection of the electron
beam in CRT
Two pairs of parallel plates are mountedinside the CRT envelope.
Horizontal plate is used to control verticaldeflection.
Vertical plate is used to control horizontal
deflection.
-
8/13/2019 cg_into_ch1
25/83
Random and Raster Scan Systems:There are two types of display, random scan andraster scan.
These are based on the scan technology that is
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 inparticular order, from left to right, top to bottom,all the time to generate graphics.
-
8/13/2019 cg_into_ch1
26/83
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
pattern of illuminated spots.Intensity values retrieved from frame buffer one
line at a time(scanline) according fig.Intensity range for pixel positions depends onthe capability of the raster system.
-
8/13/2019 cg_into_ch1
27/83
-
8/13/2019 cg_into_ch1
28/83
Direct view storage tube(DVST)DVST was introduced in 1960 as an alternative andinexpensive solution to refresh display, which was
very expensive because of refresh buffer memory
DVST eliminates the refresh processor completelyand use special type of phosphor embedded in astorage tube that has a long lasting glowing effect.
An old picture has to be erased completely for a newone to be drawn.Due to lack of selective erasure, the DVST cannotprovide colours and animation.
-
8/13/2019 cg_into_ch1
29/83
-
8/13/2019 cg_into_ch1
30/83
Liquid Crystal DisplaysLight passingthrough the liquidcrystal is twisted so itgets through the
polarizer A vo tage is app ieusing thecrisscrossing
conductors to stopthe twisting and turnpixels off
-
8/13/2019 cg_into_ch1
31/83
Raster display, based on standard televisiontechnology, was adopted in 1970 as a viablealternative of DVST.
A typical resolution of a raster display is 1280 x
Raster Display
1024 and can reach upto 4096 x4096 as in DVST,but at a comparatively much lower price. So itbecame popular.
The most common method of implementing araster CRT graphics device is by using a framebuffer.
As a minimum, there is one memory bit for each
pixel in the raster. This amount of memory iscalled a bit plane.
-
8/13/2019 cg_into_ch1
32/83
A 512 x 512, that is, 2 9 x 2 9 elements square rasterrequires 2 18 or 262144 memory bits in single bitplane.
time (either 0 or 1) causing black or white display.Now, this bit information of frame buffer has to betransformed to raster CRT which is an analog device.So, DAC is required.
-
8/13/2019 cg_into_ch1
33/83
-
8/13/2019 cg_into_ch1
34/83
For more intensity levels, N bit plane frame buffer is used inplace of the one bit plane.The intensity of each pixel on the CRT is controlled by acorresponding pixel location in each of the N bit planes.
he binary value (0 or 1) for each of the N bit planes for greylevels is loaded into the corresponding position in a register.The total of 8 (2 n=3 ) intensity levels is possible with three bitplanes.Each bit plane requires the full coplement of memory for givenraster resolution, e.g. 3 bit plane frame buffer for a 512 x 512requires 3 x 512 x 512=786432 memory bits.
-
8/13/2019 cg_into_ch1
35/83
-
8/13/2019 cg_into_ch1
36/83
For colour display, a simple colour frame buffercontains three bit planes for each primary colour, i.e.red (R), green(G) and blue(B).
each of the primary colours used in the colour video.These three primary colours, RGB may be combinedat the CRT to yield eight colours.More shades of RGB can be achieved by usingmultiple bit plane colour frrame buffer with 8 bitplanes per colour, that is 24 bit plane frame bufferwhich generates 2 8 =256 shades of RGB. These arecombined into (2 8)3 =16,777,216 possible colours.
-
8/13/2019 cg_into_ch1
37/83
-
8/13/2019 cg_into_ch1
38/83
Black and white system:Each screen point is either on or off.
the intensity of screen positions.
bit 1: electron beam turned onbit 0 : electron beam turned off For high-quality system: upto 24 bits/pixel
(additional bits for color and intensityvariations
-
8/13/2019 cg_into_ch1
39/83
Contd A system with 24 bits per pixel & screenresolution of 1024 x 1024 require 3
megabytes of storage for frame buffer. Bitmap: on black & white system with
one bit per pixel, the frame buffer calledbitmap.Pixmap : For the systems with multiplebits per pixel , the frame buffer calledpixmap.
-
8/13/2019 cg_into_ch1
40/83
Horizontal Retrace: At the end of each scan line, theelectron beam returns to the left of thescreen to begin displaying the next scanline.
Vertical Retrace: At the end of each frame , the electronbeam returns to the top left corner ofthe screen to begin the next frame.
-
8/13/2019 cg_into_ch1
41/83
Output PrimitivesDDA Line Drawing algorithmBresenhams Line Drawing Algorithm
Bresenhams Cirlcle (Midpoint) Drawing AlgorithmBresenhams Ellipse (Midpoint) Drawing
Algorithm
-
8/13/2019 cg_into_ch1
42/83
WHERE TO DRAW A LINE??
Line drawing is accomplished by calculatingintermediate positions along the line path betweenspecified end points.
-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-x1b= y1-m.x1
-
8/13/2019 cg_into_ch1
43/83
Line Drawing (cont)Also for any given interval x along a line, we cancompute the corresponding y interval y from
y= m. x m ar y we can o a n e x n erva xcorresponding to a specified y as
x= y / m
These equations form the basis for determiningdeflection voltages in analog devices.
-
8/13/2019 cg_into_ch1
44/83
Line Drawing (cont)On Raster systems, lines are plotted with pixels,and step sizes in the horizontal and verticaldirections are constrained by pixel separations.Hence we ought to sample a line at discretepositions an etermine t e nearest pixe to t eline at each sampled position.
-
8/13/2019 cg_into_ch1
45/83
DDA ALGORITHMThe digital differential analyzer (DDA) samples the line at unitintervals in one coordinate corresponding integer values nearestthe line path of the other coordinate.
- conversion(DDA) algorithm for line drawing
for x from x0 to x1Compute y=mx+b
Draw_fn(x, round(y))Major deficiency in the above approach :Uses floatsHas rounding operations
-
8/13/2019 cg_into_ch1
46/83
Consider first a line with positive slope, if slope is lessthan 1, we sample at unit x intervals ( x=1) andcompute each successive y value as
k+1 k
Where k takes integer values starting from 1, for thefirst point, and increases by 1 until final endpoint isreached.For lines with a positive slope greater than 1, wesample at unit y intervals ( y=1) and calculate eachsucceeding x value as
Xk+1
= xk
+ 1/m
-
8/13/2019 cg_into_ch1
47/83
Both the previous equation are to be processed fromthe left end point to the right endpoint.
If this processing is reversed, so that the starting- ,yk+1 =y k - m
for y=-1
Xk+1 = x k - 1/m
-
8/13/2019 cg_into_ch1
48/83
DDA Illustration
(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
-
8/13/2019 cg_into_ch1
49/83
DDA AlgorithmProcedure lineDDA (xa , ya, xb, yb : integer); Var
dx , dy , steps , k : integer;xIncrement , yIncrement , x, y : real;
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;
-
8/13/2019 cg_into_ch1
50/83
X := xa; Y := ya;Setpixel (round(x),round(y),1);For k:=1 to ste s do
beginx:=x + xIncrement;
Y:=y + yIncrement;
Setpixel (round(x),round(y),1)EndEnd; (lineDDA)
-
8/13/2019 cg_into_ch1
51/83
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
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.
-
8/13/2019 cg_into_ch1
52/83
Bresenhams Line drawing algorithm: Accurate & Efficient line generating algorithm.Scan converts lines using only incremental integer
calculations. rs approcac or s op s pos ve u :I. Pixel positions along a line path determined by
sampling at unit x intervals .
II. Starting from the left end point (x 0,y0) of given line ,step to each successive column ( x position) andplot the pixel whose scan-line y value is closet tothe line path.
-
8/13/2019 cg_into_ch1
53/83
Assuming that the pixel at (x k , y k ) is to bedisplayed, next need to decide which pixel to plot incolumn x
k+1. k , k and (x k + 1, y k+1 )
At sampling position x k + 1, we label vertical pixelseparations from the mathematical line path as d1and d2.
-
8/13/2019 cg_into_ch1
54/83
For slope(m) >0(positive)
Find (11,11) or
Y axis- scan line conversionX axis- pixel columns
,(10,11)
For slope(m) < 0(Negative)
Find (51,49) or(51,50) near to(50,50)
-
8/13/2019 cg_into_ch1
55/83
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 themathematical path as d1 & d2:
d1 = y - y k d2 = (y k +1) - y
-
8/13/2019 cg_into_ch1
56/83
A decision parameter p k for the kth step in the line algorithmcanbe obtained by rearranging equation of d1-d2, so it involvesonly integer calculations.
By substituting m= y/ x, where y and x are the verticalan or zon a separa ons o e en po n pos ons, andefining:
Pk = 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 +1i.e. d1
-
8/13/2019 cg_into_ch1
57/83
Now, at step k+1, the decision parameter isevaluated from equation of p k as,
pk+1 = 2 y*x k+1 -2x*y k+1 +c u rac ng e equa on,pk+1 p k = 2 y*(x k+1 - xk ) - 2x*(y k+1 -yk )
But x k+1 = x k +1 so that
pk+1 = p k + 2 y - 2x*(y k+1 -yk )The first parameter, p 0 is evaluated from equation of p k
at the starting pixel (x 0,y0) and with m evaluated as y/ x:
P0=2 y - x
-
8/13/2019 cg_into_ch1
58/83
Bresenhams Line-Drawing Algo(for |m|
-
8/13/2019 cg_into_ch1
59/83
-
8/13/2019 cg_into_ch1
60/83
Beginx := x a;
y := y a;xEnd := x b;
End;Setpixel (x,y,1);while x < xEnd do
beginx := x+1;if p< 0 then p := p+2 *dy
elsebegin
y := y+1;p := p+2 * (dy-dx)
end;setpixel (x,y,1)
end;End; {linebre}
-
8/13/2019 cg_into_ch1
61/83
Example on bresenham line drawingThe 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 decisionparameters p k+1.
-
8/13/2019 cg_into_ch1
62/83
k p k (x k+1 , y k+1 )
0 6 (21,11)
1 2 (22,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)
-
8/13/2019 cg_into_ch1
63/83
Where do we draw a circle???Properties of a circle: A circle is defined as a set of points that are all the givendistance (x c ,y c ) . This distance relationship is expressed by thepythagorean theorem in Cartesian coordinates as
(x x ) 2 + (y y ) 2 = r 2 We could use this equation to calculate the points on the circlecircumference by stepping along x-axis in unit steps from x c -r tox c +r and calculate the corresponding y values at each positionas
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
-
8/13/2019 cg_into_ch1
64/83
Polar co-ordinates for a circleWe 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 spacedpoints along the circumference
A step size of 1/r can be used to set pixel positions toapproximately 1 unit apart for a continuous boundaryBut, note that circle sections in adjacent octants within onequadrant are symmetric with respect to the 45 deg line dividingthe to octantsThus we can generate all pixel positions around a circle bycalculating just the points within the sector from x=0 to x=yThis method is still computationally expensive
-
8/13/2019 cg_into_ch1
65/83
-
8/13/2019 cg_into_ch1
66/83
-
8/13/2019 cg_into_ch1
67/83
Bresenham to MidpointBresenham requires explicit equation
Not always convenient (many equationsare im licitBased on implicit equations: Midpoint
Algorithm (circle, ellipse, etc.)
Implicit equations have the form F(x,y)=0.
-
8/13/2019 cg_into_ch1
68/83
Midpoint Circle AlgorithmWe will first calculate pixel positions for a circle centered aroundthe origin (0,0). Then, each calculated position (x,y) is moved toits proper screen position by adding xc to x and yc to y
octant, the slope of the curve varies from 0 to -1
Circle function around the origin is given byfcircle(x,y) = x 2 + y 2 r 2
Any point (x,y) on the boundary of the circle satisfies theequation and circle function is zero
-
8/13/2019 cg_into_ch1
69/83
-
8/13/2019 cg_into_ch1
70/83
Midpoint Circle AlgorithmFor a point in the interior of the circle, the circle function is negativeand for a point outside the circle, the function is positiveThus,
f circle(x,y) < 0 if (x,y) is inside the circle boundaryf circle(x,y) = 0 if (x,y) is on the circle boundaryf circle(x,y) > 0 if (x,y) is outside the circle boundary
yk
Yk-1
xk xk+1 Xk+3Midpoint
X2+y 2-r2=0
Midpoint between candidatepixels at sampling positionx k +1 along a circular path
-
8/13/2019 cg_into_ch1
71/83
Midpoint Circle Algorithm Assuming we have just plotted the pixel at (x k ,y k ) , we nextneed to determine whether the pixel at position ( x k + 1, y k -1) iscloser to the circle
Our decision parameter is the circle function evaluated at them po n e ween ese wo p xe s
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 thescan line y k is closer to the circle boundary. Otherwise, themid position is outside or on the circle boundary, and we selectthe pixel on the scan line y k -1
-
8/13/2019 cg_into_ch1
72/83
Midpoint Circle AlgorithmSuccessive decision parameters are obtained using incrementalcalculations
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
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 pk Increments for obtaining P k+1 :2x k+1 +1 if p k is negative 2x k+1 +1-2y k+1 otherwise
-
8/13/2019 cg_into_ch1
73/83
Midpoint circle algorithmNote that following can also be done incrementally:
2x k+1 = 2x k +2 2 y k+1 = 2y k 2
At the start osition 0 r these two terms have the values 2and 2r-2 respectivelyInitial decision parameter is obtained by evaluating the circlefunction 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 top 0 = 1-r
-
8/13/2019 cg_into_ch1
74/83
The actual algorithm1: Input radius r and circle center (x c,yc) and obtain the firstpoint on the circumference of the circle centered on the originas
(x0,y0) = (0,r) 2: Calculate the initial value of the decision parameter as
P0 = 5/4 - r3: 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(xk+1 , y k ) and
pk+1 = p k + 2x k+1 + 1
-
8/13/2019 cg_into_ch1
75/83
The algorithmOtherwise the next point along the circle is (x k+1 , y k-1) and
pk+1 = p k + 2x k+1 +1 -2y k+1
Where 2x = 2x and 2 = 2 -2
4: Determine symmetry points in the other seven octants
5: Move each calculated pixel position (x,y) onto thecircular path centered on (x,yc) and plot the coordinatevalues
x = x+ x c , y= y+ y c
6: Repeat steps 3 through 5 until x >= y
-
8/13/2019 cg_into_ch1
76/83
Midpoint EllipseDerivation
-
8/13/2019 cg_into_ch1
77/83
-
8/13/2019 cg_into_ch1
78/83
-
8/13/2019 cg_into_ch1
79/83
-
8/13/2019 cg_into_ch1
80/83
Midpoint Ellipse AlgorithmInput and ellipse center and obtain thefirst point on an ellipse centered on the origin as
y x r r , cc y x ,
r y x ,0, 00 Calculate the initial value of the decision parameter inregion 1 as
2220 4
11 x y x y r r r r p
-
8/13/2019 cg_into_ch1
81/83
Midpoint Ellipse.. At each position in region 1, starting at k =0, perform the following test. if , thenext point along the ellipse centered on (0,0)
k x
01 k p
Otherwise, the next point along the ellipse is
and
withand continue until
k k ,12
12
1 211 yk yk k r xr p p
1,1 k k y x 21
21
21 2211 yk xk yk k r yr xr p p
221
2221
2 222,222 xk xk x yk yk y r yr yr r xr xr
yr xr x y22 22
-
8/13/2019 cg_into_ch1
82/83
Midpoint Ellipse Contd.Calculate the initial value of the decision parameter inregion 2 as
where is the last position calculated in region 1
222022
02
0 121
2 y x x y r r yr xr p
00 , y x At each position in region 2, starting at k=0,perform the following test. if , the next pointalong the ellipse centered on (0,0) is and
Otherwise, the next point along the ellipse isand
Using the same incremental calculations for x and yas in region 1. Continue until y=0
k y02 k p
1, k k y x2
12
1 222 xk xk k r yr p p
1,1 k k y x2
12
12
1 2222 xk xk yk k r yr xr p p
-
8/13/2019 cg_into_ch1
83/83
Midpoint EllipseFor both regions, determine symmetrypoints in the other three quadrants
,y) onto the elliptical path that iscentered on and plot the
coordinate values
cc y x ,
cc y y y x x x ,