introducion and output primitives - final for site use 2014
TRANSCRIPT
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
1/79
Computer Graphics -Introduction & Output
Primitives
Class: 5CEB
Priyank Thakkar
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
2/79
Books Computer Graphics, Donald Hearn and M.
Pauline Baker, PEARSON EDUCATION.
Computer Graphics Principles and Practice,
James D. Foley, Andries van Dam, Steven K.Feiner, John F. Hughes, Addison-Wesley.
Computer Graphics: A programming approach,Steven Harrington, McGraw Hill
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
3/79
Blog and Course SiteBlog Link:http://2ce321pbt.wordpress.com
Course Site:https://sites.google.com/a/nirmauni.ac.in/2ce321/
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
4/79
Teaching & Evaluation SchemeTeaching Scheme:
Evaluation Methodology:
Theory Tutorial Practical Credits
3 0 2 4
LPW SEE TA
Exam Duration Continuous Evaluation + 2Hrs. End Semester Exam
3.0 Hrs. Continuous
Evaluation
Component
Weightage
0.2 0.4 0.4
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
5/79
Introduction What is Computer Graphics?
Applications CAD
Product Design, Circuit Design, Building Layout Design,etc.
Presentation GraphicsSummarizing financial, statistical, mathematical, scientific
and economic data for various reports
Computer Art
Paintbrush, Mathematical Art Entertainment
Special Effects, Scenes involving animals
Education & Training
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
6/79
Introduction Visualization
GUI
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
7/79
Displays Raster Scan Displays
Pixels, Beam Sweeping, Frame Buffer Random Scan Displays
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
8/79
Line Drawing Algorithms Line with Positive Slope
m>1, 0
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
9/79
Line Drawing Algorithms Similarly, we can obtain the x interval x
corresponding to a specifiedy as
Raster System and Step Size
DDA (Digital Differential Analyzer) (1,1)->(5,3) and (1,1)->(3,5)
If 0 < m 1
Assumption for the above equations
L to R, What if R to L?
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
10/79
Line Drawing Algorithms DDA (Digital Differential Analyzer)
For Positive Slope and Left to Right
DDA vs. Direct Method (Multiplication avoided)
DDAs Limitations (Incremental but Floating Point
Arithmetic, Rounding)
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
11/79
Line Drawing Algorithms DDA (Digital Differential Analyzer) (Code)
What about drawing line from right to left?Beginning point needs to be (xa,ya) and end point needs tobe (xb,yb).
What about line having negative slope?Above code will work for negative slopes as well.
DDA (Digital Differential Analyzer) (Equation)
Positive Slope (L-R)Increase Both
Positive Slope (R-L)Decrease BothNegative Slope (L-R)
Increase x, Decrease y
Negative Slope (R-L)Decrease x, Increase
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
12/79
Line Drawing Algorithms Sampling Concept
(1, 1) -> (5, 3) m = (3 - 1) / (5 - 1) => m = 0.5
b = y1m * x1=> 1 - (0.5 * 1) => b = 0.5
If we unit sample y then we have to find x at y = 2
x = (y - b) / m => x = (2 0.5) / 0.5 => x = 3 (1 , 1) -> (3, 2) -> (5, 3)
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
13/79
Line Drawing Algorithms Sampling Concept
(1, 1) -> (5, 3) m = (3 - 1) / (5 - 1) => m = 0.5
b = ym * x => 1 - (0.5 * 1) => b = 0.5
If we unit sample x then we have to find y at x = 2,
3 and 4 x = 2 => y = (0.5 * 2) + 0.5 = 1.5 2
x = 3 => y = (0.5 * 3) + 0.5 = 2
x = 4 => y = (0.5 * 4) + 0.5 = 2.5 3
(1 , 1) -> (2, 2) -> (3, 2) -> (4, 3) -> (5, 3)
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
14/79
Line Drawing Algorithms BresenhamsLine Algorithm
Incremental Integer CalculationsAssume a line with positive slope < 1
Starting Position (10, 11)
Next Position?
(11, 11) or (11, 12)?
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
15/79
Line Drawing Algorithms BresenhamsLine Algorithm
Assume a line with negative slope > -1Starting Position (50, 50)
Next Position?
(51, 50) or (51, 49)?
Distance between Line Path andPixel Position?
Identify an integer whose value is
proportional to the differencebetween the separations of the two pixel positionsfrom the actual line path
Sign of this integer parameter will answer the
question
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
16/79
Line Drawing Algorithms BresenhamsLine Algorithm
Assume positive slope less than 1 Pixels along the line path is determined by sampling
at unit x interval
Start process from the left end point (x0, y0)
Figure demonstrates kth step in this process
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
17/79
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
18/79
Line Drawing Algorithms BresenhamsLine Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
19/79
Line Drawing Algorithms BresenhamsLine Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
20/79
Line Drawing Algorithms BresenhamsLine Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
21/79
Line Drawing Algorithms BresenhamsLine Algorithm
Using only pkformula, all the midpoints can be calculated.
However this formula is not additive. At each stepmultiplications (however still it is only integer arithmetic) areinvolved.
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
22/79
Line Drawing Algorithms BresenhamsLine Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
23/79
Line Drawing Algorithms BresenhamsLine Algorithm
Always use absolute value of xand y to tackle negativeslopes.
For m>1 and m
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
24/79
Examples
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
25/79
Circle Generating Algorithms Equation of a Circle in Cartesian Coordinate System
Plotting the Circle
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
26/79
Circle Generating Algorithms Parametric Equation of a Circle
Angular Step
Fixed Step Size
Step Size = 1/r Reducing the Computation by considering
Symmetry
QuadrantsOctants
Ending of Octant
Square Root Calculations
Trigonometric Calculations
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
27/79
Circle Generating Algorithms Circle Function
Assume center (0, 0) and radius r
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
28/79
Circle Generating Algorithms Midpoint Circle Algorithm
Assume center (0, 0) & radius r, octant from x = 0to x = y
We are at kth step and (xk, yk) is already displayed
Candidates at step k + 1 are: (xk+1, yk) & (xk+1, yk- 1)
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
29/79
Circle Generating Algorithms Midpoint Circle Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
30/79
Circle Generating Algorithms Midpoint Circle Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
31/79
Circle Generating Algorithms Midpoint Circle Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
32/79
Circle Generating Algorithms Midpoint Circle Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
33/79
Circle Generating Algorithms Midpoint Circle Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
34/79
Circle Generating Algorithms Midpoint Circle Algorithm
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
35/79
Circle Generating Algorithms Midpoint Circle Algorithm
E l
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
36/79
Examples
Ell l h
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
37/79
Ellipse Generating Algorithms Properties of Ellipses
Focus
Major and Minor Axis
Ellipse in nonstandard position
Ell G l h
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
38/79
Ellipse Generating Algorithms Properties of Ellipses
Ellipse in standard position
Ell G l h
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
39/79
Ellipse Generating Algorithms Properties of Ellipses
Symmetry Concept
Direct Method and Square root or TrigonometricOperations
Elli G i l i h
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
40/79
Ellipse Generating Algorithms Ellipse Function
Assume center (0, 0)
Elli G i Al i h
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
41/79
Ellipse Generating Algorithms Remember:
0 |y2 y1| < |x2x1|So, if the absolute range of x is greater than
that of y then |m| [0, 1)
|m| = 1 => |y2y1| = |x2x1|
|m| > 1 => |y2y1| > |x2x1|So, if the absolute range of y is greater than
that of x then |m| > 1
Elli G i Al i h
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
42/79
Ellipse Generating Algorithms Midpoint Ellipse Algorithm
Region 1 & 2 Visual Inspection of range of x
and y in regions
Mathematical Interpretation
Elli G ti Al ith
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
43/79
Ellipse Generating Algorithms Midpoint Ellipse Algorithm
Elli G ti Al ith
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
44/79
Ellipse Generating Algorithms Midpoint Ellipse Algorithm
Elli G ti Al ith
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
45/79
Ellipse Generating Algorithms Midpoint Ellipse Algorithm
Elli G ti Al ith
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
46/79
Ellipse Generating Algorithms Midpoint Ellipse Algorithm
Elli G ti Al ith
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
47/79
Ellipse Generating Algorithms Midpoint Ellipse Algorithm
Elli G ti Al ith
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
48/79
Ellipse Generating Algorithms Midpoint Ellipse Algorithm
Elli G ti Al ith
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
49/79
Ellipse Generating Algorithms Midpoint Ellipse Algorithm
Elli G ti Al ith
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
50/79
Ellipse Generating Algorithms Midpoint Ellipse Algorithm
Examples
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
51/79
Examples
Examples
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
52/79
Examples
Poly on Fillin Al orithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
53/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm
Identify scan lines crossing a polygon For each such scan line locate the intersection
points with polygon edges.
Sort intersection points from left to right and set
corresponding frame buffer positions between eachintersection pair to the specified fill color.
Example
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
54/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm
Some intersections at polygon vertices requirespecial handling
Odd vs. even number of intersections and pairing.
Topological difference between scan line y and y
and identifying vertices which require specialhandling
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
55/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm
Approach of Shortening Edges
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
56/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm
Determining edge intersections
= +
=
()
, + =+ +
, + =+ +
+ = +
+ =
+
+ = +
()
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
57/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm
Determining edge intersections
To avoid Rounding Operation from the above equation, wecan use following:
Initialize counter to 0.
Increment the counter by x each time we move up to anew scan line
If counter >= y, then x coordinate of intersection pointbetween the current scan line and polygon edge is one more
than the x coordinate of intersection point between previousscan line and polygon edge and decrease the counter value byy.
Else x coordinate of intersection between the current scanline and polygon edge is same as the x coordinate of
intersection point between previous scan line and polygonedge.
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
58/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm
Determining edge intersections
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
59/79
Polygon Filling Algorithms Sorted Edge Table (SET) and Active Edge List/Table
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
60/79
Polygon Filling Algorithms Sorted Edge Table (SET) and Active Edge List/Table
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
61/79
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
62/79
Polygon Filling Algorithms Sorted Edge Table (SET) and Active Edge List/Table
Status of AET at Scanline 8
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
63/79
Polygon Filling Algorithms Sorted Edge Table (SET) and Active Edge List/Table
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
64/79
Polygon Filling Algorithms Sorted Edge Table (SET) and Active Edge List/Table
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
65/79
Polygon Filling Algorithms Sorted Edge Table (SET) and Active Edge List/Table
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
66/79
Polygon Filling Algorithms Sorted Edge Table (SET) and Active Edge List/Table
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
67/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm (Other than standardpolygon)
Inside Outside Tests
Odd-even rule/Odd parity rule/Even-odd rule
Nonzero winding number rule
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
68/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm
Inside Outside Tests
Odd-even rule/Odd parity rule/Even-odd rule
Assume a distant point outside the coordinate extent
Assume a line from any test point P to this distantpoint not passing through any of the vertices
If this line crosses odd number of polygon edges, thenpoint P is an interior point otherwise it is an exteriorpoint.
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
69/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm
Inside Outside Tests
Nonzero winding number rule
Assume a distant point outside the coordinate extent ofthe object
Winding number is initialized to zero for each of the testpoint P.
As we move along the line from position P to the distinctpoint, we add one to winding number every time lineintersects an edge that crosses it from right to left.(cross product is positive)
If intersecting edge crosses the line from left to right(cross product is positive), we subtract one from windingnumber.
If the final value of the winding number is nonzero, P isdefined to be an interior point otherwise it is defined asan exterior point.
Determining Directional edge crossings
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
70/79
Polygon Filling Algorithms Scan-Line Polygon Fill Algorithm
Inside Outside Tests
Nonzero winding number rule
Determining Directional edge crossings
Cross product
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
71/79
Polygon Filling Algorithms Boundary Fill Algorithm
Start at a point inside a region and paint the interior outward
toward the boundaryIf the boundary is specified in single color, the fill algorithm
proceeds outward pixel by pixel until the boundary color isencountered.
This method is particularly useful in interactive paintingpackages, where interior points are easily selected.
To display a solid color region (with no border), the designercan choose fill color to be the same as the boundary color.
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
72/79
Polygon Filling Algorithms Boundary Fill Algorithm
Which are the inputs to boundary-fill procedure?
Starting from (x, y), the procedure tests neighboringpositions to determine whether they are of the boundarycolor
If not?
This process continues until all pixels up to theboundary color for the area have been tested.
Figure 3-43
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
73/79
Polygon Filling Algorithms Boundary Fill Algorithm
When can boundaryfill4 fail?
Some interior pixels are already displayed in fill color
To avoid this, first change the color of any interiorpixels that are initially set to the fill color beforeapplying the boundary-fill procedure
4-connected vs. 8-connected
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
74/79
olygon F ll ng lgor thms Boundary Fill Algorithm & Alternative
Since the boundaryFill4 procedure requires considerable
stacking of neighboring points, more efficient methods aregenerally employed.
These methods fill horizontal pixel spans across scan lines,instead of proceeding to 4-connected or 8-connectedneighboring points.
This requires only stacking a beginning position for eachhorizontal pixel span, instead of stacking all unprocessedneighboring positions around the current position.
Spans are defined as the contiguous horizontal string ofpositions bounded by pixels displayed in the area border
color.At each subsequent step, the next start position is unstacked
and the process is repeated.
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
75/79
yg F g g m Alternative Method
Process scan lines successively from the start line to top
boundaryAfter all upper scan lines are processed, fill in the pixel spans
on the remaining scan lines in order down to the bottomboundary
The leftmost pixel position for each horizontal span is located
and stacked, in left to right order across successive scanlines.
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
76/79
yg g g m Scan-Line Polygon Fill Algorithm
Boundary Fill Algorithm
Addressing stacking of neighboring points
Polygon Filling Algorithms
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
77/79
yg g g Flood Fill Algorithm
Sometimes we may want to recolor
Sometimes we may want to fill in an area that is not definedwithin a single color boundary
If the area we want to paint has more than one interiorcolor?
First reassign pixel values so that all interior points have
the same color.
Character Generations
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
78/79
Serif fonts and Sans Serif fonts
Serif: Hello WorldSmall lines or accents at the ends of main character strokes
Sans Serif: Hello WorldDoes not have accents
-
8/11/2019 Introducion and Output Primitives - Final for Site Use 2014
79/79