Program: 43066
Project: 43066
Buggy source:
/** 
 * Generate X3D binary geometry from the specificed parameters.
 * @param params The parameters
 * @param os The stream to write out the file.
 */
public void generate(Map<String,Object> params,OutputStream os) throws IOException {
  pullParams(params);
  if (geometry.equalsIgnoreCase("String_Node_Str")) {
    if (bodyWidth > bodyHeight) {
      bodyWidth=bodyHeight;
    }
 else {
      bodyHeight=bodyWidth;
    }
  }
  double max_width=bodyWidth * 1.2;
  double max_height=(bodyHeight + bailOuterRadius) * 1.2;
  double max_depth=0;
  if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
    max_depth=2 * bodyImageDepth + bodyDepth;
  }
 else {
    if (Math.abs(bodyImageDepth) > bodyDepth) {
      max_depth=Math.abs(bodyImageDepth) * 1.2;
    }
 else {
      max_depth=bodyDepth * 1.2;
    }
  }
  if (geometry.equalsIgnoreCase("String_Node_Str")) {
    double max=max_width;
    if (max_height > max)     max=max_height;
    if (max_depth > max)     max=max_depth;
    max_width=max;
    max_height=max;
    max_depth=max;
  }
  boolean bigIndex=false;
  int voxelsX=(int)Math.ceil(max_width / resolution);
  int voxelsY=(int)Math.ceil(max_height / resolution);
  int voxelsZ=(int)Math.ceil(max_depth / resolution);
  if ((long)voxelsX * voxelsY * voxelsZ > Math.pow(2,31)) {
    bigIndex=true;
  }
  System.out.println("String_Node_Str" + voxelsX + "String_Node_Str"+ voxelsY+ "String_Node_Str"+ voxelsZ);
  Grid grid=null;
  if (bigIndex) {
    grid=new ArrayGridByteIndexLong(voxelsX,voxelsY,voxelsZ,resolution,resolution);
  }
 else {
    grid=new ArrayGridByte(voxelsX,voxelsY,voxelsZ,resolution,resolution);
  }
  if (DEBUG_LEVEL > 0)   grid=new RangeCheckWrapper(grid);
  double body_cx=max_width / 2.0;
  double body_cy=max_height / 2.0;
  double body_cz=max_depth / 2.0;
  int mat=1;
  if (geometry.equalsIgnoreCase("String_Node_Str")) {
    createCube(grid,body_cx,body_cy,body_cz,bodyWidth,bodyHeight,bodyDepth,mat);
  }
 else   if (geometry.equalsIgnoreCase("String_Node_Str")) {
    System.out.println("String_Node_Str" + body_cx + "String_Node_Str"+ body_cy+ "String_Node_Str"+ body_cz);
    grid=new RangeCheckWrapper(grid);
    createCylinder(grid,body_cx,body_cy,body_cz,1,0,0,1.57075,bodyDepth,bodyWidth / 2.0f,64,mat);
  }
  int bodyWidthPixels=(int)Math.ceil(bodyWidth / resolution);
  int bodyHeightPixels=(int)Math.ceil(bodyHeight / resolution);
  int bodyDepthPixels=(int)Math.ceil(bodyDepth / resolution);
  System.out.println("String_Node_Str" + bodyWidthPixels + "String_Node_Str"+ bodyHeightPixels+ "String_Node_Str"+ bodyDepthPixels);
  int bodyImageMarginWidthPixels=(int)Math.ceil(minWallThickness / resolution);
  int bodyImageMarginHeightPixels=(int)Math.ceil(minWallThickness / resolution);
  System.out.println("String_Node_Str" + bodyImageMarginWidthPixels);
  int bodyImageWidthPixels=0;
  int bodyImageHeightPixels=0;
  int picTxPixels=0;
  int picTyPixels=0;
  int picTzPixels=0;
  int bodyImageDepthPixels=0;
  if (geometry.equalsIgnoreCase("String_Node_Str")) {
    bodyImageWidthPixels=bodyWidthPixels - 2 * bodyImageMarginWidthPixels;
    bodyImageHeightPixels=bodyHeightPixels - 2 * bodyImageMarginHeightPixels;
    picTxPixels=((int)Math.ceil((body_cx - bodyWidth / 2.0) / resolution)) + bodyImageMarginWidthPixels;
    picTyPixels=((int)Math.ceil((body_cy - bodyHeight / 2.0) / resolution)) + bodyImageMarginHeightPixels;
    if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
      picTzPixels=(int)((body_cz + bodyDepth / 2.0) / resolution);
      bodyImageDepthPixels=(int)Math.ceil(bodyImageDepth / resolution);
    }
 else {
      picTzPixels=0;
      bodyImageDepthPixels=(int)Math.ceil(max_depth / resolution);
    }
    System.out.println("String_Node_Str" + picTxPixels + "String_Node_Str"+ picTyPixels+ "String_Node_Str"+ picTzPixels);
  }
 else   if (geometry.equalsIgnoreCase("String_Node_Str")) {
    double radius=bodyWidth / 2.0;
    if (bodyImageType.equalsIgnoreCase("String_Node_Str")) {
      bodyImageWidthPixels=(int)(2 * Math.floor((((radius - minWallThickness) * Math.sin(0.785398163)) / resolution)));
      bodyImageHeightPixels=bodyImageWidthPixels;
      picTxPixels=(int)((body_cx - ((radius - minWallThickness) * Math.sin(0.785398163))) / resolution);
      picTyPixels=(int)((body_cy - ((radius - minWallThickness) * Math.sin(0.785398163))) / resolution);
      if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
        picTzPixels=(int)((body_cz + bodyDepth / 2.0) / resolution);
        bodyImageDepthPixels=(int)Math.ceil(bodyImageDepth / resolution);
      }
 else {
        picTzPixels=0;
        bodyImageDepthPixels=(int)Math.ceil(max_depth / resolution);
      }
    }
 else     if (bodyImageType.equalsIgnoreCase("String_Node_Str")) {
      bodyImageWidthPixels=(int)(2 * Math.floor((((radius - minWallThickness)) / resolution)));
      bodyImageHeightPixels=bodyImageWidthPixels;
      picTxPixels=(int)((body_cx - ((radius - minWallThickness))) / resolution);
      picTyPixels=(int)((body_cy - ((radius - minWallThickness))) / resolution);
      if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
        picTzPixels=(int)((body_cz + bodyDepth / 2.0) / resolution);
        bodyImageDepthPixels=(int)Math.ceil(bodyImageDepth / resolution);
      }
 else {
        picTzPixels=0;
        bodyImageDepthPixels=(int)Math.ceil(max_depth / resolution);
      }
    }
  }
 else   if (geometry.equalsIgnoreCase("String_Node_Str")) {
    bodyImageWidthPixels=bodyWidthPixels;
    bodyImageHeightPixels=bodyHeightPixels;
    picTxPixels=((int)Math.ceil((body_cx - bodyWidth / 2.0) / resolution));
    picTyPixels=((int)Math.ceil((body_cy - bodyHeight / 2.0) / resolution));
    picTzPixels=0;
    bodyImageDepthPixels=(int)Math.ceil(bodyImageDepth / resolution);
  }
  int threshold=75;
  boolean removeStray=true;
  Grid grid2=null;
  Grid grid3=null;
  Operation op=null;
  if (!filename.equalsIgnoreCase("String_Node_Str")) {
    BufferedImage image=ImageIO.read(new File(filename));
    grid2=grid.createEmpty(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
    if (DEBUG_LEVEL > 0)     grid2=new RangeCheckWrapper(grid2);
    System.out.println("String_Node_Str" + picTxPixels + "String_Node_Str"+ picTyPixels+ "String_Node_Str"+ picTzPixels);
    System.out.println("String_Node_Str" + bodyImageWidthPixels + "String_Node_Str"+ bodyImageHeightPixels+ "String_Node_Str"+ ((int)Math.abs(bodyImageDepthPixels)));
    op=new ApplyImage(image,picTxPixels,picTyPixels,picTzPixels,bodyImageWidthPixels,bodyImageHeightPixels,threshold,invert,bodyImageDepthPixels,removeStray,mat);
    op.execute(grid2);
    if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
      op=new Subtract(grid2,0,0,0,1);
    }
 else     op=new Union(grid2,0,0,0,1);
    op.execute(grid);
  }
  if (bailStyle.equalsIgnoreCase("String_Node_Str")) {
    double bail_tx=bodyWidth / 2.0f;
    double bail_ty=bodyHeight;
    double bail_tz=bodyDepth / 2.0f;
    System.out.println("String_Node_Str" + bail_tx + "String_Node_Str"+ bail_ty+ "String_Node_Str"+ bail_tz);
    bail_tx=body_cx;
    bail_ty=body_cy + bodyHeight / 2.0;
    bail_tz=body_cz;
    System.out.println("String_Node_Str" + bail_tx + "String_Node_Str"+ bail_ty+ "String_Node_Str"+ bail_tz);
    grid2=grid.createEmpty(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
    if (DEBUG_LEVEL > 0)     grid2=new RangeCheckWrapper(grid2);
    createTorus(grid2,bail_tx,bail_ty,bail_tz,1,0,0,1.5707f,bailInnerRadius,bailOuterRadius,64,mat,true);
    grid3=grid.createEmpty(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
    if (geometry.equalsIgnoreCase("String_Node_Str")) {
      createCube(grid3,bail_tx,bail_ty - (bailOuterRadius + bailInnerRadius) / 2.0 - bailInnerRadius,bail_tz,(bailOuterRadius + bailInnerRadius) * 2,(bailOuterRadius + bailInnerRadius),bodyDepth,mat);
    }
 else {
      createCube(grid3,bail_tx,bail_ty - (bailOuterRadius + bailInnerRadius) / 2.0,bail_tz,(bailOuterRadius + bailInnerRadius) * 2,(bailOuterRadius + bailInnerRadius),bodyDepth,mat);
    }
    op=new Subtract(grid3,0,0,0,1);
    op.execute(grid2);
    op=new Union(grid2,0,0,0,1);
    op.execute(grid);
  }
  if (1 == 0) {
    System.out.println("String_Node_Str");
    grid2=new OctreeGridByte(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
    Operation op2=new Copy(grid2,0,0,0);
    op2.execute(grid);
    grid=grid2;
  }
  System.out.println("String_Node_Str");
  try {
    ErrorReporter console=new PlainTextErrorReporter();
    write(grid,"String_Node_Str",os,console);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}

Fixed version (ground truth):
/** 
 * Generate X3D binary geometry from the specificed parameters.
 * @param params The parameters
 * @param os The stream to write out the file.
 */
public void generate(Map<String,Object> params,OutputStream os) throws IOException {
  pullParams(params);
  if (geometry.equalsIgnoreCase("String_Node_Str")) {
    if (bodyWidth > bodyHeight) {
      bodyHeight=bodyWidth;
    }
 else {
      bodyWidth=bodyHeight;
    }
  }
  double max_width=bodyWidth * 1.2;
  double max_height=(bodyHeight + bailOuterRadius) * 1.2;
  double max_depth=0;
  if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
    max_depth=2 * bodyImageDepth + bodyDepth;
  }
 else {
    if (Math.abs(bodyImageDepth) > bodyDepth) {
      max_depth=Math.abs(bodyImageDepth) * 1.2;
    }
 else {
      max_depth=bodyDepth * 1.2;
    }
  }
  if (geometry.equalsIgnoreCase("String_Node_Str")) {
    double max=max_width;
    if (max_height > max)     max=max_height;
    if (max_depth > max)     max=max_depth;
    max_width=max;
    max_height=max;
    max_depth=max;
  }
  boolean bigIndex=false;
  int voxelsX=(int)Math.ceil(max_width / resolution);
  int voxelsY=(int)Math.ceil(max_height / resolution);
  int voxelsZ=(int)Math.ceil(max_depth / resolution);
  if ((long)voxelsX * voxelsY * voxelsZ > Math.pow(2,31)) {
    bigIndex=true;
  }
  System.out.println("String_Node_Str" + voxelsX + "String_Node_Str"+ voxelsY+ "String_Node_Str"+ voxelsZ);
  Grid grid=null;
  if (bigIndex) {
    grid=new ArrayGridByteIndexLong(voxelsX,voxelsY,voxelsZ,resolution,resolution);
  }
 else {
    grid=new ArrayGridByte(voxelsX,voxelsY,voxelsZ,resolution,resolution);
  }
  if (DEBUG_LEVEL > 0)   grid=new RangeCheckWrapper(grid);
  double body_cx=max_width / 2.0;
  double body_cy=max_height / 2.0;
  double body_cz=max_depth / 2.0;
  int mat=1;
  if (geometry.equalsIgnoreCase("String_Node_Str")) {
    createCube(grid,body_cx,body_cy,body_cz,bodyWidth,bodyHeight,bodyDepth,mat);
  }
 else   if (geometry.equalsIgnoreCase("String_Node_Str")) {
    System.out.println("String_Node_Str" + body_cx + "String_Node_Str"+ body_cy+ "String_Node_Str"+ body_cz);
    grid=new RangeCheckWrapper(grid);
    createCylinder(grid,body_cx,body_cy,body_cz,1,0,0,1.57075,bodyDepth,bodyWidth / 2.0f,64,mat);
  }
  int bodyWidthPixels=(int)Math.ceil(bodyWidth / resolution);
  int bodyHeightPixels=(int)Math.ceil(bodyHeight / resolution);
  int bodyDepthPixels=(int)Math.ceil(bodyDepth / resolution);
  System.out.println("String_Node_Str" + bodyWidthPixels + "String_Node_Str"+ bodyHeightPixels+ "String_Node_Str"+ bodyDepthPixels);
  int bodyImageMarginWidthPixels=(int)Math.ceil(minWallThickness / resolution);
  int bodyImageMarginHeightPixels=(int)Math.ceil(minWallThickness / resolution);
  System.out.println("String_Node_Str" + bodyImageMarginWidthPixels);
  int bodyImageWidthPixels=0;
  int bodyImageHeightPixels=0;
  int picTxPixels=0;
  int picTyPixels=0;
  int picTzPixels=0;
  int bodyImageDepthPixels=0;
  if (geometry.equalsIgnoreCase("String_Node_Str")) {
    bodyImageWidthPixels=bodyWidthPixels - 2 * bodyImageMarginWidthPixels;
    bodyImageHeightPixels=bodyHeightPixels - 2 * bodyImageMarginHeightPixels;
    picTxPixels=((int)Math.ceil((body_cx - bodyWidth / 2.0) / resolution)) + bodyImageMarginWidthPixels;
    picTyPixels=((int)Math.ceil((body_cy - bodyHeight / 2.0) / resolution)) + bodyImageMarginHeightPixels;
    if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
      picTzPixels=(int)((body_cz + bodyDepth / 2.0) / resolution);
      bodyImageDepthPixels=(int)Math.ceil(bodyImageDepth / resolution);
    }
 else {
      picTzPixels=0;
      bodyImageDepthPixels=(int)Math.ceil(max_depth / resolution);
    }
    System.out.println("String_Node_Str" + picTxPixels + "String_Node_Str"+ picTyPixels+ "String_Node_Str"+ picTzPixels);
  }
 else   if (geometry.equalsIgnoreCase("String_Node_Str")) {
    double radius=bodyWidth / 2.0;
    if (bodyImageType.equalsIgnoreCase("String_Node_Str")) {
      bodyImageWidthPixels=(int)(2 * Math.floor((((radius - minWallThickness) * Math.sin(0.785398163)) / resolution)));
      bodyImageHeightPixels=bodyImageWidthPixels;
      picTxPixels=(int)((body_cx - ((radius - minWallThickness) * Math.sin(0.785398163))) / resolution);
      picTyPixels=(int)((body_cy - ((radius - minWallThickness) * Math.sin(0.785398163))) / resolution);
      if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
        picTzPixels=(int)((body_cz + bodyDepth / 2.0) / resolution);
        bodyImageDepthPixels=(int)Math.ceil(bodyImageDepth / resolution);
      }
 else {
        picTzPixels=0;
        bodyImageDepthPixels=(int)Math.ceil(max_depth / resolution);
      }
    }
 else     if (bodyImageType.equalsIgnoreCase("String_Node_Str")) {
      bodyImageWidthPixels=(int)(2 * Math.floor((((radius - minWallThickness)) / resolution)));
      bodyImageHeightPixels=bodyImageWidthPixels;
      picTxPixels=(int)((body_cx - ((radius - minWallThickness))) / resolution);
      picTyPixels=(int)((body_cy - ((radius - minWallThickness))) / resolution);
      if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
        picTzPixels=(int)((body_cz + bodyDepth / 2.0) / resolution);
        bodyImageDepthPixels=(int)Math.ceil(bodyImageDepth / resolution);
      }
 else {
        picTzPixels=0;
        bodyImageDepthPixels=(int)Math.ceil(max_depth / resolution);
      }
    }
  }
 else   if (geometry.equalsIgnoreCase("String_Node_Str")) {
    bodyImageWidthPixels=bodyWidthPixels;
    bodyImageHeightPixels=bodyHeightPixels;
    picTxPixels=((int)Math.ceil((body_cx - bodyWidth / 2.0) / resolution));
    picTyPixels=((int)Math.ceil((body_cy - bodyHeight / 2.0) / resolution));
    picTzPixels=0;
    bodyImageDepthPixels=(int)Math.ceil(bodyImageDepth / resolution);
    bodyImageStyle="String_Node_Str";
  }
  int threshold=75;
  boolean removeStray=true;
  Grid grid2=null;
  Grid grid3=null;
  Operation op=null;
  if (!filename.equalsIgnoreCase("String_Node_Str")) {
    BufferedImage image=ImageIO.read(new File(filename));
    grid2=grid.createEmpty(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
    if (DEBUG_LEVEL > 0)     grid2=new RangeCheckWrapper(grid2);
    System.out.println("String_Node_Str" + picTxPixels + "String_Node_Str"+ picTyPixels+ "String_Node_Str"+ picTzPixels);
    System.out.println("String_Node_Str" + bodyImageWidthPixels + "String_Node_Str"+ bodyImageHeightPixels+ "String_Node_Str"+ ((int)Math.abs(bodyImageDepthPixels)));
    op=new ApplyImage(image,picTxPixels,picTyPixels,picTzPixels,bodyImageWidthPixels,bodyImageHeightPixels,threshold,invert,bodyImageDepthPixels,removeStray,mat);
    op.execute(grid2);
    if (bodyImageStyle.equalsIgnoreCase("String_Node_Str")) {
      op=new Subtract(grid2,0,0,0,1);
    }
 else     op=new Union(grid2,0,0,0,1);
    op.execute(grid);
  }
  if (bailStyle.equalsIgnoreCase("String_Node_Str")) {
    double bail_tx=bodyWidth / 2.0f;
    double bail_ty=bodyHeight;
    double bail_tz=bodyDepth / 2.0f;
    System.out.println("String_Node_Str" + bail_tx + "String_Node_Str"+ bail_ty+ "String_Node_Str"+ bail_tz);
    bail_tx=body_cx;
    bail_ty=body_cy + bodyHeight / 2.0;
    bail_tz=body_cz;
    System.out.println("String_Node_Str" + bail_tx + "String_Node_Str"+ bail_ty+ "String_Node_Str"+ bail_tz);
    grid2=grid.createEmpty(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
    if (DEBUG_LEVEL > 0)     grid2=new RangeCheckWrapper(grid2);
    createTorus(grid2,bail_tx,bail_ty,bail_tz,1,0,0,1.5707f,bailInnerRadius,bailOuterRadius,64,mat,true);
    grid3=grid.createEmpty(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
    if (geometry.equalsIgnoreCase("String_Node_Str")) {
      createCube(grid3,bail_tx,bail_ty - (bailOuterRadius + bailInnerRadius) / 2.0 - bailInnerRadius,bail_tz,(bailOuterRadius + bailInnerRadius) * 2,(bailOuterRadius + bailInnerRadius),bodyDepth,mat);
    }
 else {
      createCube(grid3,bail_tx,bail_ty - (bailOuterRadius + bailInnerRadius) / 2.0,bail_tz,(bailOuterRadius + bailInnerRadius) * 2,(bailOuterRadius + bailInnerRadius),bodyDepth,mat);
    }
    op=new Subtract(grid3,0,0,0,1);
    op.execute(grid2);
    op=new Union(grid2,0,0,0,1);
    op.execute(grid);
  }
  if (1 == 0) {
    System.out.println("String_Node_Str");
    grid2=new OctreeGridByte(grid.getWidth(),grid.getHeight(),grid.getDepth(),grid.getVoxelSize(),grid.getSliceHeight());
    Operation op2=new Copy(grid2,0,0,0);
    op2.execute(grid);
    grid=grid2;
  }
  System.out.println("String_Node_Str");
  try {
    ErrorReporter console=new PlainTextErrorReporter();
    write(grid,"String_Node_Str",os,console);
  }
 catch (  Exception e) {
    e.printStackTrace();
  }
}