Your SlideShare is downloading. ×
0
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

# Polygon Fill

1,473

Published on

Published in: Technology, Design
0 Comments
0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

No Downloads
Views
Total Views
1,473
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
70
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

### Transcript

• 1. &#x2022; &#x2022; &#x2022; &#x2022; &#x2022; Different types of Polygons Simple Convex Simple Concave Non-simple : self-intersecting With holes Convex Concave Self-intersecting
• 2. Polygon Scan Conversion &#x2022; Scan Conversion = Fill &#x2022; How to tell inside from outside &#x2013; Convex easy &#x2013; Nonsimple difficult &#x2013; Odd even test &#x2022; Count edge crossings odd-even fill
• 3. Winding Number &#x2022; Count clockwise crossings as positive and counterclockwise crossings as negative winding number = 1 winding number = 2 &#x2022; Alternate definition of inside: inside if winding number &#x2260; 0
• 4. Filling in the Frame Buffer &#x2022; Fill at end of pipeline &#x2013; Convex Polygons only &#x2013; Nonconvex polygons assumed to have been tessellated &#x2013; Shades (colors) have been computed for vertices (Gouraud shading) &#x2013; March across scan lines interpolating shades &#x2022; Incremental work small
• 5. Using Interpolation C1 C2 C3 specified by glColor or by vertex shading C4 determined by interpolating between C1 and C2 C5 determined by interpolating between C2 and C3 interpolate between C4 and C5 along span C1 C4 scan line C2 C5 span C3
• 6. Scan Line Polygon Fill &#x2022; Determine overlap Intervals for scan lines that cross that area. &#x2013; Requires determining intersection positions of the edges of the polygon with the scan lines &#x2013; Fill colors are applied to each section of the scanline that lies within the interior of the region. &#x2013; Interior regions determined as in odd-even test 10 13 16 19 Interior pixels along a scan line passing through a polygon area
• 7. 10 13 16 19 &#x2022; In the given example, four pixel intersections are at x=10, x=13, x=16 and x=19 &#x2022; These intersection points are then sorted from left to right , and the corresponding frame buffer positions between each intersection pair are set to specified color &#x2013; 10 to 13, and 16 to 19
• 8. Scan Line Polygon Fill &#x2022; Some scan line intersections at polygon vertices require special handling: &#x2013; A scan line passing through a vertex intersects two polygon edges at that position
• 9. Scan Line y&#x2019; 1 2 1 Scan Line y 1 2 1 1 Intersection points along the scan lines that intersect polygon vertices. Scan line y&#x2019; generates an even number of intersections that can be paired to identify correctly the interior pixel spans. To identify the interior pixels for scan line y, we must count the vertex intersection as only one point.
• 10. Scan Line Polygon Fill &#x2022; The topological difference between scan Line y and scan Line y&#x2019; &#x2022; For scan line y, the two edges sharing an intersection vertex are on opposite sides of the scan line. &#x2013; Count this vertex as one intersection point &#x2022; For scan line y&#x2019;, the two intersecting edges are both above the scan line
• 11. Scan Line Polygon Fill &#x2022; We can distinguish these cases by tracing around the polygon boundary either in clockwise or counterclockwise order and observing the relative changes in vertex y coordinates as we move from one edge to the next. &#x2022; Let (y1, y2) and (y2, y3) be the endpoint y values of two consecutive edges. If y1, y2, y3 monotonically increase or decrease, we need to count the middle vertex as a single intersection point for any scan line passing through that vertex.
• 12. Scan Line Polygon Fill &#x2022; One method for implementing the adjustment to the vertex intersection count is to shorten some polygon edges to split those vertices that should be counted as one intersection &#x2013; When the end point y coordinates of the two edges are increasing , the y value of the upper endpoint for the current edge is decreased by 1 &#x2013; When the endpoint y values are monotonically decreasing, we decrease the y coordinate of the upper endpoint of the edge following the current edge
• 13. Scan Line Polygon Fill Algorithm (a) (b) Adjusting endpoint values for a polygon, as we process edges in order around the polygon perimeter. The edge currently being processed is indicated as a solid like. In (a), the y coordinate of the upper endpoint of the current edge id decreased by 1. In (b), the y coordinate of the upper end point of the next edge is decreased by 1
• 14. The scan conversion algorithm works as follows i. Intersect each scanline with all edges ii. Sort intersections in x iii. Calculate parity of intersections to determine in/out iv. Fill the &#x201C;in&#x201D; pixels Special cases to be handled: i. Horizontal edges should be excluded ii. Vertices lying on scanlines handled by shortening of edges, &#x2022; Coherence between scanlines tells us that Edges that intersect scanline y are likely to intersect y + 1 X changes predictably from scanline y to y + 1 (Incremental Calculation Possible) (Xk + 1, Yk + 1) (Xk , Yk ) Scan Line yk + 1 Scan Line yk
• 15. &#x2022; The slope of the edge is constant from one scan line to the next: &#x2013; let m denote the slope of the edge. yk +1 &#x2212; yk = 1 1 xk +1 = xk + m &#x2022; Each successive x is computed by adding the inverse of the slope and rounding to the nearest integer
• 16. Integer operations &#x2022; Recall that slope is the ratio of two integers: &#x2206;y m= &#x2206;x &#x2022; So, incremental calculation of x can be expressed as &#x2206;y xk +1 = xk + &#x2206;x
• 17. Integer operations &#x2022; How to compute x intercepts incrementally using integer operations: &#x2013; Initialize a counter to 0 &#x2013; Increment counter by &#x2206;x each time we move up to a new scan line. &#x2013; If counter becomes greater or equal to &#x2206;y, increment the current x intersection value by 1 and decrease the counter by &#x2206;y
• 18. &#x2022; Example: m=7/3 &#x2022; Initial scanline counter = 0 &#x2022; Next scanlines &#x2013; Counter =3 &#x2013; Counter =6 &#x2013; Counter =9 &#x2022; increment x intercept by &#x2022; Reset counter to 9-7 = 2
• 19. Line with slope 7/3 yk xk
• 20. decrement decrement 0 4 1 5 2 6 3 0 y0 counter decrement x0
• 21. &#x2022; Above scheme truncates integers. &#x2022; How do we round to nearest integer? &#x2013; We need to compare the counter to &#x2206;y/2. &#x2013; Can be done by integer arithmetic by incrementing counter by 2&#x2206;x at each step and comparing with &#x2206;y &#x2013; When the counetr is greater than or equal to &#x2206;y, increase x value by 1 and decrement the counter by 2&#x2206;y
• 22. &#x2022; Example: m=7/3 &#x2022; Initial scanline counter = 0 &#x2022; Next scanlines &#x2013; Counter =6 &#x2013; Counter =12 &#x2022; increment x intercept by &#x2022; Reset counter to 12-(2*7) = -2
• 23. decrement decrement 0 -6 2 -4 4 decrement -2 6 0 y0 counter x0
• 24. Sorted Edge Table (SET) In SET, there is an entry for each scanline. Traverse edges of the polygon to construct a Sorted Edge Table (SET) 1. Eliminate horizontal edges 2. Add edge to linked-list for the scan line corresponding to the y_lower vertex. Shorten edges if necessary to resolve the vertex-intersection problem. 3. For each edge entry, store the following: - y_upper: the largest y value on that edge (last scanline to consider) - x_lower: the x intercept at that scanline (initial x value) - 1/m: for incrementing x 4. For each scan line the edges are sorted from left to right (based on x)
• 25. B yC yA C E C&#x2019; yB xC 1 / mBC yE x A 1 / mAE D A 1 0 y B x A 1 / mAB
• 26. Active Edge List (AEL) &#x2022; Construct Active Edge List during scan conversion. AEL is a linked list of active edges on the current scanline, y. The active edges are kept sorted by x &#x2013; The active edge list contains all the edges crossed by that scan line. &#x2013; As we move up, update the active edge list using the sorted edge table if necessary.
• 27. Algorithm 1. 2. 3. Set y to the smallest y coordinate that has an entry in the SET; i.e, y for the first nonempty bucket. Initialize the AEL to be empty. For each scanline y repeat: 3.1 Copy from SET bucket y to the AEL those edges whose y_min = y (entering edges). 3.2 The sort the AEL on x is easier because SET is presorted. 3.3 Fill in desired pixel values on scanline y by using pairs of x coordinates from AEL. 3.5 Remove from the AEL those entries for which y = y_max (edges not involved in the next scanline.) 3.4 Increment y by 1 (to the coordinate of the next scanline). 3.5 For each nonvertical edge remaining in the AEL, update x for the new y.
• 28. Flood Fill Algorithm &#x2022; These algorithms assume that at least one pixel interior to a polygon or region is known -assume that the boundary is defined by Bresenham&#x2019;s
• 29. Flood Fill &#x2022; Fill can be done recursively if we know a seed point (x,y) located inside (WHITE) &#x2022; Scan convert edges into buffer in edge/inside color (BLACK) flood_fill(int x, int y) { if(read_pixel(x,y)= = WHITE) { write_pixel(x,y,BLACK); flood_fill(x-1, y); flood_fill(x+1, y); flood_fill(x, y+1); flood_fill(x, y-1); } }
• 30. Depth or Z-Buffer &#x2022; For each pixel, we store COLOR (color buffer) and DEPTH (depth buffer). &#x2022; Algorithm: Initialize all elements of buffer COLOR(row, col) to background color, and DEPTH(row, col) to maximum-depth; FOR EACH polygon: Rasterize polygon to frame; FOR EACH pixel center (x, y) that is covered: IF polygon depth at (x, y) &lt; DEPTH(x, y) THEN COLOR(x, y) = polygon color at (x, y) AND DEPTH(x, y) = polygon depth at (x, y)
• 31. Depth Buffer Operation Frame Depth &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; Initialize (&#x201C;New Frame&#x201D;)
• 32. Depth Buffer Operation &#x2013; First Polygon Frame Depth &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; 24 &#x221E; &#x221E; &#x221E; &#x221E; 26 27 &#x221E; &#x221E; &#x221E; 28 29 30 &#x221E; Pink Triangle -- depths computed at pixel centers
• 33. Depth Buffer Operation -- First Polygon Frame Depth &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; &#x221E; 24 &#x221E; &#x221E; &#x221E; &#x221E; 26 27 &#x221E; &#x221E; &#x221E; 28 29 30 &#x221E; Pink Triangle -- pixel values assigned
• 34. Depth Buffer Operation &#x2013; Second Polygon Frame Depth &#x221E; &#x221E; 10 9 &#x221E; &#x221E; 24 9 8 &#x221E; &#x221E; 26 8 7 &#x221E; &#x221E; 28 7 6 &#x221E; Green Rectangle -- depths computed at pixel centers
• 35. Depth Buffer Operation &#x2013; Second Polygon Frame Depth &#x221E; &#x221E; 10 9 &#x221E; &#x221E; 24 9 8 &#x221E; &#x221E; 26 8 7 &#x221E; &#x221E; 28 7 6 &#x221E; Green Rectangle -- pixel values assigned: NOTE REPLACEMENTS!
• 36. Depth Buffer Operation &#x2013; Third Polygon Frame 68 not stored Depth &#x221E; &#x221E; 10 9 72 &#x221E; 24 9 8 75 &#x221E; 26 8 7 &#x221E; &#x221E; 28 7 6 &#x221E; Blue Pentagon -- depths computed at pixel centers 71 not stored
• 37. Depth Buffer Operation &#x2013; Third Polygon Frame Depth &#x221E; &#x221E; 10 9 72 &#x221E; 24 9 8 75 &#x221E; 26 8 7 &#x221E; &#x221E; 28 7 6 &#x221E; Blue Pentagon -- pixel values assigned: NOTE &#x2018;GOES BEHIND&#x2019;!
• 38. screen scan-line