Drawing Lines The Bresenham Algorithm for drawing lines and filling polygons.

Slides:



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

Graphics Primitives Part II: Bresenhams line and circle.
5.1 Si23_03 SI23 Introduction to Computer Graphics Lecture 5 – Drawing A Line.
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.
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.
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.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
CS 450: COMPUTER GRAPHICS FILLING POLYGONS SPRING 2015 DR. MICHAEL J. REALE.
Output Primitives Computer Graphics.
Drawing Lines The Bresenham Algorithm for drawing lines and filling polygons.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Finite Mathematics & Its Applications, 10/e by Goldstein/Schneider/SiegelCopyright © 2010 Pearson Education, Inc. 1 of 71 Chapter 1 Linear Equations and.
Michener’s Algorithm An efficient scheme for drawing circles (and filling circular disks) on a raster graphics display.
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.
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.
Solving Equations. Is a statement that two algebraic expressions are equal. EXAMPLES 3x – 5 = 7, x 2 – x – 6 = 0, and 4x = 4 To solve a equation in x.
Rasterizing primitives: know where to draw the line Dr Nicolas Holzschuch University of Cape Town Modified.
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.
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.
Triangle Scan Conversion. 2 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009 Rasterization Rasterization (scan conversion) –Determine which.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
Introduction to Computer Graphics with WebGL
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
Introduction Computer Graphics & Its application Types of computer graphics Graphic display : random Scan & Raster Scan display Frame buffer and video.
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)
Chapter 3 Scan Conversion Lecture-02. Bresenham’s Line Algorithm Bresenham’s line algorithm – is a highly efficient incremental method for scan- converting.
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
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.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
Graphics Pipeline Rasterization CMSC 435/634. Drawing Terms Primitive – Basic shape, drawn directly – Compare to building from simpler shapes Rasterization.
Lecture 13: Raster Graphics and Scan Conversion
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
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 I, Fall 2010 Scan conversion algorithms.
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
Objectives Understand Bresenhams line drawing algorithm. Apply the algorithm to plot a line with the end points specified.
Scan Conversion or Rasterization
Lecture 9 Line Drawing Algorithms (Bresenham’s Line Algorithm)
COMPUTER ORGANIZATION & ASSEMBLY LANGUAGE
Scan Conversion or Rasterization
University of New Mexico
Implementation III.
Introduction to Computer Graphics with WebGL
Rasterizing Lines 1 Lecture 32 Mon, Nov 12, 2007.
Rasterization and Antialiasing
Line Drawing Algorithms
Computer Graphics Implementation III
Rasterization and Antialiasing
Chapter 3 Graphics Output Primitives
Presentation transcript:

Drawing Lines The Bresenham Algorithm for drawing lines and filling polygons

Plotting a line-segment Bresenham published algorithm in 1965 It was originally to be used with a plotter It adapts well to raster “scan conversion” It uses only integer arithmetic operations It is an “iterative” algorithm: each step is based on results from the previous step The sign of an “error term” governs the choice among two alternative actions

Scan conversion The actual line is comprised of points drawn from a continuum, but it must be “approximated” using pixels from a discrete grid.

The various cases Horizontal or vertical lines are easy cases Lines that have slope 1 or -1 are easy, too Symmetries leave us one remaining case: 0 < slope < 1 As x-coodinate is incremented, there are just two possibilities for the y-coordinate: (1) y-coordinate is increased by one; or(2) y-coordinate remains unchanged

0 < slope < 1 y increases by 1y does not change X-axis Y-axis

Integer endpoints ΔXΔX ΔYΔY slope = ΔY/ΔX (X0,Y0) (X1,Y1) ΔY = Y1 – Y0 ΔX = X1 – X0 0 < ΔY < ΔX

Which point is closer? A B x i -1 xixi y = mx + b error(A) = (y i ) – y* error(B) = y* - (y i -1 ) ideal line y i -1 y i -1 +1

The Decision Variable Choose B if and only if error(B)<error(A) Or equivalently: error(B) – error(A) < 0 Formula: error(B) – error(A) = 2m(x i – x 0 ) + 2(y 0 – y i -1 ) -1 Remember: m = Δy/Δx (slope of line) Multiply through by Δx (to avoid fractions) Let d i = Δx( error(B) – error(A) ) Rule is: choose B if and only if d i < 0

Computing d i+1 from d i d i+1 = 2(Δy)(x i+1 – x 0 ) +2(Δx)(y 0 – y i ) – Δx d i = 2(Δy)(x i – x 0 ) + 2(Δx)(y 0 – y i-1 ) – Δx The difference can be expressed as: d i+1 = d i + 2(Δy)(x i+1 – x i ) – 2(Δy)(y i – y i-1 ) Recognize that x i+1 – x i = 1 at every step And also: y i – y i-1 will be either 0 or 1 (depending on the sign of the previous d)

How does algorithm start? At the outset we start from point (x 0,y 0 ) Thus, at step i =1, our formula for d i is: d 1 = 2(Δy) - Δx And, at each step thereafter: if ( d i < 0 ) { d i+1 = d i + 2(Δy); y i+1 = y i ; } else{ d i+1 = d i + 2(Δy-Δx); y i+1 = y i + 1; } x i+1 = x i + 1;

‘bresdemo.cpp’ The example-program is on class website: It draws line-segments with various slopes The Michener algorithm (for a circle-fill) is also included, for comparative purposes Extreme slopes (close to zero or infinity) are not displayed in this demo program They can be added by you as an exercise

Filling a triangle or polygon The Bresenham’s method can be adapted But an efficient data-structure is needed All the sides need to be handled together We let the y-coordinate steadily increment For sides which are “nearly horizontal” the x-coordinates can change by more than 1

Triangle Illustration

Non-Convex Polygons

Bucket-Sort Y XLOXHI 13 17

Handling Corners

Legacy Software We have a polygon-fill demo: ‘polyfill.cpp’ You can find it now on our class website But it was written in 1997 for MS-DOS We’d like to run it on our Linux system But it will need a number of modifications This is our first programming assignment: to “adapt” this obsolete application so it can execute on a contemporary platform

What are some issues? GNU compiler enforces stricter standards Sizes of some data-types are now larger Physical VRAM now must be “mapped” I/O instructions now require permissions Real-Mode addresses must be converted Not all the header-files are still supported Interface to CPU registers is a bit different

Converting addresses TURBO-C++ allowed use of ‘far’ pointers Use a macro to create a pointer to VRAM: uchar *vram = MK_FP( 0xA000, 0x0000 ); Real-mode address has two components: (16-bit segment and 16-bit offset) For Linux we convert to a 32-bit address: uchar *vram = (uchar*)0x000A0000; Formula: address = 16*segment + offset

Hardware Issues? Pentium CPUs are “backward compatible” BIOS firmware can use Virtual-8086 mode SVGA still supports older graphics modes The keyboard’s mechanism is unchanged Feasibility test: if we will “boot” MS-DOS, we can easily run the ‘polyfill’ application So it’s just a software problem to give our MS-DOS program a new life under Linux!