1 Line Drawing Version B: Semi-Formal Methods Derivation ©Anthony Steed 1999-2003.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
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.
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.
CS 376 Introduction to Computer Graphics 02 / 02 / 2007 Instructor: Michael Eckmann.
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.
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 Algorithms
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.
Larry F. Hodges (modified by Amos Johnson) 1 Design of Line, Circle & Ellipse Algorithms.
The lines of this object appear continuous However, they are made of pixels 2April 13, 2015.
Komputer Grafik 2 (AK045206) Scan Conversion 1/31 Scan Conversion.
Raster conversion algorithms for line and circle
Bresenham’s Midpoint Algorithm CS5600 Computer Graphics Rich Riesenfeld Spring 2006 Lecture Set 1.
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.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
Rasterization Foley, Ch: 3. Pixels are represented as disjoint circles centered on uniform grid Each (x,y) of the grid has a pixel Y X (1,1) (1,2) (0,0)
CS 450: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE.
CGMB214: Introduction to Computer Graphics
Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.
Dr. Scott Schaefer Scan Conversion of Lines. 2/78 Displays – Cathode Ray Tube.
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Scan Conversion. Also known as rasterization In our programs objects are represented symbolically –3D coordinates representing an object’s position –Attributes.
1 CPE 333 : Computer Graphics มหาวิทยาลัยเทคโนโลยีพระจอม เกล้าธนบุรี Dr. Natasha Dejdumrong.
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
Introduction This chapter gives you several methods which can be used to solve complicated equations to given levels of accuracy These are similar to.
Informationsteknologi Monday, November 26, 2007Computer Graphics - Class 121 Today’s class Drawing lines Bresenham’s algorithm Compositing Polygon filling.
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
Larry F. Hodges 1 Design of Line and Circle Algorithms.
10/15/02 (c) 2002 University of Wisconsin, CS559 Last Time Clipping.
June 2007 Computer Arithmetic, Function EvaluationSlide 1 VI Function Evaluation Topics in This Part Chapter 21 Square-Rooting Methods Chapter 22 The CORDIC.
Graphics Graphics & Graphical Programming Lecture 14 - Lines & Circles.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
 A line segment in a scene is defined by the coordinate positions of the line end-points x y (2, 2) (7, 5)
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.
Computer Graphics Drawing Line. Lines and Polylines Convex: For every pair of points in the polygon, the line between them is fully contained in the polygon.
Computer Graphics Rendering 2D Geometry CO2409 Computer Graphics Week 2.
CS-321 Dr. Mark L. Hornick 1 Line Drawing Algorithms.
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.
CS 551 / 645: Introductory Computer Graphics
Rendering.
Scan Conversion.
Lecture 13: Raster Graphics and 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.
Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
Scan Conversion of Line Segments. What is Scan conversion? Final step of rasterization (the process of taking geometric shapes and converting them into.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
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.
Scan Conversion or Rasterization
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Scan Conversion or Rasterization
Computer Graphics Implementation I.
CSCE 441 Lecture 2: Scan Conversion of Lines
2D Scan-line Conversion
Line Drawing ©Anthony Steed 1999.
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
S.JOSEPHINE THERESA, DEPT OF CS, SJC, TRICHY-2
Presentation transcript:

1 Line Drawing Version B: Semi-Formal Methods Derivation ©Anthony Steed

2 Overview n Line drawing is hard! n Ideal lines and drawing them n Bresenham’s algorithm Stages of optimisation n Going Faster n Going Faster Still

3 Ideal Lines n From the equation of a line n Find a discretisation

4 Octants n We will choose one case (1 st octant) Line gradient is > 0 and is < 1 n There are eight variations of the following algorithms 4 iterate over X 4 iterate over Y 1 st octant (x2,y2) (x1,y1)

5 In the 1 st Octant n We know that there is more than one pixel on every row (i.e. X increases faster than y) n Also Y increase as X increases n Note that horizontal, vertical and 45 degree lines usually treated as special cases

6 Naïve Algorithm dx = x 2 -x 1 dy = y 2 - y 1 for (x=x 1 ;x<=x 2 ;x++) { y = round(y1+(dy/dx)*(x-x 1 )) setPixel(x,y) } n Problems one divide, one round, two adds, one multiply per pixel

7 What have we got n Only integer arithmetic n One if, 1/2 adds per pixel One hidden if in the loop n Can we get faster than that Well we can get rid of one loop if we are not afraid of programming assembler and using the jmp statement!

8 Step 0 dx = x 2 -x 1 dy = y 2 - y 1 for (x=x 1 ;x<=x 2 ;x++) { y = round(y1+(dy/dx)* (x-x 1 )) setPixel(x,y) } Step 1: Convert to incremental algorithm dx = x 2 -x 1 dy = y 2 - y 1 y = y 1 for (x=x 1 ;x<=x 2 ;x++) { y += dy/dx setPixel(x,round(y)) }

9 Step 1Step 2: Replace round dx = x 2 -x 1 dy = y 2 - y 1 y = y 1 for (x=x 1 ;x<=x 2 ;x++) { y += dy/dx setPixel(x,(int)(y+0.5)) } dx = x 2 -x 1 dy = y 2 - y 1 y = y 1 for (x=x 1 ;x<=x 2 ;x++) { y += dy/dx setPixel(x,round(y)) }

10 Step 2 Step 3: Split y into an integer and fraction part dx = x 2 -x 1 dy = y 2 - y 1 y = y 1 for (x=x 1 ;x<=x 2 ;x++) { y += dy/dx setPixel(x,(int)(y+0.5)) } dx = x 2 -x 1 dy = y 2 - y 1 y i = y 1 y f = 0.0 for (x=x 1 ;x<=x 2 ;x++) { y f += dy/dx if (y f > 0.5) { y i ++ y f -- } setPixel(x,y i ) } Note y f is always in range –0.5 to 0.5

11 Step 3Step 4: Shift y f by 0.5 dx = x 2 -x 1 dy = y 2 - y 1 y i = y 1 y f = 0.0 for (x=x 1 ;x<=x 2 ;x++) { y f += dy/dx if (y f > 0.5) { y i ++ y f -- } setPixel(x,y i ) } dx = x 2 -x 1 dy = y 2 - y 1 y i = y 1 y f = -0.5 for (x=x 1 ;x<=x 2 ;x++) { y f += dy/dx if (y f > 0.0) { y i ++ y f -- } setPixel(x,y i ) }

12 Step 4 Step 5: Multiply y f through by 2dx dx = x 2 -x 1 dy = y 2 - y 1 y i = y 1 y f = 0.0 for (x=x 1 ;x<=x 2 ;x++) { y f += dy/dx if (y f > 0.0) { y i ++ y f -- } setPixel(x,y i ) } dx = x 2 -x 1 dy = y 2 - y 1 y i = y 1 y f = -dx for (x=x 1 ;x<=x 2 ;x++) { y f += 2dy if (y f > 0.0) { y i ++ y f += -2dx } setPixel(x,y i ) } We now have all integer arithmetic

13 Step 5Step 6: Re-arrange if dx = x 2 -x 1 dy = y 2 - y 1 y i = y 1 y f = -dx for (x=x 1 ;x<=x 2 ;x++) { if (y i > 0.0) { y i ++ y f += 2dy -2dx } else { y f += 2dy } setPixel(x,y i ) } This has one less add statement dx = x 2 -x 1 dy = y 2 - y 1 y i = y 1 y f = -dx for (x=x 1 ;x<=x 2 ;x++) { y f += 2dy if (y f > 0.0) { y i ++ y f += -2dx } setPixel(x,y i ) }

14 Step 6 Step 7: Make all constants dx = x 2 -x 1 dy = y 2 - y 1 y i = y 1 y f = -dx e = 2dy – 2dx f = 2dy for (x=x 1 ;x<=x 2 ;x++) { if (y i > 0.0) { y i ++ y f +=e } else { y f += f } setPixel(x,y i ) } Reduced to one if, 1 or 2 adds dx = x 2 -x 1 dy = y 2 - y 1 y i = y 1 y f = -dx for (x=x 1 ;x<=x 2 ;x++) { if (y i > 0.0) { y i ++ y f += 2dy -2dx } else { y f += 2dy } setPixel(x,y i ) }

15 What have we got n Only integer arithmetic n One if, 1/2 adds per pixel One hidden if in the loop n Can we get faster than that Well we can get rid of one loop if we are not afraid of programming assembler and using the jmp statement!

16 Faster - Mid-Point Drawing n Note that lines are symmetric n (a,b) to (c,d) should generate the same pixels. Thus the lines are symmetric about the mid-point n Implies... draw outwards from mid-point in both directions n Is almost twice as fast (one extra add gives an extra pixel)

17 Faster - Two-Step n Note we considered whether to choose P or Q n What if we choose between the four cases n Almost twice the speed again

18 Summary n Bresenham’s algorithm uses only integer arithmetic and 2/3 ops per pixel Ideal for hardware implementation n Can be improved almost four-fold in speed, with added complexity Good for software implementations Pixel scanning is usually not the bottleneck these days so wouldn’t be cast into hardware