CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu.

Slides:



Advertisements
Similar presentations
Graphics Primitives: line
Advertisements

Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
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
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 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.
30/9/2008Lecture 21 Computer Graphics Assistant Professor Dr. Sana’a Wafa Al-Sayegh 2 nd Semester ITGD3107 University of Palestine.
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.
Okay, you have learned … OpenGL drawing Viewport and World Window setup main() { glViewport(0,0,300,200); glMatrixMode(GL_PROJECTION); glLoadIndentity();
CS 352: Computer Graphics Chapter 7: The Rendering Pipeline.
Output Primitives Computer Graphics.
Implementation Dr. Amy Zhang. Reading 2  Hill, Chapters  Hill, Chapter 10.
CS5500 Computer Graphics © Chun-Fa Chang, Spring 2007 CS5500 Computer Graphics May 3, 2007.
Implementation III Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico.
Course Website: Computer Graphics 5: Line Drawing Algorithms.
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.
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
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
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.
Line Drawing and Generalization. Outline  overview  line drawing  circle drawing  curve drawing.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 2D Viewing 고려대학교 컴퓨터 그래픽스 연구실.
CGMB214: Introduction to Computer Graphics
1 Introduction to Computer Graphics with WebGL Ed Angel Professor Emeritus of Computer Science Founding Director, Arts, Research, Technology and Science.
Computer Graphics Chapter 6 Andreas Savva. 2 Interactive Graphics Graphics provides one of the most natural means of communicating with a computer. Interactive.
Image Synthesis Rabie A. Ramadan, PhD 7. 2 Image Rasterization.
Computer Graphics Rendering 2D Geometry CO2409 Computer Graphics Week 2.
1 CSCE 441 Lecture 2: Scan Conversion of Lines Jinxiang Chai.
GEOMETRY AND LINE GENERATION Geometry and Line Generation Chapter 2.
In the name of God Computer Graphics. Today Introduction Sampling Graphic Output Primitives 1.Line 2.Circle 3.Curve 4.polygon.
Scan Conversion.
Lecture 13: Raster Graphics and Scan Conversion
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 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 I, Fall 2010 Scan conversion algorithms.
Rasterization, or “What is glBegin(GL_LINES) really doing?” Course web page: February 23, 2012  Lecture 4.
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.
CSCE 441 Lecture 2: Scan Conversion of Lines
Basic Raster Graphics Algorithms for Drawing 2D Primitives
CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1
University of New Mexico
Implementation III.
Introduction to Computer Graphics with WebGL
CSCE 441 Lecture 2: Scan Conversion of Lines
2D Scan-line Conversion
Introduction to Computer Graphics
Rasterization and Antialiasing
Lecture 13 Clipping & Scan Conversion
Computer Graphics Implementation III
Rasterization and Antialiasing
Chapter 3 Graphics Output Primitives
Basic Raster Graphics Algorithms for Drawing 2D Primitives
Implementation III Ed Angel Professor Emeritus of Computer Science
Presentation transcript:

CS 4731: Computer Graphics Lecture 20: Raster Graphics Part 1 Emmanuel Agu

2D Graphics Pipeline Object World Coordinates Object subset window to viewport mapping Object Screen coordinates RasterizationDisplay Applying world window Clipping Simple 2D Drawing Pipeline

Rasterization (Scan Conversion) Convert high-level geometry description to pixel colors in the frame buffer Example: given vertex x,y coordinates determine pixel colors to draw line Two ways to create an image: Scan existing photograph Procedurally compute values (rendering) Viewport Transformation Rasterization

A fundamental computer graphics function Determine the pixels’ colors, illuminations, textures, etc. Implemented by graphics hardware Rasterization algorithms Lines Circles Triangles Polygons

Rasterization Operations Drawing lines on the screen Manipulating pixel maps (pixmaps): copying, scaling, rotating, etc Compositing images, defining and modifying regions Drawing and filling polygons Previously glBegin(GL_POLYGON), etc Aliasing and antialiasing methods

Line drawing algorithm Programmer specifies (x,y) values of end pixels Need algorithm to figure out which intermediate pixels are on line path Pixel (x,y) values constrained to integer values Actual computed intermediate line values may be floats Rounding may be required. E.g. computed point (10.48, 20.51) rounded to (10, 21) Rounded pixel value is off actual line path (jaggy!!) Sloped lines end up having jaggies Vertical, horizontal lines, no jaggies

Line Drawing Algorithm Line: (3,2) -> (9,6) ? Which intermediate pixels to turn on?

Line Drawing Algorithm Slope-intercept line equation y = mx + b Given two end points (x0,y0), (x1, y1), how to compute m and b? (x0,y0) (x1,y1) dx dy

Line Drawing Algorithm Numerical example of finding slope m: (Ax, Ay) = (23, 41), (Bx, By) = (125, 96)

Digital Differential Analyzer (DDA): Line Drawing Algorithm (x0,y0) (x1,y1) dx dy  Walk through the line, starting at (x0,y0)  Constrain x, y increments to values in [0,1] range  Case a: x is incrementing faster (m < 1)  Step in x=1 increments, compute and round y  Case b: y is incrementing faster (m > 1)  Step in y=1 increments, compute and round x

DDA Line Drawing Algorithm (Case a: m < 1) (x0, y0) x = x0 + 1 y = y0 + 1 * m Illuminate pixel (x, round(y)) x = x + 1 y = y + 1 * m Illuminate pixel (x, round(y)) … Until x == x1 (x1,y1) x = x0 y = y0 Illuminate pixel (x, round(y))

DDA Line Drawing Algorithm (Case b: m > 1) y = y0 + 1 x = x0 + 1 * 1/m Illuminate pixel (round(x), y) y = y + 1 x = x + 1 /m Illuminate pixel (round(x), y) … Until y == y1 x = x0 y = y0 Illuminate pixel (round(x), y) (x1,y1) (x0,y0)

DDA Line Drawing Algorithm Pseudocode compute m; if m < 1: { float y = y0; // initial value for(int x = x0;x <= x1; x++, y += m) setPixel(x, round(y)); } else // m > 1 { float x = x0; // initial value for(int y = y0;y <= y1; y++, x += 1/m) setPixel(round(x), y); } Note: setPixel(x, y) writes current color into pixel in column x and row y in frame buffer

Line Drawing Algorithm Drawbacks DDA is the simplest line drawing algorithm Not very efficient Round operation is expensive Optimized algorithms typically used. Integer DDA E.g.Bresenham algorithm (Hill, ) Bresenham algorithm Incremental algorithm: current value uses previous value Integers only: avoid floating point arithmetic Several versions of algorithm: we’ll describe midpoint version of algorithm

Bresenham’s Line-Drawing Algorithm Problem: Given endpoints (Ax, Ay) and (Bx, By) of a line, want to determine best sequence of intervening pixels First make two simplifying assumptions (remove later): (Ax < Bx) and (0 < m < 1) Define Width W = Bx – Ax Height H = By - Ay

Bresenham’s Line-Drawing Algorithm Based on assumptions: W, H are +ve H < W As x steps in +1 increments, y incr/decr by <= +/–1 y value sometimes stays same, sometimes increases by 1 Midpoint algorithm determines which happens

Bresenham’s Line-Drawing Algorithm Using similar triangles: H(x – Ax) = W(y – Ay) -W(y – Ay) + H(x – Ax) = 0 Above is ideal equation of line through (Ax, Ay) and (Bx, By) Thus, any point (x,y) that lies on ideal line makes eqn = 0 Doubling expression and giving it a name, F(x,y) = -2W(y – Ay) + 2H(x – Ax)

Bresenham’s Line-Drawing Algorithm So, F(x,y) = -2W(y – Ay) + 2H(x – Ax) Algorithm, If: F(x, y) < 0, (x, y) above line F(x, y) > 0, (x, y) below line Hint: F(x, y) = 0 is on line Increase y keeping x constant, F(x, y) becomes more negative

Bresenham’s Line-Drawing Algorithm Example: to find line segment between (3, 7) and (9, 11) F(x,y) = -2W(y – Ay) + 2H(x – Ax) = (-12)(y – 7) + (8)(x – 3) For points on line. E.g. (7, 29/3), F(x, y) = 0 A = (4, 4) lies below line since F = 44 B = (5, 9) lies above line since F = -8

Bresenham’s Line-Drawing Algorithm (x0, y0) M = (x0 + 1, Y0 + ½) If F(Mx,My) < 0, M lies above line, shade lower pixel … (x1,y1) What Pixels to turn on or off? Consider pixel midpoint M(Mx, My) M(Mx,My) If F(Mx,My) > 0, M lies above line, shade upper pixel(same y as before)

Bresenham’s Line-Drawing Algorithm Algorithm: // loop till you get to ending x Set pixel at (x, y) to desired color value x++ if F < 0 F = F + 2H else Y++, F = F - 2(W – H) Recall: F is equation of line

Bresenham’s Line-Drawing Algorithm Final words: we developed algorithm with restrictions Can add code to remove restrictions To get the same line when Ax > Bx (swap and draw) Lines having slope greater than unity (interchange x with y) Lines with negative slopes (step x++, decrement y not incr) Horizontal and vertical lines (pretest a.x = b.x and skip tests) Important: Read Hill

References Hill, chapter 10