Scan Conversion Algorithms www.smartphonetech.org.

Slides:



Advertisements
Similar presentations
Line Drawing Algorithms
Advertisements

Graphics Primitives: line
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Section 3-1 to 3-2, 3-5 Drawing Lines Some of the material in these slides may have been adapted from university of Virginia, MIT, and Åbo Akademi University.
4- 1 Raster Display Model Pixel (Picture Element, 像素 )
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.
1 King ABDUL AZIZ University Faculty Of Computing and Information Technology CS 454 Computer graphics Drawing Elementary Figures Dr. Eng. Farag Elnagahy.
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.
Lecture 5 Rendering lines 1.Steps of line rendering 2.Scan-conversion for line segments 3.A1 tutorial CP411 Computer Graphics Fall 2007 Wilfrid Laurier.
Scan conversion of Line , circle & ellipse
Line Drawing Algorithms. Rasterization-Process of determining which pixels give the best approximation to a desired line on the screen. Scan Conversion-Digitizing.
Computer Graphics Lecture 3 Line & Circle Drawing.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
Lecture 2 Line & Circle Drawing
Lecture 17 Fun with Graphics Dr. Dimitrios S. Nikolopoulos CSL/UIUC.
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
CS 376 Introduction to Computer Graphics 01 / 29 / 2007 Instructor: Michael Eckmann.
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Lecture 16 Fun with graphics
Raster conversion algorithms for line and circle
Output Primitives Computer Graphics.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
C O M P U T E R G R A P H I C S Guoying Zhao 1 / 50 C O M P U T E R G R A P H I C S Guoying Zhao 1 / 45 Computer Graphics Implementation I.
University of Missouri at Columbia 2D Scan-line Conversion University of Missouri at Columbia.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
Dr. S.M. Malaek Assistant: M. Younesi
Graphics Primitives: line. Pixel Position
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
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
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)
CS-321 Dr. Mark L. Hornick 1 Line Drawing Algorithms.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
CS 551 / 645: Introductory Computer Graphics
Scan Conversion.
Bresenham’s Line Algorithm
Example: (7,9) (12,0) Example 2: Point1 V:(7,9 ) C:( 0,255,0) Point2 V:(12,0) C:(0,255,0) (0,0) (18,0) (0,9) What are the problems with this method? Slope>1.
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
Computer Graphics : output primitives.. 2 of 32 T1 – pp. 103–123, 137–145, 147–150, 164–171 Points and LinesPoints Line Drawing AlgorithmsLine Mid–Point.
Computer Graphics Lecture 05 Line Drawing Techniques Taqdees A. Siddiqi
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.
Line Drawing Algorithms
CSCE 441 Lecture 2: Scan Conversion of Lines
Computer graphics 2D graphics.
Lecture 8 Shear and Line Drawing Algorithms
Computer Graphics Implementation I.
Chapter Three Part I Output Primitives CS 380.
Computer Graphics 5: Line Drawing Algorithms
Computer Graphics 5: Line Drawing Algorithms
CSCE 441 Lecture 2: Scan Conversion of Lines
2D Scan-line Conversion
Rasterization and Antialiasing
Computer Graphics 5: Line Drawing Algorithms
Rasterization and Antialiasing
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Scan Conversion (From geometry to pixels)
Chapter 3 Graphics Output Primitives
Line Drawing Algorithms
OUTPUT PRIMITIVES / DISPLAY TECHNIQUES
Presentation transcript:

Scan Conversion Algorithms

Line Drawing  Description :  Given the specification of a straight line, find the collection of addressable pixels which closely approximate this line.  Goals :  Straight lines should appear straight  Lines should start and end accurately  Lines should be drawn as quickly as possible.  Line drawing algorithms:  DDA (Digital Differential Analyzer) Algorithm  Bresenham’s Line Algorithm

DDA Algorithm  Consider the slope-intercept equation of a line y = m. x + b where m  slope & b  y-intercept  Given two end-points (x 1,y 1 ) & (x 2,y 2 ) m = (y 2 -y 1 ) / (x 2 -x 1 ) b = y1 – m. x 1  Now, given any x-interval or y-interval we can calculate the corresponding y-interval or x- interval through the slope ∆y = m. ∆x ∆x = ∆y / m  Thus considering an interval of 1 pixel, we have y k+1 = y k + m x k+1 = x k + 1/m  If m > 1, we should calculate x otherwise we should calculate y

void lineDDA(int x1, int y1, int x2, int y2){ int dx = x2 –x1, dy = y2 –y1, steps, k; float x = x1, y = y1, xIncr, yIncr; if(abs(dx) > abs(dy)) setps = abs(dx); else steps = abs(dy); xIncr = dx / steps; yIncr = dy / steps; setPixel(Round(x), Round(y)); for(k = 0; k<steps; k++){ x += xIncr; y += yIncr; setPixel(Round(x), Round(y)); } } DDA Algorithm (cont.) x 1, y 1 x 2, y 2 x 1, y 1 dy dx 1 2

 Also called Midpoint Line Algorithm.  Considering slope and end point ordering, a line can belong to one of the eight octants. Given the current pixel, which one do we chose next : E or NE (for octant 1) is based on the Midpoint. If the line goes above the midpoint, M then NE is chosen otherwise E is chosen as the next pixel.  Let us consider two forms of a Line equation y = (dy / dx). x + B F(x,y) = a. x + b. y + c = 0  Thus we get a = dy, b = - dx & c = B. dx (1)  Again the midpoint M is below the line if F(M) > 0 otherwise M is above the line. Bresenham’s Line Algorithm E NE M

 The value of F(M) can be calculated in an incremental way as follows:  Consider a decision variable d = F(x p +1, y p + ½)  The decision variable helps to chose E or NE. If d <= 0 chose E otherwise chose NE.  The next decision variable is calculated as follows: Set d old = d Case E is chosen: (current point is x p + 1, y p ) d new = F(x p + 2, y p + ½) = a. x p +2a + b. y p + b/2 +c (∆d) E = d new – d old = a = dy Case NE is chosen: (current point is x p + 1, y p + 1) d new = F(x p + 2, y p + 3/2) = a. x p +2a + b. y p + 3b/2 +c (∆d) NE = d new – d old = a + b = dy – dx Bresenham’s Line Algorithm (cont.) x p +1,y p E NE M x p, y p x p +1,y p +1 x p +1,y p +1/2

 The initial decision value of the decision variable is calculated as d start = F(x 0 +1, y 0 +1/2) = a. x 0 + a + b. y 0 + b/2 + c = a + b/2 = dy – dx/2 = ½ (2dy - dx)  To avoid fractional computation we can assume decision variable values for 2.F(x,y). Thus d start = 2dy – dx (∆d) E = 2dy (∆d) NE = 2(dy –dx)  Thus we can plot the successive points as follows while(x < x1){ if(d<=0) /*chose E */ d = d + (∆d) E ; else{ /* chose NE */ d = d + (∆d) NE ; y = y + 1; } x = x + 1; setPixel(x, y); } Bresenham’s Line Algorithm (cont.)

Bresenham’s Line Algorithm (cont.)  What’s about lines belong to other octants? OctantChange 1None 2Swap x & y 3Plot from P 1 to P 0 ; Swap x & y; Use y = y - 1 4Plot from P 1 to P 0 ; Use y = y - 1 5Plot from P 1 to P 0 6Plot from P 1 to P 0 ; Swap x & y 7Swap x & y; Use y = y - 1 8Use y = y - 1

 Due to symmetry in circle, it needs to plot only octant 2 Others can be plotted though mirror effect. Thus setCirclePixel(x c, y c, x, y){ setPixel(x c + x, y c + y);  2 setPixel(x c - x, y c + y);  3 setPixel(x c - y, y c + x);  4 setPixel(x c - y, y c - x);  5 setPixel(x c - x, y c - y);  6 setPixel(x c + x, y c - y);  7 setPixel(x c + y, y c - x);  8 setPixel(x c + y, y c + x);  1 }  Now for octant 2 choice is between E and SE and the decision function is F(x, y) = x 2 +y 2 –R 2 = 0; Midpoint Circle Algorithm E SE M

 The decision variable now becomes d = F(x p + 1, y p – ½) (∆d) E = F(x p + 2, y p – ½) - F(x p + 1, y p – ½) = 2 x p + 3 (∆d) SE = F(x p + 2, y p – 3/2) - F(x p + 1, y p – ½) = 2 x p - 2y p + 5 d start = F(x0 + 1, y0 – ½) = F(1, R – ½) = 5/4 – R  To get rid of the fraction, let h = d – ¼ => h start = 1 – R  Since h is initialized and incremented by integers we can use h instead of d for the decision. Midpoint Circle Algorithm (cont.) E SE M

 The algorithm x = 0; y = R; h = 1 – R; setCirclePixel(x c, y c, x, y); while(y > x){ if(h <= 0) /* chose E */ h = h + 2x + 3; else{ /* chose SE */ h = h + 2(x – y) + 5; y = y – 1; } x = x + 1; setCirclePixel(x c, y c, x, y); } Midpoint Circle Algorithm (cont.)

Midpoint Ellipse Algorithm a b -b -a Slope = -1 R2 R1 E SE M S M setEllipsePixel(x c, y c, x, y){ setPixel(x c + x, y c + y);  1 setPixel(x c - x, y c + y);  2 setPixel(x c - x, y c - y);  3 setPixel(x c +x, y c - y);  4 }

 Let us consider the following ellipse equation F(x, y) = b 2 x 2 + a 2 y 2 –a 2 b 2 = 0  Slope of the equation at a point (x, y) is dy/dx = - b 2 x/a 2 y  The magnitude of the slope is 0 in (0, b) and gradually increments and finally becomes infinity at (a, 0)  Thus the condition for R1 is b 2 x = a 2 y  Analysis for R1:  The decision variable becomes d = F(x p + 1, y p – ½) (∆d) E = F(x p + 2, y p – ½) - F(x p + 1, y p – ½) = b 2 (2x p + 3) (∆d) SE1 = F(x p + 2, y p – 3/2) - F(x p + 1, y p – ½) = b 2 (2x p + 3) -2a 2 (y p - 1) d start = F(1, b – ½ ) = b 2 + a 2 (1/4 – b)  Analysis for R2:  The decision variable becomes d = F(x p + ½, y p – 1) (∆d) SE2 = F(x p + 3/2, y p – 2) - F(x p + ½, y p – 1) = 2b 2 (x p + 1) – a 2 (2y p - 3) (∆d) S = F(x p + ½, y p – 2) - F(x p + ½, y p – 1) = - a 2 (2y p - 3) Midpoint Ellipse Algorithm (cont.) a b -b -a E SE M S M

 The Algorithm: sa = sqr(a); sb = sqr(b); d = b 2 + a 2 (1/4 – b); setEllipsePixel(x c, y c, 0, b); while(b 2.(x+1) < a2.(y – ½ )){ /* For R1 */ if(d<0) /* chose E */ d += sb. ((x << 1)+3); else{ /* chose SE */ d += sb. ((x << 1)+3) – sa. ((y<<1) - 2) ; y--; } x++; setEllipsePixel(x c, y c, x, y); } Midpoint Ellipse Algorithm (cont.) d = sb. sqr(x+1/2) + sa. sqr(y-1) – sa. sb; while(y>0){ /* For R2 */ if(d<0){ /* chose SE */ d += sb. ((x++)+2) – sa. ((y<<1)-3); x++; }else{ d -= sa. ((y<<1)-3); } y--; setEllipsePixel(x c, y c, x, y); }

Thank You