From: megacz Date: Wed, 4 Mar 2009 16:08:12 +0000 (-0800) Subject: add Marching Tetrahedrons code X-Git-Url: http://git.megacz.com/?p=anneal.git;a=commitdiff_plain;h=daed1206997768114d9a7ab5d8603e206c0b4a52 add Marching Tetrahedrons code --- diff --git a/src/edu/berkeley/qfat/voxel/MarchingCubes.java b/src/edu/berkeley/qfat/voxel/MarchingCubes.java index 3112d8d..46b83b6 100644 --- a/src/edu/berkeley/qfat/voxel/MarchingCubes.java +++ b/src/edu/berkeley/qfat/voxel/MarchingCubes.java @@ -49,11 +49,11 @@ public class MarchingCubes { (mesh.numTriangles()-initialTriangles) + " triangles"); for(int iY = 0; iY < voxels.getNumSamplesY(); iY++) for(int iZ = 0; iZ < voxels.getNumSamplesZ(); iZ++) - march(voxels, mesh, threshold, - iX*scaleX + voxels.getMinX(), - iY*scaleY + voxels.getMinY(), - iZ*scaleZ + voxels.getMinZ(), - scaleX, scaleY, scaleZ); + /*marchCubes*/marchTetrahedrons(voxels, mesh, threshold, + iX*scaleX + voxels.getMinX(), + iY*scaleY + voxels.getMinY(), + iZ*scaleZ + voxels.getMinZ(), + scaleX, scaleY, scaleZ); } System.out.print("\r"); for(int i=0; i<78; i++) System.out.print(' '); @@ -62,9 +62,9 @@ public class MarchingCubes { } /** performs the Marching Cubes algorithm on a single cube */ - static void march(VoxelData voxels, Mesh mesh, double threshold, - double fX, double fY, double fZ, - double scaleX, double scaleY, double scaleZ) { + static void marchCubes(VoxelData voxels, Mesh mesh, double threshold, + double fX, double fY, double fZ, + double scaleX, double scaleY, double scaleZ) { int iCorner, iVertex, iVertexTest, iEdge, iTriangle, iFlagIndex, iEdgeFlags; double fOffset; GLvector sColor; @@ -110,6 +110,8 @@ public class MarchingCubes { vGetNormal(voxels, asEdgeNorm[iEdge], asEdgeVertex[iEdge].fX, asEdgeVertex[iEdge].fY, asEdgeVertex[iEdge].fZ); } + System.out.println(); + // Draw the triangles that were found. There can be up to five per cube for(iTriangle = 0; iTriangle < 5; iTriangle++) { if(a2iTriangleConnectionTable[iFlagIndex][3*iTriangle] < 0) @@ -132,7 +134,124 @@ public class MarchingCubes { points[1].equals(points[2])) continue; - mesh.newT(points[0], points[1], points[2], norm.norm().times(-1)); + System.out.println("creating triangle: " + points[0] + " " + points[1] + " " + points[2]); + try { + Mesh.T t = mesh.newT(points[0], points[1], points[2], norm.norm().times(-1)); + System.out.println(" created " + t); + } catch (Throwable t) { } + } + } + + /** + * marchTetrahedron performs the Marching Tetrahedrons algorithm + * on a single tetrahedron + */ + static void marchTetrahedron(VoxelData voxels, Mesh mesh, double threshold, + GLvector[] pasTetrahedronPosition, + float[] pafTetrahedronValue, + double scaleX, double scaleY, double scaleZ) { + + int iEdge, iVert0, iVert1, iEdgeFlags, iTriangle, iCorner, iVertex, iFlagIndex = 0; + double fOffset, fInvOffset, fValue = 0.0; + GLvector[] asEdgeVertex = new GLvector[6]; + GLvector[] asEdgeNorm = new GLvector[6]; + GLvector sColor = new GLvector(); + for(int i=0; i