Exemple #1
0
  public void wrapJaiWarpPolynomial() {

    logger.info("Start JAI wrapper");

    float[] xyMaster = new float[2 * numObservations];
    float[] xySlave = new float[2 * numObservations];

    // work only with survived points!
    for (int i = 0; i < numObservations; i++) {
      final int j = 2 * i;
      xyMaster[j] = (float) xMaster.getQuick(i);
      xyMaster[j + 1] = (float) yMaster.getQuick(i);

      //            if (!demRefinement) {
      xySlave[j] = (float) (xSlave.getQuick(i));
      xySlave[j + 1] = (float) (ySlave.getQuick(i));
      //            } else {
      //                xySlave[j] = (float) (xSlaveGeometry.getQuick(i));
      //                xySlave[j + 1] = (float) (ySlaveGeometry.getQuick(i));
      //            }
    }

    jaiWarp =
        WarpPolynomial.createWarp(
            xySlave, 0, xyMaster, 0, 2 * numObservations, 1f, 1f, 1f, 1f, cpmDegree);

    float[] xCoefJai_TEMP = jaiWarp.getXCoeffs();
    float[] yCoefJai_TEMP = jaiWarp.getYCoeffs();
    final int size = xCoefJai_TEMP.length;
    xCoefJai = new double[size];
    yCoefJai = new double[size];

    for (int i = 0; i < size; ++i) {
      xCoefJai[i] = xCoefJai_TEMP[i];
      yCoefJai[i] = yCoefJai_TEMP[i];
    }
  }
 /**
  * @param warp
  * @param interpolation
  * @param dstData
  */
 private void warpTransform(WarpPolynomial warp, Interpolation interpolation, RasterData dstData) {
   byte[] pixel = new byte[dstData.getBands() * dstData.getDataType().getSize()];
   float[] srcCoords = new float[dstData.getColumns() * 2];
   for (int y = 0; y < dstData.getRows(); y++) {
     // look-up the pixel positions in the source raster for every pixel in this row, the srcCoords
     // will contain
     // the x,y ([2n],[2n+1]) values in the source raster (defined in the native CRS) for this row
     // of pixels.
     warp.warpRect(0, y, dstData.getColumns(), 1, srcCoords);
     for (int x = 0; x < dstData.getColumns(); x++) {
       // get the interpolated pixel and set the value into the result raster
       interpolation.getPixel(srcCoords[x * 2], srcCoords[x * 2 + 1], pixel);
       dstData.setPixel(x, y, pixel);
     }
   }
 }
  private WarpPolynomial createWarp(
      int dstWidth,
      int dstHeight,
      ICRS srcCRS,
      RasterGeoReference srcREnv,
      RasterGeoReference dstREnv)
      throws TransformationException {
    int k = 0;
    // create/calculate reference points
    float dx = (dstWidth - 1) / (float) (refPointsGridSize - 1);
    float dy = (dstHeight - 1) / (float) (refPointsGridSize - 1);
    float[] srcCoords = new float[refPointsGridSize * refPointsGridSize * 2];
    float[] dstCoords = new float[refPointsGridSize * refPointsGridSize * 2];
    List<Point3d> points = new ArrayList<Point3d>(refPointsGridSize * refPointsGridSize);
    for (int j = 0; j < refPointsGridSize; j++) {
      for (int i = 0; i < refPointsGridSize; i++) {
        dstCoords[k] = i * dx;
        dstCoords[k + 1] = j * dy;
        double[] dstWCoords =
            dstREnv.getWorldCoordinate((int) dstCoords[k], (int) dstCoords[k + 1]);
        points.add(new Point3d(dstWCoords[0], dstWCoords[1], Double.NaN));
        k += 2;
      }
    }
    List<Point3d> resultList = transformDstToSrc(srcCRS, points);

    k = 0;
    for (Point3d point : resultList) {
      double[] srcRCoords = srcREnv.getRasterCoordinateUnrounded(point.x, point.y);
      srcCoords[k] = (float) srcRCoords[0];
      srcCoords[k + 1] = (float) srcRCoords[1];
      k += 2;
    }

    // create a best fit polynomial for out grid
    WarpPolynomial warp =
        WarpPolynomial.createWarp(
            srcCoords, 0, dstCoords, 0, srcCoords.length, 1f, 1f, 1f, 1f, polynomialOrder);
    return warp;
  }