adjust MarchingCubes to use sampling fields where positive values are the interior
authormegacz <adam@megacz.com>
Sat, 28 Feb 2009 23:17:30 +0000 (15:17 -0800)
committermegacz <adam@megacz.com>
Sat, 28 Feb 2009 23:17:30 +0000 (15:17 -0800)
src/edu/berkeley/qfat/Main.java
src/edu/berkeley/qfat/voxel/MarchingCubes.java

index bec0cc2..5e1fa0b 100644 (file)
@@ -303,10 +303,10 @@ public class Main extends InteractiveMeshViewer {
                                     x-=0.7;
                                     y-=0.7;
                                     z-=0.7;
                                     x-=0.7;
                                     y-=0.7;
                                     z-=0.7;
-                                    return (float)Math.sqrt(x*x+y*y+z*z);
+                                    return (float)(0.8-Math.sqrt(x*x+y*y+z*z));
                                 }
                             },
                                 }
                             },
-            0.8, 20, 0.1, mesh);
+            0, 20, 0.1, mesh);
         setTile(mesh);
         //fixupTile();
     }
         setTile(mesh);
         //fixupTile();
     }
index bda9531..88adf81 100644 (file)
@@ -35,7 +35,7 @@ public class MarchingCubes {
     };
 
     /** march iterates over the entire dataset, calling vMarchCube on each cube */
     };
 
     /** march iterates over the entire dataset, calling vMarchCube on each cube */
-    public static void march(SampledField sampledField, double targetValue, int iDataSetSize, double fStepSize, Mesh mesh) {
+    public static void march(SampledField sampledField, double threshold, int iDataSetSize, double fStepSize, Mesh mesh) {
         int iX, iY, iZ;
         int initialTriangles = mesh.numTriangles();
         for(iX = 0; iX < iDataSetSize; iX++) {
         int iX, iY, iZ;
         int initialTriangles = mesh.numTriangles();
         for(iX = 0; iX < iDataSetSize; iX++) {
@@ -46,7 +46,7 @@ public class MarchingCubes {
                              (mesh.numTriangles()-initialTriangles) + " triangles");
             for(iY = 0; iY < iDataSetSize; iY++)
                 for(iZ = 0; iZ < iDataSetSize; iZ++)
                              (mesh.numTriangles()-initialTriangles) + " triangles");
             for(iY = 0; iY < iDataSetSize; iY++)
                 for(iZ = 0; iZ < iDataSetSize; iZ++)
-                    march(sampledField, mesh, targetValue, iX*fStepSize, iY*fStepSize, iZ*fStepSize, fStepSize);
+                    march(sampledField, mesh, threshold, iX*fStepSize, iY*fStepSize, iZ*fStepSize, fStepSize);
         }
         System.out.print("\r");
         for(int i=0; i<78; i++) System.out.print(' ');
         }
         System.out.print("\r");
         for(int i=0; i<78; i++) System.out.print(' ');
@@ -55,7 +55,7 @@ public class MarchingCubes {
     }
 
     /** performs the Marching Cubes algorithm on a single cube */
     }
 
     /** performs the Marching Cubes algorithm on a single cube */
-    static void march(SampledField sampledField, Mesh mesh, double targetValue, double fX, double fY, double fZ, double fScale) {
+    static void march(SampledField sampledField, Mesh mesh, double threshold, double fX, double fY, double fZ, double fScale) {
         int iCorner, iVertex, iVertexTest, iEdge, iTriangle, iFlagIndex, iEdgeFlags;
         double fOffset;
         GLvector sColor;
         int iCorner, iVertex, iVertexTest, iEdge, iTriangle, iFlagIndex, iEdgeFlags;
         double fOffset;
         GLvector sColor;
@@ -75,7 +75,7 @@ public class MarchingCubes {
         // Find which vertices are inside of the surface and which are outside
         iFlagIndex = 0;
         for(iVertexTest = 0; iVertexTest < 8; iVertexTest++) {
         // Find which vertices are inside of the surface and which are outside
         iFlagIndex = 0;
         for(iVertexTest = 0; iVertexTest < 8; iVertexTest++) {
-            if (afCubeValue[iVertexTest] <= targetValue) {
+            if (afCubeValue[iVertexTest] >= threshold) {
                 iFlagIndex |= 1<<iVertexTest;
             }
         }
                 iFlagIndex |= 1<<iVertexTest;
             }
         }
@@ -92,7 +92,7 @@ public class MarchingCubes {
             // If there is an intersection on this edge
             if ((iEdgeFlags & (1<<iEdge))==0) continue;
             fOffset = fGetOffset(afCubeValue[ a2iEdgeConnection[iEdge][0] ], 
             // If there is an intersection on this edge
             if ((iEdgeFlags & (1<<iEdge))==0) continue;
             fOffset = fGetOffset(afCubeValue[ a2iEdgeConnection[iEdge][0] ], 
-                                 afCubeValue[ a2iEdgeConnection[iEdge][1] ], targetValue);
+                                 afCubeValue[ a2iEdgeConnection[iEdge][1] ], threshold);
             
             asEdgeVertex[iEdge].fX = fX + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][0]  +  fOffset * a2fEdgeDirection[iEdge][0]) * fScale;
             asEdgeVertex[iEdge].fY = fY + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][1]  +  fOffset * a2fEdgeDirection[iEdge][1]) * fScale;
             
             asEdgeVertex[iEdge].fX = fX + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][0]  +  fOffset * a2fEdgeDirection[iEdge][0]) * fScale;
             asEdgeVertex[iEdge].fY = fY + (a2fVertexOffset[ a2iEdgeConnection[iEdge][0] ][1]  +  fOffset * a2fEdgeDirection[iEdge][1]) * fScale;
@@ -118,7 +118,7 @@ public class MarchingCubes {
             if (points[0].equals(points[1])) continue;
             if (points[0].equals(points[2])) continue;
             if (points[1].equals(points[2])) continue;
             if (points[0].equals(points[1])) continue;
             if (points[0].equals(points[2])) continue;
             if (points[1].equals(points[2])) continue;
-            mesh.newT(points[0], points[1], points[2], norm.norm(), 1);
+            mesh.newT(points[0], points[1], points[2], norm.norm().times(-1));
         }
     }
 
         }
     }