Program: 43064
Project: 43064
Buggy source:
/** 
 * Cast a ray along the specified axis and find interior voxels.
 * @param axis The axis to cast along
 * @param rayX The ray x origin
 * @param rayY The ray y origin
 * @param rayZ The ray z origin
 */
private void findInterior(TunnelRegion.Axis axis,double rayX,double rayY,double rayZ,int[] tris,Grid grid){
  boolean[] t_result=new boolean[numVoxels];
  float[] pos=new float[3];
  float[] workingTri;
  TriangleIntersectionDoubleUtil intersectTester=new TriangleIntersectionDoubleUtil();
  ArrayList hits=new ArrayList(tris.length);
  double rx=rayX;
  double ry=rayY;
  double rz=rayZ;
  for (int j=0; j < tris.length; j++) {
    int id=tris[j];
    workingTri=spatial.getTriangle(id);
switch (axis) {
case X:
      if (intersectTester.xAxisRayTriangle(rx,ry,rz,workingTri)) {
        hits.add(new HitRecord(axis,intersectTester.getLastIntersectionPoint(),rx,ry,rz,workingTri));
      }
    break;
case Y:
  if (intersectTester.yAxisRayTriangle(rx,ry,rz,workingTri)) {
    hits.add(new HitRecord(axis,intersectTester.getLastIntersectionPoint(),rx,ry,rz,workingTri));
  }
break;
case Z:
if (intersectTester.zAxisRayTriangle(rx,ry,rz,workingTri)) {
hits.add(new HitRecord(axis,intersectTester.getLastIntersectionPoint(),rx,ry,rz,workingTri));
}
break;
}
}
Collections.sort(hits);
int hlen=hits.size() - 1;
HitRecord a;
HitRecord b;
int idx=0;
double av;
double bv;
double dist;
double EPSILON=0.00000001;
int[] minCoords=new int[3];
int[] maxCoords=new int[3];
boolean show_details=false;
while (idx < hlen) {
a=(HitRecord)hits.get(idx++);
b=(HitRecord)hits.get(idx++);
av=a.getPosition();
bv=b.getPosition();
dist=bv - av;
if (show_details) {
System.out.println("String_Node_Str" + a);
System.out.println("String_Node_Str" + java.util.Arrays.toString(a.tricoords) + "String_Node_Str");
System.out.println("String_Node_Str" + b);
System.out.println("String_Node_Str" + java.util.Arrays.toString(b.tricoords) + "String_Node_Str");
System.out.println("String_Node_Str" + dist);
}
pos[0]=(float)a.getX();
pos[1]=(float)a.getY();
pos[2]=(float)a.getZ();
spatial.findGridCoordsFromWorldCoords(pos,minCoords);
pos[0]=(float)b.getX();
pos[1]=(float)b.getY();
pos[2]=(float)b.getZ();
spatial.findGridCoordsFromWorldCoords(pos,maxCoords);
switch (axis) {
case X:
minCoords[0]+=1;
maxCoords[0]-=1;
break;
case Y:
minCoords[1]+=1;
maxCoords[1]-=1;
break;
case Z:
minCoords[2]+=1;
maxCoords[2]-=1;
break;
}
fillCells(true,t_result,origin,axis,minCoords,maxCoords);
}
hits.clear();
int[] coords=new int[3];
pos[0]=(float)rayX;
pos[1]=(float)rayY;
pos[2]=(float)rayZ;
spatial.findGridCoordsFromWorldCoords(pos,coords);
if (axis == TunnelRegion.Axis.X) {
int len=t_result.length;
int start=0;
for (int i=start; i < len; i++) {
if (t_result[i] == true) {
result.setData(i - origin[0],coords[1] - origin[1],coords[2] - origin[2],Grid.INTERIOR,result.getMaterial(i - origin[0],coords[1] - origin[1],coords[2] - origin[2]) + 1);
}
}
}
 else if (axis == TunnelRegion.Axis.Y) {
int len=t_result.length;
int start=0;
for (int i=start; i < len; i++) {
if (t_result[i] == true) {
result.setData(coords[0] - origin[0],i - origin[1],coords[2] - origin[2],Grid.INTERIOR,result.getMaterial(coords[0] - origin[0],i - origin[1],coords[2] - origin[2]) + 1);
}
}
}
 else if (axis == TunnelRegion.Axis.Z) {
int len=t_result.length;
int start=0;
for (int i=start; i < len; i++) {
if (t_result[i] == true) {
result.setData(coords[0] - origin[0],coords[1] - origin[1],i - origin[2],Grid.INTERIOR,result.getMaterial(coords[0] - origin[0],coords[1] - origin[1],i - origin[2]) + 1);
}
}
}
}

Fixed version (ground truth):
/** 
 * Cast a ray along the specified axis and find interior voxels.
 * @param axis The axis to cast along
 * @param rayX The ray x origin
 * @param rayY The ray y origin
 * @param rayZ The ray z origin
 */
private void findInterior(TunnelRegion.Axis axis,double rayX,double rayY,double rayZ,int[] tris,Grid grid){
  boolean[] t_result=new boolean[numVoxels];
  float[] pos=new float[3];
  float[] workingTri;
  TriangleIntersectionDoubleUtil intersectTester=new TriangleIntersectionDoubleUtil();
  ArrayList hits=new ArrayList(tris.length);
  double rx=rayX;
  double ry=rayY;
  double rz=rayZ;
  for (int j=0; j < tris.length; j++) {
    int id=tris[j];
    workingTri=spatial.getTriangle(id);
switch (axis) {
case X:
      if (intersectTester.xAxisRayTriangle(rx,ry,rz,workingTri)) {
        hits.add(new HitRecord(axis,intersectTester.getLastIntersectionPoint(),rx,ry,rz,workingTri));
      }
    break;
case Y:
  if (intersectTester.yAxisRayTriangle(rx,ry,rz,workingTri)) {
    hits.add(new HitRecord(axis,intersectTester.getLastIntersectionPoint(),rx,ry,rz,workingTri));
  }
break;
case Z:
if (intersectTester.zAxisRayTriangle(rx,ry,rz,workingTri)) {
hits.add(new HitRecord(axis,intersectTester.getLastIntersectionPoint(),rx,ry,rz,workingTri));
}
break;
}
}
Collections.sort(hits);
int hlen=hits.size() - 1;
HitRecord a;
HitRecord b;
int idx=0;
double av;
double bv;
double dist;
double EPSILON=0.00000001;
int[] minCoords=new int[3];
int[] maxCoords=new int[3];
boolean show_details=false;
while (idx < hlen) {
a=(HitRecord)hits.get(idx++);
b=(HitRecord)hits.get(idx++);
av=a.getPosition();
bv=b.getPosition();
dist=bv - av;
if (show_details) {
System.out.println("String_Node_Str" + a);
System.out.println("String_Node_Str" + java.util.Arrays.toString(a.tricoords) + "String_Node_Str");
System.out.println("String_Node_Str" + b);
System.out.println("String_Node_Str" + java.util.Arrays.toString(b.tricoords) + "String_Node_Str");
System.out.println("String_Node_Str" + dist);
}
pos[0]=(float)a.getX();
pos[1]=(float)a.getY();
pos[2]=(float)a.getZ();
grid.getGridCoords(pos[0],pos[1],pos[2],minCoords);
pos[0]=(float)b.getX();
pos[1]=(float)b.getY();
pos[2]=(float)b.getZ();
grid.getGridCoords(pos[0],pos[1],pos[2],maxCoords);
switch (axis) {
case X:
minCoords[0]+=1;
maxCoords[0]-=1;
break;
case Y:
minCoords[1]+=1;
maxCoords[1]-=1;
break;
case Z:
minCoords[2]+=1;
maxCoords[2]-=1;
break;
}
fillCells(true,t_result,axis,minCoords,maxCoords);
}
hits.clear();
int[] coords=new int[3];
pos[0]=(float)rayX;
pos[1]=(float)rayY;
pos[2]=(float)rayZ;
if (axis == TunnelRegion.Axis.X) {
int len=t_result.length;
int start=0;
grid.getGridCoords(0,pos[1],pos[2],coords);
for (int i=start; i < len; i++) {
if (t_result[i] == true) {
result.setData(i,coords[1],coords[2],Grid.INTERIOR,result.getMaterial(i,coords[1],coords[2]) + 1);
}
}
}
 else if (axis == TunnelRegion.Axis.Y) {
int len=t_result.length;
int start=0;
grid.getGridCoords(pos[0],0,pos[2],coords);
for (int i=start; i < len; i++) {
if (t_result[i] == true) {
result.setData(coords[0],i,coords[2],Grid.INTERIOR,result.getMaterial(coords[0],i,coords[2]) + 1);
}
}
}
 else if (axis == TunnelRegion.Axis.Z) {
int len=t_result.length;
int start=0;
grid.getGridCoords(pos[0],pos[1],0,coords);
for (int i=start; i < len; i++) {
if (t_result[i] == true) {
result.setData(coords[0],coords[1],i,Grid.INTERIOR,result.getMaterial(coords[0],coords[1],i) + 1);
}
}
}
}