What algorithm can I use to distinguish between closed and open raster polygons?

328 Views Asked by At

Imagine I have two point arrays. One of them is an open polygon, which looks like this.

Image 1

Xes are black dots and points ('.') - white ones.

The second point array contains a closed polygon:

Image 2

I need the name of an algorithm, which allows me to determine whether a given point array is a closed polygon or an open one. I need this information to determine, whether I can flood filll it (I cannot flood fill the first example, but I can flood fill the second one).

What is the algorithm called, which allows me to distinguish between the two types of polygons?

Update 1 (10.10.2015 10:05 MSK): I need to distinguish between closed and open polygons in order to prevent flood fill errors.

A flood fill errors, is when I apply flood fill to an open polygon like

.....
..XXX
.X..X
X...X

and end up with a completely filled grid:

XXXXX
XXXXX
XXXXX
XXXXX

My original idea was to

  1. take the polygon,
  2. check, if it's open or closed and
  3. if it's closed, apply flood fill.

Now, I could do it differently:

  1. Flood fill the polygon.
  2. If the entire grid is filled, then it's an open one, otherwise (at least one point in the grid after flood fill is white), it's a closed one.

If there is a way to avoid doing flood fill for determining, whether a polygon is open or closed, please tell me.

1

There are 1 best solutions below

0
DhawalV On

I don't have any experience with this but while I was researching something else I found this and thought it might be helpful for you:

http://www.cs.tufts.edu/~sarasu/courses/comp175-2009fa/pdf/comp175-05-region-filling.pdf

The slides mention 3 different algorithms:

  • X-intersection array algorithm
  • Edge list algorithm
  • Pineda’s algorithm