Ejemplo n.º 1
0
  /**
   * Perform decomposition for given tile.
   *
   * @param targetBand The target band.
   * @param targetTile The current tile associated with the target band to be computed.
   * @throws OperatorException If an error occurs during computation of the filtered value.
   */
  public void computeTile(final Band targetBand, final Tile targetTile) {
    PolBandUtils.PolSourceBand srcBandList = bandMap.get(targetBand);

    if (!clusterCentersComputed) {
      computeTerrainClusterCenters(srcBandList, op);
    }

    final Rectangle targetRectangle = targetTile.getRectangle();
    final int x0 = targetRectangle.x;
    final int y0 = targetRectangle.y;
    final int w = targetRectangle.width;
    final int h = targetRectangle.height;
    final int maxY = y0 + h;
    final int maxX = x0 + w;
    final ProductData targetData = targetTile.getDataBuffer();
    final TileIndex trgIndex = new TileIndex(targetTile);
    // System.out.println("x0 = " + x0 + ", y0 = " + y0 + ", w = " + w + ", h = " + h);

    for (int y = y0; y < maxY; ++y) {
      trgIndex.calculateStride(y);
      for (int x = x0; x < maxX; ++x) {
        targetData.setElemIntAt(trgIndex.getIndex(x), getOutputClusterIndex(x, y));
      }
    }
  }
Ejemplo n.º 2
0
  @Override
  public void computeTile(Band band, Tile targetTile, ProgressMonitor pm) throws OperatorException {

    ProductData dataBuffer = targetTile.getRawSamples();
    Rectangle rectangle = targetTile.getRectangle();
    try {
      productReader.readBandRasterData(
          band, rectangle.x, rectangle.y, rectangle.width, rectangle.height, dataBuffer, pm);
      targetTile.setRawSamples(dataBuffer);
    } catch (IOException e) {
      throw new OperatorException(e);
    }
  }
  /**
   * Called by the framework in order to compute a tile for the given target band.
   *
   * <p>The default implementation throws a runtime exception with the message "not implemented".
   *
   * @param targetBand The target band.
   * @param targetTile The current tile associated with the target band to be computed.
   * @param pm A progress monitor which should be used to determine computation cancelation
   *     requests.
   * @throws OperatorException If an error occurs during computation of the target raster.
   */
  @Override
  public void computeTile(Band targetBand, Tile targetTile, ProgressMonitor pm)
      throws OperatorException {

    try {
      final Band sourceBand = sourceProduct.getBand(targetBand.getName());
      final Tile srcTile = getSourceTile(sourceBand, targetTile.getRectangle());

      final Stx stx = sourceBand.getStx();
      double origMin = stx.getMinimum();
      double origMax = stx.getMaximum();
      ScalingType scaling = verifyScaling(targetScaling, dataType);

      final double newMin = getMin(dataType);
      final double newMax = getMax(dataType);
      final double newRange = newMax - newMin;

      if (origMax <= newMax
          && origMin >= newMin
          && sourceBand.getDataType() < ProductData.TYPE_FLOAT32) scaling = ScalingType.NONE;

      final ProductData srcData = srcTile.getRawSamples();
      final ProductData dstData = targetTile.getRawSamples();

      final double srcNoDataValue = sourceBand.getNoDataValue();
      final double destNoDataValue = targetBand.getNoDataValue();

      if (scaling == ScalingType.LINEAR_PEAK_CLIPPED) {
        final Histogram histogram = new Histogram(stx.getHistogramBins(), origMin, origMax);
        final int[] bitCounts = histogram.getBinCounts();
        double rightPct = 0.025;
        for (int i = bitCounts.length - 1; i > 0; --i) {
          if (bitCounts[i] > 10) {
            rightPct = i / (double) bitCounts.length;
            break;
          }
        }
        final Range autoStretchRange = histogram.findRange(0.025, rightPct);
        origMin = autoStretchRange.getMin();
        origMax = autoStretchRange.getMax();
      } else if (scaling == ScalingType.LINEAR_CLIPPED) {
        final Histogram histogram = new Histogram(stx.getHistogramBins(), origMin, origMax);
        final Range autoStretchRange = histogram.findRangeFor95Percent();
        origMin = autoStretchRange.getMin();
        origMax = autoStretchRange.getMax();
      }
      final double origRange = origMax - origMin;

      final int numElem = dstData.getNumElems();
      double srcValue;
      for (int i = 0; i < numElem; ++i) {
        srcValue = srcData.getElemDoubleAt(i);
        if (srcValue == srcNoDataValue) {
          dstData.setElemDoubleAt(i, destNoDataValue);
        } else {
          if (scaling == ScalingType.NONE) dstData.setElemDoubleAt(i, srcValue);
          else if (scaling == ScalingType.TRUNC)
            dstData.setElemDoubleAt(i, truncate(srcValue, newMin, newMax));
          else if (scaling == ScalingType.LOGARITHMIC)
            dstData.setElemDoubleAt(i, logScale(srcValue, origMin, newMin, origRange, newRange));
          else {
            if (srcValue > origMax) srcValue = origMax;
            if (srcValue < origMin) srcValue = origMin;
            dstData.setElemDoubleAt(i, scale(srcValue, origMin, newMin, origRange, newRange));
          }
        }
      }

      targetTile.setRawSamples(dstData);
    } catch (Exception e) {
      throw new OperatorException(e.getMessage());
    }
  }