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

Similar documents
From Ver(ces to Fragments: Rasteriza(on

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

Rendering. A simple X program to illustrate rendering

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

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

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

Scan Conversion. Drawing Lines Drawing Circles

Rasterization: Geometric Primitives

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

Scan Converting Lines

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

Line Drawing. Foundations of Computer Graphics Torsten Möller

Chapter 8: Implementation- Clipping and Rasterization

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

COMP30019 Graphics and Interaction Scan Converting Polygons and Lines

Line Drawing Week 6, Lecture 9

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

Realtime 3D Computer Graphics Virtual Reality

Computer Graphics. - Rasterization - Philipp Slusallek

Rendering. A simple X program to illustrate rendering

COMP371 COMPUTER GRAPHICS

Topics. From vertices to fragments

1 Introduction to Graphics

CS Rasterization. Junqiao Zhao 赵君峤

CPSC / Scan Conversion

Topic #1: Rasterization (Scan Conversion)

Chapter - 2: Geometry and Line Generations

EF432. Introduction to spagetti and meatballs

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

The Traditional Graphics Pipeline

Graphics (Output) Primitives. Chapters 3 & 4

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

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

Display Technologies: CRTs Raster Displays

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

Einführung in Visual Computing

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

RASTERIZING POLYGONS IN IMAGE SPACE

An Improved Algorithm for Scan-converting a Line

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

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

EF432. Introduction to spagetti and meatballs

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

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

Computer Graphics D Graphics Algorithms

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

Scan Conversion. Lines and Circles

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

FROM VERTICES TO FRAGMENTS. Lecture 5 Comp3080 Computer Graphics HKBU

The Traditional Graphics Pipeline

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

Rasteriza2on and Clipping

Efficient Plotting Algorithm

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

Painter s HSR Algorithm

Computer Graphics: Graphics Output Primitives Line Drawing Algorithms

2D rendering takes a photo of the 2D scene with a virtual camera that selects an axis aligned rectangle from the scene. The photograph is placed into

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

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

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

Digital Differential Analyzer Bresenhams Line Drawing Algorithm

CS 130. Scan Conversion. Raster Graphics

The Traditional Graphics Pipeline

CSCI 4620/8626. Coordinate Reference Frames

CS 543: Computer Graphics. Rasterization

Pipeline implementation II

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

Output Primitives Lecture: 4. Lecture 4

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

CS452/552; EE465/505. Clipping & Scan Conversion

Manipal Institute of Technology Manipal University Manipal

Rendering. Basic Math Review. Rasterizing Lines and Polygons Hidden Surface Remove Multi-pass Rendering with Accumulation Buffers.

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

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

(Refer Slide Time: 00:03:51)

Computer Graphics D Graphics Algorithms

The graphics pipeline. Pipeline and Rasterization. Primitives. Pipeline

UNIT -8 IMPLEMENTATION

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

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

CSC Computer Graphics

Rasterization. CS4620 Lecture 13

Incremental Form. Idea. More efficient if we look at d k, the value of the decision variable at x = k

Pipeline and Rasterization. COMP770 Fall 2011

Scan Converting Circles

Unit 2 Output Primitives and their Attributes

Rendering approaches. 1.image-oriented. 2.object-oriented. foreach pixel... 3D rendering pipeline. foreach object...

Overview of Computer Graphics

Computer Graphics. Chapter 4 Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

Surface shading: lights and rasterization. Computer Graphics CSE 167 Lecture 6

Computer Graphics. Attributes of Graphics Primitives. Somsak Walairacht, Computer Engineering, KMITL 1

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

From Vertices To Fragments-1

From 3D World to 2D Screen. Hendrik Speleers

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

A New Line Drawing Algorithm Based on Sample Rate Conversion

Raster Scan Displays. Framebuffer (Black and White)

CS6504 & Computer Graphics Unit I Page 1

A is any set of ordered pairs of real numbers. This is a set of ordered pairs of real numbers, so it is a.

Transcription:

Pixels Pixel: Intensity or color sample. Raster Image: Rectangular grid of pixels. Rasterization: Conversion of a primitive s geometric representation into A set of pixels. An intensity or color for each pixel (shading, antialiasing). For now, we will assume that the background is white and we need only change the color of selected pixels to black. The University of Texas at Austin 1

Pixel Grids Pixel Centers: Address pixels by integer coordinates (i, j) Pixel Center Grid: Set of lines passing through pixel centers. Pixel Domains: Rectangular semi-open areas surrounding each pixel center: P i,j = (i 1/2, i + 1/2) (j 1/2, j + 1/2) Pixel Domain Grid: Set of lines formed by domain boundaries. 3 2 1 0 3 2 1 0 0 1 2 3 0 1 2 3 Pixel center grid Pixel domain grid The University of Texas at Austin 2

Specifications and Representations Each rendering primitive (point, line segment, polygon, etc.) needs both A geometric specification, usually calligraphic. A pixel (rasterized) representation. Standard device-level geometric specifications include: Point: A = (x A, y A ) R 2. Line Segment: l(ab) specified with two points, A and B. The line segment l(ab) is the set of all collinear points between point A and point B. Polygon: Polygon P(A 1 A 2... A n ) specified with an ordered list of points A 1 A 2... A n. A polygon is a region of the plane with a piecewise linear boundary; we connect A n to A 1. This list of points specification is flawed... a more precise definition will be given later. The University of Texas at Austin 3

Line Segments Let l(ab) = {P R 2 P = (1 t)a + tb, t [0, 1]} Problem: Given a line segment l(ab) specified by two points A and B, Decide: Which pixels to illuminate to represent l(ab). Desired properties: Rasterization of line segment should 1. Appear as straight as possible; 2. Include pixels whose domains contain A and B; 3. Have relatively constant intensity (i.e., all parts should be the same brightness); 4. Have an intensity per unit length that is independent of slope; 5. Be symmetric; 6. Be generated efficiently. The University of Texas at Austin 4

Line Segment Representations 1. Given AB, choose a set of pixels L 1 (AB) given by L 1 (AB) = {(i, j) Z 2 l(ab) P i,j } 3 2 1 0 0 1 2 3 4 5 6 7 8 Unfortunately, this results in a very blotchy, uneven looking line. The University of Texas at Austin 5

2. Given AB, choose a set of pixels L 2 (AB) given by L 2 (AB) = x B x A y B y A {(i, j) Z 2 (i, j) = (i, [y]), (i, y) l(ab), y R} ([x A ], [y A ]) ([x B ], [y B ]). x B x A < y B y A {(i, j) Z 2 (i, j) = ([x], j), (x, j), l(ab), x R} ([x A ], [y A ]) ([x B ], [y B ]). Where [z] = z + 1/2, and w is the greatest integer less than or equal to w. 3 2 1 0 0 1 2 3 4 5 6 7 8 The University of Texas at Austin 6

Line Equation Algorithm Based on the line equation y = mx + b, we can derive: LineEquation (int xa, ya, xb, yb) float m, b; int xi, dx; m = (yb - ya)/(xb - xa); b = ya - m xa; if ( xb - xa > 0 ) then dx=1; else dx = -1; for xi = xa to xb step dx do y = m xi + b; WritePixel( xi, [y] ); endfor Problems: One pixel per column so lines of slope > 1 have gaps The University of Texas at Austin 7

Vertical lines cause divide by zero To fix these problems, we need to use x = m 1 (y b) when m > 1. The University of Texas at Austin 8

Discrete Differential Analyzer Observation: Roles of x and y are symmetric... Change roles of x and y if y B y A > x B x A Observation: Multiplication of m inside loop... The value of m is constant for all iterations. Can reduce computations inside loop: y i+1 and be computed incrementally from y i y i+1 = m(x i + 1) + b = y i + m The University of Texas at Austin 9

DDA (int xa, ya, xb, yb) int length, dx, dy, i; float x,y,xinc,yinc; dx = xb - xa; dy = yb - ya; length = max ( dx > dy ); xinc = dx/length; # either xinc or yinc is -1 or 1 yinc = dy/length; x = xa; y = ya; for i=0 to length do WritePixel( [x], [y] ); x += xinc; y += yinc; endfor The University of Texas at Austin 10

Bresenham s Algorithm Completely integer; Will assume (at first) that x A, y A, x B, y B are also integer. Only addition, subtraction, and shift in inner loop. Originally for a pen plotter. Optimal in that it picks pixels closest to line, i.e., L 2 (AB). Assumes 0 (y B y A ) (x B x A ) 1 (i.e., slopes between 0 and 1). Use reflections and endpoint reversal to get other slopes: 8 cases. The University of Texas at Austin 11

D NE[i] M[i+1] B P[i-1] M[i] E[i] A C Suppose we know at step i 1 that pixel (x i, y i ) = P i 1 was chosen. Thus, the line passed between points A and B. Slope between 0 and 1 line must pass between points C and D at next step E i = (x i + 1, y i ) and N E i = (x i + 1, y i + 1) are only choices for next pixel. If M i above line, choose E i ; The University of Texas at Austin 12

If M i below line, choose N E i. The University of Texas at Austin 13

Implicit representations for line: F(x, y) = (2 y) }{{} Q y = y x x + b x + ( 2 x) }{{} R y + 2 xb }{{} S = 0 where x y b = x B x A = y B y A = y A y x x A S = 2 xy A 2 yx A Note that 1. F(x, y) < 0 (x, y) above line. 2. F(x, y) > 0 (x, y) below line. 3. Q, R, S are all integers. The mystery factor of 2 will be explained later. The University of Texas at Austin 14

Look at F(M i ). Remember, F is 0 if the point is on the line: F(M i ) < 0 M i above line choose P i = E i. F(M i ) > 0 M i below line choose P i = N E i. F(M i ) = 0 arbitrary choice, consider choice of pixel domains... We ll use d i = F(M i ) as an decision variable. Can compute d i incrementally with integer arithmetic. The University of Texas at Austin 15

At each step of algorithm, we know P i 1 and d i... Want to choose P i and compute d i+1 Note that If E i is chosen then If N E i is chosen then d i = F(M i ) = F(x i 1 + 1, y i 1 + 1/2) = Q (x i 1 + 1) + R (y i 1 + 1/2) + S d i+1 = F(x i 1 + 2, y i 1 + 1/2) = Q (x i 1 + 2) + R (y i 1 + 1/2) + S = d i + Q d i+1 = F(x i 1 + 2, y i 1 + 1/2 + 1) = Q (x i 1 + 2) + R (y i 1 + 1/2 + 1) + S = d i + Q + R The University of Texas at Austin 16

Initially, we have d 1 = F(x A + 1, y A + 1/2) = Q xa + R ya + S + Q + R/2 = F(x A, y A ) + Q + R/2 = Q + R/2 Note that F(x A, y A ) = 0 since (x A, y A ) l(ab). Why the mysterious factor of 2? It makes everything integer. The University of Texas at Austin 17

Bresenham (int xa, ya, xb, yb) int d, dx, dy, xi, yi int ince, incne dx = xb - xa dy = yb - ya ince = dy<<1 / Q / incne = ince - dx<<1; / Q + R / d = ince - dx / Q + R/2 / xi = xa; yi = ya WritePixel( xi, yi ) while ( xi < xb ) xi++ if ( d < 0 ) then / choose E / d += ince else / choose NE / d += incne yi++ endif The University of Texas at Austin 18

WritePixel( xi, yi ) endwhile The University of Texas at Austin 19

Some asymmetries (choice when ==). Did we meet our goals? 1. Straight as possible: yes, but depends on metric. 2. Correct termination. 3. Even distribution of intensity: yes, more or less, but: 4. Intensity varies as function of slope. Can t do better without gray scale. Worst case: diagonal compared to horizontal (same number of pixels, but 2 longer line). 5. Careful coding required to achieve some form of symmetry. 6. Fast! (if integer math fast...) Interaction with clipping? Subpixel positioning of endpoints? Variations that look ahead more than one pixel at once... Variations that compute from both end of the line at once... Similar algorithms for circles, ellipses,... (8 fold symmetry for circles) The University of Texas at Austin 20

Reading Assignment and News Chapter 2 pages 37-74, of Recommended Text. (Recommended Text: Interactive Computer Graphics, by Edward Angel, 3rd edition, Addison- Wesley) On Wednesday September 3 (tomorrow) Peter Djeu shall conduct a recitation class from 2:30pm - 4:00pm on OpenGL programming and describe our programming environment for all the Project Assignments. Please also track the News section of the Course Web Pages for the most recent Announcements related to this course. (http://www.cs.utexas.edu/users/bajaj/graphics23/cs354/) The University of Texas at Austin 21