1 / 35

Computer Graphics

Computer Graphics. Filling. Filling Polygons. So we can figure out how to draw lines and circles How do we go about drawing polygons? We use an incremental algorithm known as the scan-line algorithm. Polygon. Ordered set of vertices (points) Usually counter-clockwise

phyllish
Download Presentation

Computer Graphics

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. Computer Graphics Filling

  2. Filling Polygons • So we can figure out how to draw lines and circles • How do we go about drawing polygons? • We use an incremental algorithm known as the scan-line algorithm

  3. Polygon • Ordered set of vertices (points) • Usually counter-clockwise • Two consecutive vertices define an edge • Left side of edge is inside • Right side is outside • Last vertex implicitly connected to first • In 3D vertices are co-planar

  4. Filling Polygons • Three types of polygons • Simple convex 2. simple concave 3. non-simple (self-intersection) Convex polygons have the property that intersecting lines crossing it either one (crossing a corner), two (crossing an edge, going through the polygon and going out the other edge), or an infinite number of times (if the intersecting line lies on an edge).

  5. Some Problems 1. Which pixels should be filled in? 2. Which happened to the top pixels? To the rightmost pixels?

  6. Maxima /Minima Scan Line Fill PolygonVertices EdgePixels Scan-Line Polygon Example

  7. Scan Line Algorithms Create a list of vertex events (bucket sorted by y)

  8. 10 Scan Line 8 6 4 2 0 2 4 6 8 10 12 14 16 Scan-Line Polygon Fill Algorithm

  9. Scan-Line Polygon Fill Algorithm • The basic scan-line algorithm is as follows: • Find the intersections of the scan line with all edges of the polygon • Sort the intersections by increasing x coordinate • Fill in all pixels between pairs of intersections that lie interior to the polygon

  10. triangles arbitrary polygons (non-simple, non-convex) • split into two regions • fill in between edges • build edge table • for each scanline • obtain list of intersections, i.e., AEL • use parity test to determine in/out and fill in the pixels Scanline Algorithms • given vertices, fill in the pixels

  11. Scan-Line Polygon Fill Algorithm (cont…)

  12. Examples:

  13. Solutions:

  14. Scan Line Algorithms Create a list of the edges intersecting the first scanline Sort this list by the edge’s x value on the first scanline Call this the active edge list

  15. Polygon Fill B C Parity 0 = even 1 = odd Parity 0 1 0 D A E F

  16. Polygon Fill 2 B C Parity 0 = even 1 = odd F D Parity 0 1 0 1 0 A E

  17. Edge Tables • edge table (ET) • store edges sorted by y in linked list • at ymin, store ymax, xmin, slope • active edge table (AET) • active: currently used for computation • store active edges sorted by x • update each scanline, store ET values + current_x • for each scanline (from bottom to top) • do EAT bookkeeping • traverse EAT (from leftmost x to rightmost x) • draw pixels if parity odd

  18. Scanline Rasterization Special Handling • Intersection is an edge end point, say: (p0, p1, p2) ?? • (p0,p1,p1,p2), so we can still fill pairwise • In fact, if we compute the intersection of the scanline with edge e1 and e2 separately, we will get the intersection point p1 twice. Keep both of the p1.

  19. Scanline Rasterization Special Handling • But what about this case: still (p0,p1,p1,p2)

  20. Edge Table

  21. Active Edge Table (AET) • A list of edges active for current scanline, sorted in increasing x y = 9 y = 8

  22. Edge Table Bookkeeping • setup: sorting in y • bucket sort, one bucket per pixel • add: simple check of ET[current_y] • delete edges if edge.ymax > current_y • main loop: sorting in x • for polygons that do not self-intersect, order of edges does not change between two scanlines • so insertion sort while adding new edges suffices

  23. Parity (Odd-Even) Rule Begin from a point outside the polygon, increasing the x value, counting the number of edges crossed so far, a pixel is inside the polygon if the number of edges crossed so far (parity) is odd, and outside if the number of edges crossed so far (parity) is even. This is known as the parity, or the odd-even, rule. It works for any kind of polygons. Parity starting from even even even odd odd odd even odd

  24. Polygon Scan-conversion Algorithm Construct the Edge Table (ET); Active Edge Table (AET) = null; for y = Ymin to Ymax Merge-sort ET[y] into AET by x value Fill between pairs of x in AET for each edge in AET if edge.ymax = y remove edge from AET else edge.x = edge.x + dx/dy sort AET by x value end scan_fill

  25. -Edge Shortening Trick: -Recall Odd-Parity Rule Problem: -Implement “Count Once” case with edge shortening: Rasterization Special Cases A A B B B B B B ' ' C C xA,yB’,1/mAB xC,yB’,1/mCB

  26. Scan Line Algorithms For each scanline: • Maintain active edge list (using vertex events) • Increment edge’s x-intercepts, sort by x-intercepts • Output spans between left and right edges replace insert delete

  27. Penetrating Polygons False edges and new polygons! Compare z value & intersection when AET is calculated

  28. Flood Fill • 4-fill • Neighbor pixels are only up, down, left, or right from the current pixel • 8-fill • Neighbor pixels are up, down, left, right, or diagonal

  29. 4 vs 8 connected Define: 4-connected versus 8-connected, its about the neighbors

  30. 4 vs 8 connected  Fill Result: 4-connected versus 8-connected “seed pixel”

  31. Flood Fill • Algorithm: • Draw all edges into some buffer • Choose some “seed” position inside the area to be filled • As long as you can • “Flood out” from seed or colored pixels • 4-Fill, 8-Fill

  32. Seed Position Edge “Color” Fill “Color” Flood Fill Algorithm void boundaryFill4(int x, int y, int fill, int boundary) { int curr; curr = getPixel(x, y); if ((current != boundary) && (current != fill)) { setColor(fill); setPixel(x, y); boundaryFill4(x+1, y, fill, boundary); boundaryFill4(x-1, y, fill, boundary); boundaryFill4(x, y+1, fill, boundary); boundaryFill4(x, y-1, fill, boundary); } }

  33. D F even b even c d a odd odd E C A B Example Let’s apply the rules to scan line 8 below. We fill in the pixels from point a, pixel (2, 8), to the first pixel to the left of point b, pixel (4, 8), and from the first pixel to the right of point c, pixel (9, 8), to one pixel to the left of point d, pixel (12, 8). For scan line 3, vertex A counts once because it is the ymin vertex of edge FA, but the ymax vertex of edge AB; this causes odd parity, so we draw the span from there to one pixel to the left of the intersection with edge CB.

  34. G F G F H H I I E D C D C J J B A B A Four Elaborations (cont.) E

  35. Halftoning For 1-bit (B&W) displays, fill patterns with different fill densities can be used to vary the range of intensities of a polygon. The result is a tradeoff of resolution (addressability) for a greater range of intensities and is called halftoning. The pattern in this case should be designed to avoid being noticed. These fill patterns are chosen to minimize banding.

More Related