here is a problem for you ;)
I have a 3-dimensional array filled with 1s and 0s. The 1s represent 3 dimensional complex polygons ( not simple polygons ). Only the boundaries of the polygons have the value 1, the inside is filled with 0s. Now here is the problem:
I need a fast algorithm to flood-fill these polygons with 1s. The arrays usually have a dimension of approx. 512x512x100.
Thanks in advance!
Here is an example in 2d:
0000111110000
0000100010000
0000100010000
0000111110000
should result in
0000111110000
0000111110000
0000111110000
0000111110000
is this the correct 3 dimensional solution for @Mikolas algorithm?
void scan_polygon(int frames, int rows, int cols, char data[][][], char result[][][]){
for(int f=0; f < frames; ++f)
for(int r=0; r<rows; ++r)
for(int s = 0, c=0; c<cols-1; ++c)
{
s ^= s ? ( data[f][r][c] && !data[f][r][c+1]) :
(!data[f][r][c] && data[f][r][c-1]);
result[f][r][c] = s;
}
for(int f=0; f < frames; ++f)
for(int c=0; c<cols; ++c)
for(int s = 0, r=0; r<rows-1; ++r)
{
s ^= s ? ( data[f][r][c] && !data[f][r+1][c]) :
(!data[f][r][c] && data[f][r-1][c]);
result[f][r][c] &= s;
}
}
Best regards,
stef