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;
          }
        }
      }
    }
  }
  /** Proceso de calculo de la transformación tasseeledCap */
  public void process() throws InterruptedException {
    if (!exec) return;
    setBuffer();
    GridExtent layerExtent = new GridExtent(rasterSE.getFullRasterExtent(), rasterSE.getCellSize());

    // TODO: Tipo salida float
    rasterResult =
        RasterBuffer.getBuffer(
            IBuffer.TYPE_FLOAT,
            layerExtent.getNX(),
            layerExtent.getNY(),
            matrixParams.length,
            true);

    // Algoritmo TasseledCap. Trasformacion
    double valor = 0;
    int iNX = layerExtent.getNX();
    int iNY = layerExtent.getNY();

    // BUFFER TYPE_BYTE
    if (buffer.getDataType() == IBuffer.TYPE_BYTE) {
      for (int i = 0; i < iNY; i++) {
        for (int j = 0; j < iNX; j++) {
          for (int k = 0; k < matrixParams.length; k++) {
            for (int s = 0; s < matrixParams[0].length; s++) {
              valor += (double) (buffer.getElemByte(i, j, s) & 0xff) * matrixParams[k][s];
            }
            rasterResult.setElem(i, j, k, (float) valor);
            valor = 0;
          }
        }
        percent = (int) (i * 100 / iNY);
      }
    }

    // BUFFER TYPE_SHORT
    if (buffer.getDataType() == IBuffer.TYPE_SHORT) {
      for (int i = 0; i < iNY; i++) {
        for (int j = 0; j < iNX; j++) {
          for (int k = 0; k < matrixParams.length; k++) {
            for (int s = 0; s < matrixParams[0].length; s++) {
              valor += (double) buffer.getElemShort(i, j, s) * matrixParams[k][s];
            }
            rasterResult.setElem(i, j, k, (float) valor);
            valor = 0;
          }
        }
        percent = (int) (i * 100 / iNY);
      }
    }

    // BUFFER TYPE INT
    if (buffer.getDataType() == IBuffer.TYPE_INT) {
      for (int i = 0; i < iNY; i++) {
        for (int j = 0; j < iNX; j++) {
          for (int k = 0; k < matrixParams.length; k++) {
            for (int s = 0; s < matrixParams[0].length; s++) {
              valor += (double) buffer.getElemInt(i, j, s) * matrixParams[k][s];
            }
            rasterResult.setElem(i, j, k, (float) valor);
            valor = 0;
          }
        }
        percent = (int) (i * 100 / iNY);
      }
    }

    // BUFFER TYPE FLOAT
    if (buffer.getDataType() == IBuffer.TYPE_FLOAT) {
      for (int i = 0; i < iNY; i++) {
        for (int j = 0; j < iNX; j++) {
          for (int k = 0; k < matrixParams.length; k++) {
            for (int s = 0; s < matrixParams[0].length; s++) {
              valor += (double) buffer.getElemFloat(i, j, s) * matrixParams[k][s];
            }
            rasterResult.setElem(i, j, k, (float) valor);
            valor = 0;
          }
        }
        percent = (int) (i * 100 / iNY);
      }
    }

    // BUFFER TYPE DOUBLE
    if (buffer.getDataType() == IBuffer.TYPE_DOUBLE) {
      for (int i = 0; i < iNY; i++) {
        for (int j = 0; j < iNX; j++) {
          for (int k = 0; k < matrixParams.length; k++) {
            for (int s = 0; s < matrixParams[0].length; s++) {
              valor += (double) buffer.getElemDouble(i, j, s) * matrixParams[k][s];
            }
            rasterResult.setElem(i, j, k, (float) valor);
            valor = 0;
          }
        }
        percent = (int) (i * 100 / iNY);
      }
    }

    // Escritura del resultado en disco
    GeoRasterWriter grw = null;
    writerBufferServer = new WriterBufferServer(rasterResult);

    if (fileName == null) return;

    int endIndex = fileName.lastIndexOf(".");
    if (endIndex < 0) endIndex = fileName.length();

    try {
      grw =
          GeoRasterWriter.getWriter(
              writerBufferServer,
              fileName,
              rasterResult.getBandCount(),
              aTransform,
              rasterResult.getWidth(),
              rasterResult.getHeight(),
              rasterResult.getDataType(),
              GeoRasterWriter.getWriter(fileName).getParams(),
              null);
      grw.dataWrite();
      grw.setWkt(rasterSE.getWktProjection());
      grw.writeClose();
      rasterResult.free();
      tasseledCapFinalize(fileName);
    } catch (NotSupportedExtensionException e1) {
      RasterToolsUtil.messageBoxError(
          PluginServices.getText(this, "error_writer_notsupportedextension"), this, e1);
    } catch (RasterDriverException e1) {
      e1.printStackTrace();
    } catch (IOException e) {
      RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e);
    } catch (InterruptedException e) {
      Thread.currentThread().interrupt();
    }
  }