Professional Documents
Culture Documents
DEPARTMENT
OF
COMPUTER SCIENCE AND ENGINEERING
HANDOUT
on
COMPUTER GRAPHICS
Vision
Mission
============================================================
2. Pre-Requisites
4. Course Outcomes:
Upon successful completion of the course, the students will be able to
CO1: design a conceptual model for the mathematical model to
determine the set of pixels to turn on for displaying an object.
CO2: analyze the functionalities of various display devices and visible
surface detection methods
CO3: analyze the performance of different algorithms to draw different
shapes.
CO4: choose different transformations and viewing functions on objects.
CO5: apply raster animations for Engine oil advertisements.
5. Program Outcomes:
Graduates of the Computer Science and Engineering Program will have
Engineering Graduates will be able to:
a. Engineering knowledge: Apply the knowledge of mathematics, science,
engineering fundamentals, and an engineering specialization to the
solution of complex engineering problems.
l. Life-long learning: Recognize the need for, and have the preparation and
ability to engage in independent and life-long learning in the broadest
context of technological change.
a b c d e f g h i j k L
CO1 H M L
CO2 M L M
CO3 H L
CO4 H L M
CO5 L M
3- High 2- Medium 1-Low
UNIT-I: Introduction
Translation, Scaling 1
Rotation, Reflection 2
Shear Transformations 1
Matrix Representations 1
Homogenous Coordinates 1
Composite Transformations 1
Viewing Functions 1
Translation, Scaling 1
Rotation, Reflection 2
Shear Transformations 1
Composite Transformations 1
3D viewing pipeline 1
Parallel Projections 2
Perspective projections 2
Classification 1
Back-face Detection 1
Raster Animations 1
UNIT – I
Objective:
To familiarize with the functionalities of various graphics systems.
Syllabus:
Introduction:
Applications of Computer Graphics
Raster scan displays
Random scan displays
Filled Area Primitives:
Points and lines
Inside and outside tests
Line drawing algorithms
Scan line polygon fill algorithm
Learning Outcomes:
Students will be able to
Understand the functionalities of raster and random scan systems.
Attain a conceptual model understanding of the underlying mathematical
model for determining the set of pixels to turn on for displaying an object.
Learning Material
Computer graphics is an art of drawing pictures on computer screens
with the help of programming. It involves computations, creation, and
manipulation of data. In other words, we can say that computer graphics is
a rendering tool for the generation and manipulation of images.
1.1 APPLICATIONS OF COMPUTER GRAPHICS
(1) Computer Aided Design:
A major use of computer graphics is in design processes, particularly
for engineering and architectural systems, but almost all products are
now computer designed.
Computer-Aided Design methods are used in the design of buildings,
automobiles, aircraft, watercraft, spacecraft, computers, textiles, and
many other products.
For some design applications, objects are first displayed in a
wireframe outline form that shows the overall sham and internal
features of objects.
Wireframe displays also allow designers to quickly see the effects of
interactive adjustments to design shapes.
(2) Presentation Graphics:
Presentation graphics, used to produce illustrations for reports using
projectors.
Presentation graphics is commonly used to summarize financial,
statistical, mathematical, scientific, and economic data for research
reports, managerial reports, consumer information bulletins, and
other types of reports.
Typical examples of presentation graphics are bar charts, line graphs,
surface graphs, pie charts, and other displays shows relationships
between multiple parameters.
Video Controller:
A fixed area of the system memory is reserved for the frame buffer,
and the Video Controller is given direct access to the Frame-Buffer
Memory.
Frame-Buffer locations and the corresponding screen positions are
referred in Cartesian Coordinates.
For many graphics monitors, the coordinate origin is defined at the
lower left screen corner.
The basic refresh operations of the Video Controller:
Two registers are used to store the coordinates of the screen pixels.
Initially, x register is set to 0 and y is set to ymax.
The value stored in the frame buffer for this pixel position is then
retrieved and used to set the intensity of the CRT beam.
Similar methods are used for scan converting curved lines and
polygon outlines.
For Example, Characters can be defined with rectangular grids or they
can be defined with curved outlines.
subscript k takes integer values starting from 1, for the first point,
and increases by 1 until the final endpoints is reached. Since m can
be any real number between 0 & 1, the calculated y values must be
rounded to the nearest integer.
For lines with a positive slope greater than 1, we reserve the roles of
x & y. That is, we sample at unit y intervals (Dy=1) and calculate each
succeeding x value as
Advantages :
The DDA algorithm is a faster method for calculating pixel position
than the direct use of slope intercept form equation.
Disadvantages:
The accumulation of round off error in successive additions of the
floating-point increment, however, can cause the calculated pixel
positions to drift away from the true line path for long line
segments.
Furthermore, the rounding operations and floating-point arithmetic in
procedure line DDA are still time-consuming.
The algorithm is orientation dependent. Hence end point accuracy is
poor.
Improvements can be done in this algorithm are :
We can improve the performance of the DDA algorithm by separating
the increments m and 1/m into integer and fractional parts so that all
calculations are reduced to integer operations.
1.5.2 Bresenham's Line Algorithm
An accurate and efficient raster line-generating algorithm, developed
by Bresenham, will scan converts lines using only incrementa1
integer calculations that can be adapted to display circles and other
curves.
We first consider the scan-conversion process for lines with positive
slope less than 1. Pixel positions along a line path are then
determined by sampling at unit
x intervals. Starting from the
left endpoint (x0, y0) of a line,
we step to each successive
column (x position) and plot the
pixel whose scan-line y value is
closest to the line path.
The beside 1st figure demonstrates the kth step in this process.
Assuming we have determined that the pixel at (xk, yk) is to be
displayed, we next need to decide which pixel to plot in column xk+1.
Our choices are the pixels at positions
(xk+1, yk) and (xk+1, yk+1).
At sampling position xk+1, we label vertical pixel separations from the
mathematical line path as d1 and d2 shown in the besides 2nd figure .
The y coordinate on the mathematical line at pixel column position
xk+1 is calculated as
y = m (xk + 1) + b ------------(1)
Then,
d1 = y - yk
= m (xk + 1) + b - yk
and
d2 = (yk+1) - y
= yk + 1 – m (xk + 1) - b
The difference between these two separations is
d1 - d2 = 2m (xk + 1) - 2yk + 2b – 1 ---------------- (2)
A decision parameter pk for the kth step in the line algorithm can
be obtained by rearranging equation (2) so that it involves only integer
calculations.
We accomplish this by substituting m = Dy / Dx, where Dy and Dx
are the vertical and horizontal separations of the endpoint positions,
and defining:
pk = Dx(d1-d2)
= 2Dy.xk - 2Dx . yk + c -----------------(3)
The sign of pk is the same as sign of d1-d2, since Dx > 0 for our
examples.
Example: Draw a line from (20,10) and (30, 18) using Bresenham’s Line
Drawing Algorithm
odd-even rule
nonzero winding number rule
(a) Odd -even Rule:
We apply the odd-even rule, also called the odd parity rule or the even
odd rule, by conceptually drawing a line from any position P to a
distant point outside the coordinate extents of the object and counting
the number of edge crossings along the line. If the number of polygon
edges crossed by this line is odd, then P is an interior point.
Otherwise, P is an exterior point. To obtain an accurate edge count,
we must be sure that the line path we choose does not intersect any
polygon vertices.
The above figure shows the interior and exterior regions obtained from
the odd-even rule for a self-intersecting set of edges. The scan-line
polygon fill algorithm discussed in the previous section is an example
of area filling using the odd-even rule.
(b)Nonzero winding number rule:
This rule counts the number of times the polygon edges wind around
a particular point in the counter clockwise direction. This count is
called the winding number, and the interior points of a two-
dimensional object are defined to be those that have a nonzero value
for the winding number.
In the above figure, the four pixel intersection positions with the
polygon boundaries define two stretches of interior pixels from x = 10
to x = 14 and from x = 18 to x = 24. Some scan-line intersections at
polygon vertices require special handling.
A scan line passing through a vertex intersects two edges at that
position, adding two points to the list of intersections for the scan line.
II Year - II Semester 2019-20 CSE
Computer Graphics 32
The above figure shows two scan lines at positions y and y' that
intersect edge endpoints. Scan line y intersects five polygon edges.
Scan line y', however, intersects an even number of edges although it
also passes through a vertex.
Intersection points along scan line y' correctly identify the interior
pixel spans. But with scan line y, we need to do some additional
processing to determine the correct interior points.
The topological difference between scan line y and scan line y' is
identified by noting the position of the intersecting edges relative to
the scan line.
For scan line y, the two intersecting edges sharing a vertex are on
opposite sides of the scan line. But for scan line y', the two
intersecting edges are both above the scan line.
Thus, the vertices that require additional processing are those that
have connecting edges on opposite sides of the scan line. We can
identify these vertices by tracing around the polygon boundary either
in clockwise or counter clockwise order and observing the relative
changes in vertex y coordinates as we move from one edge to the next.
If the endpoint y values of two consecutive edges monotonically
increase or decrease, we need to count the middle vertex as a single
intersection point for any scan line passing through that vertex.
Otherwise, the shared vertex represents a local extremum (minimum
or maximum) on the polvgon boundary, and the two edge
II Year - II Semester 2019-20 CSE
Computer Graphics 33
intersections with the scan line passing through that vertex can be
added to the intersection list.
Shortening of an edge:
One way to resolve the question as to whether we should count a
vertex as one intersection or two is to shorten some polygon edges to
split those vertices that should be counted as one intersection.
We can process non horizontal edges around the polygon boundary in
the order specified, either clockwise or counter clockwise. As we
process each edge, we can check to determine whether that edge and
the next non horizontal edge have either monotonically increasing or
decreasing endpoint y values.
If so, the lower edge can be shortened to ensure that only one
intersection point is generated for the scan line going through the
common vertex joining the two edges.
When the endpoint y coordinates of the two edges are increasing, the y
value of the upper endpoint for the current edge 1s decreased by 1.
When the endpoint y values are monotonically decreasing, we
decrease they coordinate of the upper endpoint of the edge following
the current edge.
Calculations performed in scan-conversion and other graphics
algorithms typically take advantage of various coherence properties of
a scene that is to be displayed.
Coherence : The properties of one part of a scene are related in some
way to other parts of the scene so that the relationship can be used to
reduce processing. Coherence methods often involve incremental
calculations applied along a single scan line or between successive
II Year - II Semester 2019-20 CSE
Computer Graphics 34
The above figure shows two successive scan lines crossing a left edge
of a polygon. The slope of this polygon boundary line can be expressed
in terms of the scan-line intersection coordinates:
In our previous example with m = 7/3, the counter values for the first
few scan lines above the initial scan line on this edge would now be 6,
12 (reduced to -2), 4, 10 (reduced to -4), 2, 8 (reduced to -6), 0, 6, and
12 (reduced to - 2). Now x would be incremented on scan lines 2, 4, 6,
9, etc., above the initial scan line for this edge. The extra calculations
required for each edge are 2∆x = ∆x + ∆x and 2Ay = ∆y-+ ∆y.
To efficiently perform a polygon fill, we can first store the polygon
boundary in a sorted edge table that contains a11 the information
necessary to process the scan lines efficiently.
Proceeding around the edges in either a clockwise or a counter
clockwise order, we can use a bucket sort to store the edges, sorted on
the smallest y value of each edge, in the correct scan-he positions.
Only non horizontal edges are entered into the sorted edge table. As
the edges are processed, we can also shorten certain edges to resolve
the vertex intersection question.
Each entry in the table for a particular scan line contains the
maximum y value for that edge, the x-intercept value (at the lower
vertex) for the edge, and the inverse slope of the edge. For each scan
line, the edges are in sorted order from left to right.
The below figure shows a polygon and the associated sorted edge
table:
UNIT-I
Assignment-Cum-Tutorial Questions
SECTION-A
Objective Questions
1. The number of pixels stored in the frame buffer of a graphics system is
known a [ ]
a. Resolution b. Depth c. Resolution d. a & b
6. On a black and white system with one bit per pixel, the frame buffer is
commonly called as [ ]
a. Pix map b. Multi map
c. Bitmap d. All of the mentioned
7. To store black and white images ,black pixels are represented by________
in the frame buffer and white pixels by_______ [ ]
a. Zero and one b. One and Zero
c. Both a & b d. None of these
a. Number of pixels
b. Ratio of vertical points to horizontal points
c. Ratio of horizontal points to vertical points
d. Both b and c
12. A line connecting the points (1, 1) and (5, 3) is to be drawn, using DDA
algorithm. Find the value of x and y increments [ ]
a. x-increments = 1; y-increments =1
b. x-increments = 0.5; y-increments =1
c. x-increments = 1; y-increments =0.5
d. None of above
13. Digitizing a picture definition into a set of intensity values is known as
........ [ ]
a. Digitization b. Scan conversion
c. Refreshing d. Scanning
SECTION-B
SUBJECTIVE QUESTIONS
2. Explain the architecture of Raster Scan Systems and also mention the
significance of graphics controller.
8. How Many k bytes does a frame buffer needs in a 600 x 400 pixel?
9. Consider two raster systems with the resolutions of 640 x 480 and 1280
x 1024.How many pixels could be accessed per second in each of these
systems by a display controller that refreshes the screen at a rate of 60
frames per second?
10. Digitize the line with endpoints (0,0) and (-8,-4) using DDA line drawing
algorithm.
11. Plot the intermediate pixels for a line with endpoints (20,10) and (30,18)
using Bresenham’s line drawing algorithm.
12. Consider three different raster systems with resolutions of 640 x 480,
1280 x 1024, and 2560 x 2048.
a. What size is frame buffer (in bytes) for each of these systems to store 12
bits per pixel?
b. How much storage (in bytes) is required for each system if 24 bits per
pixel are to be stored?