public void setUp() {
    System.err.println("TestBufferInterpolation running...");
    int[] drawableBands = {0, 1, 2};
    try {
      f = RasterDataset.open(null, path);
    } catch (NotSupportedExtensionException e) {
      e.printStackTrace();
      return;
    } catch (RasterDriverException e) {
      e.printStackTrace();
      return;
    }
    ds = new BufferFactory(f);
    ds.setDrawableBands(drawableBands);
    try {
      ds.setAreaOfInterest(0, 0, f.getWidth(), f.getHeight());
    } catch (InvalidSetViewException e1) {
      e1.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (RasterDriverException e) {
      e.printStackTrace();
    }
    RasterBuffer buf = (RasterBuffer) ds.getRasterBuf();

    try {
      IBuffer b1 =
          buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_NearestNeighbour);
      convertBufferToTif(fileNeighbour, f.getAffineTransform(), b1);
      b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_Bilinear);
      convertBufferToTif(fileBilinear, f.getAffineTransform(), b1);
      b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_InverseDistance);
      convertBufferToTif(fileInverseDistance, f.getAffineTransform(), b1);
      b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_BSpline);
      convertBufferToTif(fileBSpline, f.getAffineTransform(), b1);
      b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_BicubicSpline);
      convertBufferToTif(fileBicubicSpline, f.getAffineTransform(), b1);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (RasterDriverException e) {
      e.printStackTrace();
    }
  }
 private void dataTest2() throws InterruptedException {
   IBuffer raster = ds.getRasterBuf();
   // Upper Left
   assertEquals((int) (raster.getElemByte(0, 0, 0) & 0xff), 64);
   assertEquals((int) (raster.getElemByte(0, 0, 1) & 0xff), 81);
   assertEquals((int) (raster.getElemByte(0, 0, 2) & 0xff), 39);
   // Upper Right
   assertEquals((int) (raster.getElemByte(0, 1, 0) & 0xff), 64);
   assertEquals((int) (raster.getElemByte(0, 1, 1) & 0xff), 81);
   assertEquals((int) (raster.getElemByte(0, 1, 2) & 0xff), 39);
   // Lower Left
   assertEquals((int) (raster.getElemByte(1, 0, 0) & 0xff), 64);
   assertEquals((int) (raster.getElemByte(1, 0, 1) & 0xff), 81);
   assertEquals((int) (raster.getElemByte(1, 0, 2) & 0xff), 39);
   // Lower Right
   assertEquals((int) (raster.getElemByte(1, 1, 0) & 0xff), 64);
   assertEquals((int) (raster.getElemByte(1, 1, 1) & 0xff), 81);
   assertEquals((int) (raster.getElemByte(1, 1, 2) & 0xff), 39);
 }
  private void dataTest1() throws InterruptedException {
    IBuffer raster = ds.getRasterBuf();
    // Upper Left
    assertEquals((int) (raster.getElemByte(0, 0, 0) & 0xff), 14);
    assertEquals((int) (raster.getElemByte(0, 0, 1) & 0xff), 14);
    assertEquals((int) (raster.getElemByte(0, 0, 2) & 0xff), 0);
    // Upper Right
    assertEquals((int) (raster.getElemByte(0, 24, 0) & 0xff), 68);
    assertEquals((int) (raster.getElemByte(0, 24, 1) & 0xff), 90);
    assertEquals((int) (raster.getElemByte(0, 24, 2) & 0xff), 52);
    // Lower Left
    assertEquals((int) (raster.getElemByte(23, 0, 0) & 0xff), 129);
    assertEquals((int) (raster.getElemByte(23, 0, 1) & 0xff), 122);
    assertEquals((int) (raster.getElemByte(23, 0, 2) & 0xff), 106);
    // Lower Right
    assertEquals((int) (raster.getElemByte(23, 24, 0) & 0xff), 145);
    assertEquals((int) (raster.getElemByte(23, 24, 1) & 0xff), 140);
    assertEquals((int) (raster.getElemByte(23, 24, 2) & 0xff), 134);

    assertEquals((int) (raster.getElemByte(6, 6, 0) & 0xff), 21);
    assertEquals((int) (raster.getElemByte(6, 6, 1) & 0xff), 37);
    assertEquals((int) (raster.getElemByte(6, 6, 2) & 0xff), 10);

    assertEquals((int) (raster.getElemByte(6, 23, 0) & 0xff), 91);
    assertEquals((int) (raster.getElemByte(6, 23, 1) & 0xff), 105);
    assertEquals((int) (raster.getElemByte(6, 23, 2) & 0xff), 92);

    assertEquals((int) (raster.getElemByte(23, 6, 0) & 0xff), 153);
    assertEquals((int) (raster.getElemByte(23, 6, 1) & 0xff), 133);
    assertEquals((int) (raster.getElemByte(23, 6, 2) & 0xff), 122);

    assertEquals((int) (raster.getElemByte(9, 14, 0) & 0xff), 63);
    assertEquals((int) (raster.getElemByte(9, 14, 1) & 0xff), 69);
    assertEquals((int) (raster.getElemByte(9, 14, 2) & 0xff), 55);

    assertEquals((int) (raster.getElemByte(6, 13, 0) & 0xff), 70);
    assertEquals((int) (raster.getElemByte(6, 13, 1) & 0xff), 78);
    assertEquals((int) (raster.getElemByte(6, 13, 2) & 0xff), 55);
  }
  /**
   * Compara dos ficheros raster
   *
   * @param f1
   * @param f2
   * @throws InterruptedException
   */
  private void compareResult(String f1, String f2) throws InterruptedException {
    int[] drawableBands = {0, 1, 2};
    RasterDataset d1 = null;
    RasterDataset d2 = null;
    try {
      d1 = RasterDataset.open(null, f1);
      d2 = RasterDataset.open(null, f2);
    } catch (NotSupportedExtensionException e) {
      e.printStackTrace();
      return;
    } catch (RasterDriverException e) {
      e.printStackTrace();
      return;
    }
    BufferFactory ds = new BufferFactory(d1);
    ds.setDrawableBands(drawableBands);
    try {
      ds.setAreaOfInterest(0, 0, d1.getWidth(), d1.getHeight());
    } catch (InvalidSetViewException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (RasterDriverException e) {
      e.printStackTrace();
    }
    IBuffer b1 = ds.getRasterBuf();

    ds = new BufferFactory(d2);
    ds.setDrawableBands(drawableBands);
    try {
      ds.setAreaOfInterest(0, 0, d1.getWidth(), d1.getHeight());
    } catch (InvalidSetViewException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (RasterDriverException e) {
      e.printStackTrace();
    }
    IBuffer b2 = ds.getRasterBuf();

    for (int k = 0; k < b1.getBandCount(); k++) {
      for (int i = 0; i < b1.getHeight(); i++) {
        for (int j = 0; j < b1.getWidth(); j++) {
          switch (b1.getDataType()) {
            case IBuffer.TYPE_BYTE:
              assertEquals(b1.getElemByte(i, j, k), b2.getElemByte(i, j, k));
              break;
            case IBuffer.TYPE_SHORT:
              assertEquals(b1.getElemShort(i, j, k), b2.getElemShort(i, j, k));
              break;

            case IBuffer.TYPE_INT:
              assertEquals(b1.getElemInt(i, j, k), b2.getElemInt(i, j, k));
              break;

            case IBuffer.TYPE_FLOAT:
              assertEquals((int) b1.getElemFloat(i, j, k), (int) b2.getElemFloat(i, j, k));
              break;

            case IBuffer.TYPE_DOUBLE:
              assertEquals((int) b1.getElemDouble(i, j, k), (int) b2.getElemDouble(i, j, k));
              break;
          }
        }
      }
    }
  }