2013-04-29 6 views
0

나는이 포럼을 광범위하게 검색 했으므로이 내용을 다루지는 않았습니다. 나는 기본적으로 열거 형의 배열에 3D Flood Fill 알고리즘이라고 부르는 것을하려고합니다. 배열 요소의 "색"을 변경하는 대신 열거 형을 변경하고 싶습니다. 이것은 내가 지금까지 가지고있는 것입니다. 만약 당신이 이것이 효과가 있다고 생각하거나 어떤 제안이 있다면 당신이 저에게 알려주시겠습니까?3D 배열 (3D 배열)에 3D 홍수 채우기 알고리즘

/* 
    * 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

몇 가지 :

  • 휴식 당신이 그것을하지 무슨 생각을 의미하지 않는다. return을 사용하여 함수를 떠나야합니다.
  • 인접한 셀의 함수를 호출하기 전에 도메인의 경계에 있는지 확인해야합니다 (그렇지 않으면 충돌합니다)
  • 홍수 채우기에 대한 재귀를 사용합니다 교육적인 목적으로 만. 대기열을 사용하는 것이 훨씬 더 효율적입니다.
  • 간단한 것은 그것을 시험해보고 작동하는지 확인하는 것입니다!
+0

도움 주셔서 감사합니다. 매우 유용했습니다. 나는 많은 진전을 이루었습니다. 여기에서 후속 질문을 참조 할 수 있습니까? http://stackoverflow.com/questions/16294856/using-recursion-for-3d-array-manipulation-causing-stackoverflow-not-infinite –