Revision: 5191
Author:   hansonr
Date:     2006-05-28 22:35:14 -0700 (Sun, 28 May 2006)
ViewCVS:  http://svn.sourceforge.net/jmol/?rev=5191&view=rev

Log Message:
-----------
bob200603 stronger isosurface interpolation; some extra testing stuff

Modified Paths:
--------------
    branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java
    branches/bob200603/Jmol/src/org/jmol/viewer/Mesh.java
Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java
===================================================================
--- branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java 2006-05-28 
15:55:49 UTC (rev 5190)
+++ branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java 2006-05-29 
05:35:14 UTC (rev 5191)
@@ -188,7 +188,7 @@
       currentMesh.visible = true;
       discardTempData();
       System.out.println("\n"
-          + getJvxlFile(currentMesh, (iHaveColorData ? "mapped" : "")));
+          + getJvxlFile(currentMesh, (isJvxlColorMapped ? "mapped" : "")));
       return;
     }
     if ("plane" == propertyName) {
@@ -247,8 +247,6 @@
   }
 
   boolean isJvxl;
-  int[][] edgeInfo;
-  int edgeCount;
 
   void readData(boolean isMapData) {
     isJvxl = false;
@@ -256,8 +254,8 @@
     if (!isMapData) {
       currentMesh.surfaceData = "";
       currentMesh.edgeData = "";
-      edgeInfo = null;
-      edgeCount = 0;
+      currentMesh.edgeInfo = null;
+      currentMesh.edgeCount = 0;
     }
 
     int nSurfaces = readVolumetricHeader();
@@ -442,7 +440,7 @@
     surfaceData = "";
     strFractionTemp = "";
     fractionData = "";
-    iHaveColorData = false;
+    isJvxlColorMapped = false;
     thisInside = (!isJvxl || thePlane == null);
     nDataPoints = 0;
     int nPointsX = voxelCounts[0];
@@ -499,7 +497,7 @@
       currentMesh.jvxlPlane = thePlane;
     }
     System.out.println("Successfully read " + nPointsX + " x " + nPointsY
-        + " x " + nPointsZ + " data points; " + edgeCount + " edges");
+        + " x " + nPointsZ + " data points; " + currentMesh.edgeCount + " 
edges");
   }
 
   float calcVoxelPlaneDistance(int x, int y, int z) {
@@ -518,7 +516,7 @@
   int nStructureData;
   int nEdgeData;
   int nColorData;
-  boolean iHaveColorData;
+  boolean isJvxlColorMapped;
   float jvxlCutoff;
 
   void readJvxlDefinitionLine(boolean showMsg) throws Exception {
@@ -543,7 +541,7 @@
       }
       System.out.println("plane read: " + thePlane);
     }
-    iHaveColorData = (nColorData > 0);
+    isJvxlColorMapped = (nColorData > 0);
   }
 
   int thisValue;
@@ -607,12 +605,12 @@
       if (isJvxl) {
         readJvxlDefinitionLine(true);
         System.out.println("JVXL skipping: nStructureData=" + nStructureData
-            + " nEdgeData=" + nEdgeData + " iHaveColorData=" + iHaveColorData);
+            + " nEdgeData=" + nEdgeData + " isJvxlColorMapped=" + 
isJvxlColorMapped);
         if (nStructureData > 0)
           skipData(nPoints, true);
         if (nEdgeData > 0)
           skipData(nEdgeData, false);
-        if (iHaveColorData)
+        if (isJvxlColorMapped)
           skipData(nColorData, false);
       } else {
         skipData(nPoints, true);
@@ -726,7 +724,7 @@
           + insideCount + " outsideCount=" + outsideCount + " surfaceCount="
           + surfaceCount + " total="
           + (insideCount + outsideCount + surfaceCount));
-      if (iHaveColorData) {
+      if (isJvxlColorMapped) { 
         fractionPtr = 0;
         setJvxlColixes(currentMesh, "roygb");
         currentMesh.colorData = fractionData;
@@ -810,9 +808,10 @@
       float valueA = vertexValues[vertexA];
       float valueB = vertexValues[vertexB];
       calcVertexPoints(vertexA, vertexB);
-      addEdgeInfo(x, y, z, vertexA, vertexB);
       float fraction = calcSurfacePoint(cutoff, valueA, valueB,
           surfacePoints[iEdge]);
+      //currentMesh.addEdgeInfo(x, y, z, cubeVertexOffsets[vertexA],
+        //  cubeVertexOffsets[vertexB], edgeTypeTable[iEdge], fraction);
       int assocVertex = (fraction < assocCutoff ? -1
           : fraction > 1 - assocCutoff ? 1 : 0);
       String sKey = (assocVertex == 0 ? "" : calcDataKey(x, y, z,
@@ -948,21 +947,6 @@
     voxelOrigin.scaleAdd(z, volumetricVectors[2], voxelOrigin);
   }
 
-  void addEdgeInfo(int x, int y, int z, int vertexA, int vertexB) {
-    if (edgeInfo == null)
-      edgeInfo = new int[256][];
-    else if (edgeCount == edgeInfo.length)
-      edgeInfo = (int[][]) Util.doubleLength(edgeInfo);
-    int i = edgeCount++;
-    edgeInfo[i] = new int[6];
-    edgeInfo[i][0] = x + cubeVertexOffsets[vertexA].x;
-    edgeInfo[i][1] = y + cubeVertexOffsets[vertexA].y;
-    edgeInfo[i][2] = z + cubeVertexOffsets[vertexA].z;
-    edgeInfo[i][3] = x + cubeVertexOffsets[vertexB].x;
-    edgeInfo[i][4] = y + cubeVertexOffsets[vertexB].y;
-    edgeInfo[i][5] = z + cubeVertexOffsets[vertexB].z;
-  }
-
   final static Point3i[] cubeVertexOffsets = { new Point3i(0, 0, 0),
       new Point3i(1, 0, 0), new Point3i(1, 0, 1), new Point3i(0, 0, 1),
       new Point3i(0, 1, 0), new Point3i(1, 1, 0), new Point3i(1, 1, 1),
@@ -991,6 +975,35 @@
     return v;
   }
 
+  /*                     Y 
+   *                      4 --------4--------- 5  
+   *                     /|                   /|
+   *                    / |                  / |
+   *                   /  |                 /  |
+   *                  7   8                5   |
+   *                 /    |               /    9
+   *                /     |              /     |
+   *               7 --------6--------- 6      |
+   *               |      |             |      |
+   *               |      0 ---------0--|----- 1    X
+   *               |     /              |     /
+   *              11    /               10   /
+   *               |   3                |   1
+   *               |  /                 |  /
+   *               | /                  | /
+   *               3 ---------2-------- 2
+   *              Z 
+   * 
+   * 
+   * type 0: x-edges: 0 2 4 6
+   * typw 1: y-edges: 8 9 10 11
+   * type 2: z-edges: 1 3 5 7
+   * 
+   * 
+   * 
+   */
+  final static int edgeTypeTable[] = { 0, 2, 0, 2, 0, 2, 0, 2, 1, 1, 1, 1}; 
+
   final static byte edgeVertexes[] = { 0, 1, 1, 2, 2, 3, 3, 0, 4, 5, 5, 6, 6,
       7, 7, 4, 0, 4, 1, 5, 2, 6, 3, 7 };
 
@@ -1407,8 +1420,14 @@
       mesh.vertexColixes = colixes = new short[vertexCount];
     float diff = max - min;
     String list = "";
-    for (int i = 0; i < vertexCount; i++) {
+    //int edgePtr = 0;
+    int incr = (mesh.hasGridPoints ? 3 : 1);
+    for (int i = 0; i < vertexCount; i += incr) {
       float value = lookupInterpolatedVoxelValue(vertexes[i]);
+      //assumes two volume sets are identical:
+      //float value = lookupInterpolatedVoxelValue(vertexes[i], 
mesh.edgeInfo[edgePtr], mesh.fractionInfo[edgePtr]);
+      //float value = lookupInterpolatedVoxelValue(vertexes[i], 
mesh.edgeInfo[edgePtr], (int)mesh.edgeData.charAt(edgePtr));
+      //++edgePtr;
       if (value < min) {
         value = min + diff * 0.0001f;
       }
@@ -1429,8 +1448,14 @@
     int vertexCount = mesh.vertexCount;
     Point3f[] vertexes = mesh.vertices;
     float min = Float.MAX_VALUE;
-    for (int i = vertexCount; --i >= 0;) {
+    //int edgePtr = 0;
+    int incr = (mesh.hasGridPoints ? 3 : 1);
+    for (int i = 0; i < vertexCount; i += incr) {
       float challenger = lookupInterpolatedVoxelValue(vertexes[i]);
+      //assumes two volume sets are identical:
+      //float challenger = lookupInterpolatedVoxelValue(vertexes[i], 
mesh.edgeInfo[edgePtr], mesh.fractionInfo[edgePtr]);
+      //float challenger = lookupInterpolatedVoxelValue(vertexes[i], 
mesh.edgeInfo[edgePtr], (int)mesh.edgeData.charAt(edgePtr));
+      //++edgePtr;
       if (challenger < min)
         min = challenger;
     }
@@ -1441,18 +1466,40 @@
     int vertexCount = mesh.vertexCount;
     Point3f[] vertexes = mesh.vertices;
     float max = -Float.MAX_VALUE;
-    for (int i = vertexCount; --i >= 0;) {
+    //int edgePtr = 0;
+    int incr = (mesh.hasGridPoints ? 3 : 1);
+    for (int i = 0; i < vertexCount; i += incr) {
       float challenger = lookupInterpolatedVoxelValue(vertexes[i]);
+      //float challenger = lookupInterpolatedVoxelValue(vertexes[i], 
mesh.edgeInfo[edgePtr], mesh.fractionInfo[edgePtr]);
+      //float challenger = lookupInterpolatedVoxelValue(vertexes[i], 
mesh.edgeInfo[edgePtr], (int)mesh.edgeData.charAt(edgePtr));
+      //++edgePtr;
       if (challenger > max)
         max = challenger;
     }
     return max;
   }
 
-  int i;
+
+  //approximation based on 90-cell bins
+  float lookupInterpolatedVoxelValue(Point3f point, int[]edgeXYZ, int ich) {
+    float fraction = fractionFromCharacter(ich, edgeFractionBase, 
edgeFractionRange, 0.5f);
+    float valueA = voxelData[edgeXYZ[0]][edgeXYZ[1]][edgeXYZ[2]];
+    float valueB = voxelData[edgeXYZ[3]][edgeXYZ[4]][edgeXYZ[5]];
+    return valueA + fraction * (valueB - valueA);
+  }
+
+  //perfect interpolation -- volume blocks identical
+  float lookupInterpolatedVoxelValue(Point3f point, int[]edgeXYZ, float 
fraction) {
+    float valueA = voxelData[edgeXYZ[0]][edgeXYZ[1]][edgeXYZ[2]];
+    float valueB = voxelData[edgeXYZ[3]][edgeXYZ[4]][edgeXYZ[5]];
+    return valueA + fraction * (valueB - valueA);
+  }
+
   final Vector3f pointVector = new Vector3f();
   final Point3f cubeLocation = new Point3f();
 
+  //generic for nonequivalent volume sets
+  
   float lookupInterpolatedVoxelValue(Point3f point) {
     pointVector.sub(point, volumetricOrigin);
     float x = scaleByVoxelVector(pointVector, 0);
@@ -1465,63 +1512,41 @@
     return (vector.dot(unitVolumetricVectors[voxelVectorIndex]) / 
volumetricVectorLengths[voxelVectorIndex]);
   }
 
-  int indexDown(float value, int voxelVectorIndex) {
+  int indexDown(float value, int iMax) {
+    if (value < 0)
+      return 0;
     int floor = (int) value;
-    float delta = value - floor;
-    if (delta > 0.9f)
-      ++floor;
-    int lastValue = voxelCounts[voxelVectorIndex] - 1;
-    if (floor > lastValue)
-      floor = lastValue;
-    return floor;
+    return (floor >= iMax ? iMax - 1 : floor);
   }
 
-  int indexUp(float value, int voxelVectorIndex) {
+  int indexUp(float value, int iMax) {
     if (value < 0)
       return 0;
     int ceil = ((int) value) + 1;
-    float delta = ceil - value;
-    if (delta > 0.9f)
-      --ceil;
-    int lastValue = voxelCounts[voxelVectorIndex] - 1;
-    if (ceil > lastValue)
-      ceil = lastValue;
-    return ceil;
+    return (ceil >= iMax ? iMax - 1 : ceil);
   }
 
   float getInterpolatedValue(float x, float y, float z) {
-    int xDown = indexDown(x, 0);
-    int xUp = indexUp(x, 0);
-    int yDown = indexDown(y, 1);
-    int yUp = indexUp(y, 1);
-    int zDown = indexDown(z, 2);
-    int zUp = indexUp(z, 2);
+    int iMax;
+    int xDown = indexDown(x, iMax = voxelCounts[0]);
+    int xUp = indexUp(x, iMax);
+    int yDown = indexDown(y, iMax = voxelCounts[1]);
+    int yUp = indexUp(y, iMax);
+    int zDown = indexDown(z, iMax = voxelCounts[2]);
+    int zUp = indexUp(z, iMax);
 
-    float valueDown = voxelData[xDown][yDown][zDown];
-    float valueUp = voxelData[xUp][yUp][zUp];
-    float valueDelta = valueUp - valueDown;
-    float delta;
-    int differentMask;
-    differentMask = ((((xUp == xDown) ? 0 : 1) << 0)
-        | (((yUp == yDown) ? 0 : 1) << 1) | (((zUp == zDown) ? 0 : 1) << 2));
-    switch (differentMask) {
-    case 0:
-      return valueDown;
-    case 1:
-      delta = x - xDown;
-      break;
-    case 2:
-      delta = y - yDown;
-      break;
-    case 4:
-      delta = z - zDown;
-      break;
-    default:
-      // I don't feel like dealing with all the cases
-      // just stick it in the middle
-      delta = 0.5f;
-    }
-    return valueDown + delta * valueDelta;
-
+    float v1 = getFractional2DValue(x - xDown, y - yDown,
+        voxelData[xDown][yDown][zDown], voxelData[xUp][yDown][zDown],
+        voxelData[xDown][yUp][zDown], voxelData[xUp][yUp][zDown]);
+    float v2 = getFractional2DValue(x - xDown, y - yDown,
+        voxelData[xDown][yDown][zUp], voxelData[xUp][yDown][zUp],
+        voxelData[xDown][yUp][zUp], voxelData[xUp][yUp][zUp]);
+    return v1 + (z - zDown) * (v2 - v1);
   }
+  
+  float getFractional2DValue(float fx, float fy, float x11, float x12, float 
x21, float x22) {
+     float v1 = x11 + fx * (x12 - x11);
+     float v2 = x21 + fx * (x22 - x21);
+     return v1 + fy * (v2 - v1);
+  }
 }

Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Mesh.java
===================================================================
--- branches/bob200603/Jmol/src/org/jmol/viewer/Mesh.java       2006-05-28 
15:55:49 UTC (rev 5190)
+++ branches/bob200603/Jmol/src/org/jmol/viewer/Mesh.java       2006-05-29 
05:35:14 UTC (rev 5191)
@@ -27,6 +27,7 @@
 
 import org.jmol.g3d.*;
 
+import javax.vecmath.Point3i;
 import javax.vecmath.Point3f;
 import javax.vecmath.Point4f;
 import javax.vecmath.Vector3f;
@@ -44,6 +45,9 @@
   int nBytes;
   boolean hasGridPoints;
   boolean hideBackground;
+  int[][] edgeInfo;
+  float[] fractionInfo;
+  int edgeCount;
 
   boolean visible = true;
   short colix;
@@ -414,4 +418,24 @@
     }
   }
 
+  void addEdgeInfo(int x, int y, int z, Point3i offsetA, Point3i offsetB, int 
edgeType, float fraction) {
+    // not used currently
+    if (edgeInfo == null) {
+      edgeInfo = new int[256][];
+      fractionInfo = new float[256];
+    } else if (edgeCount == edgeInfo.length) {
+      edgeInfo = (int[][]) Util.doubleLength(edgeInfo);
+      fractionInfo = (float[]) Util.doubleLength(fractionInfo);
+    }
+    int i = edgeCount++;
+    edgeInfo[i] = new int[6];
+    edgeInfo[i][0] = x + offsetA.x;
+    edgeInfo[i][1] = y + offsetA.y;
+    edgeInfo[i][2] = z + offsetA.z;
+    edgeInfo[i][3] = x + offsetB.x;
+    edgeInfo[i][4] = y + offsetB.y;
+    edgeInfo[i][5] = z + offsetB.z;
+    fractionInfo[i] = fraction;
+  }
+
 }


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



-------------------------------------------------------
All the advantages of Linux Managed Hosting--Without the Cost and Risk!
Fully trained technicians. The highest number of Red Hat certifications in
the hosting industry. Fanatical Support. Click to learn more
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=107521&bid=248729&dat=121642
_______________________________________________
Jmol-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to