CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Similar documents
CS 548: COMPUTER GRAPHICS DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

CS 450: COMPUTER GRAPHICS RASTERIZING LINES SPRING 2016 DR. MICHAEL J. REALE

From Ver(ces to Fragments: Rasteriza(on

Scan Conversion. CMP 477 Computer Graphics S. A. Arekete

MODULE - 4. e-pg Pathshala

Rasterization: Geometric Primitives

CS 4731: Computer Graphics Lecture 21: Raster Graphics: Drawing Lines. Emmanuel Agu

OpenGL Graphics System. 2D Graphics Primitives. Drawing 2D Graphics Primitives. 2D Graphics Primitives. Mathematical 2D Primitives.

Rasterization, or What is glbegin(gl_lines) really doing?

CSCI 4620/8626. Coordinate Reference Frames

Chapter - 2: Geometry and Line Generations

Scan Conversion. Lines and Circles

Chapter 3: Graphics Output Primitives. OpenGL Line Functions. OpenGL Point Functions. Line Drawing Algorithms

Computer Graphics : Bresenham Line Drawing Algorithm, Circle Drawing & Polygon Filling

Output Primitives Lecture: 3. Lecture 3. Output Primitives. Assuming we have a raster display, a picture is completely specified by:

CS 130. Scan Conversion. Raster Graphics

Line Drawing Week 6, Lecture 9

OUTPUT PRIMITIVES. CEng 477 Introduction to Computer Graphics METU, 2007

Output Primitives. Dr. S.M. Malaek. Assistant: M. Younesi

Rendering. A simple X program to illustrate rendering

CS Rasterization. Junqiao Zhao 赵君峤

From Vertices to Fragments: Rasterization. Reading Assignment: Chapter 7. Special memory where pixel colors are stored.

CS 543: Computer Graphics. Rasterization

Scan Converting Circles

Rendering. A simple X program to illustrate rendering

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

Computer Graphics (CS 543) Lecture 10: Rasterization and Antialiasing

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 14

This library uses only GL functions but contains code for creating common objects and simplifying viewing.

Line Drawing. Foundations of Computer Graphics Torsten Möller

Overview of Computer Graphics

Efficient Plotting Algorithm

In today s lecture we ll have a look at: A simple technique The mid-point circle algorithm

Tópicos de Computação Gráfica Topics in Computer Graphics 10509: Doutoramento em Engenharia Informática. Chap. 2 Rasterization.

Scan Converting Lines

UNIT 2 GRAPHIC PRIMITIVES

Painter s HSR Algorithm

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Computer Graphics

Computer Graphics: Line Drawing Algorithms

CS488 2D Graphics. Luc RENAMBOT

Scan Conversion. Drawing Lines Drawing Circles

Computer Graphics. Lecture 2. Doç. Dr. Mehmet Gokturk

Announcements. Midterms graded back at the end of class Help session on Assignment 3 for last ~20 minutes of class. Computer Graphics

Introduction to Computer Graphics (CS602) Lecture 05 Line Drawing Techniques

Computer Graphics. - Rasterization - Philipp Slusallek

Pipeline implementation II

Renderer Implementation: Basics and Clipping. Overview. Preliminaries. David Carr Virtual Environments, Fundamentals Spring 2005

Chapter 8: Implementation- Clipping and Rasterization

Computer Graphics Lecture Notes

Raster Displays and Scan Conversion. Computer Graphics, CSCD18 Fall 2008 Instructor: Leonid Sigal

R asterisation. Part I: Simple Lines. Affine transformation. Transform Render. Rasterisation Line Rasterisation 2/16

Line Rasterization and Antialiasing

Topic #1: Rasterization (Scan Conversion)

Display Technologies: CRTs Raster Displays

Einführung in Visual Computing

Rasterization. Rasterization (scan conversion) Digital Differential Analyzer (DDA) Rasterizing a line. Digital Differential Analyzer (DDA)

UNIT -8 IMPLEMENTATION

1 Introduction to Graphics

Computer Graphics Lecture 5

Department of Computer Sciences Graphics Fall 2003 (Lecture 2) Pixels

GRAPHICS OUTPUT PRIMITIVES

CPSC / Scan Conversion

Rasterization. CS4620/5620: Lecture 12. Announcements. Turn in HW 1. PPA 1 out. Friday lecture. History of graphics PPA 1 in 4621.

Department of Computer Science Engineering, Mits - Jadan, Pali, Rajasthan, India

Implementation III. Ed Angel Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Graphics System. Processor. Output Display. Input Devices. Frame Buffer. Memory. Array of pixels. Resolution: # of pixels Depth: # of bits/pixel

2D Graphics Primitives II. Additional issues in scan converting lines. 1)Endpoint order. Want algorithms to draw the same pixels for each line

Computer Graphics D Graphics Algorithms

Fall CSCI 420: Computer Graphics. 7.1 Rasterization. Hao Li.

Output Primitives Lecture: 4. Lecture 4

Computer Graphics. Lecture 3 Graphics Output Primitives. Somsak Walairacht, Computer Engineering, KMITL

Chapter 3. Sukhwinder Singh

Computer Graphics. Chapter 3 Computer Graphics Software

Line Drawing. Introduction to Computer Graphics Torsten Möller / Mike Phillips. Machiraju/Zhang/Möller

CS-321 Thursday 12 September 2002 Quiz (3 pts.) What is the purpose of a control grid in a cathode ray tube (CRT)?

CS6504 & Computer Graphics Unit I Page 1

(Refer Slide Time: 00:03:51)

CS2401 Computer Graphics

0. Introduction: What is Computer Graphics? 1. Basics of scan conversion (line drawing) 2. Representing 2D curves

Section 1.1 The Distance and Midpoint Formulas

Unit 2 Output Primitives and their Attributes

Realtime 3D Computer Graphics Virtual Reality

The Traditional Graphics Pipeline

UNIT 2 Scan Conversion Techniques and Image Representation Unit-02/Lecture-01

CSCI 420 Computer Graphics Lecture 14. Rasterization. Scan Conversion Antialiasing [Angel Ch. 6] Jernej Barbic University of Southern California

An Improved Algorithm for Scan-converting a Line

EF432. Introduction to spagetti and meatballs

The Traditional Graphics Pipeline

CSC Computer Graphics

Graphics (Output) Primitives. Chapters 3 & 4

Graphics Output Primitives Hearn & Baker Chapter 3. Some slides are taken from Robert Thomsons notes.

UNIT I INTRODUCTION. Survey of Computer Graphics

(Refer Slide Time: 9:36)

Computer Graphics D Graphics Algorithms

Lossy Coding 2 JPEG. Perceptual Image Coding. Discrete Cosine Transform JPEG. CS559 Lecture 9 JPEG, Raster Algorithms

Rasteriza2on and Clipping

1.1 Survey of Computer graphics Computer graphics is the pictorial representation of information using a computer program.

Rasterization. COMP 575/770 Spring 2013

I Internal Examination (Model Paper) B.Tech III Year VI semester, Computer Science & Engineering

Transcription:

CS 450: COMPUTER GRAPHICS REVIEW: DRAWING LINES AND CIRCLES SPRING 2015 DR. MICHAEL J. REALE

DRAWING PRIMITIVES: LEGACY VS. NEW Legacy: specify primitive in glbegin() glbegin(gl_points); glvertex3f(1,5,0); glvertex3f(2,3,1); glend(); OpenGL 3.0+: specify primitive in gldrawarrays() or gldrawelementarrays() gldrawarrays(gl_points, 0, pointcnt);

DRAWING POINTS AND LINES GL_POINTS = draws a point per vertex GL_LINES = draw individual lines with every 2 vertices Ignores unpaired vertices GL_LINE_STRIP = draw a polyline connecting all vertices in sequence GL_LINE_LOOP = draw a polyline, and then also connect the first and last vertices closed polyline

THE PROBLEM WITH PIXELS Modern displays use grid of pixels Discrete (digital) locations Problem: mathematical lines don t fall perfectly into pixel locations I.e., have to round line coordinates to integers Lines end up having this stair-step effect ( jaggies ) aliasing

DDA ALGORITHM m y x end end y x 0 0 dy dx Digital differential analyzer (DDA) Scan-conversion line algorithm based on calculating either dy or dx Sample one coordinate at unit intervals find nearest integer value for other coordinate If dx > dy increment x, add slope to y, and round to nearest integer: If dy > dx swap roles of x and y (increment y, add inverse slope to x, and round) If going in reverse decrement x and/or y x y k1 k y k 1 xk m 1 m

DDA ALGORITHM: CODE // Get dx and dy int dx = x1 - x0; int dy = y1 - y0; int steps, k; float xincrement, yincrement; // Set starting point float x = x0; float y = y0;

DDA ALGORITHM: CODE // Determine which coordinate we should step in if (abs(dx) > abs(dy)) steps = abs(dx); else steps = abs(dy); // Compute increments xincrement = float(dx) / float(steps); yincrement = float(dy) / float(steps);

DDA ALGORITHM: CODE // Let s assume we have a magic function called setpixel(x,y) that sets a pixel at (x,y) to the appropriate color. // Set value of pixel at starting point setpixel(round(x), round(y)); // For each step for (k = 0; k < steps; k++) { // Increment both x and y x += xincrement; y += yincrement; } // Set pixel to correct color // NOTE: we need to round off the values to integer locations setpixel(round(x), round(y));

DDA ALGORITHM: PROS AND CONS Advantage: Faster than using the slope-intercept form directly no multiplication, only addition Caveat: initial division necessary Disadvantages: Accumulation of round-off error can cause the line to drift off true path Rounding procedure still time-consuming

BRESENHAM S LINE ALGORITHM Uses only integers Slope m = fraction of integers Only uses addition/subtraction in main loop Basic idea: given (x+1), choose either y or (y+1) based on decision variable Based on distance from true line

BRESENHAM S LINE ALGORITHM: SUMMARIZED 1. Input two line endpoints and store LEFT endpoint in (x 0, y 0 ) 2. Plot first point (x 0, y 0 ) 3. Compute constants Δx, Δy, 2Δy, and 2Δy - 2Δx. Also compute first value of decision variable: p 0 = 2Δy Δx 4. At each x k, test p k : If p k < 0 plot (x k + 1, y k ) p k+1 = p k + 2Δy Otherwise plot (x k + 1, y k +1) p k+1 = p k + 2Δy - 2Δx 5. Perform step 4 (Δx 1) times NOTE: Effectively assuming line starts at (0,0) and thus b = 0 p k 2y x 2y(0) 2x(0) 2y x(2(0) 1) 2y x( 1) k 2y x 2x y k 2y x(2b 1) NOTE: This version ONLY works with 0 < m < 1.0!!! Ergo, Δx and Δy are positive here!

BRESENHAM S LINE ALGORITHM: CODE // NOTE: dx and dy are ABSOLUTE VALUES in this code int dx = fabs(x1 - x0); int dy = fabs(y1 - x0); int p = 2*dy - dx; int twody = 2*dy; int twodyminusdx = 2*(dy - dx); int x,y;

BRESENHAM S LINE ALGORITHM: CODE // Determine which endpoint to use as start position if(x0 > x1) { x = x1; y = y1; x1 = x0; } else { x = x0; y = y0; } // Plot first pixel setpixel(x,y);

BRESENHAM S LINE ALGORITHM: CODE while(x < x1) { x++; } if(p < 0) p += twody; else { y++; p += twodyminusdx; } setpixel(x,y);

BRESENHAM S LINE ALGORITHM: GENERALIZED What we re talked about only works with 0 < m < 1.0 For slopes other than 0 < m < 1.0, use symmetry: If dy > dx swap x and y After swapping endpoints and potentially swapping x and y, if y0 > y1 decrement y rather than increment NOTE: y may actually be x if you swapped them Two more warnings: 1) In the sample code, dx and dy are ABSOLUTE VALUES 2) In the next image, when I say x and y, I mean the actual x and y

MIDPOINT ALGORITHM Bresenham = specific form of midpoint algorithm Uses the implicit representation e.g., implicit line equation If a point is on the inside, F(x,y) < 0 If a point is on the outside, F(x,y) > 0 If a point is exactly on the boundary, F(x,y) = 0 F( x, y) Ax By C Test whether the point F(x+1, y + ½) is inside or outside choose closest point 0

MIDPOINT CIRCLE ALGORITHM SUMMARIZED 1. Input radius r and circle center (x c, y c ); first point = (x 0, y 0 ) = (0,r) 2. Calculate initial decision variable value*: 5 p0 r 4 3. At each x k, test p k : p p x 1 If p k < 0 next point is (x k+1, y k ) and: Otherwise next point is (x k+1, y k - 1) and: Where: 2x 2y k 1 k1 2x k 2y k 2 2 p k1 k 2 k1 p k1 k 2xk 1 1 2yk 1 4. For each calculated position (x,y), plot (x + x c, y + y c ) 5. Plot corresponding symmetric points in other seven octants 6. Repeat steps 3 through 5 UNTIL x >= y *NOTE: If r = integer, then can use p 0 = 1 r