Program: 11477
Project: 11477
Buggy source:
/** 
 * Called by the framework in order to compute the stack of tiles for the given target bands. <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 * @param targetTiles     The current tiles to be computed for each target band.
 * @param targetRectangle The area in pixel coordinates to be computed (same for all rasters in <code>targetRasters</code>).
 * @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 rasters.
 */
@Override public void computeTileStack(Map<Band,Tile> targetTiles,Rectangle targetRectangle,ProgressMonitor pm) throws OperatorException {
  try {
    processingStarted=true;
    try {
      if (!isElevationModelAvailable) {
        getElevationModel();
      }
    }
 catch (    Exception e) {
      throw new OperatorException(e);
    }
    final int x0=targetRectangle.x;
    final int y0=targetRectangle.y;
    final int w=targetRectangle.width;
    final int h=targetRectangle.height;
    final TileGeoreferencing tileGeoRef=new TileGeoreferencing(targetProduct,x0 - 1,y0 - 1,w + 2,h + 2);
    double[][] localDEM=new double[h + 2][w + 2];
    if (useAvgSceneHeight) {
      DEMFactory.fillDEM(localDEM,avgSceneHeight);
    }
 else {
      final boolean valid=DEMFactory.getLocalDEM(dem,demNoDataValue,demResamplingMethod,tileGeoRef,x0,y0,w,h,sourceProduct,nodataValueAtSea,localDEM);
      if (!valid && nodataValueAtSea)       return;
    }
    final GeoPos geoPos=new GeoPos();
    final PosVector earthPoint=new PosVector();
    final PosVector sensorPos=new PosVector();
    final int srcMaxRange=sourceImageWidth - 1;
    final int srcMaxAzimuth=sourceImageHeight - 1;
    ProductData demBuffer=null;
    ProductData latBuffer=null;
    ProductData lonBuffer=null;
    ProductData localIncidenceAngleBuffer=null;
    ProductData projectedLocalIncidenceAngleBuffer=null;
    ProductData incidenceAngleFromEllipsoidBuffer=null;
    final List<TileData> trgTileList=new ArrayList<>();
    final Set<Band> keySet=targetTiles.keySet();
    for (    Band targetBand : keySet) {
      if (targetBand.getName().equals("String_Node_Str")) {
        demBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        latBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        lonBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        localIncidenceAngleBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        projectedLocalIncidenceAngleBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        incidenceAngleFromEllipsoidBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      final Band[] srcBands=targetBandNameToSourceBand.get(targetBand.getName());
      final TileData td=new TileData(targetTiles.get(targetBand),srcBands,isPolsar,targetBand.getName(),getBandUnit(targetBand.getName()),absRoot,calibrator,imgResampling);
      td.applyRadiometricNormalization=targetBandApplyRadiometricNormalizationFlag.get(targetBand.getName());
      td.applyRetroCalibration=targetBandApplyRetroCalibrationFlag.get(targetBand.getName());
      trgTileList.add(td);
    }
    final int maxY=y0 + h;
    final int maxX=x0 + w;
    final TileData[] trgTiles=trgTileList.toArray(new TileData[trgTileList.size()]);
    final EarthGravitationalModel96 egm=EarthGravitationalModel96.instance();
    int diffLat=Math.abs(latitude.getPixelInt(0,0) - latitude.getPixelInt(0,targetImageHeight));
    for (int y=y0; y < maxY; y++) {
      final int yy=y - y0 + 1;
      for (int x=x0; x < maxX; x++) {
        final int index=trgTiles[0].targetTile.getDataBufferIndex(x,y);
        double alt=localDEM[yy][x - x0 + 1];
        if (alt == demNoDataValue && !useAvgSceneHeight) {
          if (nodataValueAtSea) {
            continue;
          }
        }
        tileGeoRef.getGeoPos(x,y,geoPos);
        final double lat=geoPos.lat;
        double lon=geoPos.lon;
        if (lon >= 180.0) {
          lon-=360.0;
        }
        if (alt == demNoDataValue && !nodataValueAtSea) {
          alt=egm.getEGM(lat,lon);
        }
        GeoUtils.geo2xyzWGS84(lat,lon,alt,earthPoint);
        double zeroDopplerTime=SARGeocoding.getEarthPointZeroDopplerTime(firstLineUTC,lineTimeInterval,wavelength,earthPoint,orbit.sensorPosition,orbit.sensorVelocity);
        if (Double.compare(zeroDopplerTime,SARGeocoding.NonValidZeroDopplerTime) == 0) {
          if (saveDEM) {
            demBuffer.setElemDoubleAt(index,demNoDataValue);
          }
          continue;
        }
        double slantRange=SARGeocoding.computeSlantRange(zeroDopplerTime,orbit,earthPoint,sensorPos);
        if (!skipBistaticCorrection) {
          zeroDopplerTime+=slantRange / Constants.lightSpeedInMetersPerDay;
          slantRange=SARGeocoding.computeSlantRange(zeroDopplerTime,orbit,earthPoint,sensorPos);
        }
        double rangeIndex=SARGeocoding.computeRangeIndex(srgrFlag,sourceImageWidth,firstLineUTC,lastLineUTC,rangeSpacing,zeroDopplerTime,slantRange,nearEdgeSlantRange,srgrConvParams);
        if (rangeIndex == -1.0) {
          if (saveDEM) {
            demBuffer.setElemDoubleAt(index,demNoDataValue);
          }
          continue;
        }
        if (!nearRangeOnLeft) {
          rangeIndex=srcMaxRange - rangeIndex;
        }
        final double azimuthIndex=(zeroDopplerTime - firstLineUTC) / lineTimeInterval;
        if (!SARGeocoding.isValidCell(rangeIndex,azimuthIndex,lat,lon,diffLat,latitude,longitude,srcMaxRange,srcMaxAzimuth,sensorPos)) {
          if (saveDEM) {
            demBuffer.setElemDoubleAt(index,demNoDataValue);
          }
        }
 else {
          final double[] localIncidenceAngles={SARGeocoding.NonValidIncidenceAngle,SARGeocoding.NonValidIncidenceAngle};
          if (saveLocalIncidenceAngle || saveProjectedLocalIncidenceAngle || saveSigmaNought) {
            final LocalGeometry localGeometry=new LocalGeometry(x,y,tileGeoRef,earthPoint,sensorPos);
            SARGeocoding.computeLocalIncidenceAngle(localGeometry,demNoDataValue,saveLocalIncidenceAngle,saveProjectedLocalIncidenceAngle,saveSigmaNought,x0,y0,x,y,localDEM,localIncidenceAngles);
            if (saveLocalIncidenceAngle && localIncidenceAngles[0] != SARGeocoding.NonValidIncidenceAngle) {
              localIncidenceAngleBuffer.setElemDoubleAt(index,localIncidenceAngles[0]);
            }
            if (saveProjectedLocalIncidenceAngle && localIncidenceAngles[1] != SARGeocoding.NonValidIncidenceAngle) {
              projectedLocalIncidenceAngleBuffer.setElemDoubleAt(index,localIncidenceAngles[1]);
            }
          }
          if (saveDEM) {
            demBuffer.setElemDoubleAt(index,alt);
          }
          if (saveLatLon) {
            latBuffer.setElemDoubleAt(index,lat);
            lonBuffer.setElemDoubleAt(index,lon);
          }
          if (saveIncidenceAngleFromEllipsoid && incidenceAngle != null) {
            incidenceAngleFromEllipsoidBuffer.setElemDoubleAt(index,incidenceAngle.getPixelDouble(rangeIndex,azimuthIndex));
          }
          double satelliteHeight=0;
          double sceneToEarthCentre=0;
          if (saveSigmaNought) {
            satelliteHeight=Math.sqrt(sensorPos.x * sensorPos.x + sensorPos.y * sensorPos.y + sensorPos.z * sensorPos.z);
            sceneToEarthCentre=Math.sqrt(earthPoint.x * earthPoint.x + earthPoint.y * earthPoint.y + earthPoint.z * earthPoint.z);
          }
          for (          TileData tileData : trgTiles) {
            int[] subSwathIndex={INVALID_SUB_SWATH_INDEX};
            double v=getPixelValue(azimuthIndex,rangeIndex,tileData,subSwathIndex);
            if (v != tileData.noDataValue && tileData.applyRadiometricNormalization) {
              if (localIncidenceAngles[1] != SARGeocoding.NonValidIncidenceAngle) {
                v=calibrator.applyCalibration(v,rangeIndex,azimuthIndex,slantRange,satelliteHeight,sceneToEarthCentre,localIncidenceAngles[1],tileData.bandPolar,tileData.bandUnit,subSwathIndex);
              }
 else {
                v=tileData.noDataValue;
              }
            }
            tileData.tileDataBuffer.setElemDoubleAt(index,v);
          }
          orthoDataProduced=true;
        }
      }
    }
    localDEM=null;
  }
 catch (  Throwable e) {
    orthoDataProduced=true;
    OperatorUtils.catchOperatorException(getId(),e);
  }
}

Fixed version (ground truth):
/** 
 * Called by the framework in order to compute the stack of tiles for the given target bands. <p>The default implementation throws a runtime exception with the message "not implemented".</p>
 * @param targetTiles     The current tiles to be computed for each target band.
 * @param targetRectangle The area in pixel coordinates to be computed (same for all rasters in <code>targetRasters</code>).
 * @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 rasters.
 */
@Override public void computeTileStack(Map<Band,Tile> targetTiles,Rectangle targetRectangle,ProgressMonitor pm) throws OperatorException {
  try {
    processingStarted=true;
    try {
      if (!isElevationModelAvailable) {
        getElevationModel();
      }
    }
 catch (    Exception e) {
      throw new OperatorException(e);
    }
    final int x0=targetRectangle.x;
    final int y0=targetRectangle.y;
    final int w=targetRectangle.width;
    final int h=targetRectangle.height;
    final TileGeoreferencing tileGeoRef=new TileGeoreferencing(targetProduct,x0 - 1,y0 - 1,w + 2,h + 2);
    double[][] localDEM=new double[h + 2][w + 2];
    if (useAvgSceneHeight) {
      DEMFactory.fillDEM(localDEM,avgSceneHeight);
    }
 else {
      final boolean valid=DEMFactory.getLocalDEM(dem,demNoDataValue,demResamplingMethod,tileGeoRef,x0,y0,w,h,sourceProduct,nodataValueAtSea,localDEM);
      if (!valid && nodataValueAtSea)       return;
    }
    final GeoPos geoPos=new GeoPos();
    final PosVector earthPoint=new PosVector();
    final PosVector sensorPos=new PosVector();
    final int srcMaxRange=sourceImageWidth - 1;
    final int srcMaxAzimuth=sourceImageHeight - 1;
    ProductData demBuffer=null;
    ProductData latBuffer=null;
    ProductData lonBuffer=null;
    ProductData localIncidenceAngleBuffer=null;
    ProductData projectedLocalIncidenceAngleBuffer=null;
    ProductData incidenceAngleFromEllipsoidBuffer=null;
    final List<TileData> trgTileList=new ArrayList<>();
    final Set<Band> keySet=targetTiles.keySet();
    for (    Band targetBand : keySet) {
      if (targetBand.getName().equals("String_Node_Str")) {
        demBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        latBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        lonBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        localIncidenceAngleBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        projectedLocalIncidenceAngleBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      if (targetBand.getName().equals("String_Node_Str")) {
        incidenceAngleFromEllipsoidBuffer=targetTiles.get(targetBand).getDataBuffer();
        continue;
      }
      final Band[] srcBands=targetBandNameToSourceBand.get(targetBand.getName());
      final TileData td=new TileData(targetTiles.get(targetBand),srcBands,isPolsar,targetBand.getName(),getBandUnit(targetBand.getName()),absRoot,calibrator,imgResampling);
      td.applyRadiometricNormalization=targetBandApplyRadiometricNormalizationFlag.get(targetBand.getName());
      td.applyRetroCalibration=targetBandApplyRetroCalibrationFlag.get(targetBand.getName());
      trgTileList.add(td);
    }
    final int maxY=y0 + h;
    final int maxX=x0 + w;
    final TileData[] trgTiles=trgTileList.toArray(new TileData[trgTileList.size()]);
    final EarthGravitationalModel96 egm=EarthGravitationalModel96.instance();
    int diffLat=Math.abs(latitude.getPixelInt(0,0) - latitude.getPixelInt(0,targetImageHeight));
    for (int y=y0; y < maxY; y++) {
      final int yy=y - y0 + 1;
      for (int x=x0; x < maxX; x++) {
        final int index=trgTiles[0].targetTile.getDataBufferIndex(x,y);
        double alt=localDEM[yy][x - x0 + 1];
        if (alt == demNoDataValue && !useAvgSceneHeight) {
          if (nodataValueAtSea) {
            continue;
          }
        }
        tileGeoRef.getGeoPos(x,y,geoPos);
        final double lat=geoPos.lat;
        double lon=geoPos.lon;
        if (lon >= 180.0) {
          lon-=360.0;
        }
        if (alt == demNoDataValue && !nodataValueAtSea) {
          alt=egm.getEGM(lat,lon);
        }
        GeoUtils.geo2xyzWGS84(lat,lon,alt,earthPoint);
        double zeroDopplerTime=SARGeocoding.getEarthPointZeroDopplerTime(firstLineUTC,lineTimeInterval,wavelength,earthPoint,orbit.sensorPosition,orbit.sensorVelocity);
        if (Double.compare(zeroDopplerTime,SARGeocoding.NonValidZeroDopplerTime) == 0) {
          if (saveDEM) {
            demBuffer.setElemDoubleAt(index,demNoDataValue);
          }
          continue;
        }
        double slantRange=SARGeocoding.computeSlantRange(zeroDopplerTime,orbit,earthPoint,sensorPos);
        if (!skipBistaticCorrection) {
          zeroDopplerTime+=slantRange / Constants.lightSpeedInMetersPerDay;
          slantRange=SARGeocoding.computeSlantRange(zeroDopplerTime,orbit,earthPoint,sensorPos);
        }
        double rangeIndex=SARGeocoding.computeRangeIndex(srgrFlag,sourceImageWidth,firstLineUTC,lastLineUTC,rangeSpacing,zeroDopplerTime,slantRange,nearEdgeSlantRange,srgrConvParams);
        if (rangeIndex == -1.0) {
          if (saveDEM) {
            demBuffer.setElemDoubleAt(index,demNoDataValue);
          }
          continue;
        }
        if (!nearRangeOnLeft) {
          rangeIndex=srcMaxRange - rangeIndex;
        }
        final double azimuthIndex=(zeroDopplerTime - firstLineUTC) / lineTimeInterval;
        if (!SARGeocoding.isValidCell(rangeIndex,azimuthIndex,lat,lon,diffLat,latitude,longitude,srcMaxRange,srcMaxAzimuth,sensorPos)) {
          if (saveDEM) {
            demBuffer.setElemDoubleAt(index,demNoDataValue);
          }
        }
 else {
          final double[] localIncidenceAngles={SARGeocoding.NonValidIncidenceAngle,SARGeocoding.NonValidIncidenceAngle};
          if (saveLocalIncidenceAngle || saveProjectedLocalIncidenceAngle || saveSigmaNought) {
            final LocalGeometry localGeometry=new LocalGeometry(x,y,tileGeoRef,earthPoint,sensorPos);
            SARGeocoding.computeLocalIncidenceAngle(localGeometry,demNoDataValue,saveLocalIncidenceAngle,saveProjectedLocalIncidenceAngle,saveSigmaNought,x0,y0,x,y,localDEM,localIncidenceAngles);
            if (saveLocalIncidenceAngle && localIncidenceAngles[0] != SARGeocoding.NonValidIncidenceAngle) {
              localIncidenceAngleBuffer.setElemDoubleAt(index,localIncidenceAngles[0]);
            }
            if (saveProjectedLocalIncidenceAngle && localIncidenceAngles[1] != SARGeocoding.NonValidIncidenceAngle) {
              projectedLocalIncidenceAngleBuffer.setElemDoubleAt(index,localIncidenceAngles[1]);
            }
          }
          if (saveDEM) {
            demBuffer.setElemDoubleAt(index,alt);
          }
          if (saveLatLon) {
            latBuffer.setElemDoubleAt(index,lat);
            lonBuffer.setElemDoubleAt(index,lon);
          }
          if (saveIncidenceAngleFromEllipsoid && incidenceAngle != null) {
            incidenceAngleFromEllipsoidBuffer.setElemDoubleAt(index,incidenceAngle.getPixelDouble(rangeIndex,azimuthIndex));
          }
          double satelliteHeight=0;
          double sceneToEarthCentre=0;
          if (saveSigmaNought) {
            satelliteHeight=Math.sqrt(sensorPos.x * sensorPos.x + sensorPos.y * sensorPos.y + sensorPos.z * sensorPos.z);
            sceneToEarthCentre=Math.sqrt(earthPoint.x * earthPoint.x + earthPoint.y * earthPoint.y + earthPoint.z * earthPoint.z);
          }
          for (          TileData tileData : trgTiles) {
            int[] subSwathIndex={INVALID_SUB_SWATH_INDEX};
            double v=getPixelValue(azimuthIndex,rangeIndex,tileData,subSwathIndex);
            if (v != tileData.noDataValue && tileData.applyRadiometricNormalization) {
              if (localIncidenceAngles[1] != SARGeocoding.NonValidIncidenceAngle) {
                v=calibrator.applyCalibration(v,rangeIndex,azimuthIndex,slantRange,satelliteHeight,sceneToEarthCentre,localIncidenceAngles[1],tileData.bandName,tileData.bandPolar,tileData.bandUnit,subSwathIndex);
              }
 else {
                v=tileData.noDataValue;
              }
            }
            tileData.tileDataBuffer.setElemDoubleAt(index,v);
          }
          orthoDataProduced=true;
        }
      }
    }
    localDEM=null;
  }
 catch (  Throwable e) {
    orthoDataProduced=true;
    OperatorUtils.catchOperatorException(getId(),e);
  }
}