我在论坛上进行了广泛的搜索,并没有完全覆盖这一点。我希望在枚举类型的数组上执行我称之为3D Flood Fill算法的操作。我想改变它中的枚举类型,而不是改变数组元素的“颜色”。这就是我到目前为止,如果您认为这样可行或者您有任何建议,请问我们。
/*
* CellType is my enum type. BOUNDRY_BOX enum type is type that I line the whole 3D array with. So the
* whole inside surface of the 3D box is filled with CellType.BOUNDRY_BOX.
**/
public void fillAllVoidCells(CellType[][][] grid, CellType targetType, CellType replacementType, int x, int y, int z)
{
if ((grid[x][y][z] != targetType) && grid[x][y][z] != CellType.BOUNDRY_BOX)
{
break;
}
else
{
grid[x][y][z] = replacementType;
fillAllVoidCells(grid, targetType, replacementType, x + 1, y, z); // right
fillAllVoidCells(grid, targetType, replacementType, x - 1, y, z); // left
fillAllVoidCells(grid, targetType, replacementType, x, y + 1, z); // in front
fillAllVoidCells(grid, targetType, replacementType, x, y - 1, z); // behind
fillAllVoidCells(grid, targetType, replacementType, x, y, z + 1); // above
fillAllVoidCells(grid, targetType, replacementType, x, y, z - 1); // below
}
}
答案 0 :(得分:0)
有几件事: