Program: 11450
Project: 11450
Buggy source:
/** 
 * Generate simulated image for normalization.
 * @param x0             X coordinate of the upper left corner pixel of given tile.
 * @param y0             Y coordinate of the upper left corner pixel of given tile.
 * @param w              Width of given tile.
 * @param h              Height of given tile.
 * @param gamma0ReferenceArea The simulated image for flattened gamma0 generation.
 * @param sigma0ReferenceArea The simulated image for flattened sigma0 generation.
 * @return Boolean flag indicating if the simulation is successful.
 */
private boolean generateSimulatedImage(final int x0,final int y0,final int w,final int h,final OverlapPercentage tileOverlapPercentage,final double[][] gamma0ReferenceArea,final double[][] sigma0ReferenceArea){
  try {
    final int ymin=Math.max(y0 - (int)(h * tileOverlapPercentage.tileOverlapUp),0);
    final int ymax=Math.min(y0 + h + (int)(h * tileOverlapPercentage.tileOverlapDown),sourceImageHeight);
    final int xmin=Math.max(x0 - (int)(w * tileOverlapPercentage.tileOverlapLeft),0);
    final int xmax=Math.min(x0 + w + (int)(w * tileOverlapPercentage.tileOverlapRight),sourceImageWidth);
    if (reGridMethod) {
      final double[] latLonMinMax=new double[4];
      computeImageGeoBoundary(xmin,xmax,ymin,ymax,latLonMinMax);
      final double delta=(double)dem.getDescriptor().getTileWidthInDegrees() / (double)dem.getDescriptor().getTileWidth();
      final double extralat=20 * delta;
      final double extralon=20 * delta;
      final double latMin=latLonMinMax[0] - extralat;
      final double latMax=latLonMinMax[1] + extralat;
      final double lonMin=latLonMinMax[2] - extralon;
      final double lonMax=latLonMinMax[3] + extralon;
      final PixelPos upperLeft=dem.getIndex(new GeoPos(latMax,lonMin));
      final PixelPos lowerRight=dem.getIndex(new GeoPos(latMin,lonMax));
      final int latMaxIdx=(int)Math.floor(upperLeft.getY());
      final int latMinIdx=(int)Math.ceil(lowerRight.getY());
      final int lonMinIdx=(int)Math.floor(upperLeft.getX());
      final int lonMaxIdx=(int)Math.ceil(lowerRight.getX());
      final int nLat=latMinIdx - latMaxIdx;
      final int nLon=lonMaxIdx - lonMinIdx;
      final PixelPos pix=new PixelPos();
      final PositionData posData=new PositionData();
      for (int i=0; i < nLat; i++) {
        final double[] azimuthIndex=new double[nLon];
        final double[] rangeIndex=new double[nLon];
        final double[] gamma0Area=new double[nLon];
        final double[] elevationAngle=new double[nLon];
        final boolean[] savePixel=new boolean[nLon];
        double[] sigma0Area=null;
        if (outputSigma0) {
          sigma0Area=new double[nLon];
        }
        for (int j=0; j < nLon; j++) {
          pix.setLocation(lonMinIdx + j,latMaxIdx + i);
          final GeoPos gp=dem.getGeoPos(pix);
          final double alt=dem.getElevation(gp);
          if (alt == demNoDataValue)           continue;
          if (!getPosition(gp.lat,gp.lon,alt,x0,y0,w,h,posData))           continue;
          final LocalGeometry localGeometry=new LocalGeometry(i,j,dem,latMaxIdx,lonMinIdx,posData.earthPoint,posData.sensorPos);
          gamma0Area[j]=computeGamma0Area(localGeometry,demNoDataValue,noDataValue);
          if (gamma0Area[j] == noDataValue)           continue;
          if (outputSigma0) {
            sigma0Area[j]=computeSigma0Area(localGeometry,demNoDataValue,noDataValue);
          }
          elevationAngle[j]=computeElevationAngle(posData.earthPoint,posData.sensorPos);
          rangeIndex[j]=posData.rangeIndex;
          azimuthIndex[j]=posData.azimuthIndex;
          savePixel[j]=rangeIndex[j] > x0 - 1 && rangeIndex[j] < x0 + w && azimuthIndex[j] > y0 - 1 && azimuthIndex[j] < y0 + h;
        }
        if (orbitOnWest) {
          double maxElevAngle=0.0;
          for (int jj=0; jj < nLon; jj++) {
            if (savePixel[jj] && (detectShadow && elevationAngle[jj] >= maxElevAngle || !detectShadow)) {
              maxElevAngle=elevationAngle[jj];
              saveGamma0Area(x0,y0,w,h,gamma0Area[jj],azimuthIndex[jj],rangeIndex[jj],gamma0ReferenceArea);
              if (outputSigma0) {
                saveSigma0Area(x0,y0,w,h,sigma0Area[jj],azimuthIndex[jj],rangeIndex[jj],sigma0ReferenceArea);
              }
            }
          }
        }
 else {
          double maxElevAngle=0.0;
          for (int jj=nLon - 1; jj >= 0; --jj) {
            if (savePixel[jj] && (detectShadow && elevationAngle[jj] >= maxElevAngle || !detectShadow)) {
              maxElevAngle=elevationAngle[jj];
              saveGamma0Area(x0,y0,w,h,gamma0Area[jj],azimuthIndex[jj],rangeIndex[jj],gamma0ReferenceArea);
              if (outputSigma0) {
                saveSigma0Area(x0,y0,w,h,sigma0Area[jj],azimuthIndex[jj],rangeIndex[jj],sigma0ReferenceArea);
              }
            }
          }
        }
      }
    }
 else {
      final int widthExt=xmax - xmin;
      final int heightExt=ymax - ymin;
      final double[][] localDEM=new double[heightExt + 2][widthExt + 2];
      final TileGeoreferencing tileGeoRef=new TileGeoreferencing(targetProduct,xmin,ymin,widthExt,heightExt);
      final boolean valid=DEMFactory.getLocalDEM(dem,demNoDataValue,demResamplingMethod,tileGeoRef,xmin,ymin,widthExt,heightExt,sourceProduct,true,localDEM);
      if (!valid) {
        return false;
      }
      final PositionData posData=new PositionData();
      final GeoPos geoPos=new GeoPos();
      for (int y=ymin; y < ymax; y++) {
        final int yy=y - ymin;
        final double[] azimuthIndex=new double[widthExt];
        final double[] rangeIndex=new double[widthExt];
        final double[] gamma0Area=new double[widthExt];
        final double[] elevationAngle=new double[widthExt];
        final boolean[] savePixel=new boolean[widthExt];
        double[] sigma0Area=null;
        if (outputSigma0) {
          sigma0Area=new double[widthExt];
        }
        for (int x=xmin; x < xmax; x++) {
          final int xx=x - xmin;
          double alt=localDEM[yy + 1][xx + 1];
          if (alt == demNoDataValue)           continue;
          tileGeoRef.getGeoPos(x,y,geoPos);
          if (!geoPos.isValid())           continue;
          double lat=geoPos.lat;
          double lon=geoPos.lon;
          if (lon >= 180.0) {
            lon-=360.0;
          }
          if (!getPosition(lat,lon,alt,x0,y0,w,h,posData))           continue;
          final LocalGeometry localGeometry=new LocalGeometry(xmin,ymin,x,y,tileGeoRef,localDEM,posData.earthPoint,posData.sensorPos);
          gamma0Area[xx]=computeGamma0Area(localGeometry,demNoDataValue,noDataValue);
          if (gamma0Area[xx] == noDataValue)           continue;
          if (outputSigma0) {
            sigma0Area[xx]=computeSigma0Area(localGeometry,demNoDataValue,noDataValue);
          }
          elevationAngle[xx]=computeElevationAngle(posData.earthPoint,posData.sensorPos);
          rangeIndex[xx]=posData.rangeIndex;
          azimuthIndex[xx]=posData.azimuthIndex;
          savePixel[xx]=rangeIndex[xx] > x0 - 1 && rangeIndex[xx] < x0 + w && azimuthIndex[xx] > y0 - 1 && azimuthIndex[xx] < y0 + h;
        }
        if (nearRangeOnLeft) {
          double maxElevAngle=0.0;
          for (int i=0; i < widthExt; i++) {
            if (savePixel[i] && (detectShadow && elevationAngle[i] > maxElevAngle || !detectShadow)) {
              maxElevAngle=elevationAngle[i];
              saveGamma0Area(x0,y0,w,h,gamma0Area[i],azimuthIndex[i],rangeIndex[i],gamma0ReferenceArea);
              if (outputSigma0) {
                saveSigma0Area(x0,y0,w,h,sigma0Area[i],azimuthIndex[i],rangeIndex[i],sigma0ReferenceArea);
              }
            }
          }
        }
 else {
          double maxElevAngle=0.0;
          for (int i=widthExt - 1; i >= 0; --i) {
            if (savePixel[i] && (detectShadow && elevationAngle[i] > maxElevAngle || !detectShadow)) {
              maxElevAngle=elevationAngle[i];
              saveGamma0Area(x0,y0,w,h,gamma0Area[i],azimuthIndex[i],rangeIndex[i],gamma0ReferenceArea);
              if (outputSigma0) {
                saveSigma0Area(x0,y0,w,h,sigma0Area[i],azimuthIndex[i],rangeIndex[i],sigma0ReferenceArea);
              }
            }
          }
        }
      }
    }
  }
 catch (  Throwable e) {
    OperatorUtils.catchOperatorException(getId(),e);
  }
  return true;
}

Fixed version (ground truth):
/** 
 * Generate simulated image for normalization.
 * @param x0             X coordinate of the upper left corner pixel of given tile.
 * @param y0             Y coordinate of the upper left corner pixel of given tile.
 * @param w              Width of given tile.
 * @param h              Height of given tile.
 * @param gamma0ReferenceArea The simulated image for flattened gamma0 generation.
 * @param sigma0ReferenceArea The simulated image for flattened sigma0 generation.
 * @return Boolean flag indicating if the simulation is successful.
 */
private boolean generateSimulatedImage(final int x0,final int y0,final int w,final int h,final OverlapPercentage tileOverlapPercentage,final double[][] gamma0ReferenceArea,final double[][] sigma0ReferenceArea){
  try {
    final int ymin=Math.max(y0 - (int)(h * tileOverlapPercentage.tileOverlapUp),0);
    final int ymax=Math.min(y0 + h + (int)(h * tileOverlapPercentage.tileOverlapDown),sourceImageHeight);
    final int xmin=Math.max(x0 - (int)(w * tileOverlapPercentage.tileOverlapLeft),0);
    final int xmax=Math.min(x0 + w + (int)(w * tileOverlapPercentage.tileOverlapRight),sourceImageWidth);
    if (reGridMethod) {
      final double[] latLonMinMax=new double[4];
      computeImageGeoBoundary(xmin,xmax,ymin,ymax,latLonMinMax);
      final double delta=(double)dem.getDescriptor().getTileWidthInDegrees() / (double)dem.getDescriptor().getTileWidth();
      final double extralat=20 * delta;
      final double extralon=20 * delta;
      final double latMin=latLonMinMax[0] - extralat;
      final double latMax=latLonMinMax[1] + extralat;
      final double lonMin=latLonMinMax[2] - extralon;
      final double lonMax=latLonMinMax[3] + extralon;
      final PixelPos upperLeft=dem.getIndex(new GeoPos(latMax,lonMin));
      final PixelPos lowerRight=dem.getIndex(new GeoPos(latMin,lonMax));
      final int latMaxIdx=(int)Math.floor(upperLeft.getY());
      final int latMinIdx=(int)Math.ceil(lowerRight.getY());
      final int lonMinIdx=(int)Math.floor(upperLeft.getX());
      final int lonMaxIdx=(int)Math.ceil(lowerRight.getX());
      final int nLat=latMinIdx - latMaxIdx;
      final int nLon=lonMaxIdx - lonMinIdx;
      final PixelPos pix=new PixelPos();
      final PositionData posData=new PositionData();
      for (int i=0; i < nLat; i++) {
        final double[] azimuthIndex=new double[nLon];
        final double[] rangeIndex=new double[nLon];
        final double[] gamma0Area=new double[nLon];
        final double[] elevationAngle=new double[nLon];
        final boolean[] savePixel=new boolean[nLon];
        double[] sigma0Area=null;
        if (outputSigma0) {
          sigma0Area=new double[nLon];
        }
        for (int j=0; j < nLon; j++) {
          final double pixelX=lonMinIdx + j;
          final double pixelY=latMaxIdx + i;
          pix.setLocation(pixelX,pixelY);
          final GeoPos gp=dem.getGeoPos(pix);
          final double alt=dem.getSample(pixelX,pixelY);
          if (alt == demNoDataValue)           continue;
          if (!getPosition(gp.lat,gp.lon,alt,x0,y0,w,h,posData))           continue;
          final LocalGeometry localGeometry=new LocalGeometry(pixelX,pixelY,dem,posData.earthPoint,posData.sensorPos);
          gamma0Area[j]=computeGamma0Area(localGeometry,demNoDataValue,noDataValue);
          if (gamma0Area[j] == noDataValue)           continue;
          if (outputSigma0) {
            sigma0Area[j]=computeSigma0Area(localGeometry,demNoDataValue,noDataValue);
          }
          elevationAngle[j]=computeElevationAngle(posData.earthPoint,posData.sensorPos);
          rangeIndex[j]=posData.rangeIndex;
          azimuthIndex[j]=posData.azimuthIndex;
          savePixel[j]=rangeIndex[j] > x0 - 1 && rangeIndex[j] < x0 + w && azimuthIndex[j] > y0 - 1 && azimuthIndex[j] < y0 + h;
        }
        if (orbitOnWest) {
          double maxElevAngle=0.0;
          for (int jj=0; jj < nLon; jj++) {
            if (savePixel[jj] && (detectShadow && elevationAngle[jj] >= maxElevAngle || !detectShadow)) {
              maxElevAngle=elevationAngle[jj];
              saveGamma0Area(x0,y0,w,h,gamma0Area[jj],azimuthIndex[jj],rangeIndex[jj],gamma0ReferenceArea);
              if (outputSigma0) {
                saveSigma0Area(x0,y0,w,h,sigma0Area[jj],azimuthIndex[jj],rangeIndex[jj],sigma0ReferenceArea);
              }
            }
          }
        }
 else {
          double maxElevAngle=0.0;
          for (int jj=nLon - 1; jj >= 0; --jj) {
            if (savePixel[jj] && (detectShadow && elevationAngle[jj] >= maxElevAngle || !detectShadow)) {
              maxElevAngle=elevationAngle[jj];
              saveGamma0Area(x0,y0,w,h,gamma0Area[jj],azimuthIndex[jj],rangeIndex[jj],gamma0ReferenceArea);
              if (outputSigma0) {
                saveSigma0Area(x0,y0,w,h,sigma0Area[jj],azimuthIndex[jj],rangeIndex[jj],sigma0ReferenceArea);
              }
            }
          }
        }
      }
    }
 else {
      final int widthExt=xmax - xmin;
      final int heightExt=ymax - ymin;
      final double[][] localDEM=new double[heightExt + 2][widthExt + 2];
      final TileGeoreferencing tileGeoRef=new TileGeoreferencing(targetProduct,xmin,ymin,widthExt,heightExt);
      final boolean valid=DEMFactory.getLocalDEM(dem,demNoDataValue,demResamplingMethod,tileGeoRef,xmin,ymin,widthExt,heightExt,sourceProduct,true,localDEM);
      if (!valid) {
        return false;
      }
      final PositionData posData=new PositionData();
      final GeoPos geoPos=new GeoPos();
      for (int y=ymin; y < ymax; y++) {
        final int yy=y - ymin;
        final double[] azimuthIndex=new double[widthExt];
        final double[] rangeIndex=new double[widthExt];
        final double[] gamma0Area=new double[widthExt];
        final double[] elevationAngle=new double[widthExt];
        final boolean[] savePixel=new boolean[widthExt];
        double[] sigma0Area=null;
        if (outputSigma0) {
          sigma0Area=new double[widthExt];
        }
        for (int x=xmin; x < xmax; x++) {
          final int xx=x - xmin;
          double alt=localDEM[yy + 1][xx + 1];
          if (alt == demNoDataValue)           continue;
          tileGeoRef.getGeoPos(x,y,geoPos);
          if (!geoPos.isValid())           continue;
          double lat=geoPos.lat;
          double lon=geoPos.lon;
          if (lon >= 180.0) {
            lon-=360.0;
          }
          if (!getPosition(lat,lon,alt,x0,y0,w,h,posData))           continue;
          final LocalGeometry localGeometry=new LocalGeometry(xmin,ymin,x,y,tileGeoRef,localDEM,posData.earthPoint,posData.sensorPos);
          gamma0Area[xx]=computeGamma0Area(localGeometry,demNoDataValue,noDataValue);
          if (gamma0Area[xx] == noDataValue)           continue;
          if (outputSigma0) {
            sigma0Area[xx]=computeSigma0Area(localGeometry,demNoDataValue,noDataValue);
          }
          elevationAngle[xx]=computeElevationAngle(posData.earthPoint,posData.sensorPos);
          rangeIndex[xx]=posData.rangeIndex;
          azimuthIndex[xx]=posData.azimuthIndex;
          savePixel[xx]=rangeIndex[xx] > x0 - 1 && rangeIndex[xx] < x0 + w && azimuthIndex[xx] > y0 - 1 && azimuthIndex[xx] < y0 + h;
        }
        if (nearRangeOnLeft) {
          double maxElevAngle=0.0;
          for (int i=0; i < widthExt; i++) {
            if (savePixel[i] && (detectShadow && elevationAngle[i] > maxElevAngle || !detectShadow)) {
              maxElevAngle=elevationAngle[i];
              saveGamma0Area(x0,y0,w,h,gamma0Area[i],azimuthIndex[i],rangeIndex[i],gamma0ReferenceArea);
              if (outputSigma0) {
                saveSigma0Area(x0,y0,w,h,sigma0Area[i],azimuthIndex[i],rangeIndex[i],sigma0ReferenceArea);
              }
            }
          }
        }
 else {
          double maxElevAngle=0.0;
          for (int i=widthExt - 1; i >= 0; --i) {
            if (savePixel[i] && (detectShadow && elevationAngle[i] > maxElevAngle || !detectShadow)) {
              maxElevAngle=elevationAngle[i];
              saveGamma0Area(x0,y0,w,h,gamma0Area[i],azimuthIndex[i],rangeIndex[i],gamma0ReferenceArea);
              if (outputSigma0) {
                saveSigma0Area(x0,y0,w,h,sigma0Area[i],azimuthIndex[i],rangeIndex[i],sigma0ReferenceArea);
              }
            }
          }
        }
      }
    }
  }
 catch (  Throwable e) {
    OperatorUtils.catchOperatorException(getId(),e);
  }
  return true;
}