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.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.
Line and Curve Drawing Algorithms. Line Drawing x0x0 y0y0 x end y end.
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.
Basic Raster Graphics Algorithms for Drawing 2D Primitives
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.
+ CPCS 391 Computer Graphics 1 Instructor: Dr. Sahar Shabanah Lecture 3.
Scan Conversion Algorithms
ECE291 Computer Engineering II Lecture 19 Josh Potts University of Illinois at Urbana- Champaign.
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.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
OUTPUT PRIMITIVES Screen vs. World coordinate systems ● Objects positions are specified in a Cartesian coordinate system called World Coordinate.
Lecture 16 Fun with graphics
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Raster conversion algorithms for line and circle
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
Line Drawing by Algorithm. Line Drawing Algorithms Line drawn as pixels Graphics system –Projects the endpoints to their pixel locations in the frame.
CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.
CAP4730: Computational Structures in Computer Graphics Chapter 3 Hearn & Baker Portions obtained from Leonard McMillan’s COMP136 Notes:
1/1/20001 Topic >>>> Scan Conversion CSE Computer Graphics.
Dr. S.M. Malaek Assistant: M. Younesi
Jehee Lee Seoul National University
Graphics Primitives: line. Pixel Position
Scan Conversion Line and Circle
CS 325 Introduction to Computer Graphics 02 / 01 / 2010 Instructor: Michael Eckmann.
1Computer Graphics Implementation III Lecture 17 John Shearer Culture Lab – space 2
CS 480/680 Computer Graphics Implementation III Dr. Frederick C Harris, Jr. Fall 2011.
Graphics Output Primitives
CGMB214: Introduction to Computer Graphics
Graphics Output Primitives Hearn & Baker Chapter 3
Review on Graphics Basics. Outline Polygon rendering pipeline Affine transformations Projective transformations Lighting and shading From vertices to.
CS 325 Introduction to Computer Graphics 02 / 03 / 2010 Instructor: Michael Eckmann.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
CS 551 / 645: Introductory Computer Graphics
Lecture 13: Raster Graphics and Scan Conversion
1 Module U08181: Computer Graphics graphics primitives part 1: scan conversion and filling.
Bresenham’s Line Algorithm
Lecture 2: 19/4/1435 Graphical algorithms Lecturer/ Kawther Abas CS- 375 Graphics and Human Computer Interaction.
Rasterization Overview Raster Display Device. Scan Conversion / Rasterization: converting vector graphics into raster graphics (determining pixels in.
Computer Graphics CC416 Lecture 04: Bresenham Line Algorithm & Mid-point circle algorithm Dr. Manal Helal – Fall 2014.
Computer Graphics Inf4/MSc Computer Graphics Lecture 4 Line & Circle Drawing.
10/10/2006TCSS458A Isabelle Bichindaritz1 Line and Circle Drawing Algorithms.
Rasterization CENG 477 Introduction to Computer Graphics Slides from Steve Marschner, CS4620, 2008 Cornell University.
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.
Primitive graphic objects
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
Lecture 8 Shear and Line Drawing Algorithms
University of New Mexico
Implementation III.
Rasterization and Antialiasing
Line and Curve Drawing Algorithms
Computer Graphics Implementation III
Rasterization and Antialiasing
Edited from The Rasterization Problem: Idealized Primitives Map to Discrete Display Space Edited from.
Scan Conversion (From geometry to pixels)
Implementation III Ed Angel Professor Emeritus of Computer Science
Line Drawing Algorithms
Presentation transcript:

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 University 1

CP411 Computer Graphics 2 1. Line-Drawing Steps 1.Description of a line in WC 2.A line is projected to view plane and clipped by clipping window. It becomes a line segment, with two ends within the clipping window 3.Line segment is transformed to normalized coordinate system 4.Line segment is mapped to screen coordinates, then converted to integers in view port ordinate system of the display 5.A line segment in SC is a graphics output primitives. It needs to be converted to pixels in SC by scan-conversion or rasterization algorithm. i.e. to set up pixels in the frame buffer. Each pixel position (x, y) has a location in frame buffer setPixel(x, y) is to set the color value at pixel (x, y)

CP411 Computer Graphics Fall 2007 Wilfrid Laurier University 3 (x1,y1) (x2,y2) (x1,y1) (x2,y2)

CP411 Computer Graphics 4 Scan conversion From SC description to pixels by scan conversion –Transforming the continuous into this discrete by sampling. Can never be ideal. –The best we can do is a discrete approximation of an ideal line.

CP411 Computer Graphics 5 The Basic idea of drawing lines Let (x0, y0) and (x1, y1) be the screen coordinates of the two end points of a line segment. x0  x1 Step through the x-coordinate from x0 to x1. Set the pixels closest to the line. (x1,y1) (x2,y2)

CP411 Computer Graphics 6 Important line qualities Continuous appearance Uniform thickness and brightness Turn on the pixels nearest the ideal line How fast is the line generated Preferred algorithms –Use integers rater than floating point –Use addition, subtraction rather than multiplication and division –Use iteration or recurrence –Use increment

CP411 Computer Graphics 7 Simple Line Algorithm I int x0=, y0=, x1=, y1= ; int dx = x1 - x0; int dy = y1 - y0; setPixel(x0, y0); if (dx != 0) { float m = (float) dy / (float)dx; float b = y0 - m*x0; dx = (x1 > x0) ? 1 : -1; while (x0 != x1) { x0 += dx; y0 = Math.round(m*x0 + b); setPixel(x0, y0); } y = m x + b m = (y1-y0)/(x1-x0) x = x0, x0+1, …, x1 y = mx + b

CP411 Computer Graphics 8 The above algorithm only works well when the angle between the line and the x-axis, , is less than 45 o The left figure is resulted for a line with  = 70 o. The pixels on the line are too sparsely set. A more desirable one is shown on the right.  = 70 o

CP411 Computer Graphics 9 Algorithm I improvement int x0 =, y0=,x1=, y1=..; int dx = x1 - x0; int dy = y1 - y0; setPixel(x0, y0); if (Math.abs(dx) > Math.abs(dy)) { float m = (float) dy / (float) dx; float b = y0 - m*x0; dx = (dx < 0) ? -1 : 1; while (x0 != x1) { x0 += dx; setPixel(x0, Math.round(m*x0 + b)); } } else if (dy != 0) { float m = (float) dx / (float) dy; float b = x0 - m*y0; dy = (dy < 0) ? -1 : 1; while (y0 != y1) { y0 += dy; setPixel(Math.round(m*y0 + b), y0); } }

CP411 Computer Graphics 10 Algorithm II – by increment, remove multiplication int x0 = …, y0 = …, x1 = …, y1 = …; int x = x0; float y = y0, dy = (y1 – y0) / (x1 – x0); for (x = x0; x  x1; ++x) { setPixel( x, round(y) ); y = y + dy; } Round operation is slow as well dx=1 d y

CP411 Computer Graphics 11 Algorithm III error is the distance between the centre of a pixel and the line) int x0 = …, y0 = …, x 1 …, y1 = …; int x, y = y0; float error = 0.0, dy = (y1 – y0) / (x1 – x0); for (x = x0; x  x1; ++x) { setPixel( x, y ); error = error + dy; if (error > 0.5) { ++y; error = error - 1.0; } }

CP411 Computer Graphics 12 Algorithm III _ improvement The floating point arithmetic can be entirely eliminated by scaling up error and  y by 2(x2-x1) int x0 = …, x =1 …, y0 = …, y1 = …; int x, y = y0, dx = 2*(x1 – x0), d y = 2*(y1 – y0), error = 0; for (x = x1; x  x1; ++x) { setPixel( x, y ); error = error + d y; if (error > dx/2) { ++y; error = error - dx; } }

CP411 Computer Graphics 13 Algorithm III _improvement The program runs even faster if we offset error by dx/2 int x0 = …, x1 = …, y0 = …, y1 = …; int x, y = y0, dx = 2*(x1 – x0), d y = 2*(y1 – y0), error = -dx / 2; for (x = x0; x  x1; ++x) { setPixel( x, y ); error = error + d y; if (error > 0) { ++y; error = error - dx; } }

CP411 Computer Graphics 14 Algorithm V The Bresenham’s line drawing algorithm Combine the operations error = error + d y and error = error – dx into one when error > 0 ; int x0 = …, x1 = …, y0 = …, y1 = …; int x, y = y0, dx = 2*(x1 – x0), d y = 2*(y1 – y0), error = -dx / 2 - d y, dymx = d y - dx; for (x = x1; x  x2; ++x) { setPixel( x, y ); if (error < 0) error = error + d y; else { ++y; error = error + dymx; } }

CP411 Computer Graphics 15 void lineBres (int x0, int y0, int xEnd, int yEnd) { int dx = fabs (xEnd - x0), dy = fabs(yEnd - y0); int p = 2 * dy - dx; int twoDy = 2 * dy, twoDyMinusDx = 2 * (dy - dx); int x, y; /* Determine which endpoint to use as start position. */ if (x0 > xEnd) { x = xEnd; y = yEnd; xEnd = x0; } else { x = x0; y = y0; } setPixel (x, y); while (x < xEnd) { x++; if (p < 0) p += twoDy; else { y++; p += twoDyMinusDx; } setPixel (x, y); }