1 / 16

3D Programming Fundamentals: Line and Fill Algorithms in DIG1705

Learn about scan conversion, Bresenham's algorithm, flood fill, and OpenGL concepts. Implement recursive flood fill in C#.

chongd
Download Presentation

3D Programming Fundamentals: Line and Fill Algorithms in DIG1705

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. Welcome toDIG17053D ProgrammingFollow on : dig1705

  2. Scan Conversion

  3. Line Drawing • Algorithm: • Draw a straight line between two points • Set all pixels along line to foreground color • Set all other pixels to background color

  4. Line Drawing • Algorithm (Bresenham):

  5. Fill Algorithms • Goal: • Fill all pixels inside contourwith foreground color Seed point

  6. Fill Algorithms • Flood Fill: • Start from seed point • Recursively fill neighboring pixels if not contour pixels

  7. Fill Algorithms • Flood Fill: • Start from seed point • Recursively fill 4 neighboring pixels if not contour pixels Flood_fill (x, y, bg, fg) if (get_pixel(x, y) == bg) put_pixel(x, y, fg); Flood_fill (x+1, y, bg, fg); Flood_fill (x-1, y, bg, fg); Flood_fill (x, y+1, bg, fg); Flood_fill (x, y-1, bg, fg);

  8. Fill Algorithms • Goal: • Fill all pixels inside contourwith foreground color

  9. Fill Algorithms • Goal: • Fill all pixels inside contourwith foreground color Problem: • Narrow areas Solution: • Include diagonally connected pixels(8 neighbors)

  10. Fill Algorithms • Goal: • Fill all pixels inside contourwith foreground color

  11. Fill Algorithms • Goal: • Fill all pixels inside contourwith foreground color Flood_fill (x, y, bg, fg) if (get_pixel(x, y) == bg) put_pixel(x, y, fg); Flood_fill (x+1, y, bg, fg); Flood_fill (x-1, y, bg, fg); Flood_fill (x, y+1, bg, fg); Flood_fill (x, y-1, bg, fg); Flood_fill (x+1, y+1, bg, fg); Flood_fill (x+1, y-1, bg, fg); Flood_fill (x-1, y+1, bg, fg); Flood_fill (x-1, y-1, bg, fg);

  12. Task 5.1 • Goal: Implement recursive flood fill • Use Program.cs from Homework 2 • Add functionColor get_pixel (int x, int y, intsize_x, intsize_y, byte[] array); • Add functionvoid flood_fill (int x, int y, intsize_x, intsize_y, Color bg, Color fg, byte[] array); • In Main function: • Comment out draw_line statements • Use same color for both gradient colors • Call: flood_fill (size_x/2, size_y/2, size_x, size_y,your_frame_color, your_fill_color, pixels);

  13. Recap: OpenGL • Concepts • GL.Clear (ClearBufferMask mask)clears frame buffer and selects type, e.g., ColorBufferBit • GL.MatrixMode(MatrixMode.Modelview);GL.LoadMatrix(ref modelview);selects and loads transformation matrix • GL.Begin(PrimitiveType.Triangles); GL.Color3(1.0f, 1.0f, 0.0f); GL.Vertex3(-1.0f, -1.0f, 4.0f); GL.Color3(1.0f, 0.0f, 0.0f); GL.Vertex3(1.0f, -1.0f, 4.0f); GL.Color3(0.2f, 0.9f, 1.0f); GL.Vertex3(0.0f, 1.0f, 4.0f);GL.End();creates a triangle • SwapBuffers();

  14. Task 4 • Goal: Create OpenGL program • In Visual Studio, open "New Project" dialog and select "Open Visual Studio Installer". • Under "Individual Components",find "NuGet Package Manager”. • Create new project called "OpenGL" • Open in Tools->NuGet Package Manager:NuGet Package Manager Console • At the prompt, type:Install-Package OpenTK -Version 2.0.0 • Overwrite “Program.cs” with “opengl.txt” from http://tinyurl.com/dig1705

  15. Task 5.2 • Goal: Add rotation to OpenGL program • Add the following declarations to the beginning of the Game class:float angle = 0.0f; static Vector3 axis; • Add the following line to Main: axis = new Vector3(0.0f, 1.0f, 0.0f); // y axis • Add the following lines to OnRenderFramebelowGL.LoadMatrix(ref modelview);:GL.Translate(0.0f, 0.0f, 4.0f); GL.Rotate(angle, axis); GL.Translate(0.0f, 0.0f, -4.0f); angle += 1.0f; if (angle >= 360.0f) angle = 0.0f;

  16. Questions? Joerg Meyer, Ph.D. Miami Dade College Wolfson Campus jmeyer2@mdc.edu http://joergmeyer.ddns.net/COURSES/DIG1705

More Related