1 / 123

CSCE 441 Lecture 2: Scan Conversion of Lines

CSCE 441 Lecture 2: Scan Conversion of Lines. Jinxiang Chai. OpenGL Geometric Primitives. All geometric primitives are specified by vertices. GL_LINES. GL_POLYGON. GL_LINE_STRIP. GL_LINE_LOOP. GL_POINTS. GL_TRIANGLES. GL_QUADS. GL_TRIANGLE_FAN. GL_TRIANGLE_STRIP. GL_QUAD_STRIP.

hosmer
Download Presentation

CSCE 441 Lecture 2: Scan Conversion of Lines

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CSCE 441 Lecture 2:Scan Conversion of Lines Jinxiang Chai

  2. OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_LINES GL_POLYGON GL_LINE_STRIP GL_LINE_LOOP GL_POINTS GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN GL_TRIANGLE_STRIP GL_QUAD_STRIP 2/110

  3. OpenGL Geometric Primitives All geometric primitives are specified by vertices GL_LINES GL_POLYGON GL_LINE_STRIP GL_LINE_LOOP GL_POINTS GL_TRIANGLES GL_QUADS GL_TRIANGLE_FAN GL_TRIANGLE_STRIP GL_QUAD_STRIP 3/110

  4. Line-drawing using “Paint”

  5. How can we represent and display images?

  6. Displays – Liquid Crystal Displays

  7. Displays – Plasma

  8. Displays – Smart Phone 8/110

  9. Displays – Oculus 9/110

  10. Image Representation An image is a 2D rectilinear array of Pixels - A width*height array where each entry of the array stores a single pixel - Each pixel stores color information (255,255,255)

  11. Displays – Pixels • Pixel: the smallest element of picture - Integer position (i,j) - Color information (r,g,b) y x (0,0)

  12. Image Representation A pixel stores color information Luminance pixels - gray-scale images (intensity images) - 0-1.0 or 0-255 - 8 bits per pixel Red, green, blue pixels (RGB) - Color images - Each channel: 0-1.0 or 0-255 - 24 bits per pixel

  13. Digital Scan Conversion • Convert graphics output primitives into a set of pixel values for storage in the frame buffer

  14. Outline • How to draw a line? - Digital Differential Analyzer (DDA) - Midpoint algorithm • Required readings - HB 6.1 to 6.8

  15. Problem • Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line

  16. Problem • Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line

  17. Problem • Given two points (P, Q) on the screen (with integer coordinates) determine which pixels should be drawn to display a unit width line

  18. Line-drawing using “Paint”

  19. Special Lines - Horizontal

  20. Special Lines - Horizontal Increment x by 1, keep y constant

  21. Special Lines - Vertical

  22. Special Lines - Vertical Keep x constant, increment y by 1

  23. Special Lines - Diagonal

  24. Special Lines - Diagonal Increment x by 1, increment y by 1

  25. How about Arbitrary Lines? • How to draw an arbitrary line?

  26. Arbitrary Lines Slope-intercept equation for a line: m: slope b: y-intercept

  27. Arbitrary Lines Slope-intercept equation for a line: How can we compute the equation from (xL,yL), (xH,yH)? m: slope b: y-intercept

  28. Arbitrary Lines Slope-intercept equation for a line: How can we compute the equation from (xL,yL), (xH,yH)? m: slope b: y-intercept

  29. Arbitrary Lines • Assume

  30. Arbitrary Lines Assume Other lines by swapping x, y or negating - e.g., reverse the role of x and y if m>1 30/110

  31. Arbitrary Lines Assume Other lines by swapping x, y or negating - e.g., reverse the role of x and y if m>1 - e.g., negate y if 31/110

  32. Arbitrary Lines Assume Other lines by swapping x, y or negating A simple idea: Take steps in x and determine where to fill y 32/110

  33. Digital Differential Analyzer • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = mxi+1 + b

  34. Digital Differential Analyzer Simple algorithm: - sample unit intervals in one coordinate - find the nearest pixel for each sampled point.

  35. Digital Differential Analyzer (DDA) • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) //sample unit intervals in x coordinate DrawPixel ( xi, Round ( yi) ) //find the nearest pixel for each sampled point. xi+1 = xi+ 1 yi+1 = m ( xi + 1 ) + b

  36. DDA • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = mxi + m + b

  37. DDA • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = mxi + b + m

  38. DDA • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = mxi + b + m

  39. DDA • Start from (xL, yL) and draw to (xH, yH) where xL< xH ( x0, y0 ) = ( xL, yL ) For ( i = 0; i <= xH-xL; i++ ) DrawPixel ( xi, Round ( yi) ) xi+1 = xi+ 1 yi+1 = yi + m

  40. DDA - Example

  41. DDA - Example

  42. DDA - Example

  43. DDA - Example

  44. DDA - Example

  45. DDA - Example

  46. DDA - Example

  47. DDA - Example

  48. DDA - Example

  49. DDA - Example

  50. DDA - Example

More Related