Presentation is loading. Please wait.

Presentation is loading. Please wait.

College of Computer and Information Science, Northeastern UniversitySeptember 12, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture.

Similar presentations


Presentation on theme: "College of Computer and Information Science, Northeastern UniversitySeptember 12, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture."— Presentation transcript:

1 College of Computer and Information Science, Northeastern UniversitySeptember 12, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture 5 – January 14, 2009

2 College of Computer and Information Science, Northeastern UniversitySeptember 12, 20152 Today’s Topics Raster Algorithms  Lines - Section 3.5 in Shirley et al.  Antialiasing Line Attributes

3 College of Computer and Information Science, Northeastern UniversitySeptember 12, 20153 (3,1) (0,3) (0,0) Pixel Coordinates y x x = -0.5 y = -0.5 y = 3.5 x = 4.5

4 College of Computer and Information Science, Northeastern UniversitySeptember 12, 20154 (3,2) (0,0) (0,3) Pixel Coordinates y x x = -0.5 y = 3.5 y = -.5 x = 4.5

5 College of Computer and Information Science, Northeastern UniversitySeptember 12, 20155 What Makes a Good Line? Not too jaggy Uniform thickness along a line Uniform thickness of lines at different angles Symmetry, Line(P,Q) = Line(Q,P) A good line algorithm should be fast.

6 College of Computer and Information Science, Northeastern UniversitySeptember 12, 20156 Line Drawing

7 College of Computer and Information Science, Northeastern UniversitySeptember 12, 20157 Line Drawing

8 College of Computer and Information Science, Northeastern UniversitySeptember 12, 20158 Which Pixels Should We Color? Given P 0 = (x 0, y 0 ), P 1 = (x 1, y 1 ) We could use the equation of the line:  y = mx + b  m = (y 1 – y 0 )/(x 1 – x 0 )  b = y 1 - mx 1 And a loop for x = x 0 to x 1 y = mx + b draw (x, y) This calls for real multiplication for each pixel This only works if x 0  x 1 and |m|  1.

9 College of Computer and Information Science, Northeastern UniversitySeptember 12, 20159 Midpoint Algorithm Pitteway 1967 Van Aiken abd Nowak 1985 Draws the same pixels as Bresenham Algorithm 1965. Uses integer arithmetic and incremental computation. Uses a decision function to decide on the next point Draws the thinnest possible line from (x 0, y 0 ) to (x 1, y 1 ) that has no gaps. A diagonal connection between pixels is not a gap.

10 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201510 Implicit Equation of a Line (x 0, y 0 ) (x 1, y 1 )f(x,y) = (y 0 – y 1 )x +(x 1 - x 0 )y + x 0 y 1 - x 1 y 0 We will assume x 0  x 1 and that m = (y 1 – y 0 )/(x 1 - x 0 ) is in [0, 1]. f(x,y) = 0 f(x,y) > 0 f(x,y) < 0

11 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201511 Basic Form of the Algotithm y = y 0 for x = x 0 to x 1 do draw (x, y) if (some condition) then y = y + 1 Since m  [0, 1], as we move from x to x+1, the y value stays the same or goes up by 1. We want to compute this condition efficiently.

12 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201512 Above or Below the Midpoint?

13 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201513 Finding the Next Pixel Assume we just drew (x, y). For the next pixel, we must decide between (x+1, y) and (x+1, y+1). The midpoint between the choices is (x+1, y+0.5). If the line passes below (x+1, y+0.5), we draw the bottom pixel. Otherwise, we draw the upper pixel.

14 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201514 The Decision Function if f(x+1, y+0.5) < 0 // midpoint below line y = y + 1 f(x,y) = (y 0 – y 1 )x +(x 1 - x 0 )y + x 0 y 1 - x 1 y 0 How do we compute f(x+1, y+0.5) incrementally? using only integer arithmetic?

15 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201515 Incremental Computation f(x,y) = (y 0 – y 1 )x +(x 1 - x 0 )y + x 0 y 1 - x 1 y 0 f(x + 1, y) = f(x, y) + (y 0 – y 1 ) f(x + 1, y + 1) = f(x, y) + (y 0 – y 1 ) + (x 1 - x 0 ) y = y 0 d = f(x 0 + 1, y + 0.5) for x = x 0 to x 1 do draw (x, y) if d < 0 then y = y + 1 d = d + (y 0 – y 1 ) + (x 1 - x 0 ) else d = d + + (y 0 – y 1 )

16 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201516 Integer Decision Function f(x,y) = (y 0 – y 1 )x +(x 1 - x 0 )y + x 0 y 1 - x 1 y 0 f(x 0 + 1, y + 0.5) = (y 0 – y 1 )(x 0 + 1) +(x 1 - x 0 )(y + 0.5) + x 0 y 1 - x 1 y 0 2f(x 0 + 1, y + 0.5) = 2(y 0 – y 1 )(x 0 + 1) +(x 1 - x 0 )(2y + 1) + 2x 0 y 1 - 2x 1 y 0 2f(x, y)= 0 if (x, y) is on the line. < 0 if (x, y) is below the line. > 0 if (x, y) is above the line.

17 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201517 Midpoint Line Algorithm y = y 0 d = 2(y 0 – y 1 )(x 0 + 1) +(x 1 - x 0 )(2y 0 + 1) + 2x 0 y 1 - 2x 1 y 0 for x = x 0 to x 1 do draw (x, y) if d < 0 then y = y + 1 d = d + 2(y 0 – y 1 ) + 2(x 1 - x 0 ) else d = d + 2(y 0 – y 1 ) These are constants and can be computed before the loop.

18 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201518 Some Lines

19 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201519 Some Lines Magnified

20 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201520 Antialiasing by Downsampling

21 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201521 Antialiasing by Downsampling

22 College of Computer and Information Science, Northeastern UniversitySeptember 12, 201522 Antialiasing by Downsampling


Download ppt "College of Computer and Information Science, Northeastern UniversitySeptember 12, 20151 CS U540 Computer Graphics Prof. Harriet Fell Spring 2009 Lecture."

Similar presentations


Ads by Google