Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.

Slides:



Advertisements
Similar presentations
Graphics Primitives Part II: Bresenhams line and circle.
Advertisements

5.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 5 – Drawing A Line.
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
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.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Computer Graphics Lecture 3 Line & Circle Drawing.
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
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.
Raster conversion algorithms for line and circle
Drawing Lines The Bresenham Algorithm for drawing lines and filling polygons.
Graphics Output Primitives Pixel Addressing and Fill Area Dr. M. Al-Mulhem Feb. 1, 2008.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
2D transformations and homogeneous coordinates Dr Nicolas Holzschuch University of Cape Town Modified.
Circle Drawing algo..
CGMB214: Introduction to Computer Graphics
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
1 CS 430/536 Computer Graphics I Circle Drawing and Clipping Week 3, Lecture 6 David Breen, William Regli and Maxim Peysakhov Geometric and Intelligent.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
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
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
Defining complex objects Dr Nicolas Holzschuch University of Cape Town Modified by Longin Jan Latecki.
College of Computer and Information Science, Northeastern UniversityOctober 12, CS G140 Graduate Computer Graphics Prof. Harriet Fell Spring 2006.
1 Line Drawing Version B: Semi-Formal Methods Derivation ©Anthony Steed
Graphics Output Primitives
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
CGMB214: Introduction to Computer Graphics
3D transformations Dr Nicolas Holzschuch University of Cape Town Modified by Longin Jan Latecki
Chapter 3 Scan Conversion Lecture-02. Bresenham’s Line Algorithm Bresenham’s line algorithm – is a highly efficient incremental method for scan- converting.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
MIDPOINT CIRCLE & ELLIPSE GENERARTING ALGORITHMS
November 18, We could solve for y in terms of x ( x 0, y 0 ) are the origin points A Simple Circle Drawing Algorithm The equation for a circle.
© 97 N. Holzschuch 3D objects representation and data structure Dr Nicolas Holzschuch University of Cape Town
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.
University of British Columbia CPSC 314 Computer Graphics Jan-Apr 2013 Tamara Munzner Rasterization.
Midpoint Circle Algorithm
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
Lecture 13: Raster Graphics and Scan Conversion
Clipping Polygons Dr Nicolas Holzschuch University of Cape Town Modified by Longin Jan Latecki
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.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
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
Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
OUTPUT PRIMITIVES CEng 477 Computer Graphics METU, 2004.
Primitive graphic objects
Scan Conversion or Rasterization
Computer graphics 2D graphics.
CS G140 Graduate Computer Graphics
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
Lecture 05: Mid-point Ellipse algorithm Dr. Manal Helal – Fall 2014
Chapter Three Part I Output Primitives CS 380.
Scan Conversion of Circles
Line Drawing Algorithms
Chapter 3 Graphics Output Primitives
3D transformations Dr Nicolas Holzschuch University of Cape Town
Presentation transcript:

Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified by Longin Jan Latecki Sep 2002

Rasterization of Primitives How to draw primitives? –Convert from geometric definition to pixels – rasterization = selecting the pixels Will be done frequently –must be fast: use integer arithmetic use addition instead of multiplication

Rasterization Algorithms Algorithmics: –Line-drawing: Bresenham, 1965 –Polygons: uses line-drawing –Circles: Bresenham, 1977 Currently implemented in all graphics libraries –You’ll probably never have to implement them yourself

Why should I know them? Excellent example of efficiency: –no superfluous computations Possible extensions: –efficient drawing of parabolas, hyperbolas Applications to similar areas: –robot movement, volume rendering The CG equivalent of Euler’s algorithm

Map of the lecture Line-drawing algorithm – naïve algorithm –Bresenham algorithm Circle-drawing algorithm – naïve algorithm –Bresenham algorithm

Naïve algorithm for lines Line definition: ax+by+c = 0 Also expressed as: y = mx + d – m = slope – d = distance For x=xmin to xmax compute y = m*x+d light pixel (x,y)

Extension by symmetry Only works with -1  m  1: m = 1/3 m = 3 Extend by symmetry for m > 1

Problems 2 floating-point operations per pixel Improvements: compute y = m*p+d For x=xmin to xmax y += m light pixel (x,y) Still 1 floating-point operation per pixel Compute in floats, pixels in integers

Bresenham algorithm: core idea At each step, choice between 2 pixels (0  m  1) Line drawn so far Either I lit this pixel… …or that one

Bresenham algorithm I need a criterion to pick between them Distance between line and center of pixel: –the error associated with this pixel Error pixel 1 Error pixel 2

Bresenham Algorithm (2) The sum of the 2 errors is 1 –Pick the pixel with error < 1/2 If error of current pixel < 1/2, –draw this pixel Else: –draw the other pixel. Error of current pixel = 1 - error

How to compute the error? Origin (0,0) is the lower left corner Line defined as: y = ax + c Distance from pixel (p,q) to line: d = y(p) – q = ap - q + c Draw this pixel iff: ap - q + c < 1/2 Update for next pixel: x += 1, d += a

We’re still in floating point! Yes, but now we can get back to integer: e = 2ap - 2q + 2c - 1 < 0 If e 0, move up. Update for next pixel: –If I stay horizontal: x+=1, e += 2a –If I move up: x+=1, y+=1, e += 2a - 2

Bresenham algorithm: summary Several good ideas: –use of symmetry to reduce complexity –choice limited to two pixels –error function for choice criterion –stay in integer arithmetics Very straightforward: –good for hardware implementation –good for assembly language

Circle: naïve algorithm Circle equation: x 2 +y 2 -r 2 = 0 Simple algorithm: for x = xmin to xmax y = sqrt(r*r - x*x) draw pixel(x,y) Work by octants and use symmetry

Circle: Bresenham algorithm Choice between two pixels: Circle drawn so far …or that one Either I lit this pixel…

Bresenham for circles Mid-point algorithm: If the midpoint between pixels is inside the circle, E is closer, draw E If the midpoint is outside, SE is closer, draw SE E SE

Bresenham for circles (2) Error function: d = x 2 +y 2 - r 2 Compute d at the midpoint: If the last pixel drawn is (x,y), then E = (x+1,y), and SE = (x+1,y-1). Hence, the midpoint = (x+1,y-1/2). d(x,y) = (x+ 1 ) 2 + (y - 1/2 ) 2 - r 2 d < 0: draw E d  0: draw SE

Updating the error In each step (go to E or SE), i.e., increment x: x+=1 : d += 2 x +3 If I go to SE, i.e., x+=1, y+=-1: d += -2 y + 2 Two mult, two add per pixel Can you do better?

Doing even better The error is not linear However, what I add to the error is Keep  x and  y : –At each step:  x += 2,  y += -2 d +=  x –If I decrement y, d +=  y 4 additions per pixel

Midpoint algorithm: summary Extension of line drawing algorithm Test based on midpoint position Position checked using function: –sign of (x 2 +y 2 -r 2 ) With two steps, uses only additions

Extension to other functions Midpoint algorithm easy to extend to any curve defined by: f(x,y) = 0 If the curve is polynomial, can be reduced to only additions using n-order differences

Conclusion The basics of Computer Graphics: –drawing lines and circles Simple algorithms, easy to implement with low-level languages