0% found this document useful (0 votes)
237 views5 pages

Scanline Polygon Fill Algo

The scanline fill algorithm involves intersecting a scanline with the edges of a polygon to determine the pixels to fill between intersections. It requires special handling of intersections that fall on integer coordinates, intersections where an edge endpoint falls on the scanline, and ensuring only interior pixels are filled. Intersections at an edge's minimum y-value are counted, but other intersections at edge endpoints are not counted twice to avoid filling incorrect pixels.

Uploaded by

Santosh Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
237 views5 pages

Scanline Polygon Fill Algo

The scanline fill algorithm involves intersecting a scanline with the edges of a polygon to determine the pixels to fill between intersections. It requires special handling of intersections that fall on integer coordinates, intersections where an edge endpoint falls on the scanline, and ensuring only interior pixels are filled. Intersections at an edge's minimum y-value are counted, but other intersections at edge endpoints are not counted twice to avoid filling incorrect pixels.

Uploaded by

Santosh Sharma
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Scanline Fill Algorithm

Intersect scanline with polygon edges Fill between pairs of intersections Basic algorithm: For y = ymin to ymax 1) intersect scanline y with each edge 2) sort interesections by increasing x [p0,p1,p2,p3] 3) fill pairwise (p0 > p1, p2> p3, ....)
ymax p0 p1 p2 p3

ymin

However, we need to handle some special cases and improve the performance Special handling: a) Make sure we only fill the interior pixels Define interior: For a given pair of intersectin points (Xi, Y), (Xj, Y) > Fill ceiling(Xi) to floor(Xj) important when we have polygons adjacent to each other b) Intersection has an integer X coordinate > if Xi is integer, we define it to be interior > if Xj is integer, we define it to be exterior (so dont fill)

Special handling (contd) c) Intersection is an edge end point


ymax

e1 scanline
p0 p1

e2
p2

ymin

Intersection points: (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.

Special handling (contd) c) Intersection is an edge end point (contd)

p0

e1

p1

p2

p3

e2

However, in this case we dont want to count p1 twice (p0,p1,p1,p2,p3), otherwise we will fill pixels between p1 and p2, which is wrong

Special handling (contd) c) Intersection is an edge end point (contd) Rule: If the intersection is the ymin of the edges endpoint, count it. Otherwise, dont.
ymax

e1 scanline
p0 p1

e2
p2

Yes, count p1 for both e1 and e2

ymin

p0

e1

p1

p2

p3

No, dont count p1 for the edge e2

e2

You might also like