Computer Graphics D Graphics Algorithms

Similar documents
Computer Graphics D Graphics Algorithms

Rasterization: Geometric Primitives

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

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

From Ver(ces to Fragments: Rasteriza(on

Chapter - 2: Geometry and Line Generations

Points and lines. x x 1 + y 1. y = mx + b

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

COMP371 COMPUTER GRAPHICS

Scan Conversion. Drawing Lines Drawing Circles

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

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

Rendering. A simple X program to illustrate rendering

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

Line Drawing Week 6, Lecture 9

Line Drawing. Foundations of Computer Graphics Torsten Möller

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

An Improved Algorithm for Scan-converting a Line

1 Introduction to Graphics

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

Rendering. A simple X program to illustrate rendering

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

UNIT -8 IMPLEMENTATION

Chapter 8: Implementation- Clipping and Rasterization

MODULE - 4. e-pg Pathshala

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

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

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

RASTERIZING POLYGONS IN IMAGE SPACE

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

Scan Converting Lines

Computer Graphics. - Rasterization - Philipp Slusallek

EF432. Introduction to spagetti and meatballs

CS 130. Scan Conversion. Raster Graphics

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

Overview of Computer Graphics

Einführung in Visual Computing

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

2D Image Synthesis. 2D image synthesis. Raster graphics systems. Modeling transformation. Vectorization. u x u y 0. o x o y 1

Display Technologies: CRTs Raster Displays

Scan Converting Circles

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

CS Rasterization. Junqiao Zhao 赵君峤

CPSC / Scan Conversion

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

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

CS335 Fall 2007 Graphics and Multimedia. 2D Drawings: Lines

GRAPHICS OUTPUT PRIMITIVES

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

Computer Graphics. Rasterization. Teacher: A.prof. Chengying Gao( 高成英 ) School of Data and Computer Science

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

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

Pipeline implementation II

Painter s HSR Algorithm

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

Computer Graphics Introduction to OpenGL

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

Topic #1: Rasterization (Scan Conversion)

CSCI 4620/8626. Coordinate Reference Frames

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

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

UNIT 2 GRAPHIC PRIMITIVES

A New Line Drawing Algorithm Based on Sample Rate Conversion

Topic 0. Introduction: What Is Computer Graphics? CSC 418/2504: Computer Graphics EF432. Today s Topics. What is Computer Graphics?

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

Raster Scan Displays. Framebuffer (Black and White)

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

Scan Conversion. Lines and Circles

EF432. Introduction to spagetti and meatballs

Computer Graphics Lecture 5

CS6504 & Computer Graphics Unit I Page 1

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

CS 543: Computer Graphics. Rasterization

Output Primitives Lecture: 4. Lecture 4

Unit 2 Output Primitives and their Attributes

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

A Mathematical Overview of Bresenham Algorithms in the Determination of Active Pixel Positions

Clipping and Scan Conversion

(Refer Slide Time: 9:36)

Rasteriza2on and Clipping

MET71 COMPUTER AIDED DESIGN

Efficient Plotting Algorithm

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

Computer Graphics and GPGPU Programming

Realtime 3D Computer Graphics Virtual Reality

CSC Computer Graphics

Solution Notes. COMP 151: Terms Test

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

Rasterization. CS 4620 Lecture Kavita Bala w/ prior instructor Steve Marschner. Cornell CS4620 Fall 2015 Lecture 16

Computer Graphics Lecture Notes

OXFORD ENGINEERING COLLEGE (NAAC Accredited with B Grade) DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING LIST OF QUESTIONS

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

Lecture 6 of 41. Scan Conversion 1 of 2: Midpoint Algorithm for Lines and Ellipses

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

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

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

From 3D World to 2D Screen. Hendrik Speleers

Line Drawing Algorithms

Rasterization. CS4620 Lecture 13

SE Mock Online Test 1-CG

Transcription:

! Computer Graphics 2014! 2. 2D Graphics Algorithms Hongxin Zhang State Key Lab of CAD&CG, Zhejiang University 2014-09-26!

Screen

Nikon D40 Sensors 3

Rasterization - The task of displaying a world modeled using primitives like lines, polygons, filled / patterned areas, etc. can be carried out in two steps - determine the pixels through which the primitive is visible, a process called Rasterization or scan conversion - determine the color value to be assigned to each such pixel.

Rasterization

Raster Graphics Packages - The efficiency of these steps forms the main criteria to determine the performance of a display - The raster graphics package is typically a collection of efficient algorithms for scan converting (rasterization) of the display primitives - High performance graphics workstations have most of these algorithms implemented in hardware

Why Study these Algorithms? - Some of these algorithms are very good examples of clever algorithmic optimization done to dramatically improve performance using minimal hardware facilities! - Mobile graphics - Inspiration

Scan Converting a Line Segment - The line is a powerful element used since the days of Euclid to model the edges in the world. Given a line segment defined by its endpoints determine the pixels and color which best model the line segment.

Scan converting lines start from (x 1, y 1 ) end at (x 2, y 2 )

Scan converting lines start from (x 1, y 1 ) end at (x 2, y 2 ) (x 1, y 1 )

Scan converting lines start from (x 1, y 1 ) end at (x 2, y 2 ) (x 2, y 2 ) (x 1, y 1 )

Scan converting lines start from (x 1, y 1 ) end at (x 2, y 2 ) (x 2, y 2 ) (x 1, y 1 )

Scan converting lines start from (x 1, y 1 ) end at (x 2, y 2 ) (x 2, y 2 ) (x 1, y 1 )

Scan converting lines - Requirements - chosen pixels should lie as close to the ideal line as possible - the sequence of pixels should be as straight as possible - all lines should appear to be of constant brightness independent of their length and orientation - should start and end accurately - should be drawn as rapidly as possible - should be possible to draw lines with different width and line styles

Question 1: How? (x 1, y 1 ), (x 2, y 2 )

Question 1: How? (x 1, y 1 ), (x 2, y 2 ) y=mx+b x 1 +1 y=?, rounding x 1 +2 y=?, rounding x 1 +i y=?, rounding

Question 1: How? (x 1, y 1 ), (x 2, y 2 ) y=mx+b x 1 +1 y=?, rounding x 1 +2 y=?, rounding x 1 +i y=?, rounding Question 2: How to speed up?

Equation of a Line Equation of a line is y - m x + c = 0 For a line segment joining points P(x 1, y 1 ) and Q(x 2, y 2 ) Slope m means that for every unit increment in x the increment in y is m units y m l x

Digital Differential Analyzer (DDA) - We consider the line in the first octant. Other cases can be easily derived. - Uses differential equation of the line!! - Incrementing X-coordinate by 1! y i = mx i +c - Illuminate the pixel x i = x i_prev +1 y i = y i_prev +m

Digital Differential Analyzer (DDA) - We consider the line in the first octant. Other cases can be easily derived. - Uses differential equation of the line!! - Incrementing X-coordinate by 1! y i = mx i +c - Illuminate the pixel x i = x i_prev +1 y i = y i_prev +m Discussion1: What technique makes it fast?

Digital Differential Analyzer (DDA) - We consider the line in the first octant. Other cases can be easily derived. - Uses differential equation of the line!! - Incrementing X-coordinate by 1! y i = mx i +c - Illuminate the pixel x i = x i_prev +1 y i = y i_prev +m Discussion1: What technique makes it fast? Discussion2: Is there any problem in the algorithm? How to avoid it?

If x< y

If x< y

If x< y

If x< y

If x< y

If x< y

If x< y

If x< y

If x< y y += 1; x += 1/m;

If x< y y += 1; x += 1/m;

If x< y y += 1; x += 1/m;

If x< y y += 1; x += 1/m;

If x< y y += 1; x += 1/m;

If x< y y += 1; x += 1/m;

If x< y y += 1; x += 1/m;

If x< y y += 1; x += 1/m;

If x< y y += 1; x += 1/m; Divide and conquer!

Digital Differential Analyzer - Digital Differential Analyzer algorithm (a.k.a. DDA) - Incremental algorithm: at each step it makes incremental calculations based on the calculations done during the preceding step - The algorithm uses floating point operations.! - An algorithm to avoid this problem is first proposed by J. Bresenham of IBM. - The algorithm is well known as Bresenham s Line Drawing Algorithm. 13

Bresenham Line Drawing y i = mx i +c 14

Bresenham Line Drawing y i = mx i +c 14

Bresenham Line Drawing y i +1 y actual d 2 y i d 1 y i = mx i +c x i x i +1 14

Bresenham Line Drawing y i +1 y actual d 2 y i d 1 y i = mx i +c x i x i +1 14

d 1 >d 2? y i+1 =y i or y i+1 =y i +1 y = m(x i + 1) + b d 1 = y y i (2.1) (2.2) d 2 = y i +1 y (2.3) If d 1 d 2 >0,then y i+1 =y i +1,else y i+1 =y i substitute (2.1) (2.2) (2.3) into d 1 d 2, d 1 d 2 = 2y - 2y i -1= 2dy/dx*x i + 2dy/dx + 2b-2y i -1 on each side of the equation, * dx, denote (d 1 d 2 ) dx as P i, we have P i = 2x i dy 2y i dx + 2dy + (2b 1)dx (2.4) Because in first octant dx>0,we have sign(d 1 d 2 )=sign (P i )! If P i >0,then y i+1 =y i +1,else y i+1 =y i P i+1 = 2x i+1 dy 2y i+1 dx+2dy+(2b 1)dx, note that x i+1 =x i +1 P i+1 = P i +2dy 2(y i+1 y i ) dx (2.5)

Bresenham algorithm in first octant 1.Initialization P 0 = 2 dy dx 2.draw (x 1, y 1 ),dx=x 2 x 1,dy=y 2 y 1, Calculate P 1 =2dy dx,i=1; 3.x i+1 = x i + 1 if P i >0,then y i+1 =y i +1,else y i+1 =y i ; 4.draw (x i+1, y i+1 ); 5.calculate P i+1 : if P i >0 then P i+1 =P i +2dy 2dx, else P i+1 =P i +2dy; 6.i=i+1;if i<dx+1 then goto 3;else end

Bresenham algorithm in first octant 1.Initialization P 0 = 2 dy dx 2.draw (x 1, y 1 ),dx=x 2 x 1,dy=y 2 y 1, Calculate P 1 =2dy dx,i=1; 3.x i+1 = x i + 1 if P i >0,then y i+1 =y i +1,else y i+1 =y i ; 4.draw (x i+1, y i+1 ); 5.calculate P i+1 : if P i >0 then P i+1 =P i +2dy 2dx, else P i+1 =P i +2dy; 6.i=i+1;if i<dx+1 then goto 3;else end Question 3: Is it faster than DDA?

Bresenham algorithm in first octant 1.Initialization P 0 = 2 dy dx 2.draw (x 1, y 1 ),dx=x 2 x 1,dy=y 2 y 1, Calculate P 1 =2dy dx,i=1; 3.x i+1 = x i + 1 if P i >0,then y i+1 =y i +1,else y i+1 =y i ; 4.draw (x i+1, y i+1 ); 5.calculate P i+1 : if P i >0 then P i+1 =P i +2dy 2dx, else P i+1 =P i +2dy; 6.i=i+1;if i<dx+1 then goto 3;else end Question 3: Is it faster than DDA? Question 4: What technique?

Bresenham algorithm in first octant 1.Initialization P 0 = 2 dy dx 2.draw (x 1, y 1 ),dx=x 2 x 1,dy=y 2 y 1, Calculate P 1 =2dy dx,i=1; 3.x i+1 = x i + 1 if P i >0,then y i+1 =y i +1,else y i+1 =y i ; 4.draw (x i+1, y i+1 ); 5.calculate P i+1 : if P i >0 then P i+1 =P i +2dy 2dx, else P i+1 =P i +2dy; 6.i=i+1;if i<dx+1 then goto 3;else end Question 3: Is it faster than DDA? Question 4: What technique?

3D DDA and 3D Bresenham

3D DDA and 3D Bresenham algorithm

Scan converting circles A circle with center (x c, y c ) and radius r: (x x c ) 2 + (y y c ) 2 = r 2 orthogonal coordinate