Exemple #1
0
  /** Test that ST and MT yield the exact same result */
  public void testMTEquals() {
    int size1 = 10;
    int size2 = 15;
    byte state1 = Grid.INSIDE;
    byte state2 = Grid.INSIDE;

    Grid grid1 = new ArrayGridByte(size1, size1, size1, 0.001, 0.001);
    Grid grid2 = new ArrayGridByte(size2, size2, size2, 0.002, 0.002);
    Grid grid3 = new ArrayGridByte(size2, size2, size2, 0.002, 0.002);

    // set grid1
    for (int x = 3; x < 7; x++) {
      grid1.setState(x, 5, 5, state1);
    }

    // set grid2
    for (int y = 5; y < size2; y++) {
      grid2.setState(1, y, 10, state2);
    }
    // set grid3
    for (int y = 5; y < size2; y++) {
      grid3.setState(1, y, 10, state2);
    }

    // get the subtraction of grid1 from grid2
    SubtractOpMT op = new SubtractOpMT(grid1, Runtime.getRuntime().availableProcessors());
    Grid subtrGridMT = op.execute(grid2);

    SubtractOp op2 = new SubtractOp(grid1, 0, 0, 0, 1);
    Grid subtrGridST = op2.execute(grid2);

    assertEquals(size2, subtrGridST.getWidth());
    assertEquals(size2, subtrGridMT.getWidth());

    // check filled voxel state and material
    for (int x = 0; x < size2; x++) {
      for (int y = 0; y < size2; y++) {
        for (int z = 0; z < size2; z++) {
          assertEquals(
              "(" + x + ", " + y + ", " + z + ") state is not equal",
              subtrGridST.getState(x, y, z),
              subtrGridMT.getState(x, y, z));
        }
      }
    }
  }
  void dumpScanLine(int x, int yy, int z) {

    for (int y = 0; y <= ny1; y++) {

      byte state = grid.getState(x, y, z);
      printf("y: %d, mat: %d\n", y, state);
    }
  }
Exemple #3
0
  /** Grids sharing a voxel coordinate should have those voxels subtracted */
  public void _testSharedVoxelMT() {
    int size1 = 10;
    int size2 = 15;
    byte state1 = Grid.INSIDE;
    byte state2 = Grid.INSIDE;

    Grid grid1 = new ArrayGridByte(size1, size1, size1, 0.001, 0.001);
    Grid grid2 = new ArrayGridByte(size2, size2, size2, 0.002, 0.002);

    // set grid1
    for (int x = 3; x < 7; x++) {
      grid1.setState(x, 5, 5, state1);
    }

    // set grid2
    for (int y = 5; y < size2; y++) {
      grid2.setState(3, y, 5, state2);
    }

    // get the subtration of grid1 from grid2
    SubtractOpMT op = new SubtractOpMT(grid1, Runtime.getRuntime().availableProcessors());
    Grid subtrGrid = (Grid) op.execute(grid2);

    assertEquals(size2, subtrGrid.getWidth());

    // check filled voxel state and material
    for (int x = 0; x < size2; x++) {
      for (int y = 0; y < size2; y++) {
        for (int z = 0; z < size2; z++) {

          if (x == 3 && y >= 6 && y < size2 && z == 5) {
            assertEquals(
                "(" + x + ", " + y + ", " + z + ") state is not " + state2,
                state2,
                subtrGrid.getState(x, y, z));
          } else {
            assertEquals(
                "(" + x + ", " + y + ", " + z + ") state is not outside",
                Grid.OUTSIDE,
                subtrGrid.getState(x, y, z));
          }
        }
      }
    }
  }
Exemple #4
0
  /** Test basic operation */
  public void testBasic() {
    int size1 = 10;
    int size2 = 15;
    byte state1 = Grid.INSIDE;
    byte state2 = Grid.INSIDE;

    Grid grid1 = new ArrayGridByte(size1, size1, size1, 0.001, 0.001);
    Grid grid2 = new ArrayGridByte(size2, size2, size2, 0.002, 0.002);

    // set grid1
    for (int x = 3; x < 7; x++) {
      grid1.setState(x, 5, 5, state1);
    }

    // set grid2
    for (int y = 5; y < size2; y++) {
      grid2.setState(1, y, 10, state2);
    }

    // get the subtraction of grid1 from grid2
    SubtractOp op = new SubtractOp(grid1, 0, 0, 0, 0);
    Grid subtrGrid = (Grid) op.execute(grid2);

    assertEquals(size2, subtrGrid.getWidth());

    // check filled voxel state and material
    for (int x = 0; x < size2; x++) {
      for (int y = 0; y < size2; y++) {
        for (int z = 0; z < size2; z++) {

          if (x == 1 && y >= 5 && y < size2 && z == 10) {
            assertEquals(
                "(" + x + ", " + y + ", " + z + ") state is not " + state2,
                state2,
                subtrGrid.getState(x, y, z));
          } else {
            assertEquals(
                "(" + x + ", " + y + ", " + z + ") state is not outside",
                Grid.OUTSIDE,
                subtrGrid.getState(x, y, z));
          }
        }
      }
    }
  }
  /** return true if voxel is non zero and has given material */
  public static boolean compareState(Grid grid, int x, int y, int z, byte state) {
    byte s = grid.getState(x, y, z);

    return (s == state);
  }
  /** Test basic operation */
  public void testBasic() {
    int size = 10;

    AttributeGrid grid = new ArrayAttributeGridByte(size, size, size, 0.001, 0.001);

    for (int y = 2; y < 8; y++) {
      for (int z = 2; z < 8; z++) {
        setX(grid, y, z, Grid.INSIDE, 1, 2, 7);
      }
    }

    int erosionDistance = 1;

    ErosionCube ec = new ErosionCube(erosionDistance);
    Grid erodedGrid = ec.execute(grid);

    int width = erodedGrid.getWidth();
    int height = erodedGrid.getHeight();
    int depth = erodedGrid.getDepth();
    for (int y = 0; y < height; y++) {
      for (int z = 0; z < depth; z++) {
        for (int x = 0; x < width; x++) {
          byte state = erodedGrid.getState(x, y, z);
          //                    System.out.println(x + ", " + y + ", " + z + ": " + state);

          if (y >= 2 && y < 6) {
            if (z >= 2 && z < 6) {
              if (x >= 2 && x < 6) {
                assertEquals(
                    "State of (" + x + " " + y + " " + z + " is not interior", Grid.INSIDE, state);
              } else {
                assertEquals(
                    "State of (" + x + " " + y + " " + z + " is not outside", Grid.OUTSIDE, state);
              }
            } else {
              assertEquals(
                  "State of (" + x + " " + y + " " + z + " is not outside", Grid.OUTSIDE, state);
            }
          } else {
            assertEquals(
                "State of (" + x + " " + y + " " + z + " is not outside", Grid.OUTSIDE, state);
          }
        }
      }
    }
    /*
            erosionDistance = 2;

            ec = new ErosionCube(erosionDistance);
            erodedGrid = ec.execute(grid);

            width = erodedGrid.getWidth();
            height = erodedGrid.getHeight();
            depth = erodedGrid.getDepth();
            for (int y=0; y<height; y++) {
                for (int z=0; z<depth; z++) {
                    for (int x=0; x<width; x++) {
                        System.out.println(x + ", " + y + ", " + z + ": " + erodedGrid.getState(x, y, z));
                    }
                }
            }
    */
  }