Scanline Polygon Filling Algorithm

Embed Size (px)

Citation preview

  • 8/18/2019 Scanline Polygon Filling Algorithm

    1/3

    Filling a Polygon using Scanline polygon filling algorithm

    Basic algorithm

     – Assume scan line start from the left and is outside the polygon.

     – When intersect an edge of polygon, start to color each pixel (because now we’re inside the

     polygon), when intersect another edge, stop coloring …

     – dd number of edges! inside

     – "#en number of edges! outside

    What happens when a scan line intersects an edge endpoint, it intersects two edges.

    $ %wo cases!

     – &ase A! edges are monotonically increasing or decreasing

     – &ase '! edges re#erse direction at endpoint

    $ n &ase A, we should consider this as only " edge intersection

    $ n &ase ', we should consider this as %W edge intersections

    $ ncremental scan line method!

    m * (y+-/ – y+/) 0 (x+-/ – x+/)

    y+-/ – y+/ *

    x[k+1] = x[k] + 1/m x[k]

  • 8/18/2019 Scanline Polygon Filling Algorithm

    2/3

    Active Edge List

    • 1tart with the sorted edge table.

     – n the abo#e diagram, there is an entry for each scan2line.

     – Add only the non2hori3ontal edges into the table.

    $ 4or each edge, we add it to the scan2line that it begins with (that is, the scan2line e5ual to its

    lowest y2#alue).

    $ 4or each edge entry, store

    () %he x2intercept with the scan2line

      (6) %he largest y#alue of the edge, and

  • 8/18/2019 Scanline Polygon Filling Algorithm

    3/3

      (7) %he in#erse of the slope.

     – "ach scan2line entry thus contains a sorted list of edges. %he edges are sorted left to right. (%o

    maintain sorted order, 8ust use insertion based on their x #alue.)

    $ ext, we process the scan lines from bottom to top.

     – We maintain an acti#e edge list for the current scan2line.

     – %he acti#e edge list contains all the edges crossed by that scan line. As we mo#e up,

    update the acti#e edge list by the sorted edge table if necessary.