SlideShare a Scribd company logo
1 of 55
1
COMPUTER
GRAPHICS
CHAPTER 3
2D GRAPHICS ALGORITHMS
2
2D Graphics Algorithms
 Output Primitives
 Line Drawing Algorithms
 DDA Algorithm
 Midpoint Algorithm
 Bersenhem’s Algorithm
 Circle Drawing Algorithms
 Midpoint Circle Algorithm
 Antialising
 Fill-Area Algorithms
3
Output Primitives
4
Output Primitives
 The basic objects out of which a
graphics display is created are
called.
 Describes the geometry of objects
and – typically referred to as
geometric primitives.
 Examples: point, line, text, filled
region, images, quadric surfaces,
spline curves
 Each of the output primitives has its
own set of attributes.
Output Primitives
 Points
 Attributes: Size, Color.
glPointSize(p);
glBegin(GL_POINTS);
glVertex2d(x1, y1);
glVertex2d(x2, y2);
glVertex2d(x3, y3);
glEnd()
Output Primitives
 Lines
 Attributes: Color, Thickness, Type
glLineWidth(p);
glBegin(GL_LINES);
glVertex2d(x1, y1);
glVertex2d(x2, y2);
glVertex2d(x3, y3);
glVertex2d(x4, y4);
glEnd()
Output Primitives
 Polylines (open)
 A set of line segments joined end to end.
 Attributes: Color, Thickness, Type
glLineWidth(p);
glBegin(GL_LINE_STRIP);
glVertex2d(x1, y1);
glVertex2d(x2, y2);
glVertex2d(x3, y3);
glVertex2d(x4, y4);
glEnd()
Output Primitives
 Polylines (closed)
 A polyline with the last point connected to
the first point .
 Attributes: Color, Thickness, Type
Note: A closed polyline cannot be filled.
glBegin(GL_LINE_LOOP);
glVertex2d(x1, y1);
glVertex2d(x2, y2);
glVertex2d(x3, y3);
glVertex2d(x4, y4);
glEnd()
Output Primitives
 Polygons
 A set of line segments joined end to end.
 Attributes: Fill color, Thickness, Fill
pattern
Note: Polygons can be filled.
glBegin(GL_POLYGON);
glVertex2d(x1, y1);
glVertex2d(x2, y2);
glVertex2d(x3, y3);
glVertex2d(x4, y4);
glEnd()
10
Output Primitives
 Text
 Attributes: Font, Color, Size,
Spacing, Orientation.
 Font:
 Type (Helvetica, Times, Courier etc.)
 Size (10 pt, 14 pt etc.)
 Style (Bold, Italic, Underlined)
11
Output Primitives
 Images
 Attributes: Image Size, Image
Type, Color Depth.
 Image Type:
 Binary (only two levels)
 Monochrome
 Color.
 Color Depth:
Number of bits used to represent
color.
TCS2111
12
Output Primitives
Output Primitive Attributes
Point Size
Color
Line Thickness (1pt, 2pt …)
Type (Dashed, Dotted, Solid)
Color
Text Font (Arial, Courier, Times Roman…)
Size (12pt, 16pt ..)
Spacing
Orientation (Slant angle)
Style (Bold, Underlined, Double lined)
Color
Filled Region Fill Pattern
Fill Type (Solid Fill, Gradient Fill)
Fill Color
Images Color Depth (Number of bits/pixel)
13
Line Drawing Algorithms
Line Drawing
• Line drawing is fundamental to computer graphics.
• We must have fast and efficient line drawing functions.
Rasterization Problem: Given only the two end points, how
to compute the intermediate pixels, so that the set of pixels
closely approximate the ideal line.
Line Drawing - Analytical Method
y y
x x
y x
b a
m
b a
c a ma



 
y
x
y=mx+c
ax bx
A(ax,ay)
B(bx,by)
• Directly based on the analytical equation of a line.
• Involves floating point multiplication and addition
• Requires round-off function.
double m = (double)(by-ay)/(bx-ax);
double c = ay - m*ax;
double y;
int iy;
for (int x=ax ; x <=bx ; x++) {
y = m*x + c;
iy = round(y);
setPixel (x, iy);
}
Line Drawing - Analytical Method
Compute one point based on the previous point:
(x0, y0)…….…………..(xk, yk) (xk+1, yk+1) …….
I have got a pixel on the line (Current Pixel).
How do I get the next pixel on the line?
Next pixel on next column
(when slope is small)
Next pixel on next row
(when slope is large)
Incremental Algorithms
Current
Pixel
(xk, yk)
To find (xk+1, yk+!):
xk+1 = xk+1
yk+1 = ?
(5,2)
(6,1)
(6,2)
(6,3)
• Assumes that the next pixel to be set is on the next column of
pixels (Incrementing the value of x !)
• Not valid if slope of the line is large.
Incrementing along x
Digital Differential Analyzer Algorithm is an incremental
algorithm.
Assumption: Slope is less than 1 (Increment along x).
Current Pixel = (xk, yk).
(xk, yk) lies on the given line. yk = m.xk + c
Next pixel is on next column. xk+1 = xk+1
Next point (xk+1, yk+1) on the line yk+1 = m.xk+1 + c
= m (xk+1) +c
= yk + m
Given a point (xk, yk) on a line, the next point is given by
xk+1 = xk+1
yk+1 = yk + m
Line Drawing - DDA
• Does not involve any floating point multiplication.
• Involves floating point addition.
• Requires round-off function
Line Drawing - DDA
double m = (double) (by-ay)/(bx-ax);
double y = ay;
int iy;
for (int x=ax ; x <=bx ; x++) {
iy = round(y);
setPixel (x, iy);
y+ = m;
}
xk+1 = xk+1
yk+1 = Either yk or yk+1
Midpoint algorithm is an incremental algorithm
Midpoint Algorithm
Assumption:
Slope < 1
Current
Pixel
Candidate Pixels
Current Pixel
( xk, yk)
Midpoint
Line
Coordinates of Midpoint = ( xk+1, yk+(1/2) )
( xk+1, yk)
( xk+1, yk+1)
Midpoint Algorithm - Notations
Midpoint Below Line Midpoint Above Line
Midpoint Algorithm:
Choice of the next pixel
•If the midpoint is below the line, then the next pixel is (xk+1, yk+1).
•If the midpoint is above the line, then the next pixel is (xk+1, yk).
A(ax,ay)
B(bx,by)
Equation of a line revisited.
Let w = bx  ax, and h = by  ay.
Then, h (x  ax)  w (y  ay) = 0.
(h, w , ax , ay are all integers).
In other words, every point (x, y) on the line
satisfies the equation F(x, y) =0, where
F(x, y) = h (x  ax)  w (y  ay).
Equation of the line:
y x
y y x x
y a x a
b a b a
 

 
Midpoint Algorithm:
Regions below and above the line.
F (x,y) > 0
(for any point below line)
F(x,y) < 0
(for any point above line)
F(x,y) = 0
F(MP) > 0
0
)
,
( 
y
x
f
Midpoint below line
F(MP) < 0
Midpoint above line
Midpoint Algorithm
Decision Criteria
Midpoint Algorithm
Decision Criteria
F(MP) = F(xk+1, yk+ ½) = Fk (Notation)
If Fk < 0 : The midpoint is above the line. So the next
pixel is (xk+1, yk).
If Fk  0 : The midpoint is below or on the line. So the
next pixel is (xk+1, yk+1).
Decision Parameter
Midpoint Algorithm – Story so far.
Midpoint Below Line
Next pixel = (xk+1, yk+1)
Fk > 0
yk+1 = yk+1
Midpoint Above Line
Next pixel = (xk+1, yk)
Fk < 0
yk+1 = yk
Midpoint Algorithm
Update Equation
Fk = F(xk+1, yk+ ½) = h (xk+1  ax)  w (yk+½  ay)
But, Fk+1 = Fk + h  w (yk+1 yk). (Refer notes)
So,
Fk< 0 : yk+1 = yk. Hence, Fk+1 = Fk + h .
Fk  0 : yk+1 = yk+1. Hence, Fk+1 = Fk + h  w.
F0 = h  w/2.
Update Equation
30
Midpoint Algorithm
int h = by-ay;
int w = bx-ax;
float F=h-w/2;
int x=ax, y=ay;
for (x=ax; x<=bx; x++){
setPixel(x, y);
if(F < 0)
F+ = h;
else{
F+ = h-w;
y++;
}
}
31
Bresenham’s Algorithm
int h = by-ay;
int w = bx-ax;
int F=2*h-w;
int x=ax, y=ay;
for (x=ax; x<=bx; x++){
setPixel(x, y);
if(F < 0)
F+ = 2*h;
else{
F+ = 2*(h-w);
y++;
}
}
32
Circle Drawing
Algorithms
33
 To determine the closest pixel position to
the specified circle path at each step.
 For given radius r and screen center
position (xc, yc), calculate pixel positions
around a circle path centered at the
coodinate origin (0,0).
 Then, move each calculated position (x, y)
to its proper screen position by adding xc to
x and yc to y.
 Along the circle section from x=0 to x=y in
the first quadrant, the gradient varies from
0 to -1.
Midpoint Circle Drawing Algorithm
TCS2111
34
Midpoint Circle Drawing Algorithm
 8 segments of octants for a circle:
TCS2111
35
Midpoint Circle Drawing Algorithm
 Circle function: fcircle (x,y) = x2 + y2 –r2
> 0, (x,y) outside the circle
< 0, (x,y) inside the circle
= 0, (x,y) is on the circle
boundary
{
fcircle (x,y) =
TCS2111
36
Midpoint Circle Drawing Algorithm
yk
yk-1
midpoint
Next pixel = (xk+1, yk)
Fk < 0
yk+1 = yk
yk
yk-1
midpoint
Next pixel = (xk+1, yk-1)
Fk >= 0
yk+1 = yk - 1
TCS2111
37
Midpoint Circle Drawing Algorithm
We know xk+1 = xk+1,
Fk = F(xk+1, yk- ½)
Fk = (xk +1)2 + (yk - ½)2 - r2 -------- (1)
Fk+1 = F(xk+1, yk- ½)
Fk+1 = (xk +2)2 + (yk+1 - ½)2 - r2 -------- (2)
(2) – (1)
Fk+1 = Fk + 2(xk+1) + (y2
k+1 – y2
k) - (yk+1 – yk) + 1
If Fk < 0, Fk+1 = Fk + 2xk+1+1
If Fk >= 0, Fk+1 = Fk + 2xk+1+1 – 2yk+1
TCS2111
38
Midpoint Circle Drawing Algorithm
For the initial point, (x0 , y0) = (0, r)
f0 = fcircle (1, r-½ )
= 1 + (r-½ )2 – r2
= 5 – r
4
≈ 1 – r
TCS2111
39
Midpoint Circle Drawing Algorithm
Example:
Given a circle radius = 10, determine the circle octant
in the first quadrant from x=0 to x=y.
Solution:
f0 = 5 – r
4
= 5 – 10
4
= -8.75
≈ –9
TCS2111
40
Midpoint Circle Drawing Algorithm
Initial (x0, y0) = (1,10)
Decision parameters are: 2x0 = 2, 2y0 = 20
k Fk x y 2xk+1 2yk+1
0 -9 1 10 2 20
1 -9+2+1=-6 2 10 4 20
2 -6+4+1=-1 3 10 6 20
3 -1+6+1=6 4 9 8 18
4 6+8+1-18=-3 5 9 10 18
5 -3+10+1=8 6 8 12 16
6 8+12+1-16=5 7 7 14 14
TCS2111
41
Midpoint Circle Drawing Algorithm
void circleMidpoint (int xCenter, int yCenter, int radius)
{
int x = 0;
Int y = radius;
int f = 1 – radius;
circlePlotPoints(xCenter, yCenter, x, y);
while (x < y) {
x++;
if (f < 0)
f += 2*x+1;
else {
y--;
f += 2*(x-y)+1; }
}
circlePlotPoints(xCenter, yCenter, x, y);
}
TCS2111
42
Midpoint Circle Drawing Algorithm
void circlePlotPoints (int xCenter, int yCenter,
int x, int y)
{
setPixel (xCenter + x, yCenter + y);
setPixel (xCenter – x, yCenter + y);
setPixel (xCenter + x, yCenter – y);
setPixel (xCenter – x, yCenter – y);
setPixel (xCenter + y, yCenter + x);
setPixel (xCenter – y, yCenter + x);
setPixel (xCenter + y, yCenter – x);
setPixel (xCenter – y, yCenter – x);
}
43
Antialiasing
44
Antialiasing
Antialiasing is a technique used to diminish
the jagged edges of an image or a line, so
that the line appears to be smoother; by
changing the pixels around the edges to
intermediate colors or gray scales.
Eg. Antialiasing disabled:
Eg. Antialiasing enabled:
Antialiasing (OpenGL)
Antialiasing disabled Antialiasing enabled
Setting antialiasing option for lines:
glEnable (GL_LINE_SMOOTH);
46
Fill Area Algorithms
47
Fill Area Algorithms
 Fill-Area algorithms are used to
fill the interior of a polygonal
shape.
 Many algorithms perform fill
operations by first identifying
the interior points, given the
polygon boundary.
48
The basic filling algorithm is commonly used
in interactive graphics packages, where the
user specifies an interior point of the region to
be filled.
Basic Filling Algorithm
4-connected pixels
49
[1] Set the user specified point.
[2] Store the four neighboring pixels in
a stack.
[3] Remove a pixel from the stack.
[4] If the pixel is not set,
Set the pixel
Push its four neighboring pixels
into the stack
[5] Go to step 3
[6] Repeat till the stack is empty.
Basic Filling Algorithm
50
void fill(int x, int y) {
if(getPixel(x,y)==0){
setPixel(x,y);
fill(x+1,y);
fill(x-1,y);
fill(x,y+1);
fill(x,y-1);
}
}
Basic Filling Algorithm (Code)
51
 Requires an interior point.
 Involves considerable amount of
stack operations.
 The boundary has to be closed.
 Not suitable for self-intersecting
polygons
Basic Filling Algorithm
52
 Boundary Fill Algorithm
 For filling a region with a single
boundary color.
 Condition for setting pixels:
 Color is not the same as border color
 Color is not the same as fill color
 Flood Fill Algorithm
 For filling a region with multiple
boundary colors.
 Condition for setting pixels:
 Color is same as the old interior color
Types of Basic Filling Algorithms
TCS2111
53
void boundaryFill(int x, int y,
int fillColor, int borderColor)
{
getPixel(x, y, color);
if ((color != borderColor)
&& (color != fillColor)) {
setPixel(x,y);
boundaryFill(x+1,y,fillColor,borderColor);
boundaryFill(x-1,y,fillColor,borderColor);
boundaryFill(x,y+1,fillColor,borderColor);
boundaryFill(x,y-1,fillColor,borderColor);
}
}
Boundary Fill Algorithm (Code)
TCS2111
54
void floodFill(int x, int y,
int fillColor, int oldColor)
{
getPixel(x, y, color);
if (color != oldColor)
{
setPixel(x,y);
floodFill(x+1, y, fillColor, oldColor);
floodFill(x-1, y, fillColor, oldColor);
floodFill(x, y+1, fillColor, oldColor);
floodFill(x, y-1, fillColor, oldColor);
}
}
Flood Fill Algorithm (Code)
Filling Polygons (OpenGL)
Enabling polygon fill (Default):
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
Disabling polygon fill:
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

More Related Content

Similar to Output Primitives in Computer Graphics and Multimedia

Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1aravindangc
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithmsMohammad Sadiq
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsAmol Gaikwad
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesAnkit Garg
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygonsaa11bb11
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons dericationKumar
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cppAlamgir Hossain
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output PrimitivesPrathimaBaliga
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2SanthiNivas
 
Open GL T0074 56 sm1
Open GL T0074 56 sm1Open GL T0074 56 sm1
Open GL T0074 56 sm1Roziq Bahtiar
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxNaveenaKarthik3
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptxAhmadAbba6
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxKokebe2
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algosimpleok
 
Shape drawing algs
Shape drawing algsShape drawing algs
Shape drawing algsMusawarNice
 

Similar to Output Primitives in Computer Graphics and Multimedia (20)

Computer Graphics Unit 1
Computer Graphics Unit 1Computer Graphics Unit 1
Computer Graphics Unit 1
 
Lines and curves algorithms
Lines and curves algorithmsLines and curves algorithms
Lines and curves algorithms
 
Unit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithmsUnit-2 raster scan graphics,line,circle and polygon algorithms
Unit-2 raster scan graphics,line,circle and polygon algorithms
 
Line drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniquesLine drawing algorithm and antialiasing techniques
Line drawing algorithm and antialiasing techniques
 
Computer graphics notes
Computer graphics notesComputer graphics notes
Computer graphics notes
 
Bresenham circlesandpolygons
Bresenham circlesandpolygonsBresenham circlesandpolygons
Bresenham circlesandpolygons
 
Bresenham circles and polygons derication
Bresenham circles and polygons dericationBresenham circles and polygons derication
Bresenham circles and polygons derication
 
Computer graphics lab report with code in cpp
Computer graphics lab report with code in cppComputer graphics lab report with code in cpp
Computer graphics lab report with code in cpp
 
Unit 3
Unit 3Unit 3
Unit 3
 
lecture 1.pptx
lecture 1.pptxlecture 1.pptx
lecture 1.pptx
 
module 1.pdf
module 1.pdfmodule 1.pdf
module 1.pdf
 
Chapter 3 Output Primitives
Chapter 3 Output PrimitivesChapter 3 Output Primitives
Chapter 3 Output Primitives
 
Computer Graphics Unit 2
Computer Graphics Unit 2Computer Graphics Unit 2
Computer Graphics Unit 2
 
CG-Lecture3.pptx
CG-Lecture3.pptxCG-Lecture3.pptx
CG-Lecture3.pptx
 
Open GL T0074 56 sm1
Open GL T0074 56 sm1Open GL T0074 56 sm1
Open GL T0074 56 sm1
 
Output Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptxOutput Primitive and Brenshamas Line.pptx
Output Primitive and Brenshamas Line.pptx
 
Rasterization.pptx
Rasterization.pptxRasterization.pptx
Rasterization.pptx
 
Chapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptxChapter 3 - Part 1 [Autosaved].pptx
Chapter 3 - Part 1 [Autosaved].pptx
 
Lab lecture 1 line_algo
Lab lecture 1 line_algoLab lecture 1 line_algo
Lab lecture 1 line_algo
 
Shape drawing algs
Shape drawing algsShape drawing algs
Shape drawing algs
 

Recently uploaded

IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...RajaP95
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...Call girls in Ahmedabad High profile
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxhumanexperienceaaa
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...ranjana rawat
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 

Recently uploaded (20)

IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
IMPLICATIONS OF THE ABOVE HOLISTIC UNDERSTANDING OF HARMONY ON PROFESSIONAL E...
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
High Profile Call Girls Dahisar Arpita 9907093804 Independent Escort Service ...
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Roadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and RoutesRoadmap to Membership of RICS - Pathways and Routes
Roadmap to Membership of RICS - Pathways and Routes
 
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptxthe ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
the ladakh protest in leh ladakh 2024 sonam wangchuk.pptx
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
(SHREYA) Chakan Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Esc...
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 

Output Primitives in Computer Graphics and Multimedia

  • 2. 2 2D Graphics Algorithms  Output Primitives  Line Drawing Algorithms  DDA Algorithm  Midpoint Algorithm  Bersenhem’s Algorithm  Circle Drawing Algorithms  Midpoint Circle Algorithm  Antialising  Fill-Area Algorithms
  • 4. 4 Output Primitives  The basic objects out of which a graphics display is created are called.  Describes the geometry of objects and – typically referred to as geometric primitives.  Examples: point, line, text, filled region, images, quadric surfaces, spline curves  Each of the output primitives has its own set of attributes.
  • 5. Output Primitives  Points  Attributes: Size, Color. glPointSize(p); glBegin(GL_POINTS); glVertex2d(x1, y1); glVertex2d(x2, y2); glVertex2d(x3, y3); glEnd()
  • 6. Output Primitives  Lines  Attributes: Color, Thickness, Type glLineWidth(p); glBegin(GL_LINES); glVertex2d(x1, y1); glVertex2d(x2, y2); glVertex2d(x3, y3); glVertex2d(x4, y4); glEnd()
  • 7. Output Primitives  Polylines (open)  A set of line segments joined end to end.  Attributes: Color, Thickness, Type glLineWidth(p); glBegin(GL_LINE_STRIP); glVertex2d(x1, y1); glVertex2d(x2, y2); glVertex2d(x3, y3); glVertex2d(x4, y4); glEnd()
  • 8. Output Primitives  Polylines (closed)  A polyline with the last point connected to the first point .  Attributes: Color, Thickness, Type Note: A closed polyline cannot be filled. glBegin(GL_LINE_LOOP); glVertex2d(x1, y1); glVertex2d(x2, y2); glVertex2d(x3, y3); glVertex2d(x4, y4); glEnd()
  • 9. Output Primitives  Polygons  A set of line segments joined end to end.  Attributes: Fill color, Thickness, Fill pattern Note: Polygons can be filled. glBegin(GL_POLYGON); glVertex2d(x1, y1); glVertex2d(x2, y2); glVertex2d(x3, y3); glVertex2d(x4, y4); glEnd()
  • 10. 10 Output Primitives  Text  Attributes: Font, Color, Size, Spacing, Orientation.  Font:  Type (Helvetica, Times, Courier etc.)  Size (10 pt, 14 pt etc.)  Style (Bold, Italic, Underlined)
  • 11. 11 Output Primitives  Images  Attributes: Image Size, Image Type, Color Depth.  Image Type:  Binary (only two levels)  Monochrome  Color.  Color Depth: Number of bits used to represent color.
  • 12. TCS2111 12 Output Primitives Output Primitive Attributes Point Size Color Line Thickness (1pt, 2pt …) Type (Dashed, Dotted, Solid) Color Text Font (Arial, Courier, Times Roman…) Size (12pt, 16pt ..) Spacing Orientation (Slant angle) Style (Bold, Underlined, Double lined) Color Filled Region Fill Pattern Fill Type (Solid Fill, Gradient Fill) Fill Color Images Color Depth (Number of bits/pixel)
  • 14. Line Drawing • Line drawing is fundamental to computer graphics. • We must have fast and efficient line drawing functions. Rasterization Problem: Given only the two end points, how to compute the intermediate pixels, so that the set of pixels closely approximate the ideal line.
  • 15. Line Drawing - Analytical Method y y x x y x b a m b a c a ma      y x y=mx+c ax bx A(ax,ay) B(bx,by)
  • 16. • Directly based on the analytical equation of a line. • Involves floating point multiplication and addition • Requires round-off function. double m = (double)(by-ay)/(bx-ax); double c = ay - m*ax; double y; int iy; for (int x=ax ; x <=bx ; x++) { y = m*x + c; iy = round(y); setPixel (x, iy); } Line Drawing - Analytical Method
  • 17. Compute one point based on the previous point: (x0, y0)…….…………..(xk, yk) (xk+1, yk+1) ……. I have got a pixel on the line (Current Pixel). How do I get the next pixel on the line? Next pixel on next column (when slope is small) Next pixel on next row (when slope is large) Incremental Algorithms
  • 18. Current Pixel (xk, yk) To find (xk+1, yk+!): xk+1 = xk+1 yk+1 = ? (5,2) (6,1) (6,2) (6,3) • Assumes that the next pixel to be set is on the next column of pixels (Incrementing the value of x !) • Not valid if slope of the line is large. Incrementing along x
  • 19. Digital Differential Analyzer Algorithm is an incremental algorithm. Assumption: Slope is less than 1 (Increment along x). Current Pixel = (xk, yk). (xk, yk) lies on the given line. yk = m.xk + c Next pixel is on next column. xk+1 = xk+1 Next point (xk+1, yk+1) on the line yk+1 = m.xk+1 + c = m (xk+1) +c = yk + m Given a point (xk, yk) on a line, the next point is given by xk+1 = xk+1 yk+1 = yk + m Line Drawing - DDA
  • 20. • Does not involve any floating point multiplication. • Involves floating point addition. • Requires round-off function Line Drawing - DDA double m = (double) (by-ay)/(bx-ax); double y = ay; int iy; for (int x=ax ; x <=bx ; x++) { iy = round(y); setPixel (x, iy); y+ = m; }
  • 21. xk+1 = xk+1 yk+1 = Either yk or yk+1 Midpoint algorithm is an incremental algorithm Midpoint Algorithm Assumption: Slope < 1 Current Pixel
  • 22. Candidate Pixels Current Pixel ( xk, yk) Midpoint Line Coordinates of Midpoint = ( xk+1, yk+(1/2) ) ( xk+1, yk) ( xk+1, yk+1) Midpoint Algorithm - Notations
  • 23. Midpoint Below Line Midpoint Above Line Midpoint Algorithm: Choice of the next pixel •If the midpoint is below the line, then the next pixel is (xk+1, yk+1). •If the midpoint is above the line, then the next pixel is (xk+1, yk).
  • 24. A(ax,ay) B(bx,by) Equation of a line revisited. Let w = bx  ax, and h = by  ay. Then, h (x  ax)  w (y  ay) = 0. (h, w , ax , ay are all integers). In other words, every point (x, y) on the line satisfies the equation F(x, y) =0, where F(x, y) = h (x  ax)  w (y  ay). Equation of the line: y x y y x x y a x a b a b a     
  • 25. Midpoint Algorithm: Regions below and above the line. F (x,y) > 0 (for any point below line) F(x,y) < 0 (for any point above line) F(x,y) = 0
  • 26. F(MP) > 0 0 ) , (  y x f Midpoint below line F(MP) < 0 Midpoint above line Midpoint Algorithm Decision Criteria
  • 27. Midpoint Algorithm Decision Criteria F(MP) = F(xk+1, yk+ ½) = Fk (Notation) If Fk < 0 : The midpoint is above the line. So the next pixel is (xk+1, yk). If Fk  0 : The midpoint is below or on the line. So the next pixel is (xk+1, yk+1). Decision Parameter
  • 28. Midpoint Algorithm – Story so far. Midpoint Below Line Next pixel = (xk+1, yk+1) Fk > 0 yk+1 = yk+1 Midpoint Above Line Next pixel = (xk+1, yk) Fk < 0 yk+1 = yk
  • 29. Midpoint Algorithm Update Equation Fk = F(xk+1, yk+ ½) = h (xk+1  ax)  w (yk+½  ay) But, Fk+1 = Fk + h  w (yk+1 yk). (Refer notes) So, Fk< 0 : yk+1 = yk. Hence, Fk+1 = Fk + h . Fk  0 : yk+1 = yk+1. Hence, Fk+1 = Fk + h  w. F0 = h  w/2. Update Equation
  • 30. 30 Midpoint Algorithm int h = by-ay; int w = bx-ax; float F=h-w/2; int x=ax, y=ay; for (x=ax; x<=bx; x++){ setPixel(x, y); if(F < 0) F+ = h; else{ F+ = h-w; y++; } }
  • 31. 31 Bresenham’s Algorithm int h = by-ay; int w = bx-ax; int F=2*h-w; int x=ax, y=ay; for (x=ax; x<=bx; x++){ setPixel(x, y); if(F < 0) F+ = 2*h; else{ F+ = 2*(h-w); y++; } }
  • 33. 33  To determine the closest pixel position to the specified circle path at each step.  For given radius r and screen center position (xc, yc), calculate pixel positions around a circle path centered at the coodinate origin (0,0).  Then, move each calculated position (x, y) to its proper screen position by adding xc to x and yc to y.  Along the circle section from x=0 to x=y in the first quadrant, the gradient varies from 0 to -1. Midpoint Circle Drawing Algorithm
  • 34. TCS2111 34 Midpoint Circle Drawing Algorithm  8 segments of octants for a circle:
  • 35. TCS2111 35 Midpoint Circle Drawing Algorithm  Circle function: fcircle (x,y) = x2 + y2 –r2 > 0, (x,y) outside the circle < 0, (x,y) inside the circle = 0, (x,y) is on the circle boundary { fcircle (x,y) =
  • 36. TCS2111 36 Midpoint Circle Drawing Algorithm yk yk-1 midpoint Next pixel = (xk+1, yk) Fk < 0 yk+1 = yk yk yk-1 midpoint Next pixel = (xk+1, yk-1) Fk >= 0 yk+1 = yk - 1
  • 37. TCS2111 37 Midpoint Circle Drawing Algorithm We know xk+1 = xk+1, Fk = F(xk+1, yk- ½) Fk = (xk +1)2 + (yk - ½)2 - r2 -------- (1) Fk+1 = F(xk+1, yk- ½) Fk+1 = (xk +2)2 + (yk+1 - ½)2 - r2 -------- (2) (2) – (1) Fk+1 = Fk + 2(xk+1) + (y2 k+1 – y2 k) - (yk+1 – yk) + 1 If Fk < 0, Fk+1 = Fk + 2xk+1+1 If Fk >= 0, Fk+1 = Fk + 2xk+1+1 – 2yk+1
  • 38. TCS2111 38 Midpoint Circle Drawing Algorithm For the initial point, (x0 , y0) = (0, r) f0 = fcircle (1, r-½ ) = 1 + (r-½ )2 – r2 = 5 – r 4 ≈ 1 – r
  • 39. TCS2111 39 Midpoint Circle Drawing Algorithm Example: Given a circle radius = 10, determine the circle octant in the first quadrant from x=0 to x=y. Solution: f0 = 5 – r 4 = 5 – 10 4 = -8.75 ≈ –9
  • 40. TCS2111 40 Midpoint Circle Drawing Algorithm Initial (x0, y0) = (1,10) Decision parameters are: 2x0 = 2, 2y0 = 20 k Fk x y 2xk+1 2yk+1 0 -9 1 10 2 20 1 -9+2+1=-6 2 10 4 20 2 -6+4+1=-1 3 10 6 20 3 -1+6+1=6 4 9 8 18 4 6+8+1-18=-3 5 9 10 18 5 -3+10+1=8 6 8 12 16 6 8+12+1-16=5 7 7 14 14
  • 41. TCS2111 41 Midpoint Circle Drawing Algorithm void circleMidpoint (int xCenter, int yCenter, int radius) { int x = 0; Int y = radius; int f = 1 – radius; circlePlotPoints(xCenter, yCenter, x, y); while (x < y) { x++; if (f < 0) f += 2*x+1; else { y--; f += 2*(x-y)+1; } } circlePlotPoints(xCenter, yCenter, x, y); }
  • 42. TCS2111 42 Midpoint Circle Drawing Algorithm void circlePlotPoints (int xCenter, int yCenter, int x, int y) { setPixel (xCenter + x, yCenter + y); setPixel (xCenter – x, yCenter + y); setPixel (xCenter + x, yCenter – y); setPixel (xCenter – x, yCenter – y); setPixel (xCenter + y, yCenter + x); setPixel (xCenter – y, yCenter + x); setPixel (xCenter + y, yCenter – x); setPixel (xCenter – y, yCenter – x); }
  • 44. 44 Antialiasing Antialiasing is a technique used to diminish the jagged edges of an image or a line, so that the line appears to be smoother; by changing the pixels around the edges to intermediate colors or gray scales. Eg. Antialiasing disabled: Eg. Antialiasing enabled:
  • 45. Antialiasing (OpenGL) Antialiasing disabled Antialiasing enabled Setting antialiasing option for lines: glEnable (GL_LINE_SMOOTH);
  • 47. 47 Fill Area Algorithms  Fill-Area algorithms are used to fill the interior of a polygonal shape.  Many algorithms perform fill operations by first identifying the interior points, given the polygon boundary.
  • 48. 48 The basic filling algorithm is commonly used in interactive graphics packages, where the user specifies an interior point of the region to be filled. Basic Filling Algorithm 4-connected pixels
  • 49. 49 [1] Set the user specified point. [2] Store the four neighboring pixels in a stack. [3] Remove a pixel from the stack. [4] If the pixel is not set, Set the pixel Push its four neighboring pixels into the stack [5] Go to step 3 [6] Repeat till the stack is empty. Basic Filling Algorithm
  • 50. 50 void fill(int x, int y) { if(getPixel(x,y)==0){ setPixel(x,y); fill(x+1,y); fill(x-1,y); fill(x,y+1); fill(x,y-1); } } Basic Filling Algorithm (Code)
  • 51. 51  Requires an interior point.  Involves considerable amount of stack operations.  The boundary has to be closed.  Not suitable for self-intersecting polygons Basic Filling Algorithm
  • 52. 52  Boundary Fill Algorithm  For filling a region with a single boundary color.  Condition for setting pixels:  Color is not the same as border color  Color is not the same as fill color  Flood Fill Algorithm  For filling a region with multiple boundary colors.  Condition for setting pixels:  Color is same as the old interior color Types of Basic Filling Algorithms
  • 53. TCS2111 53 void boundaryFill(int x, int y, int fillColor, int borderColor) { getPixel(x, y, color); if ((color != borderColor) && (color != fillColor)) { setPixel(x,y); boundaryFill(x+1,y,fillColor,borderColor); boundaryFill(x-1,y,fillColor,borderColor); boundaryFill(x,y+1,fillColor,borderColor); boundaryFill(x,y-1,fillColor,borderColor); } } Boundary Fill Algorithm (Code)
  • 54. TCS2111 54 void floodFill(int x, int y, int fillColor, int oldColor) { getPixel(x, y, color); if (color != oldColor) { setPixel(x,y); floodFill(x+1, y, fillColor, oldColor); floodFill(x-1, y, fillColor, oldColor); floodFill(x, y+1, fillColor, oldColor); floodFill(x, y-1, fillColor, oldColor); } } Flood Fill Algorithm (Code)
  • 55. Filling Polygons (OpenGL) Enabling polygon fill (Default): glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); Disabling polygon fill: glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);