Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 37

What is CG?

It is a combination of 3 words

 Computer
 Graph (mathematical diagram like lines, circles, polygons etc) + Charts
 Pics (images)

It is an art of drawing pictures, using computer with the help of program and software.

Computer graphics deals with creation, manipulation and storage of different type of images and objects.

Application of CG
Computer Art: Using computer graphics we can create fine art and commercial art which includes animation
packages, paint packages. These packages provide facilities for designing object shapes and specifying object
motion. Cartoon drawing, paintings, logo design can also be done.

Presentation Graphics: For the preparation of reports or summarizing the financial, statistical, mathematical
data for research reports, managerial reports. Moreover creation of bar graphs, pie charts, time chart, can be
done using the tools present in computer graphics.

Image Processing: Various kinds of photographs or images require editing in order to be used in different
places. Processing of existing images into refined ones for better interpretation is one of the many applications
of computer graphics.

Graphical User Interface: The use of pictures, images, icons, pop-up menus, graphical objects helps in
creating a user friendly environment where working is easy and pleasant, using computer graphics we can
create such an atmosphere where everything can be automated and anyone can get the desired action
performed in an easy fashion.

Visualization: Scientists, engineers, medical personnel, business analysts, and others often need to analyze
large amounts of information or to study the behavior of certain processes. Numerical simulations carried out
on supercomputers frequently produce data files containing thousands and even millions of data values.
Scanning these large sets of number to determine trends and relationships is a tedious and ineffective
process. But if the data are converted to a visual form, the trends and patterns are often immediately apparent.

Education: Computer generated models are extremely useful for teaching huge number of concepts and
fundamentals in an easy to understand and learn manner. Using computer graphics many educational models
can be created through which more interest can be generated among the students regarding the subject.

Training: Specialized system for training like simulators can be used for training the candidates in a way that
can be grasped in a short span of time with better understanding. Creation of training modules using computer
graphics is simple and very useful.

Entertainment: Computer graphics finds a major part of its utility in the movie industry and game industry.
Used for creating motion pictures, music video, television shows, cartoon animation films. In the game industry
where focus and interactivity are the key players, computer graphics helps in providing such features in the
efficient way.

Computer Aided Drawing: Designing of buildings, automobile, aircraft is done with the help of computer
aided drawing, this helps in providing minute details to the drawing and producing more accurate and sharp
drawings with better specifications.
Cathode Ray Tube (CRT)

A CRT is an evacuated glass tube.

An electron gun at the rear of the tube produces a beam of electrons which is directed towards the front of the
tube (screen).

Electron gun is composed of Metal Cathode & control grid.

The inner side of the screen is coated with phosphor substance which gives off light when it is stroked by
electrons.

The beam is positioned on the screen by a deflection system of the cathode-ray-tube consists of two pairs of
parallel plates, referred to as the vertical and horizontal deflection plates.

When the phosphor is hit by the electron beam it absorbs energy and jumps to a higher quantum-energy
level. As it returns to its normal level it emits visible light i.e. it phosphoresces. In the phosphors used in
graphics devices the persistence of the phosphorescence is typically 10-60 microseconds.
Before the human visual system can see a transient image it must be continually redrawn (refreshed) at a rate
higher than the critical fusion frequency of the human visual system. To allow the human visual system to see
a continuously refreshed image without flicker the refresh rate has to be at least 60 c/s.
To allow continuous refreshing of an image there must be some stored representation of the image from which
the refresh system can obtain the graphical information required to re-draw the image.

It may seem a disadvantage to continually refresh the image there are some very important advantage

 it is possible to edit an image by changing the stored representation between refresh cycles,i.e.,
changing images dynamically.

 Pixel (picture element):- It is the smallest addressable unit of screen which stores the value & intensity
of a color.
 Aspect Ratio: - it is the ratio of width to the height of the device.
 Resolution: - Number of pixel displayed without overlapping is called resolution.
Vector Scan/ Random Scan
It is a technique used to display images on screen.

Also known as calligraphic display or stroked writing display.

In the Raster scan, the beam is directed to that portion of the screen where a picture has to be drawn.

When operated as 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.

Random scan monitors draw a picture one line at a time

The component lines of a picture can be drawn and refreshed by a random-scan system in any specified order

Refresh rate on a random-scan system depends on the number of lines to be displayed.

Picture definition is now stored as a set of line drawing commands in an area of memory referred to as the
refresh display file.

Sometimes the refresh display file is called the display list, display program, or simply the refresh buffer.

To display a specified picture, the system cycles through the set of commands in the display file, drawing each
component line in turn. After all line drawing commands have been processed, the system cycles back to the
first line command in the list. Random-scan displays are designed to draw all the component lines of a picture
30 to 60 times each second.

When a small set of lines is to be displayed, each refresh cycle is delayed to avoid refresh rates greater than
60 frames per second. Otherwise, faster refreshing of the set of lines could burn out the phosphor.

 Display buffer memory (Refresh buffer):- It stores display list which contains pints and lines plotting
commands as well as character plotting commands. It is also used for refreshing.
 Display controller:- It interprets the command stored in display buffer and help beam deflection circuit
to displace electron beam writing on CRT’s phosphor screen.

Advantages

 High resolution than Raster Scan.


 Produce smooth lines
 Needs less memory to store picture definition

Disadvantages

 Cannot draw Realistic images


 Limitation on color to be displayed (Max. 4 color)
Raster Scan Display
The displayed image is stored in the form 0’s & 1’s.

The video controller reads refresh buffer & produce actual image on screen.

Frame buffer hold the intensity value of pixel.

In a raster-scan system, the electron beam is swept across the screen, one row at a time from top to bottom.

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 bit-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. Additional bits
are needed when color and intensity variations can be displayed.

Up to 24 bits per pixel are included in high-quality systems, which can require several megabytes of storage for
the frame buffer, depending on the resolution of the system.

Refreshing on raster-scan displays is carried out at the rate of 60 to 80 frames per second,

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 scan line, is called the horizontal retrace of
the electron beam. And at the end of each frame (displayed in 1/80th to 1/60th of a second), the electron beam
returns to the top left comer of the screen, to begin the next frame, known as vertical retrace.
Beam Penetration Technique (BPT)
Normal CRT produces images of single color due to limitation of phosphor coating.

Color CRT generates a range of colors by combining the emitted light from multi-layered phosphor coated
color CRT.

BPT is used with random scan display where CRT is coated with 2 layers of phosphor usually Red & Green.

Outer layer: - Red

Inner layer: - Green

Color generated depends on how far electron bean penetrates into phosphor screen.
A beam of slow electrons excites only the outer red layer and produces red color on screen.

A beam of very fast electrons penetrates through the red layer and excites the inner green layer.

At intermediate beam speeds, combinations of red and green light are emitted to show two additional colors,
orange and yellow.

The speed of the electrons, and hence the screen color at any point, is controlled by the beam-acceleration
voltage.

Advantages

 Beam penetration has been an inexpensive way to produce color in random-scan monitors,

Disadvantages

 Only four colors are possible, and the quality of pictures is not as good as with other methods.

Shadow Mask CRT


It is used in Raster scan display & produces wide range of colors.

3 phosphor dot Red, Green, Blue at each pixel position emits corresponding colors.

3 electron beam one for each color & a shadow mask grid just behind phosphor coated screen is needed. (as
shown in diagram)

Shadow mask grid consists of holes align with dot patterns. 3 electron beams are deflected and focused as a
group on shadow mask & excites a dot triangle by passing through hole.

The phosphor dots in the triangles are arranged so that each electron beam can activate only its corresponding
color dot when it passes through the shadow mask.

We obtain color variations in a shadow-mask CRT by varying the intensity levels of the three electron beams.

Directed view storage tube (DVST)


An alternative method for maintaining a screen image is to store the picture information inside the CRT instead
of refreshing the screen.
A direct-view storage tube (DVST) stores the picture information as a charge distribution just behind the
phosphor-coated screen.

Two electron guns are used in a DVST.

One, the primary gun, is used to store the picture pattern.

The second, the flood gun, maintains the picture display.

Advantages

 Since no refreshing is needed, very complex picture can be displayed at very high resolutions without
flicker.

Disadvantages

 DSTV ordinarily do not display color.


 To eliminate a picture section, the entire screen must be erased and the modified picture redrawn.

Flat Panel Display


Flat-panel display refers to a class of video devices that have reduced volume, weight, and power
requirements compared to a CRT.

They are thinner than CRTs, and we can hang them on walls or wear them on our wrists.

Example:- small TV monitors, calculators, pocket video games, laptop computers, arm rest viewing of movies
on airlines, as advertisement boards in elevators,

Flat-panel displays can be of two categories:

 Emissive displays
 Non emissive displays.

The emissive displays (or emitters) are devices that convert electrical energy into light.
Plasma panels thin film electroluminescent and Light-emitting diodes (LED’s) are examples of emissive
displays.

Non emissive displays (or non emitters) use optical effects to convert sunlight or light from some other
source into graphics patterns.
The most important example of a non emissive flat-panel display is a liquid-crystal device. (LCD’s)

Plasma Panel
Also called gas-discharge displays
Constructed by filling the region between two glass plates with a mixture of gases that usually includes neon.
A series of vertical conducting ribbons is placed on one glass panel, and a set of horizontal ribbons on other.
Firing voltages applied to a pair of horizontal and vertical conductors cause the gas at the intersection of the
two conductors to break down into a glowing plasma of electrons and ions.

Picture definition is stored in a refresh buffer, and the firing voltages are applied to refresh the pixel positions
60 times per second.

Separation between pixels is provided by the electric field of the conductors.

Disadvantage of plasma panels:- they were strictly monochromatic devices, but systems have been
developed that are now capable of displaying color and grayscale.

Thin-film electroluminescent displays


Thin-film electroluminescent displays are similar in construction to a plasma panel.

The difference is that the region between the glass plates is filled with a phosphor, such as zinc sulfide doped
with manganese atoms, instead of a gas.

When a sufficiently high voltage is applied to a pair of crossing electrodes, the phosphor becomes a conductor
in the area of the intersection of the two electrodes.

Electrical energy is then absorbed by the manganese atoms, which then release the energy as a spot of light
similar to the glowing plasma effect in a plasma panel.

Disadvantages: -

 Electroluminescent displays require more power than plasma panels


 good color and gray scale displays are hard to achieve.
Light-emitting diode (LED)
A type of emissive display device.

A matrix of diodes is arranged to form the pixel positions in the display

Picture definition is stored in a refresh buffer.

Information is read from the refresh buffer and converted to voltage levels that are applied to diodes to produce
light patterns in the display.

Liquid crystal display (LCD)


These are non emissive display devices.

These devices produces picture by passing polarized light from surroundings or from an internal light source
through a liquid-crystal material that transmit the light.

The term liquid crystal refers to the fact that these compounds have a crystalline arrangement of molecules,
yet they flow like a liquid.

Flat-panel displays commonly use nematic (threadlike) liquid-crystal compounds that tend to keep the long
axes of the rod-shaped molecules aligned.

It uses liquid crystal between two glass plates, each plate is the right angle to each other.

One glass plate consists vertical conductors while other consists of horizontal conductors.

Pixel position is determined by the intersection of vertical & horizontal conductors.

Usually in ON state, polarized light is twisted so that it will pass through opposite polarizer.

The light is then reflected back to the viewer


To turn off the pixel, we apply a voltage to the two intersecting conductors to align the molecules so that the
light is not twisted. This type of flat-panel device is referred to as a passive-matrix LCD.

Picture definitions are stored in a refresh buffer, and screen is refreshed at the rate of 60 frames per second,
as in the emissive devices.

Back lighting is also commonly applied using solid-state electronic devices, so that the system is not
completely dependent on outside light sources.

Another method for constructing LCDs is to place a transistor at each pixel location, using thin-film transistor
technology. The transistors are used to control the voltage at pixel locations and to prevent charge from
gradually leaking out of the liquid-crystal cells. These devices are called active-matrix displays.

Pointing and Positioning devices


Pointing technique refers to look at the items already on the screen.

Positioning technique refers to position the item on the screen to a new position.

1) Light Pen

 It is a pointing device.
 When light pen is pointed at an item on the screen, it generates information from which the item
can be identified by the program.
 It does not have any associated tracking hardware instead tracking is performed by software,
making use of the output function of the display.
 All light pen programs depend on a rapid response from the pen when it is pointed at the screen
 Fast response light pens can be build by using a highly sensitive photocell
2) Mouse
 Mouse is the most popular pointing and positioning device.
 It is a cursor-control device having a small palm size box with a round ball at its base, which senses the
movement of the mouse and sends corresponding signals to the CPU
 It has two buttons called the left and the right button and a wheel is present between the buttons.
 It can be used to control the position of the cursor on the screen, but it cannot be used to enter text into
the computer.

Advantages

 Easy to use
 Not very expensive
 Moves the cursor faster than the arrow keys.

Types of mouse

 Mechanical mouse
 It encloses a rubber or metal ball in it.
 The movement of the cursor depends on the movement of the ball.
 This mouse is normally used on a mouse pad made of rubber or foam to provide easy movement and
protects the mouse from dust and dirt.
 Optical mouse
 It contains no ball inside it.
 It uses a device that emits light to detect the mouse movement.
 Optical sensor or laser is used in these types of mouse.
 It is more costly than a mechanical mouse.
 Wireless or cordless mouse
 It does not require a wire to work.
 It transmits data using wireless technology like radio waves or infrared light waves.

3) Touch Screen
 The touch screen is a video display screen (pointing device) that receives input from the touch of a
finger.
 The screen is covered with a plastic layer. There are undetectable beams of infrared light at the
back of the screen.
 In order to enter data, the user touches icons or menus on the screen.

4) Tablet
It is also a positioning device
It is used to describe a flat surface separate from the display, on which the user draws with a stylus.

There are two types of tablets:


Acoustic Tablet: 
 It depends on the use of strip microphones which are mounted along two adjacent edges.
 The styles have a small piece of ceramic mounted close to its tip, and at regular intervals, a
small spark is generated across the surface of the ceramic between two electrodes.
 The microphones pick up the pulse of sound produced by the spark
 Two counters record the delay between creating the spark and receiving the sound. These two
delays are proportional to the stylus distance from the two edges of the tablet where the
microphones are mounted.

Electro-acoustic Tablet:

 In this technique, the writing surface is a sheet of magnetostrictive material acting as a row of
delay lines.
 An electric pulse travels through the sheet first horizontally and then vertically and is detected
by a sensor in the stylus.
 A counter is used to determine the delay from the time the pulse is issued to the time it is
detected; from this value, the position of the stylus can be determined.
 The electro-acoustic tablet is quieter in operation than its acoustic counterpart and is less
affected by noise or air movement.

5) Joystick
 A joystick consists of a small that is used to steer the screen cursor around.(pointing device)
 The distance that the stick is moved in any direction from its center position corresponds to the
screen-cursor movement in that direction.
 Pressure sensitive joysticks have a non-moveable stick.
 Pressure on the stick is measured with strain gauges and converted to the movement of the
cursor in the direction specified.
6) Trackball
 It is a pointing device
 It is a ball that can be rotated with the fingers to produces screen-cursor movement
 Potentiometers, attached to the ball, measure the amount and direction of rotation.
7) Spaceball
 It is used for three-dimensional positioning and selection operation in virtual reality system,
modeling, animation, CAD and other applications.
8) Touchpad
 A touchpad is a small, plane surface over which the user moves his finger.
 The user controls the movement of the cursor on the screen by moving his fingers on the
touchpad.
 It is also known as a trackpad.

Direct method of line drawing


The Cartesian slope-intercept equation for a straight line is
y= mx + b
with m representing 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

we can determine values for the slope m and y intercept b with the following calculations:
m= (y2-y1)/(x2-x1) & b= y1 – m * x1

if |m| <= 1, then for every integer value of x between x1 and x2, calculate corresponding value of y.
if |m| > 1, then for every integer value of y between y1 and y2, calculate corresponding value of x.

if |m| <= 1
then,
xi+1 = xi +1
yi+1 = m * xi+1 + b

if |m| > 1
then,
yi+1 = yi +1
yi+1 = m * xi+1 + b
DDA algorithm
The digital differential analyzer (DDA) is a scan-conversion line algorithm based on calculating either ∆y or
∆x.
If the slope is less than or equal to 1, we sample at unit x intervals (∆x = 1) and compute each
successive y value as

For lines with a positive slope greater than 1, we reverse the roles of x and
y. That is, we sample at unit y intervals (∆y = 1) and calculate each succeeding x
value as
This algorithm is summarized in the following procedure, which accepts as input the two end point pixel
positions. Horizontal and vertical differences between the endpoint positions are assigned to parameters dx
and dy. The difference with the greater magnitude determines the value of parameter steps. Starting with pixel
position (xa, ya), we determine the offset needed at each step to generate the next pixel position along the line
path. We loop through this process steps times. If the magnitude of dx is greater than the magnitude of dy and
xa is less than xb, the values of the increments in the x and y directions are 1 and m, respectively. If xa is
greater than xb, then the decrements - 1 and -m are used to generate each new point on the line.
Otherwise, we use a unit increment (or decrement) in the y direction and an x increment
(or decrement) of 1 / m.

Algorithm

#include 'device. h"


#define Round(a) ((int)(a +0.5))
void lineDDA (int xa, int ya, int xb, int yb)
{
int dx = xb - xa, dy = yb - ya, steps, k;
float xIncrement, yIncrement, x = xa, y = ya;
if (abs (dx) > abs (dy)) steps = abs (dx) ;
else steps = abs dy;
xIncrement = dx / (float) steps;
yIncrement = dy / (float) steps
setpixel (ROUND(x), ROUND(y) ) :
for (k=0; k<steps; k++) (
x += xIncrment;
y += yIncrement;
setpixel (ROUND(x), ROUND(y))
)
}

Advantages:
 It is a faster method than method of using direct use of line equation.
 This method does not use multiplication theorem.
 It allows us to detect the change in the value of x and y ,so plotting of same point twice is not
possible.
 This method gives overflow indication when a point is repositioned.
 It is an easy method because each step involves just two additions.
Disadvantages:
 It involves floating point additions rounding off is done. Accumulations of round off error cause
accumulation of error.
 Rounding off operations and floating point operations consumes a lot of time.
 It is more suitable for generating line using the software. But it is less suited for hardware
implementation.

Bresenham's Line Algorithm


Assume a pixel P1'(x1',y1'),then select subsequent pixels as we work our way to the right, one pixel position at
a time in the horizontal direction toward P2'(x2',y2').
Once a pixel in choose at any step, the next pixel is: -
 Either the one to its right (lower-bound for the line)
 One top its right and up (upper-bound for the line)
The line is best approximated by those pixels that fall the least distance from the path between P1', P2'.

Our task is to choose the next one between the bottom pixel S and top pixel T.
If S is chosen
We have xi+1=xi +1 and yi+1 = yi
if T is chosen
We have xi+1=xi +1 and yi+1 = yi +1

The actual y coordinates of the line at x = xi+1 is y=mxi+1+b, i.e.,


The distance from S to the actual line in y direction
db = y - yi
The distance from T to the actual line in y direction
da = (yi+1)-y
Now consider the difference between these 2 distance values
db – da
When (db – da) <0 ⟹ s < t The closest pixel is S & is chosen
When (db – da) ≥0 ⟹ s < t The closest pixel is T & is chosen.

This difference is
           db – da = (y-yi)-[(yi+1)-y]
                    = 2y - 2yi - 1
= 2(mxi +m) +2b -2yi -1
Substituting m by ∆y/∆x and introducing decision variable
                pi = △x (db-da)
                pi = △x (2(mxi +m) +2b -2yi -1)
                  = 2∆yxi + 2∆y +2b∆x - 2yi ∆x -∆x
              pi = 2△y.xi-2△x.yi+c
Where c= 2△y+△x (2b-1)

We can write the decision variable pi+1 for the next slip on


                pi+1=2△y.xi+1-2△x.yi+1+c
                pi+1-pi=2△y . (xi+1-xi)- 2△x(yi+1-yi)
Whether we choose S or T x(i+1)=xi+1, therefore
pi+1= pi + 2△y - 2△x(yi+1-yi)

If chosen pixel is at the top pixel T (i.e., pi≥0)⟹ yi+1=yi+1


                pi+1=pi+2△y-2△x

If chosen pixel is at the bottom pixel S (i.e., pi<0)⟹ yi+1=yi


                pi+1=pi+2△y

Finally, we calculate p1
                p1=△x[2m(x1+1)+2b-2y1-1]
                p1=△x[2(mx1+b-y1)+2m-1]
Since mx1+b-yi=0 and m = ∆y/∆x we have
                p1=2△y-△x

Algorithm

Int x = x1’, y= y1’


Int dx = x2’ – x1’ ; dy = y2’ – y1’
P = 2 * dy – dx
SetPixel (x,y)
While(x<x2’)
{
x++
if (p<0)
p = p + 2dy
else{
y++
p = p + 2dy -2dx
}
SetPixel (x,y)
}
Advantages:
 It involves only integer arithmetic, so it is simple.
 It avoids the generation of duplicate points.
 It can be implemented using hardware because it does not use multiplication and division.
 It is faster as compared to DDA (Digital Differential Analyzer) because it does not involve floating point
calculations like DDA Algorithm.
Disadvantages:
 This algorithm is meant for basic line drawing only
Circles
Equation of a circle with center (h,k) and radius r is
(x-h)2 + (y-k)2 = r2
With center origin
x2 + y2 = r2

Polynomial Method
Polar co-ordinate method
In this x = r Cos θ
y = r Sin θ

Bresenham’s Circle Drawing Algorithm


Advantages of Bresenham’s Circle Drawing Algorithm
 It is simple and easy to implement.
 The algorithm is based on simple equation x2 + y2 = r2.
Disadvantages of Bresenham’s Circle Drawing Algorithm
 The plotted points are less accurate than the midpoint circle drawing.
 It is not so good for complex images and high graphics images.
Mid point circle drawing algorithm
The mid-point circle drawing algorithm is an algorithm used to determine the points needed for rasterizing a
circle.
We use the mid-point algorithm to calculate all the perimeter points of the circle in the first octant and then print
them along with their mirror points in the other octants.
To apply the midpoint method, we define a circle function:
F(p) = x2 + y2 – r2
Any point ( x , y) on the boundary of the circle with radius r satisfies the equation
Fcircle(x, y) = 0.
If the point is in the interior of the circle, the circle function is negative. And if the point is outside the circle, the
circle function is positive.

Fcircle at mid point (xi + 1, yi -1/2)= (xi + 1)2 + (yi -1/2)2 – r2


di = (xi + 1)2 + yi2 +1/4 -yi– r2
Advantage of mid point circle algorithm:
1. it helps in scan-conversion algorithms very efficiently, by drawing the curves (Geometric) on Displays of
raster.
2. The Non-Parametric Equations are easily transformed by this method using a function (f(x,y) = 0), in order
to describe the curve, to draw a curve and convert it to algorithms

Disadvantage of mid point circle algorithm:


1.It consumes too much time.
2.The distance between the pixels is not equal so we won’t get smooth circle .
Boundary fill algorithm
An approach to area filling is to start at a point inside a region and paint the interior outward toward the
boundary. If the boundary is specified in a single color, the fill algorithm proceeds outward pixel by pixel until
the boundary color is encountered. This method, called the boundary-fill algorithm.
Flood Fill Algorithm:
In this method, a point or seed which is inside region is selected. This point is called a seed point. Then four
connected approaches or eight connected approaches is used to fill with specified color.
The flood fill algorithm has many characters similar to boundary fill. But this method is more suitable for filling
multiple colors boundary. When boundary is of many colors and interior is to be filled with one color we use this
algorithm.

Disadvantage:
 Very slow algorithm
 May be fail for large polygons
 Initial pixel required more knowledge about surrounding pixels.

Algorithm
voidfloodFill4 ( int x, int y, int fill, int old)
{
if (getpixel (x. y) == old)
{
setcolor ( fill ) ;
setpixel (x, y);
floodFill4 (x + 1, y, fill, old):
floodfill4 (x-1, y, fill, old);
floodPill4 (x, y + 1, fill, old);
floodFill4 (x, y-1, fill, old);
}
}

Scan Line Polygon filling Algorithm:-


Recursive algorithms for seed fill methods have got two difficulties:-
1. The first difficulty is that if some inside pixels are already displayed in fill color then recursive branch
terminates leaving further internal pixels unfilled.
2. Another difficulty with recursive seed fill methods is that it cannot be used for large polygons.

To avoid this problem more efficient method can be used. Such method fills horizontal pixels spans across
scan lines, instead of proceeding to 4-connected or 8-connected neighboring points. This is achieved by
identifying the rightmost and leftmost pixels of the seed pixel and then drawing a horizontal line between these
two boundary pixels. This procedure is repeated with changing the seed pixel above and below the line just
drawn until complete polygon is filled. With this efficient method we have to stack only a beginning position for
each horizontal pixel span, instead of stacking all unprocessed neighboring positions around the current
position.
The figure (a) illustrates the scan line algorithm for filling of polygon. For each scan line crossing a polygon,
this algorithm locates the intersection points of the scan line with the polygon edges. These intersection points
are then sorted from left to right, and the corresponding positions between each intersection pair are set to the
specified fill color.
In figure (a), we can see that there are two stretches of interior pixels from x =6 to x = 9 and x = 12 to x 15.The
scan line algorithm first finds the largest and smallest y values of the polygon. It then starts with the largest y
value and works its way down, scanning from left to right, in the manner of a raster display.
The important task in the scan line algorithm is to find the intersection points of the scan line with the polygon
boundary. When intersection points are even, they are sorted from left to right, paired and pixels between
paired points are set to the fill color. But in some cases intersection point is a vertex. When scan line intersects
polygon vertex a special handling is required to find the exact intersection points. To handle such cases, we
must look at the other endpoints of the two line segments of the polygon which meet at this vertex. If these
points lie on the same (up or down) side of the scan line, then the point in question counts as an even number
of intersections. If they lie on opposite sides of the scan line, then the point is counted as single intersection.
This is illustrated in figure (b).

As shown in the figure (b), each scan line intersects the vertex or vertices of the polygon. For scan line 1, the
other end points (B and D) of the two line segments of the polygon lie on the same side of the scan line, hence
there are two intersections resulting two pairs: 1-2 and 3-4. Intersections points 2 and 3 are actually same
points. For scan line 2, the other endpoints (D and F) of the two line segments of the polygon lie on the
opposite sides of the scan line, hence there is a single intersection resulting two pairs: 1 -2 and 3 - 4. For scan
line 3, two vertices are the intersection points. For vertex F the other end points E and C of the two line
segments of the polygon lie on the same side of the scan line whereas for vertex H, the other endpoints G and
I of the two line segments of the polygon lie on the opposite side of the scan line.Therefore, at vertex F there
are two intersections and at vertex H there is only one intersection. This results two pairs: 1 -2 and 3-4 and
points 2 and 3 are actually same points.
We have seen that it is necessary to calculate x intersection points for scan line with every polygon side. We
can simplify these calculations by using Coherence Properties. A coherence property of a scene is a property
of a scene by which we can relate one part of a scene with the other parts of a scene. Here, we can use a
slope of an edge as a coherence Property. By using this property we can determine the x intersection value on
the lower scan line if the x intersection value for current scan line is known. This is given as,
Where m is the slope of the edge.
As we scan from top to bottom value of y coordinates between the two scan line changes by 1.

Many times it is not necessary to compute the x intersections for scan line with every polygon side. We need to
consider only the polygon sides with endpoints straddling the current scan line. See figure (c).

It will be easier to identify which polygon sides should be tested for x-intersection. if we first sort the sides in
order of their maximum y value. Once the sides are sorted we can process the scan lines from the top of the
polygon to its bottom producing an active edge list for each scan line crossing the polygon boundaries. The
active edge list for a scan line contains all edges crossed by that scan line. The figure (d) shows sorted edges
of the polygon with active edges.
A scan line algorithm for filling a polygon begins by ordering the polygon sides on the largest y value.It begins
with the largest y value and scans down the polygon. For each y, it determines which sides can be intersected
and finds the x values of these intersection points.It then sorts, pairs and passes these x values to a line
drawing routine.

You might also like