Пример #1
0
 private void copyBand(String name) {
   Band sourceBand = getSourceProduct().getBand(name);
   Band targetBand = ProductUtils.copyBand(name, getSourceProduct(), getTargetProduct());
   targetBand.setSourceImage(sourceBand.getSourceImage());
   maybeCopyFlagCoding(sourceBand, targetBand);
   maybeCopyIndexCoding(sourceBand, targetBand);
 }
Пример #2
0
  /** Calls the given handler for all frames of the product the operator executor product. */
  public Object execute(Handler handler) throws Exception {
    int parallelism = Runtime.getRuntime().availableProcessors();
    System.out.println("parallelism = " + parallelism);
    JAI.getDefaultInstance().getTileScheduler().setParallelism(parallelism);
    Dimension frameSize = getFrameSize();
    int numXFrames = 1 + (product.getSceneRasterWidth() - 1) / frameSize.width;
    int numYFrames = 1 + (product.getSceneRasterHeight() - 1) / frameSize.height;

    Rectangle sceneRegion =
        new Rectangle(product.getSceneRasterWidth(), product.getSceneRasterHeight());

    for (int frameY = 0; frameY < numYFrames; frameY++) {
      for (int frameX = 0; frameX < numXFrames; frameX++) {

        Rectangle frameRegion =
            new Rectangle(
                    frameX * frameSize.width,
                    frameY * frameSize.height,
                    frameSize.width,
                    frameSize.height)
                .intersection(sceneRegion);

        int numBands = product.getNumBands();
        Band[] bandArray = new Band[numBands];
        ProductData[] dataArray = new ProductData[numBands];
        for (int b = 0; b < numBands; b++) {
          Band band = product.getBandAt(b);
          PlanarImage planarImage = band.getSourceImage();
          Point[] indices = planarImage.getTileIndices(null);
          System.out.println("indices = " + indices.length);
          TileRequest tileRequest = planarImage.queueTiles(indices);
          Raster raster = planarImage.getData();
          System.out.println("raster = " + raster);
          ProductData data = band.createCompatibleRasterData(frameRegion.width, frameRegion.height);
          band.readRasterData(
              frameRegion.x, frameRegion.y, frameRegion.width, frameRegion.height, data);
          bandArray[b] = band;
          dataArray[b] = data;
        }

        MyFrame frame = new MyFrame(frameRegion, bandArray, dataArray);
        handler.frameComputed(frame);
      }
    }

    return new Object();
  }
  /**
   * This method provides a real tie point grid from a 'tie point band'.
   *
   * @param band - the 'tie point band'
   * @return TiePointGrid
   */
  public static TiePointGrid getTpgFromBand(Band band) {
    final DataBuffer dataBuffer = band.getSourceImage().getData().getDataBuffer();
    float[] tpgData = new float[dataBuffer.getSize()];
    for (int i = 0; i < dataBuffer.getSize(); i++) {
      tpgData[i] = dataBuffer.getElemFloat(i);
    }

    return new TiePointGrid(
        band.getName(),
        band.getSceneRasterWidth(),
        band.getSceneRasterHeight(),
        0.0f,
        0.0f,
        1.0f,
        1.0f,
        tpgData);
  }
  /**
   * This method downscales a band by a given factor
   *
   * @param inputBand - the input band
   * @param scalingFactor - the scaling factor
   * @return Band - the downscaled band
   */
  public static Band downscaleBand(Band inputBand, float scalingFactor) {
    final RenderedImage sourceImage = inputBand.getSourceImage();
    final RenderedOp downscaledImage =
        ScaleDescriptor.create(
            sourceImage,
            1.0f / scalingFactor,
            1.0f / scalingFactor,
            0.0f,
            0.0f,
            Interpolation.getInstance(Interpolation.INTERP_NEAREST),
            null);
    Band downscaledBand =
        new Band(
            inputBand.getName(), inputBand.getDataType(),
            downscaledImage.getWidth(), downscaledImage.getHeight());

    downscaledBand.setSourceImage(downscaledImage);
    return downscaledBand;
  }
 /**
  * This method provides a rescaled tie point grid from a 'tie point band'.
  *
  * @param band - the 'tie point band'
  * @param rescaledWidth - width of the rescaled TPG
  * @param rescaledHeight - height of the rescaled TPG
  * @return TiePointGrid
  */
 public static TiePointGrid getRescaledTpgFromBand(
     Band band, int rescaledWidth, int rescaledHeight) {
   final DataBuffer dataBuffer = band.getSourceImage().getData().getDataBuffer();
   float[] tpgData = new float[rescaledWidth * rescaledHeight];
   if (rescaledWidth * rescaledHeight > band.getSceneRasterWidth() * band.getSceneRasterHeight()) {
     throw new OperatorException("Cannot create TPG - width*height too large.");
   }
   int tpgIndex = 0;
   for (int j = 0; j < rescaledHeight; j++) {
     for (int i = 0; i < rescaledWidth; i++) {
       tpgData[rescaledWidth * j + i] = dataBuffer.getElemFloat(tpgIndex);
       tpgIndex++;
     }
     for (int i = rescaledWidth; i < band.getSceneRasterWidth(); i++) {
       tpgIndex++;
     }
   }
   return new TiePointGrid(
       band.getName(), rescaledWidth, rescaledHeight, 0.0f, 0.0f, 1.0f, 1.0f, tpgData);
 }
 private static void addTpg(Product targetProduct, Band scaledBand, String name) {
   DataBuffer dataBuffer;
   float[] tpgData;
   TiePointGrid tpg;
   dataBuffer = scaledBand.getSourceImage().getData().getDataBuffer();
   tpgData = new float[dataBuffer.getSize()];
   for (int i = 0; i < dataBuffer.getSize(); i++) {
     tpgData[i] = dataBuffer.getElemFloat(i);
   }
   tpg =
       new TiePointGrid(
           name,
           scaledBand.getSceneRasterWidth(),
           scaledBand.getSceneRasterHeight(),
           0.0f,
           0.0f,
           1.0f,
           1.0f,
           tpgData);
   targetProduct.addTiePointGrid(tpg);
 }