Non-recursive implementation of Flood Fill algorithm?

前端 未结 3 1145
失恋的感觉
失恋的感觉 2021-01-02 05:32

I\'m working on a small drawing application in Java. I\'m trying to create a \'bucket-fill\' tool by implementing the Flood Fill algorithm.

I tried using a recursion

3条回答
  •  时光说笑
    2021-01-02 06:02

    EDIT: watch this video: https://www.youtube.com/watch?v=LvacRISl99Y

    My results using the above method are about 10 million pixels per second. I researched it to fill 2 billion voxels space with laberinthine structures, in about 2-3 minutes, avoiding stack overflows.

    Instead of using complex logic to track previously verified neighbor spaces, I have a 2D array that records all the verified spaces. Reading from the verified array is 2-3 instructions: IF pixel[23,23] is verified, THEN fill it and check it's neighbors and write them to the verified array (fill pixel[23,23], verify pixel[23+1,23]and the three others. code is in the video.

提交回复
热议问题