get the polygon around a point

Thanks Tom for leading me to flood fill. I think that I understand basically how flood fill works.

But how can I detect a border color? For instance, if a polygon has 12 line segments and each line segment has a different color. In order to fill this polygon with a color using flood fill , I have to detect all 12 colors and keep track each pixel as the color filling moves toward the polygon border.

Jay

If you are trying to fill a vector polygon I would FIRST look to see if your polygona renderer has it built in. (I know Java2D for instance has drawFilledFoo functions. Thats going to be the fastest solution because the filling as part of the rasterization is pretty trivial. If yo uwant to provide a "refill op I’d just draw the enw fileld oply over the old one.

If for some rason though you HAVE to do it as a flood fill then yo uare going to have to do “contains” ops for every point which will be expensive. Yo uca pergapse optimzie a it by doing a “contains” on your first point and then just doing edge/point intersection tests on the subsequent points (see Graphcis Gems).

You might even be able to optimize this with a clever solution, like doing line/edge tests against a screen wide line for each new Y value and then alternately filling he lines between inetrsections.

In the end though NONE of this will be as good or fast as the rasterizer, particualrly since the rasterizer these days is generally hardware accelerated.

[quote]But how can I detect a border color? For instance, if a polygon has 12 line segments and each line segment has a different color. In order to fill this polygon with a color using flood fill , I have to detect all 12 colors and keep track each pixel as the color filling moves toward the polygon border.
[/quote]
Usually the fill tools in painting programs are used to replace a color in an Image. Then the border is any color that is not the one that is replaced.

If that don’t apply to you, you can draw the polygons line segments to another off-screen buffer. Where the background is white and the line segments are black. Then you can use this buffer when you fill.

But, Yes, You have to know where the border is and you have to know where you have filled. Exactly how this is done depends on your application, as there are a lot of ways of doing this.

Jeff: I agree that flood fill is not the way to go if you only want to fill a single polygon. However, I enterprated the problem as first drawing one or more, possibly self intersecting, overlapping polygons, and then fill inside like a flood fill. Doing this with using polygons you would have to “AND” all the polygons that contains the start point (meaning finding the area that all the polygons overlap), and then “subtract” the rest. Either useing contains on all polygons for each pixel, or using clipping. I thought it would be easier to use a flood fill :slight_smile: