Program: 140907
Project: 140907
Buggy source:
/** 
 * Diffuses the values defined along the lines to the entire destGrid.
 * @param destGrid destination grid
 */
public void diffuse(Grid destGrid){
  float lineValue=0;
  float leftSideMaskValue=1;
  float rightSideMaskValue=2;
  if (lines == null) {
    JOptionPane.showMessageDialog(null,"String_Node_Str","String_Node_Str",JOptionPane.ERROR_MESSAGE);
    return;
  }
  Grid linesMaskGrid=Grid.shallowCopy(destGrid);
  linesMaskGrid.fill(Float.NaN);
  drawLinesToGrid(linesMaskGrid,true,lineValue,true);
  int nbrLines=lines.getNumGeometries();
  double west=destGrid.getWest();
  double north=destGrid.getNorth();
  double cellSize=destGrid.getCellSize();
  int nCols=destGrid.getCols();
  int nRows=destGrid.getRows();
  for (int lineID=0; lineID < nbrLines; lineID++) {
    LineString ridgeline=(LineString)lines.getGeometryN(lineID);
    for (int pointID=1; pointID < ridgeline.getNumPoints() - 1; pointID++) {
      Point currentPoint=ridgeline.getPointN(pointID);
      Point nextPoint=ridgeline.getPointN(pointID + 1);
      Point prevPoint=ridgeline.getPointN(pointID - 1);
      float color=leftSideMaskValue;
      final int prevID;
      int currentCol=(int)((currentPoint.getX() - west) / cellSize);
      int currentRow=(int)((north - currentPoint.getY()) / cellSize);
      int nextCol=(int)((nextPoint.getX() - west) / cellSize);
      int nextRow=(int)((north - nextPoint.getY()) / cellSize);
      int prevCol=(int)((prevPoint.getX() - west) / cellSize);
      int prevRow=(int)((north - prevPoint.getY()) / cellSize);
      int dx=prevCol - currentCol;
      int dy=prevRow - currentRow;
      prevID=ID[dy + 1][dx + 1];
      for (int i=prevID + 1; i < prevID + 7; i++) {
        int c=currentCol + DX[i];
        int r=currentRow + DY[i];
        if (c == nextCol && r == nextRow) {
          color=rightSideMaskValue;
        }
 else {
          boolean insideGrid=c >= 0 && r >= 0 && c < nCols && r < nRows;
          if (insideGrid && linesMaskGrid.getValue(c,r) != lineValue) {
            linesMaskGrid.setValue(color,c,r);
          }
        }
      }
    }
  }
  linesMaskGrid=new DilationOperator(leftSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new DilationOperator(rightSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new DilationOperator(leftSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new DilationOperator(rightSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new ReplaceValueOperator(lineValue,rightSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new DilationOperator(leftSideMaskValue).operate(linesMaskGrid);
  Grid rightSideGrid=Grid.shallowCopy(linesMaskGrid);
  rightSideGrid.fill(Float.NaN);
  drawLinesToGrid(rightSideGrid,false,-1,true);
  Grid leftSideGrid=Grid.shallowCopy(linesMaskGrid);
  leftSideGrid.fill(Float.NaN);
  drawLinesToGrid(leftSideGrid,false,-1,false);
  Grid linesGrid=Grid.shallowCopy(linesMaskGrid);
  linesGrid.fill(Float.NaN);
  new MeanFilter(linesMaskGrid,rightSideMaskValue).operate(rightSideGrid,linesGrid);
  new MeanFilter(linesMaskGrid,leftSideMaskValue).operate(leftSideGrid,linesGrid);
  int smoothingIterations=100;
  linesGrid=new MultigridDiffusor(smoothingIterations).diffuse(linesGrid);
  new CopyOperator().operate(linesGrid,destGrid);
}

Fixed version (ground truth):
/** 
 * Diffuses the values defined along the lines to the entire destGrid.
 * @param destGrid destination grid
 */
public void diffuse(Grid destGrid){
  float lineValue=0;
  float leftSideMaskValue=1;
  float rightSideMaskValue=2;
  if (lines == null) {
    throw new IllegalArgumentException("String_Node_Str");
  }
  Grid linesMaskGrid=Grid.shallowCopy(destGrid);
  linesMaskGrid.fill(Float.NaN);
  drawLinesToGrid(linesMaskGrid,true,lineValue,true);
  int nbrLines=lines.getNumGeometries();
  double west=destGrid.getWest();
  double north=destGrid.getNorth();
  double cellSize=destGrid.getCellSize();
  int nCols=destGrid.getCols();
  int nRows=destGrid.getRows();
  for (int lineID=0; lineID < nbrLines; lineID++) {
    LineString ridgeline=(LineString)lines.getGeometryN(lineID);
    for (int pointID=1; pointID < ridgeline.getNumPoints() - 1; pointID++) {
      Point currentPoint=ridgeline.getPointN(pointID);
      Point nextPoint=ridgeline.getPointN(pointID + 1);
      Point prevPoint=ridgeline.getPointN(pointID - 1);
      float color=leftSideMaskValue;
      final int prevID;
      int currentCol=(int)((currentPoint.getX() - west) / cellSize);
      int currentRow=(int)((north - currentPoint.getY()) / cellSize);
      int nextCol=(int)((nextPoint.getX() - west) / cellSize);
      int nextRow=(int)((north - nextPoint.getY()) / cellSize);
      int prevCol=(int)((prevPoint.getX() - west) / cellSize);
      int prevRow=(int)((north - prevPoint.getY()) / cellSize);
      int dx=prevCol - currentCol;
      int dy=prevRow - currentRow;
      prevID=ID[dy + 1][dx + 1];
      for (int i=prevID + 1; i < prevID + 7; i++) {
        int c=currentCol + DX[i];
        int r=currentRow + DY[i];
        if (c == nextCol && r == nextRow) {
          color=rightSideMaskValue;
        }
 else {
          boolean insideGrid=c >= 0 && r >= 0 && c < nCols && r < nRows;
          if (insideGrid && linesMaskGrid.getValue(c,r) != lineValue) {
            linesMaskGrid.setValue(color,c,r);
          }
        }
      }
    }
  }
  linesMaskGrid=new DilationOperator(leftSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new DilationOperator(rightSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new DilationOperator(leftSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new DilationOperator(rightSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new ReplaceValueOperator(lineValue,rightSideMaskValue).operate(linesMaskGrid);
  linesMaskGrid=new DilationOperator(leftSideMaskValue).operate(linesMaskGrid);
  Grid rightSideGrid=Grid.shallowCopy(linesMaskGrid);
  rightSideGrid.fill(Float.NaN);
  drawLinesToGrid(rightSideGrid,false,-1,true);
  Grid leftSideGrid=Grid.shallowCopy(linesMaskGrid);
  leftSideGrid.fill(Float.NaN);
  drawLinesToGrid(leftSideGrid,false,-1,false);
  Grid linesGrid=Grid.shallowCopy(linesMaskGrid);
  linesGrid.fill(Float.NaN);
  new MeanFilter(linesMaskGrid,rightSideMaskValue).operate(rightSideGrid,linesGrid);
  new MeanFilter(linesMaskGrid,leftSideMaskValue).operate(leftSideGrid,linesGrid);
  int smoothingIterations=100;
  linesGrid=new MultigridDiffusor(smoothingIterations).diffuse(linesGrid);
  new CopyOperator().operate(linesGrid,destGrid);
}