private FloodFillResult FloodFill(Block[,] map, int x, int y) { var result = new FloodFillResult(_boardHeight, _boardWidth); FloodFill(result, map, x, y); return(result); }
public void ExecuteSeededGrow(Int16Triple firstseed) { if (buffer == null || seedGrowExecutor == null || dataProvider == null) { throw new Exception(); } queue = new Container_Stack <LayerDataAndInput>(); Layer firstLayer = GetFirstLayer(firstseed); FloodFillInput firstInput = new FloodFillInput (buffer, firstLayer.AllWidth, firstLayer.AllHeight, firstLayer.actualDepth, firstLayer.GetAndInitFlag(), new List <Int16Triple>() { ConvertGlobalCoodToLayerCoold(firstLayer, firstseed) }, firstLayer.HasUpperLayer(), firstLayer.HasLowerLayer(), true); queue.Push(new LayerDataAndInput(firstLayer, firstInput)); while (!queue.Empty()) { LayerDataAndInput sgi = queue.Pop(); Layer layer = sgi.layer; layer.visitcount++; FloodFillInput input = sgi.input; FillLayerData(layer); FloodFillResult ret1 = seedGrowExecutor.ExecuteSeededGrow(input); input.overstepList.Clear(); //ConvertLayerCoordsToGlobalCoords(layer,ret1.resultPointSet); //resultSet.AddRange(ret1.resultPointSet); resultCount += ret1.resultCount; if (ret1.GetNeedsSeekLower()) { Layer lowerlayer = image.GetLayer(layer.indexZ - 1); if (lowerlayer == null) { ret1.boundaryRequestPoints[0].Clear(); continue; } ConvertOtherLayerCoordsToThisLayerCoords(layer, lowerlayer, ret1.boundaryRequestPoints[0]); FloodFillInput newinput = new FloodFillInput (buffer, lowerlayer.AllWidth, lowerlayer.AllHeight, lowerlayer.actualDepth, lowerlayer.GetAndInitFlag(), ret1.boundaryRequestPoints[0], lowerlayer.HasUpperLayer(), lowerlayer.HasLowerLayer(), false); queue.Push(new LayerDataAndInput(lowerlayer, newinput)); } if (ret1.GetNeedsSeekUpper()) { Layer upperlayer = image.GetLayer(layer.indexZ + 1); if (upperlayer == null) { ret1.boundaryRequestPoints[1].Clear(); continue; } ConvertOtherLayerCoordsToThisLayerCoords(layer, upperlayer, ret1.boundaryRequestPoints[1]); FloodFillInput newinput = new FloodFillInput (buffer, upperlayer.AllWidth, upperlayer.AllHeight, upperlayer.actualDepth, upperlayer.GetAndInitFlag(), ret1.boundaryRequestPoints[1], upperlayer.HasUpperLayer(), upperlayer.HasLowerLayer(), false); queue.Push(new LayerDataAndInput(upperlayer, newinput)); } } }
private void FloodFill(FloodFillResult result, Block[,] map, int x, int y) { result.FillMap[y, x] = true; if (map[y, x] != Block.Mess) { result.Count++; } if (x > 0 && (map[y, x - 1] == map[y, x] || map[y, x - 1] == Block.Mess) && !result.FillMap[y, x - 1]) { FloodFill(result, map, x - 1, y); } if (x < _boardWidth - 1 && (map[y, x + 1] == map[y, x] || map[y, x + 1] == Block.Mess) && !result.FillMap[y, x + 1]) { FloodFill(result, map, x + 1, y); } if (y > 0 && (map[y - 1, x] == map[y, x] || map[y - 1, x] == Block.Mess) && !result.FillMap[y - 1, x]) { FloodFill(result, map, x, y - 1); } if (y < _boardHeight - 1 && (map[y + 1, x] == map[y, x] || map[y + 1, x] == Block.Mess) && !result.FillMap[y + 1, x]) { FloodFill(result, map, x, y + 1); } }