Your SlideShare is downloading. ×
  • Like
Lecture  filling algorithms
Upcoming SlideShare
Loading in...5

Thanks for flagging this SlideShare!

Oops! An error has occurred.


Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Lecture filling algorithms



Published in Technology , Art & Photos
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
  • good
    Are you sure you want to
    Your message goes here
  • Best Of Luck
    Are you sure you want to
    Your message goes here
No Downloads


Total Views
On SlideShare
From Embeds
Number of Embeds



Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

    No notes for slide


  • 1. Polygon surfaces
    • A polygon is an important graphics primitive.
    • A polygon is a closed area of image bounded by straight or curved lines and filled with one solid color.
    • Since images are two dimensional, a polygon is a closed planar figure.
  • 2. Polygon surfaces
    • A polygon can be defined as an image which consists of a finite ordered set of straight boundaries called edges .
    • The polygon can also be defined by an ordered sequence of vertices , i.e, the corners of the polygon.
    • The edges of the polygon are then obtained by traversing the vertices in the given order;
    • Two consecutive vertices define one edge.
    • The polygon can be closed by connecting the last vertex to the first.
    • Face list or polygon surface table is required in order to fill the polygon.
  • 3.
  • 4. Area Filling Algorithms
    • Scan line polygon fill algorithm
    • Boundary fill algorithm
    • Flood fill algorithm
  • 5. Scan-Line Polygon Fill Algorithm
    • Odd-parity rule
    • Calculate span intersections on each scan line using parity rule to determine whether or not a point is inside a region
    • Parity is initially even
    •  each intersection encountered thus inverts the parity bit
    • parity is odd  interior point (draw)
    • parity is even  exterior point (do not draw)
    o o e e o e/o e
  • 6. Scan-Line Polygon Fill Algorithm
    • Case 1
    • Check the endpoint y values of two intersected edges
    •  if their change is monotonically, we should count the intersection only once
    •  Otherwise, we should count the intersection twice.
    • Case 2
    • At the shared vertex: shorten the lower edge one grid below the shared point, such that the two edges are disconnected;
    •  Alternative way: we only count the y[min] vertex of an edge but not the y[max] vertex for the adjacent edge.
    • For horizontal line
    •  do not count their vertices
    o o e e o e/o e Case 1: Case 2:
  • 7. Scan-Line Polygon Fill Algorithm
    • Finding intersection pairs :
    • Scan-line conversion method (for non-horizontal edges):
    •  Edge coherence property:
    • Incremental calculation between successive scan lines
    •  Or using Bresenham’s scan line conversion algorithm on each edge and keep a table of span extrema for each scan line
  • 8. Scan-Line Polygon Fill Algorithm
    • Incremental scan line method :
    • m = (y[k+1] – y[k]) / (x[k+1] – x[k])
    • y[k+1] – y[k] = 1
    • x[k+1] = x[k] + 1/m  x[k] = x[0] + k/m
    Scan line y[k] + 1 Scan line y[k] (x[k+1], y[k+1]) (x[k], y[k])
  • 9. Scan-Line Polygon Fill Algorithm
    • Incremental scan line method :
    • Bucket sorted edge table: containing all edges sorted by their smaller y coordinate.
    • Each bucket: edges are recorded in order of increasing x coordinate of the
    • lower endpoint.
    • Each entry of a bucket: y[max] of the edge, x[min] of lower endpoint and 1/m
    • (x increment)
    • Active-edge table (or list): keep track of the set of edges that the scan line intersects
    • and the intersection points in a data structure
  • 10. Scan-Line Polygon Fill Algorithm
    • Example:
    5 1 4 3 2 y5 x1 1/m[1,5] y2 x1 1/m[1,2] y5 x4 1/m[4,5] y3 x4 1/m[4,3] y3 x2 1/m[2,3] y4 : : y1 y2 : : : : 0 Sorted edge table (ET)
  • 11. Scan-Line Polygon Fill Algorithm
    • Example:
    5 1 4 3 2 y5 xa 1/m[1,5] y2 xb 1/m[1,2] y5 x5 1/m[1,5] y5 x5 1/m[4,5] y[5] : : y[a] : : : : : 0 Active edge table (AET) b a y3 xc 1/m[3,4] y2 xd 1/m[1,2] c d
  • 12. Inside-outside tests
    • Odd-even rule (odd parity rule or even-odd rule)
    • Counting the number of edge crossing along the line from point P to infinity
    • Odd number  interior point P
    • Even number  exterior point P
    • Non-zero winding number rule (vector method)
    •  winding number: no of times that the polygon edges wind around a point in the counterclockwise direction
    •  if the winding number = 0  exterior point
    •  if the winding number != 0  interior point
  • 13. Boundary Fill
    • Suppose that the edges of the polygon has already been colored.
    • Suppose that the interior of the polygon is to be colored a different color from the edge.
    • Suppose we start with a pixel inside the polygon, then we color that pixel and all surrounding pixels until we meet a pixel that is already colored.
  • 14.
    • void boundaryFill(int x, int y, int fillColor, int borderColor) {
    • int interiorColor;
    • getPixel(x,y,interiorColor);
    • if ((interiorColor!=borderColor)&&(interiorColor!=fillColor)) {
    • setPixel(x,y,fillColor);
    • boundaryFill(x+1,y,fillColor,borderColor);
    • boundaryFill(x-1,y,fillColor,borderColor);
    • boundaryFill(x,y+1,fillColor,borderColor);
    • boundaryFill(x,y-1,fillColor,borderColor);
    • }
    • }
    Boundary Fill
  • 15. Flood Fill
    • Suppose we want to color the entire area whose original color is interiorColor, and replace it with fillColor.
    • Then, we start with a point in this area, and then color all surrounding points until we see a pixel that is not interiorColor.
  • 16.
    • void floodFill(int x, int y, int fillColor, int interiorColor) {
    • int color;
    • getPixel(x,y,color)
    • if (color==interiorColor) {
    • setPixel(x,y,fillColor);
    • floodFill(x+1,y,fillColor,interiorColor);
    • floodFill(x-1,y,fillColor,interiorColor);
    • floodFill(x,y+1,fillColor,interiorColor);
    • floodFill(x,y-1,fillColor,interiorColor);
    • }
    • }
    Flood Fill