CMPE 466 COMPUTER GRAPHICS

Slides:



Advertisements
Similar presentations
Contents In today’s lecture we’ll have a look at:
Advertisements

CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
Computer Graphics 4: Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling By:Kanwarjeet Singh.
CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
CMPE 466 COMPUTER GRAPHICS
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
CMPE 466 COMPUTER GRAPHICS Chapter 8 2D Viewing Instructor: D. Arifler Material based on - Computer Graphics with OpenGL ®, Fourth Edition by Donald Hearn,
Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes ConvexConcaveSelf-intersecting.
CS 376 Introduction to Computer Graphics 02 / 05 / 2007 Instructor: Michael Eckmann.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
CS 454 Computer graphics Polygon Filling
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
CS 4731: Computer Graphics Lecture 22: Raster Graphics Part 3 Emmanuel Agu.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Circle Drawing algo..
March Shape Drawing Algorithms Shmuel Wimer Bar Ilan Univ., Engineering Faculty.
1/24/20061 Fill-Area Algorithms and Functions. 1/24/20062 Learning Objectives OpenGL state variables Color and gray scale Color functions Point attributes.
Geometric Objects Computer Graphics Lab. Sun-Jeong Kim.
CGMB214: Introduction to Computer Graphics
Dr. S.M. Malaek Assistant: M. Younesi
WHERE TO DRAW A LINE?? Line drawing is accomplished by calculating intermediate positions along the line path between specified end points. Precise definition.
Scan Conversion Line and Circle
3/4/04© University of Wisconsin, CS559 Spring 2004 Last Time Clipping Lines –Cohen-Sutherland: The use of outcodes and early reject/accept tests –Liang-Barsky:
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Graphics Graphics Korea University cgvr.korea.ac.kr Raster Graphics 고려대학교 컴퓨터 그래픽스 연구실.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
Graphics Output Primitives
CGMB214: Introduction to Computer Graphics
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
10/15/02 (c) 2002 University of Wisconsin, CS559 Who Am I? Prof Stephen Chenney These notes will be online after the lecture – in fact they’re online already.
Attributes of Graphics Primitives Hearn & Baker Chapter 4 Some slides are taken from Robert Thomsons notes.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
2D Output Primitives Points Lines Circles Ellipses Other curves Filling areas Text Patterns Polymarkers.
Lecture 15: Raster Graphics and Scan Conversion
OUTPUT PRIMITIVES A.Aruna/Faculty of Information technology/SNSCE13/19/2016.
Computer Graphics CC416 Week 14 Filling Algorithms.
Computer Graphics Lecture 08 Taqdees A. Siddiqi Computer Graphics Filled Area Primitives I Lecture 08 Taqdees A. Siddiqi
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Write Bresenham’s algorithm for generation of line also indicate which raster locations would be chosen by Bresenham’s algorithm when scan converting.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Computer Graphics Lecture 07 Ellipse and Other Curves Taqdees A. Siddiqi
Computer Graphics Lecture 06 Circle Drawing Techniques Taqdees A. Siddiqi
Computer Graphics I, Fall 2010 Scan conversion algorithms.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
Line Drawing Algorithms 1. A line in Computer graphics is a portion of straight line that extends indefinitely in opposite direction. 2. It is defined.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Chapter- 3 & Unit-2 Graphics PRIMITIVES 1. Objectives Introduction to Primitives Points & Lines Line Drawing Algorithms Digital Differential Analyzer.
Primitive graphic objects
Attributes of Graphics Primitives Hearn & Baker Chapter 4
Introduction to Polygons
Implementation III.
Chapter Three Part I Output Primitives CS 380.
Fill Area Algorithms Jan
Introduction to Computer Graphics with WebGL
Computer Graphics Implementation III
Chapter 3 Graphics Output Primitives
Primitive Drawing Algorithm
Primitive Drawing Algorithm
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

CMPE 466 COMPUTER GRAPHICS Chapter 6 Algorithms for Graphics Primitives Instructor: D. Arifler Material based on Computer Graphics with OpenGL®, Fourth Edition by Donald Hearn, M. Pauline Baker, and Warren R. Carithers Fundamentals of Computer Graphics, Third Edition by by Peter Shirley and Steve Marschner Computer Graphics by F. S. Hill

Device-level algorithms for implementing primitives Line-drawing algorithms Circle-generating algorithms Ellipse-generating algorithms Scan-line polygon-fill algorithms Antialiasing

Jaggies in line-drawing Figure 6-1 Stair-step effect (jaggies) produced when a line is generated as a series of pixel positions.

Line equations Figure 6-2 Line path between endpoint positions (x0, y0) and (x end, y end).

Determining deflection voltages

Digital differential analyzer (DDA) A scan-conversion line algorithm For m≤1 Sample at unit x intervals: δx=1 Compute yk+1=yk+m Calculated y values must be rounded to nearest int For m>1 Sample at unit y intervals: δy=1 Compute xk+1=xk+1/m Calculated x values must be rounded to nearest int If we process from right to left and m≤1, then we have δx=-1 and yk+1=yk-m If we process from right to left and m>1, then we have δy=-1 and xk+1=xk-1/m For negative slopes, look at the the magnitude of m

DDA

Problems of DDA Accumulation of round-off errors Calculated pixel positions may drift away from the true line path for long segments Rounding operations and floating point arithmetic are time-consuming

Bresenham’s line algorithm Goal: Use only incremental integer calculations (fast!) Figure 6-4 A section of a display screen where a straight-line segment is to be plotted, starting from the pixel at column 10 on scan line 11. Figure 6-5 A section of a display screen where a negative slope line segment is to be plotted, starting from the pixel at column 50 on scan line 50.

Bresenham’s line algorithm Consider lines with slope m<1 Decide which pixel to plot in column xk+1=xk+1 Choices: (xk+1, yk) or (xk+1, yk+1) Figure 6-6 A section of the screen showing a pixel in column xk on scan line yk that is to be plotted along the path of a line segment with slope 0 < m < 1.

Bresenham’s line algorithm At sampling position xk+1, label vertical pixel separations from the line path as dlower and dupper Figure 6-7 Vertical distances between pixel positions and the line y coordinate at sampling position xk + 1.

Bresenham To determine which pixel is closet , we first calculate:

Bresenham We would like to use only integer calculations Define a decision parameter pk. Letting m=Δy/Δx: Sign of pk is the same as the sign of dlower-dupper because Δx>0 Parameter c is constant and is 2Δy+Δx(2b-1) which is independent of the pixel position and will be eliminated in the recursive calculation

Bresenham If pixel at yk is closer to the line path than pixel at yk+1 (i.e. dlower<dupper) the pk is negative. In that case, we plot the lower pixel; otherwise, we plot the upper pixel We can obtain successive decision parameters recursively. At step k+1 using where yk+1-yk is either 0 or 1 depending on the sign of pk First parameter is calculated as

Bresenham algorithm

Example Figure 6-8 Pixel positions along the line path between endpoints (20, 10) and (30, 18), plotted with Bresenham’s line algorithm.

Example

Circle-generating algorithms Figure 6-11 Circle with center coordinates (xc , yc) and radius r .

Circle-generating algorithms One could use Sqrt is time-consuming Figure 6-12 Upper half of a circle plotted with Equation 6-27 and with (xc , yc) = (0, 0).

Circle equation in parametric polar form Trig calculations are time-consuming We can use symmetry Figure 6-13 Symmetry of a circle. Calculation of a circle point (x, y) in one octant yields the circle points shown for the other seven octants.

Midpoint circle algorithm First, define: We will perform the tests for the midpositions between pixels near the circle path at each sampling step

Midpoint circle algorithm Figure 6-14 Midpoint between candidate pixels at sampling position xk + 1 along a circular path.

Circles: decision parameter Define the decision parameter If pk<0 (midposition is inside), yk is closer Otherwise, midposition is outside or on the circle boundary and we select the pixel on scan line yk-1

Recursive expression for pk

Recursive expression

The algorithm (only integer add/subtract)

Example

Example

Example Figure 6-15 Pixel positions (solid circles) along a circle path centered on the origin and with radius r = 10, as calculated by the midpoint circle algorithm. Open (“hollow”) circles show the symmetry positions in the first quadrant.

Ellipse-generating algorithms Figure 6-16 Ellipse generated about foci F1 and F2.

Ellipse in standard position Figure 6-17 Ellipse centered at (xc, yc) with semimajor axis rx and semiminor axis ry.

Ellipse in standard position Figure 6-18 The bounding circle and eccentric angle θ for an ellipse with rx > ry .

Midpoint ellipse algorithm Figure 6-20 Ellipse processing regions. Over region 1, the magnitude of the ellipse slope is less than 1.0; over region 2, the magnitude of the slope is greater than 1.0.

Midpoint ellipse algorithm

Midpoint ellipse algorithm (region 1) Figure 6-21 Midpoint between candidate pixels at sampling position xk + 1 along an elliptical path.

Ellipse

Ellipse (region 2) Figure 6-22 Midpoint between candidate pixels at sampling position yk − 1 along an elliptical path.

Ellipse

Midpoint ellipse algorithm

Midpoint ellipse algorithm

Example

Example

Example

Example Figure 6-23 Pixel positions along an elliptical path centered on the origin with rx = 8 and ry = 6, using the midpoint algorithm to calculate locations within the first quadrant.

Scan-line polygon-fill algorithms For each scan-line that crosses the polygon, the edge intersections are sorted from left to right, and then pixel positions between and including each intersection pair are set to the specified fill color Figure 6-46 Interior pixels along a scan line passing through a polygon fill area.

Complexities of polygon filling Figure 6-47 Intersection points along scan lines that intersect polygon vertices. Scan line y generates an odd number of intersections, but scan line y’ generates an even number of intersections that can be paired to identify correctly the interior pixel spans.

Polygon filling For scan line y, the two edges sharing an intersection vertex are on opposite sides of the scan line For scan line y’, the two intersection edges are both above the scan line A vertex that has adjoining edge on opposite sides of an intersecting scan line should be counted as just one boundary intersection point. Endpoints of segments can be adjusted as shown in the next slide. In determining edge intersections, coherence methods are used. This often involves incremental calculations applied along a scan line or between scan lines

Polygon filling: endpoint adjustments Figure 6-48 Adjusting endpoint y values for a polygon, as we process edges in order around the polygon perimeter. The edge currently being processed is indicated as a solid line. In (a), the y coordinate of the upper endpoint of the current edge is decreased by 1. In (b), the y coordinate of the upper endpoint of the next edge is decreased by 1.

Edge tables for polygon filling To perform a polygon-fill efficiently, we first store polygon boundary in a sorted edge table Proceeding around the edges (clockwise or counterclockwise), we can use a bucket sort to store the edges, sorted on the smallest y value of each edge, in the correct scan-line positions kth position points to a list of all edges having their lower endpoint on scan line k At kth position, edges are in sorted order from left to right. Next, we process the scan lines from the bottom of the polygon to its top, producing an active edge list (AEL) for each scan line crossing the polygon boundaries The active edge list for a scan line contains all edges crossed by that scan line

Edge tables Figure 6-50 A polygon and its sorted edge table, with edge DC shortened by one unit in the y direction.

Fill methods for areas with irregular boundaries Start at an inside position and paint the interior point by point out to the boundary Boundary-fill Fill the interior of a region pixel by pixel until the boundary color is encountered Flood-fill Fill in (recolor) an area that is not defined within a single color boundary Paint by replacing a specified interior color instead of searching for a particular boundary color

Boundary-fill Boundary-fill algorithm starts from an interior point (x, y) and tests the color of neighboring positions If a tested position is not displayed in the boundary color, its color is changed to the fill color and its neighbors are tested (see next slide) This procedure continues until all pixels are processed up to the designated boundary color for the area

Processing neighboring pixels Figure 6-53 Fill methods applied to a 4-connected area (a) and to an 8-connected area (b). Hollow circles represent pixels to be tested from the current test position, shown as a solid color.

4-connected vs. 8-connected algorithm Figure 6-54 The area defined within the color boundary (a) is only partially filled in (b) using a 4-connected boundary-fill algorithm.

Boundary-fill

Flood-fill Sometimes we want to fill in (or recolor) an area that is not defined within a single color boundary We can paint such areas by replacing a specified interior color instead of searching for a particular boundary color. Figure 6-56 An area defined within multiple color boundaries.

Flood-fill

Antialiasing Aliasing: Distortion of information due to low-frequency sampling (undersampling) Increase sampling rate in raster systems Simply display at higher resolution: Requires large frame-buffers! Apple MacBook Retina Display: Over 5 million on the 15‑inch model: With so high pixel density, your eyes can’t discern individual pixels at normal viewing distance With raster systems that are capable of displaying more than two intensity levels per color, we can apply antialiasing methods to modify pixel intensities Antialiasing methods: Supersampling, postfiltering, prefiltering, pixel phasing We will focus on antialiasing methods for straight-line segments

Antialiasing Blurring to smooth an image E.g. Sharp transitions from black to white is softened by using a mixture of gray pixels near the borders When looking from a distance, eye blends the gracefully varying shades together

Supersampling (a special case of post-filtering) Sampling object characteristics at a higher resolution and displaying the results at a lower resolution Divide each pixel into a number of subpixels and count the number of subpixels that overlap the line path. The intensity for each pixel is set to a value proportional to this subpixel count “Post”filtering: involves computing intensities at subpixel grid positions and then combining the results to obtain the pixel intensities

Supersampling Figure 6-59 Supersampling subpixel positions along a straight-line segment whose left endpoint is at screen coordinates (10, 20). Figure 6-60 Supersampling subpixel positions in relation to the interior of a line of finite width.

Postfiltering: Subpixel weighting masks Give more weight to subpixel near the center of a pixel area Figure 6-61 Relative weights for a grid of 3 × 3 subpixels. Center subpixel is weighted by a factor of 1/4; the top, bottom, and side subpixels are each weighted by a factor of 1/8; and the corner subpixels are each weighted by a factor of 1/16.

Example masks or window functions (b) and (c) are approximations to the Bartlett window: Weights grow linearly from the edges toward the center

Application of weighting masks or window functions

Area sampling (prefiltering) Set pixel intensity proportional to the area of overlap of pixel with the finite-width line “Pre”filtering: the intensity of the pixel as a whole is determined without calculating subpixel intensities Computationally expensive

General filtering techniques More accurate method for antialiasing Similar to applying a weighted pixel mask but now we have a continuous weighting surface (or filter function) covering the pixel. Figure 6-62 Common filter functions used to antialias line paths. The volume of each filter is normalized to 1.0, and the height gives the relative weight at any subpixel position.

Pixel phasing On raster systems that can address subpixel positions within the screen grid (hardware solution) Move (microposition) pixel positions closer to the line path Electron beam can be shifted by a fraction of a pixel diameter Figure 6-63 Jagged lines (a), plotted on the Merlin 9200 system, are smoothed (b) with an antialiasing technique called pixel phasing. This technique increases the number of addressable points on the system from 768 by 576 to 3072 by 2304. (Courtesy of Peritek Corp.)