Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014.

Similar presentations


Presentation on theme: "CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014."— Presentation transcript:

1 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014

2 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Line Drawing  First problem statement: Draw a line on a raster screen between two points  Why is this a difficult problem?  What is “drawing” on a raster display?  What is a “line” in raster world?  Efficiency and appearance are both important Problem Statement  Given two points P and Q in XY plane, both with integer coordinates, determine which pixels on a raster screen should be on in order to best approximate a unit-width line segment starting at P and ending at Q 2 of 44 Scan Converting Lines Scan Conversion - 10/14/2014

3 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Final step of rasterization (process of taking geometric shapes and converting them into an array of pixels stored in the framebuffer to be displayed) – converting from “random scan”/vector specification to a raster scan where we specify which pixels are on based on a stored array of pixels  Takes place after clipping occurs  All graphics packages do this at end of the rendering pipeline  Takes triangles (or higher-order primitives) and maps them to pixels on screen  For 3D rendering also takes into account other processes, like lighting and shading, but we’ll focus first on algorithms for line scan conversion 3 of 44 What is Scan Conversion? Scan Conversion - 10/14/2014

4 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Special cases:  Horizontal Line:  Draw pixel P and increment x coordinate value by 1 to get next pixel.  Vertical Line:  Draw pixel P and increment y coordinate value by 1 to get next pixel.  Diagonal Line:  Draw pixel P and increment both x and y coordinate by 1 to get next pixel.  What should we do in the general case?  For slope <= 1, increment x coordinate by 1 and choose pixel on or closest to line. Slopes in other octants by reflection (e.g., in second octant, increment Y)  But how do we measure “closest”? 4 of 44 Scan-converting a Line: Finding the next pixel Scan Conversion - 10/14/2014

5 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Why can we use vertical distance as a measure of which point (pixel center) is closer?  … because vertical distance is proportional to actual distance  Similar triangles show that true distances to line (in blue) are directly proportional to vertical distances to line (in black) for each point  Therefore, point with smaller vertical distance to line is closest to line 5 of 44 Vertical Distance Scan Conversion - 10/14/2014

6 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 6 of 44 Strategy 1 – Incremental Algorithm (1/3) Scan Conversion - 10/14/2014

7 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 7 of 44 Strategy 1 – Incremental Algorithm (2/3) Scan Conversion - 10/14/2014

8 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 8 of 44 Strategy 1 – Incremental Algorithm (3/3) - Issues void Line(int x0, int y0, int x1, int y1) { int x, y; float dy = y1 – y0; float dx = x1 – x0; float m = dy / dx; y = y0; for (x = x0; x < x1; ++x) { WritePixel( x, Round(y) ); y = y + m; } Rounding takes time Since slope is fractional, need special case for vertical lines (dx = 0) Scan Conversion - 10/14/2014

9 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 9 of 44 Strategy 2 – Midpoint Line Algorithm (1/3) Scan Conversion - 10/14/2014

10 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 10 of 44 Strategy 2 – Midpoint Line Algorithm (2/3) Previous pixel E pixel NE pixel Midpoint M Q Scan Conversion - 10/14/2014

11 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 11 of 44 Strategy 2- Midpoint Line Algorithm (3/3) For line shown, algorithm chooses NE as next pixel. Now, need to find a way to calculate on which side of line midpoint lies E pixel NE pixel Scan Conversion - 10/14/2014

12 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 12 of 44 General Line Equation in Implicit Form Scan Conversion - 10/14/2014

13 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 13 of 44 Decision Variable Scan Conversion - 10/14/2014

14 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 14 of 44 Incrementing Decision Variable if E was chosen: Scan Conversion - 10/14/2014

15 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 15 of 44 If NE was chosen: Scan Conversion - 10/14/2014

16 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 16 of 44 Summary (1/2) Scan Conversion - 10/14/2014

17 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 17 of 44 Summary (2/2) Scan Conversion - 10/14/2014

18 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © void MidpointLine(int x0, int y0, int x1, int y1) { int dx = (x1 - x0), dy = (y1 - y0); int d = 2 * dy - dx; int incrE = 2 * dy; int incrNE = 2 * (dy - dx); int x = x0, y = y0; WritePixel(x, y); while (x < x1) { if (d <= 0) d = d + incrE; // East Case else { d = d + incrNE; ++y; } // Northeast Case ++x; WritePixel(x, y); } } 18 of 44 Example Code Scan Conversion - 10/14/2014

19 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 19 of 44 Scan Converting Circles (17, 0) (0, 17) (17, 0) (0, 17) Scan Conversion - 10/14/2014

20 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 20 of 44 Version 3 — Use Symmetry R (x 0 + a, y 0 + b) (x-x 0 ) 2 + (y-y 0 ) 2 = R 2 (x 0, y 0 ) Scan Conversion - 10/14/2014

21 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 21 of 44 Using the Symmetry (x 0, y 0 ) Scan Conversion - 10/14/2014

22 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 22 of 44 The Incremental Algorithm – a Pseudocode Sketch Scan Conversion - 10/14/2014

23 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 23 of 44 What we need for the Incremental Algorithm Scan Conversion - 10/14/2014

24 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 24 of 44 The Decision Variable Scan Conversion - 10/14/2014

25 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 25 of 44 The right decision variable? Scan Conversion - 10/14/2014

26 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 26 of 44 Alternate Phrasing (1/3) Scan Conversion - 10/14/2014

27 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 27 of 44 Alternate Phrasing (2/3) Scan Conversion - 10/14/2014

28 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 28 of 44 Alternate Phrasing (3/3) Scan Conversion - 10/14/2014

29 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 29 of 44 Incremental Computation Revisited (1/2) Scan Conversion - 10/14/2014

30 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 30 of 44 Incremental Computation (2/2) Scan Conversion - 10/14/2014

31 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 31 of 44 Second Differences (1/2) Scan Conversion - 10/14/2014

32 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 32 of 44 Second Differences (2/2) Scan Conversion - 10/14/2014

33 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © MidpointEighthCircle(R) { /* 1/8th of a circle w/ radius R */ int x = 0, y = R; int deltaE = 2 * x + 3; int deltaSE = 2 * (x - y) + 5; float decision = (x + 1) * (x + 1) + (y - 0.5) * (y - 0.5) – R*R; WritePixel(x, y); while ( y > x ) { if (decision > 0) { // Move East x++; WritePixel(x, y); decision += deltaE; deltaE += 2; deltaSE += 2; // Update deltas } else { // Move SouthEast y--; x++; WritePixel(x, y); decision += deltaSE; deltaE += 2; deltaSE += 4; // Update deltas } } } 33 of 44 Midpoint Eighth Circle Algorithm Scan Conversion - 10/14/2014

34 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Uses floats!  1 test, 3 or 4 additions per pixel  Initialization can be improved  Multiply everything by 4: No Floats!  Makes the components even, but sign of decision variable remains same Questions  Are we getting all pixels whose distance from the circle is less than ½?  Why is y > x the right criterion?  What if it were an ellipse? 34 of 44 Analysis Scan Conversion - 10/14/2014

35 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Aligned Ellipses  Non-integer primitives  General conics  Patterned primitives 35 of 44 Other Scan Conversion Problems Scan Conversion - 10/14/2014

36 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 36 of 44 Aligned Ellipses Scan Conversion - 10/14/2014

37 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 37 of 44 Direction Changing Criterion (1/2) Scan Conversion - 10/14/2014

38 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 38 of 44 Direction Changing Criterion (2/2) Scan Conversion - 10/14/2014

39 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Now in ENE octant, not ESE octant. Used the wrong direction because the ellipse rapidly changes slope within a pixel  This problem is an artifact of aliasing, remember filter? 39 of 44 Problems with aligned ellipses Scan Conversion - 10/14/2014

40 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 40 of 44  Patterned line from P to Q is not same as patterned line from Q to P.  Patterns can be cosmetic or geometric  Cosmetic: Texture applied after transformations  Geometric: Pattern subject to transformations Cosmetic patterned line Geometric patterned line Patterned Lines PQ PQ Scan Conversion - 10/14/2014

41 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 41 of 44 Geometric vs. Cosmetic + Geometric (Perspectivized/Filtered) Cosmetic (Real-World Contact Paper) Scan Conversion - 10/14/2014

42 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © 42 of 44 Non-Integer Primitives and General Conics Scan Conversion - 10/14/2014

43 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  What's the difference between these two solutions? Under which circumstances is the right one "better"? 43 of 44 Generic Polygons Balsa Video - http://www.youtube.com/watch?v=GXi32vnA-2Ahttp://www.youtube.com/watch?v=GXi32vnA-2A Scan Conversion - 10/14/2014

44 CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam ©  Rapid Prototyping is becoming cheaper and more prevalent  3D printers lay down layer after layer to produce solid objects  We have an RP lab across the street in Barus and Holley  Printing food - http://www.youtube.com/watch?v=55NvbBJzDpUhttp://www.youtube.com/watch?v=55NvbBJzDpU  Bio-printing - http://www.youtube.com/watch?v=-RgI_bcETkMhttp://www.youtube.com/watch?v=-RgI_bcETkM 44 of 44 Scan Converting Arbitrary Solids Scan Conversion - 10/14/2014


Download ppt "CS123 | INTRODUCTION TO COMPUTER GRAPHICS Andries van Dam © Scan Conversion CS123 1 of 44Scan Conversion - 10/14/2014."

Similar presentations


Ads by Google