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();
    }
  }
  public void testStack() {
    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(645817.0, 4923851.0, 40, 40);
      dataTest1();
    } catch (RasterDriverException e) {
      e.printStackTrace();
    } catch (InvalidSetViewException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    // print();

    try {
      ds.setAreaOfInterest(645829.8, 4923840.4, 2, 2);
      dataTest2();
    } catch (RasterDriverException e) {
      e.printStackTrace();
    } catch (InvalidSetViewException e) {
      e.printStackTrace();
    } catch (InterruptedException e) {
      e.printStackTrace();
    }

    // print();
  }
  /**
   * 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;
          }
        }
      }
    }
  }