Scan-Line Ploygon Fill:: Explaination
Scan-Line Ploygon Fill:: Explaination
As the name suggest each row OR column is scanned for a boundary point and if the
next point after the boundary point is encountered next point is checked if it is inside or not
and if it is inside the area is filled till next boundary point is encountered..
In the algorithm mentioned below ROW scan line check is performed .
EXPLAINATION:
1).Iniitialize a const k=0,now if the scanline intersects the polygon boundary once we
increment the k once i.e it becomes odd and if again it intersects the boundary we increment it
once i.e it becomes even
And when the valueof k is odd we fill the pixel and move to next pixel
And when k is even we dont fill it but just increment to next pixel
2).The above algo works fine until a vertex is encountered
At the vertex there are two conditions :
-Either it is a concave position vertex
-Or a convex position vertex
Concave vertex:
Before and after we encounter the pixel containing the vertex point the value of k
should be odd which implies that when the scan line encounters the vertex the increment
should be such that it still remains odd.
Convex vertex:
Before and after we encounter the pixel containing the vertex point the value of k
should be even which implies that when the scan line encounters the vertex the increment
should be such that it still remains even.
Thus we have to develop a different algo if scan line encounters a vertex.
Here,we use one of the various properties of coherence , coherence is nothing but the fact that
the properties of one part of the scene is related to some other part of the scene in some other
way
Now , for checking whether the scanned point is a vertex we check the previous as well
as the next scanline for two points
If the we are doing the scan line from top to bottom then ,
If we encounter multiple pixels jst previous to vertex or just after the vertex then we have to
increment the value of k twice
Else if before or after the vertex we encounter only one point the increment the value of
k once.