polygon filling
play

Polygon Filling Goal intensify the pixels that belong to the - PowerPoint PPT Presentation

Polygon Filling Goal intensify the pixels that belong to the polygon Issues which pixels belong to the polygon Approach use a (horizontal) scan line that traverses the polygon intensify the pixels along the spans (the segments of


  1. Polygon Filling Goal intensify the pixels that belong to the polygon Issues which pixels belong to the polygon Approach use a (horizontal) scan line that traverses the polygon intensify the pixels along the spans (the segments of intersection) exploit spatial coherence – little change along a span (span coherence) or between scan lines (scan-line coherence)

  2. Rectangle Filling Special case filling rectangles specified by x min , x max , y min , y max def drawRectangle(xmin, xmax, ymin, ymax): # for each vertical scan line : for y in [ymin : ymax]: # for each horizontal span : for x in [xmin : xmax]: setPixel(x, y, color)

  3. Rectangle Filling Issues in rectangle (and polygon) filling draw R1(8, 5, 16, 10) and R2(16, 5, 24, 10) 10 5 0 0 4 8 12 16 16 20 24

  4. Rectangle Filling Issues in rectangle (and polygon) filling draw R1(8, 5, 16, 10) and R2(16, 5, 24, 10) 10 5 0 0 4 8 12 16 16 20 24

  5. Rectangle Filling Issues in rectangle (and polygon) filling draw R1(8, 5, 16, 10) and R2(16, 5, 24, 10) shared edge at x = 16 – order of drawing gives different visual results 10 5 0 0 4 8 12 16 16 20 24

  6. Rectangle Filling Issues in rectangle (and polygon) filling adjacent rectangles (shared vertices, edges) Solution do not draw the right-most and top-most edges of the rectangle (arbitrary decision – could have chosen to omit left-most, bottom-most) 10 5 0 0 4 8 12 16 16 20 24

  7. Rectangle Filling Issues in rectangle (and polygon) filling adjacent rectangles (shared vertices, edges) Solution do not draw the right-most and top-most edges of the rectangle 10 5 0 0 4 8 12 16 16 20 24

  8. Polygon Filling Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge

  9. Polygon Filling Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge line drawing algorithm may pick pixels that are outside the ideal boundary

  10. Polygon Filling Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge line drawing algorithm may pick pixels that are outside the ideal boundary

  11. Polygon Filling Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge line drawing algorithm may pick pixels that are outside the ideal boundary

  12. Polygon Filling Same solution for general polygons do not draw the right-most and top-most edges of the polygon draw only pixels interior to the polygon Example polygon outline if we used the line drawing algorithm for each edge line drawing algorithm may pick pixels that are outside the ideal boundary

  13. Polygon Filling Check the x-coordinate of intersections between scan line and edges if entering the polygon (i.e. left edge ), round x up (11.4 12) → if leaving the polygon (i.e. right edge), round x down (16.7 16) → If the intersection occurs at integer x-coordinate → left edge – draw pixel at x (11 11) right edge – draw pixel at x-1 (11 10) → → → 11.4 12 16.7 16 → → 11 11 16 15

  14. Polygon Filling Check the x-coordinate of intersections between scan line and edges if entering the polygon (i.e. left edge ), round x up (11.4 12) → → if leaving the polygon (i.e. right edge), round x down (16.7 16) If the intersection occurs at integer x-coordinate: left edge – draw pixel at x , right edge – draw pixel at x-1 4 0 4 8 12 16 16 20 24

  15. Polygon Filling Horizontal edges are ignored: either they don't need to be drawn, since they are top edges or they will be drawn as part of a longer span should be ignored will be filled 4 0 4 8 12 16 16 20 24

  16. Polygon Filling Scan line at level y = 4 intersects edges at x = 11.4 , 16.7 , 21.6 , 26 Every pair of intersections represents a span that needs to be filled s1 = (11.4, 16.7) s2 = (21.6, 26) 4 0 4 8 12 16 16 20 24

  17. Polygon Filling Scan line at level y = 4 intersects edges at x = 11.4 , 16.7 , 21.6 , 26 Every pair of intersections represents a span that needs to be filled s1 = (11.4, 16.7) s2 = (21.6, 26) For each span round up left coordinate, round down the right coordinate s1 = (12, 16) s2 = (22, 25) Intensify pixels at scan line y = 4 and x = [12..17] and x = [23..25] 4 0 4 8 12 16 16 20 24

  18. Polygon Filling Move the scan line by one unit (to draw the next row of pixels) Scan line now intersects edges at x = 11, 26 ignore horizontal edges and edges whose top vertex is on the scan line Every pair of intersections represents a span that needs to be filled s1 = (11, 26) round up/down s1 = (11, 25) Intensify pixels at scan line y = 5 and x = [11..25] 4 0 4 8 12 16 16 20 24

  19. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  20. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  21. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  22. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  23. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  24. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  25. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  26. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  27. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon filled as desired

  28. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  29. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

  30. Polygon Filling Algorithm discard all horizontal edges set up a scan line at the bottom of the polygon repeat find the x intersections of scan line with the edges ( active edges ) every pair of intersections represents a span to fill/intensify move the scan line up, discard edges with top vertex on scan line until scan line reaches top of polygon

Recommend


More recommend