UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie...
Transcript of UNIT-II Polygons · Polygon Filling Filling the polygon means highlighting all pixels which lie...
UNIT-II Polygons
Syllabus
UNIT 2
Polygons (08 Hours, 16 marks)
Polygons
Types of Polygons
Polygons filing
Scan conversion algorithm
Segments
Polygons
Introduction
Terminal point
Polyline
Polygon
Types of polygon
Convex
Concave
Polygons
Representation of Polygons
Polygon drawing Primitive approach
Trapezoid primitive approach
Line and Point approach
Polygon drawing Primitive approach
Some graphics devices supports polygon drawing
primitive approach. They can directly draw the polygon
shapes. On such a devices polygons are saved as a unit.
Polygons are drawn line by line using standard graphics
line command.
Representation of Polygons(Cont….)
Trapezoid primitive approach
Trapezoids are formed from 2 scan lines & 2 line
segments.
Every polygon is broken up into trapezoids & it is
represented as a series of trapezoids.
Representation of Polygons(Cont….)
Line and Point approach
Polygons are represented using lines & points.
A polygon is represented as a unit & it is stored in display
file.
In display file polygon can not be stored only with series of
line commands because they do not specify how many of the
following line commands are the part of the polygon.
Therefore new command is used in the display file to
represent polygons.
The opcode for new command itself specify the number of
line segments in the polygons.
Representation of Polygons(Cont….)
Line and Point approach
Entering Polygons
It describes how to enter polygon command & data into
display file.
We know that, we have to enter number of sides & the
coordinates of the vertex points.
This can be entered using following algorithm
An Inside Test
After Entering ,We can draw the outline of the polygon.
To show the polygon as a solid object we have to set the
pixels inside the polygon as well as pixels on the
boundary of it.
To determine the pixel inside or outside the polygon; an
inside test is applied.
1. Even-odd method of determining polygon inside point.
2. Winding-Number Method of determining polygon inside
point.
Even-odd method of determining polygon inside point
Count how many intersections
of the line segment with the
polygon boundary occur.
If there are odd number of
intersections ,then the point
(to be tested) is inside ;
otherwise point(pixel) is
outside.
This method is called the
even-odd method of
determining polygon inside
points.
Even-odd method of determining polygon inside
point(cont…)
If the intersection point is vertex of the polygon then we have to look at the other endpoints of the two segments which meet at that vertex.
If these points lie on the same side of the constructed line, then the point counts as even number of intersections.
If they lie on the opposite sides of the constructed line , then the point is counted as a single ( odd) intersection
Winding-Number Method of determining polygon
inside point
Give direction number to each boundary line crossed.
After giving direction numbers we have to take sum of theses direction numbers which indicates whether the point in inside the polygon or not.
The sum of the direction numbers for the sides that cross the constructed horizontal line segment is called the winding number for the test point.
For polygons or two dimensional objects the point is said to be inside when the value of winding number is nonzero.
Polygon Filling
Filling the polygon means highlighting all pixels which lie inside
the polygon with any color other than background color.
Algorithm for polygon filling
Seed Fill Algorithm
Flood Fill Algorithm
Boundary Fill Algorithm/edge-
Fill Algorithm
Scan Line Algorithm
Seed Fill Algorithm
To fill a polygon is to start from a given “seed”, point
known to be inside the polygon & highlight outward from
this point i.e. Neighboring pixels until we encounter the
boundary pixels.
This approach is called seed fill because color flows from
the seed pixel until reaching the polygon boundary.
1. Boundary Fill algorithm OR Edge Fill algorithm
Algorithm that fill boundary defined regions are called
boundary fill algorithms or edge fill algorithms
In this method, edges of polygons are drawn.
Boundary Fill algorithm OR Edge Fill algorithm
Algorithm that fill boundary defined regions are called
boundary fill algorithms or edge fill algorithms
In this method, edges of polygons are drawn.
Starting with some seed , any point inside polygon we examine
the neighboring pixels to check whether the boundary pixel is
reached.
If boundary pixels are not reached, pixels are highlighted &
the process is continued until pixels are reached.
Boundary defined regions may be either 4-connected or 8-
connected as shown in figure.
Fig.Partial Filling resulted using 4-connected algorithm
Procedure shows 4-connected region using Boundary Fill Algorithm
Flood Fill algorithm
In this algorithm, we can fill areas by replacing a specified
interior color instead of searching for a boundary color.
Like boundary fill algorithm, here we start with some seed &
examine the neighboring pixels.
However, here pixels are checked for a specified interior
color instead of boundary color & they are replaced by new
color.
Either 4-connected or 8-connected approach is used for filling
the polygon.
Procedure shows 8-connected region using Flood Fill algorithm
Scan Line algorithm
This is another approach to fill polygon, which uses an inside test i.e. to check whether the pixel is inside the polygon or outside the polygon & then highlight pixels which lie inside the polygon.
It avoids the need for a seed pixel but it requires some computations.
It uses scan line.
Such method fills horizontal pixel spans across scan lines, instead of proceeding to 4-connected or 8-connected neighboring points.
This is achieved by identifying the rightmost & leftmost pixels of the seed pixel & then drawing horizontal line (scan line) between these 2 boundary pixels.
This procedure is repeated with changing the seed pixel above & below the line just drawn until complete polygon is filled.
Scan Line algorithm(Cont..)
This algorithm first finds the largest & smallest y values of polygon.
It then start from largest y value & works its way down.(left to right like raster)
Important task in the scan line algorithm is to find the intersection points of the scan line with the polygon boundary.
Apply inside test for this purpose.
If there are odd number of intersections ,then the point (pixel) is inside ; otherwise pixel is outside
If the intersection point is vertex of the polygon then we have to look at the other endpoints of the two segments which meet at that vertex.
If these points lie on the same side(either up or down) of the constructed line, then the point counts as even number of intersections.
Scan Line algorithm(Cont..)
If they lie on the opposite side(one on upside and other one on
downside) of the constructed line ,then the point is counted as a
single (odd) intersection.
It is necessary to calculate x intersection points for scan line
with every polygon side.
We can simplify these calculations by using coherence
properties.
It’s a property of any scene by we can relate one part of
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 x intersection value for current
scan line is known. This is given as-
X i+1 = Xi – (1/m)
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.
Y i+1 = Yi – 1
Filling with Patterns
Pattern is a small group of pixels with a fixed color combination used to fill the particular area in the picture.
Can be any shape.
Tiling
Tiling pattern
Pattern fill can be implemented by modifying the scan line algorithm. So that selected pattern is superimposed onto the scan lines.
In the pattern filling it is necessary to decide which pixel in the pattern corresponds to the current pixel of the primitive. Relating area of the pattern with the area of the primitive is known as anchoring.
Two methods to implement pattern filling
Stamping
True Filling
Filling with Patterns(Cont..)
Scan conversion
The process of representing pictures or graphics object as a collection of discrete pixels is called scan conversion.
It’s a process of organizing graphics picture into precise pattern required by graphics display is called scan conversion.
Display file store the information about lines & character whereas scan conversion gives the information about every pixel on the screen.
four different ways (methods) to accomplish scan conversion-
1) Real Time Scan Conversion
2) Run Length Encoding
3) Cell Encoding
4) Solid Area Scan Conversion
Real Time Scan Conversion
In a real time scan conversion the picture is randomly
represented in terms of visual attributes & geometric properties.
The color, shade & intensity are the examples of visual attributes
of the picture whereas x-y coordinates, slope & text are the
typical geometric properties of the picture.
Display processor scans through these geometric properties &
visual attributes calculates the intensity of every pixel on the
screen during the presentation of each frame.
Run Length Encoding
Picture can be defined by pixel intensity & number of successive pixels on given scan line with the same intensity i.e. Run length. Such a representation of a picture is called run length encoding.
The first number is the intensity & second is the number of successive pixel on that scan line with same intensity.
In pixel by pixel storage i.e. one piece of information for each pixel require 225 intensity values for the 15*15 raster.
However ,with run length encoding the complete picture is encoded with only 102 numbers.
Color picture is encoded in 4 groups- Red Intensity(RI),Green Intensity(GI),Blue Intensity(BI), & Run Length (RL).
Run length encoding technique can also be used for solid objects.
Run Length Encoding(Cont…)
Figure shows a simple picture on 15*15 raster & associated
encoding for each scan line.
Encoded data in 2 groups – Intensity(I) & Run length (RL).
Run Length Encoding(Cont…)
Picture is stored in compressed form with compression ratio
approaching 10:1
Less memory is required to store picture.
Saves storage space.
Saves transmission time.
As run lengths are stored sequentially ,adding or deleting lines
or texts from the picture is difficult and time consuming.
It requires extra overhead in encoding & decoding the picture.
For short runs, expansion may result instead of compression.
Cell Encoding
Picture is encode the raster as a set of rectangular or square
areas called cell encoding.
The set of rectangular or square area used to represent
minimum of information is called cell.
The entire screen is divided into cells & the size of cell is kept
large to contain one character.
Ex.Screen may be divided into areas containing 8*8 pixels
i.e.cell height & cell width both are 8 pixels wide.
There are 64*64 cells for a 512*512 display or 60*80 cells for
a 480*640 video compatible display.
Usually a cell of 8*8 is used for a 5*7 dot matrix character
display & 8*10 pixel is used for 7*9 dot matrix characters.
Solid Area Scan Conversion
Raster scan device can represent solid areas.
The generation of solid areas from simple edge or vertex
description is called Solid Area Scan Conversion/Polygon
filing.
For generating solid area – 2 techniques
1. Scan Conversion
2. Seed Fill
1. Scan Conversion :- Determine whether point is inside or outside
polygon.
2. Seed Fill :- Seed ( which is inside the polygon) is used.
Search adjacent points & fill the polygon.
Raster Scan Display
• Electron beam swept across the screen one row at a time from top to bottom.
• As the beam moves across each row the beam intensity is turned on and off to
create pattern of illuminated spots.
• Picture definition stored in memory area called frame buffer or refresh buffer
• This memory area actually holds the set of intensity values for all screen points.
These stored intensity values are then retrieved from buffer and painted on
screen one row at a time.
GUI
Plotting of graphics and charts
Flat Panel Display
Reduced volume, weight, power requirements compared to CRT
Thinner than CRT
Types
Emissive: convert electrical energy into light energy.
Non-emissive: They use optical effects to convert sunlight or
light from other source into graphics pattern.
Plasma Panel Display
It writes images on the display surface point by point.
It consists of two plates of glass with thin closely spaced gold electrodes.
The gold electrodes are attached to the inner faces and covered with dielectric material. These are attached as a series of vertical conducting ribbons on one glass plate and a set of horizontal ribbons to the other glass plate. The space between two glass plates is filled with neon-based gas and sealed.
By applying voltages between the electrodes the gas within the panel is made to behave as if it were divided into tiny cells, each one independent of its neighbors.
Plasma Panel Display
Plasma Panel Display(Continue….)
These independent cells are made to glow by placing a firing voltages of about 120 volts across it by means of the electrodes. The glow can be sustained by maintaining a high frequency.
Advantages
Refreshing not required
Produce a very steady image, totally free of flicker
Less bulky than a CRT
It has the flat screen and is transparent
Disadvantages
Relatively poor resolution of about 60dots per inch.
It requires complex addressing and writing
Costlier than the CRT.
LCD
The compounds have a crystalline arrangement of molecules, they flow like a liquid
Nematic(Thread like) liquid crystal compounds
Two glass plates each containing a light polarizer at right angles to the other plate sandwich the liquid-crystal material. Rows of horizontal transparent conductors are built into one glass plate and columns of vertical conductors are put into the other plate. The intersection of two conductors defines a pixel position.
In the ON state polarized light passing through material is twisted so that it will pass through the opposite polarizer.
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.
LCD(Continue….)
Interactive Devices
Joystick
Interactive Devices
Touch panels
Interactive Devices
Light Pens
Output Devices
Scanners
Output Devices
Digitizers/ Tablets
Line Generation algorithms
Some useful terms/concepts for understanding Line Generation
algorithms
Output primitives
Line
Point
2D,3D
Equation of line
Slope
Intercept
Line segments
Length of the line
Vectors
Incremental methods/ Incremental algorithm
Line Generation Algorithms/ Line Drawing Algorithms
The process of turning on the pixels for a line segments is called
vector generation or line generation.
General requirements of line drawing algorithm can be
fulfilled by following characteristics of line.
The line should appear as a straight line and it should start and end
accurately.
The line should be displayed with constant brightness along its length
independent of its length and orientation.
The line should drawn rapidly.
Different Lines and their orientation
Few Line Generation Algorithms based on incremental
method/ incremental Algorithm.
Vector generation/DDA Algorithm/DDA Line Drawing
algorithm. Where DDA-Digital Differential Analyzer
Bresenham’s Line Algorithm/ Bresenham’s Line Drawing
Algorithm
Generalized Bresenham’s Line Algorithm/ Bresenham’s Line
Drawing Algorithm
Line Styles
Dotted Line
Dashed line
Thick Line
Thick Lines
So far we have discussed line drawing algorithms where
thickness of line is one pixel
In raster scan displays it is possible to draw lines with thickness
greater than one pixel.
We have to run two line drawing algorithms in parallel to find
the pixels along the line edges and while stepping along the
line we have to turn on all the pixels which lie between the
boundaries.
Thick Lines(Cont…)
Antialiasing
In the line drawing algorithms we have seen that all rasterized
locations do not match with the true line and we have to select
the optimum raster locations to represent a straight line. This
problem is severe in low resolution screens. In such screens line
appears like a stair step. This effect is known as Aliasing .
The aliasing effect can be reduced by adjusting intensities of
the pixels along the line. The process of adjusting intensities of
the pixels along the line to minimize the effect of aliasing is
called Antialiasing.
The aliasing effect can be minimized by increasing resolution
of the raster display.
As shown in the figure, line looks better in twice resolution but
this improvement comes at the price of quadrupling the cost of
memory, bandwidth of memory and scan-conversion time. Thus
increasing resolution is an expensive method for reducing
aliasing effect.
Unweighted Area Sampling
Many times the line passes between two pixels. In theses cases line drawing algorithm selects the pixel which is closer to the true line.
In antialiasing instead of picking closest pixel ,both pixels are highlighted. However ,their intensity values may differ.
In unweighted are sampling the intensity of pixel is proportional to the amount of line are occupied by the pixel.
This technique produces noticeably better results than does setting pixels either to full intensity or to zero intensity.
Unweighted Area Sampling(Figure)
Weighted Area Sampling
Small area in the corner of the pixel contributes just as much as
does an equal-sized area near the pixels center. To avoid this
problem even better strategy is used in the weighted area
sampling.
Few Circle Drawing/Generation Algorithms
Vector generation/DDA Algorithm/DDA Circle Drawing
algorithm. Where DDA-Digital Differential Analyzer.
Bresenham’s Algorithm/ Bresenham’s Circle Drawing Algorithm
Midpoint Algorithm
Bresenham’s Circle Drawing Algorithm
If the circle is to be plotted efficiently the use of trigonometric and power functions must be avoided.
It is desirable to perform the calculations necessary to find the scan-converted points with only integer addition, subtraction and multiplication by powers of 2.
This algorithm considers the eight-way symmetry of the circle to generate it. It plots 1/8th part of the circle i.e. from 90o to 45o
,the x moves in positive direction and the y moves in negative direction.
To achieve best approximation to the true circle we have to select those pixels in the raster that fall the least distance from the true circle.
Bresenham’s Circle Drawing Algorithm(Cont….)
It can be noticed that if points are generated from 90o to 45o,
each new point closest to the true circle can be found by
applying either of the two options:
Increment in positive x direction by one unit or
Increment in positive x direction and negative y direction both by
one unit.
Therefore a method of selecting between these two choices is
all that is necessary to find the points closest to the true circle.
Bresenham’s Circle Drawing Algorithm(Cont….)
Midpoint Circle Drawing Algorithm
The midpoint circle drawing algorithm also uses the eight-way
symmetry of the circle to generate it.
It plots 1/8th part of the circle, from 90o to 45o.
Character Generation Methods
Letters ,numbers and other characters can be displayed in a
variety of sizes and styles to label drawing.
Mostly characters are built into graphics display devices
usually as hardware but sometimes through software.
There are mainly three methods for character generation as,
Stroke method
Starbust method
Bitmap method
Stroke method
uses small segments to generate a character.
Lines segment are generated like strokes of a pen to form
characters.
We can build our own stroke method character generator by
calls to the line drawing algorithm and necessary.
It supports scaling of characters by changing length of line
segment.
Starbust method
In this method a fix pattern of line segments are used to
generate a characters.
Total 24 line segments from these 24 segments required to
display for particular character are highlighted.
It is called starbust because of its characteristics appearance.
Patterns for particular characters are stored in the form of 24-
bit code each bit representing. One line segment set to 1 or 0.
This method not used now a days.
Starbust method(Cont…)
Disadvantages
24-bits required to represent character hence more memory
required.
Requires code conversion software to display character from
its 24-bit code.
Character quality is poor and worst for curved shaped
characters.
Bitmap method
This method also called as Dot Matrix.
In this method characters are represented by an array of dots
in matrix form. For example 5 × 7 or 7 × 9 or 9 × 13 array.
Character is placed on screen by copying pixel value from
character array into some portion of screens frame buffer.
Thank you