CG Chapter No 2
CG Chapter No 2
Output Primitives
Computer Graphics(CSE305) 1
Introduction
⮚ Shapes and colors of the objects can be described internally with pixel arraysorwithsetsof basic
geometric structures, such as straight line segments and polygoncolor areas
⮚ The picture is then displayed either by loading the pixel arrays into the framebufferorbyscan
converting the basic geometric-structure specifications into pixel patterns.
⮚ Each output primitive is specified with input coordinate data and other informationaboutthe
way that object is to be displayed.
⮚ Points and straight line segments are the simplest geometric components of pictures.
Computer Graphics(CSE305) 2
Graphics(CSE305) 3
POINTS ANDLINES
⮚ With a CRT monitor, the electron beam is turned on to illuminatethescreenphosphor
at the selected location.
⮚ For A random-scan (vector) system ⮚ stores point-plotting instructions in the display
list file andcoordinatevalues in these instructions
⮚ The frame buffer is loaded with the color codes for the intensitiesthatareto be
displayed at the screen pixel positions
Computer Graphics(CSE305) 4
POINTS ANDLINES
⮚ For a black and-white raster system ⮚ A point is
plotted by setting the bit value
corresponding to a specified screen position
within the frame buffer to 1.
tobedisplayed
with a stairstep appearance ("the jaggies"), ⮚ noticeable on systems
⮚ We can
set and get the pixel position with the help of followingcommands:⮚ setpixel (x,y)
⮚ getPixel (x,y)
Computer Graphics(CSE305) 6
LINE-DRAWINGALGORITHMS
⮚ The Cartesian slope-intercept equation for a
straight line is y= �. � + �
--------- Eq 3.1
⮚ Where �= slope of the line
� = y intercept
-----------Eq 3.2
------Eq 3.3
⮚ For any given x interval Δx along a line, we can compute the correspondingyinterval
Δy from eq 3.2 and Vise versa ,
Δy= m * Δx ----Eq 3.4
and Δx = Δy / m -----Eq 3.5
Computer Graphics(CSE305) 7
▪Δxcanbeset
▪Δycanbeset
▪
Δy
Δy
Δy
Δx Δx Δx
Computer Graphics(CSE305) 8
DDAAlgorithm
⮚ The digital deferential analyzer (DDA) is a scan-
conversionlinealgorithmbased on Calculating either Δy or Δx
DDAAlgorithm
⮚ Last equations are based on the assumption that lines are
tobeprocessedfromthe left endpoint to the right endpoint
⮚ If this processing is reversed, so that the starting endpoint is at
theright,theneither we have Δ x = -1 and
⮚ ��+1 = �� − �⮚ Where ��+1= next point and ��= Old /Prev. point ⮚
1
(when the slope is greater than I) we have Δy = -1 with ��+1 = �� − �
Computer Graphics(CSE305) 10
Example
⮚ Consider Line points are A ( 2 , 2 )
and B ( 9 , 2 ) �1 , �1
�2, �2
⮚ Now calculate Δx and Δy:
Δ x= �2 - �1 Δ y = �2- �1
=9–2=7=2–2=0
m=Δ y
0
Δ x = 7= 0
⮚ Now decide the steps = Highest value of Δx and Δy ⮚ Here Δy= 7 > Δx value
therefore Step = 7
Computer Graphics(CSE305) 11
Example
X value2 Y value
3 2
4 2
5 2
6 2
7 2
8 2
9 2
StartingpointcoordinatevaluesA( 2, 2)
Computer Graphics(CSE305) 12
Grid view
Y axis
10
9
8
7
6
5
4
3
2
1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
xaxis
Computer Graphics(CSE305) 13
DDAAlgosteps
• DDAAlgo accepts as input the two end point pixel positions. • Horizontal and vertical
differences between the endpoint positions areassignedtoparameters dx and dy.
• The difference with the greater magnitude determines the value of parameter steps. • Starting
with pixel position (xa , yb), we determine the offset neededat eachsteptogenerate 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 lessthanxb,thevalues of the
increments in the x and y directions are 1 and m, respectively. • If the greater change is in the x
direction, but xa is greater than xb, then thedecrements-1and -m are used to generate each new
point on the line.
• Otherwise, we use a unit increment (or decrement) in the y direction andanxincrement(or
decrement) of l/m
Computer Graphics(CSE305) 14
DDAAlgo Program
Computer
Graphics(CSE305) 15
Advantages
⮚It is a faster method than method of using direct
useoflineequation.
Computer Graphics(CSE305) 16
point additions rounding off is done. ⮚ Accumulations of round off error cause
accumulation of error.
BresenhamAlgorithm
⮚ An accurate and efficient raster line-generating algorithm,
developedbyBresenham
⮚ For lines with positive slope less than 1 (m<1) : ⮚ Pixel positions along a line
path are then determinedbysamplingatunitx intervals.
⮚ Starting from the left endpoint (x0, y0) of a given line, ⮚ we step to each
successive column (x position) and plot thepixelwhosescan-line y value is
closest to the line path.
Computer Graphics(CSE305) 18
Pixel positionandlines
yk+1
yk
xk xk+1
Computer Graphics(CSE305) 20
Computer Graphics(CSE305) 20
BresenhamAlgorithm
⮚ At sampling position xk+l , we label
vertical pixel separations from the
mathematical line path as d1, and d2
(Fig. 3-8).
⮚ The y coordinate on the mathematical line at pixel column position
xk+l is calculated as
� = �. (�� + �) + �
BresenhamAlgorithm
⮚ And d2 we can calculate as ,
�� = (�� + �) − �
⮚ After putting value of y, We get:
�� = (�� + �) − �. (�� +�) −�
CalculatePk
⮚ by substituting m = AyIAx, where Ay and Ax are the vertical andhorizontal
separations of the endpoint positions, and defining:
⮚ At step k + 1, the decision parameter is evaluated from
Computer Graphics(CSE305) 25
BresenhamAlgorithm
⮚ Substract the equation 4 from 3 to calculate decision parameterforallpixel,
pk + 1
- pk= 2Δ� . �� + 1 − 2Δ �. �� + 1
-2� . ��+2�. ��
pk + 1
- pk= 2Δ� (�� + 1 − �� ) − 2Δ �. (�� + 1 − ��)
⮚ Where �� + 1 = xK + 1
BresenhamAlgorithm
Computer
Graphics(CSE305) 27
as, � = �� + �� − (�
−��)�
function is negative.
⮚ if the point is outside the circle, the circle function is positive.
Computer Graphics(CSE305) 30
⮚ Midpoint: { (xk + 1
)+(xk + 1)
2,yk+ (yk − 1)
, yk- 12)
2} = (xk + 1
is
this midpoirat is inside the circle and the pixel onscanlineyk closer to the circle
boundary.
� �
� − � = � −�
�
�
�� = � + � − � +
Computer Graphics(CSE305) 33
Graphics(CSE305) 35
Graphics(CSE305) 36
Antialiasing
⮚ Definition:
“Displayed primitives generated by the raster algorithms have a jagged, orstairstep,
appearance because the sampling process digitizes coordinatepintsonanobject to discrete
integer pixel positions. This distortion of informationduetolow frequency sampling
(undersampling) is called aliasing.”
Computer Graphics(CSE305) 37
Methods of Antialiasing(AA)
⮚ Four methods:
1. Using high-resolution display,
2. Post filtering (Supersampling),
3. Pre-filtering (Area Sampling),
4. Pixel phasing.
⮚ we are increasing the sampling resolution by treating the screenasif it’smadeof a much
more fine grid, due to which the effective pixel size is reduced.⮚ Now, intensity from each
subpixel is calculated and average intensityofthepixel is found from the average of
intensities of subpixels.
Computer Graphics(CSE305) 38
Methods of Antialiasing(AA)
Computer Graphics(CSE305) 39
⮚ For example: Suppose, a line passes through two pixels. The pixel
coveringbiggerportion(90%) of line displays 90% intensity while less area(10%)
coveringpixeldisplays 10-15% intensity.
⮚ If pixel area overlaps with different color areas, then the final pixel color istakenasan average
of colors of the overlap area.
Methods of Antialiasing(AA)
Comput
er Graphics(CSE305) 41
Methods of Antialiasing(AA)
⮚ Pixel phasing:
⮚ It’s a technique to remove aliasing.
Computer Graphics(CSE305) 42
FILLED-AREAPRIMITIVES
⮚ Area filling is a method or process that helps us to fill anobject, area,orimage.
We can easily fill the polygon.
⮚ Algorithms
1. Scan Line Polygon Fill Algorithm 2. Boundary-Fill Algorithm 3. Flood-
Fill Algorithm
Computer Graphics(CSE305) 43
1. Scan Line PolygonFill Algorithm
⮚ For each scan line crossing a polygon, the area-fill
algorithmlocatestheintersection points of the scan line with the polygon
edges.
Computer Graphics(CSE305) 44
⮚ 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.
Computer
Graphics(CSE305) 47
2.Boundary-Fill Algorithm
⮚ Another approach to area filling is to start at a point insidearegionandpaint
the interior outward toward the boundary.
⮚ If the boundary is specified in a single color, the fill
algorithmproceedsoutward pixel by pixel until the boundary color is
encountered.
Computer Graphics(CSE305) 48
2.Boundary-Fill Algorithm
⮚ two methods for proceeding to neighboring pixels fromthecurrenttestposition.
For 8 connectedpixel
Computer Graphics(CSE305) 50
2.Boundary-Fill Algorithm
Computer
Graphics(CSE305) 51
3.Flood-Fill Algorithm
⮚ Sometimes we want to fill in (or recolor) an area that is not definedwithin a single
color boundary.
Comp
uter Graphics(CSE305) 52
Inside-OutsideTests
⮚ Area-filling algorithms and other graphics processes
oftenneedtoidentifyinterior regions of objects
⮚ two methods are used
1. Odd-even rule, also called the odd parity rule or the evenoddrule• If the
number of polygon edges crossed by this lineisodd, thenPis an interior point.
Otherwise, P is an exterior point.
Inside-OutsideTests
Computer
Graphics(CSE305) 54