Revision: 5167
Author:   hansonr
Date:     2006-05-24 18:10:38 -0700 (Wed, 24 May 2006)
ViewCVS:  http://svn.sourceforge.net/jmol/?rev=5167&view=rev

Log Message:
-----------
bob200306 isosurface JVXL Jmol Voxel File format Phase II 
complete (reading and writing mapped JVXL files at 100-500:1 compression)
see http://www.stolaf.edu/people/hansonr/jmol/test/proto/new.htm

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-24 
18:30:06 UTC (rev 5166)
+++ branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java 2006-05-25 
01:10:38 UTC (rev 5167)
@@ -90,6 +90,9 @@
   final float ANGSTROMS_PER_BOHR = JmolConstants.ANGSTROMS_PER_BOHR;
   final static char defaultEdgeFractionBase = 35; //#$%.......
   final static float defaultEdgeFractionRange = 90f;
+  final static char defaultColorFractionBase = 35; 
+  final static float defaultColorFractionRange = 
JmolConstants.argbsRoygbScale.length;
+  
 
   final Point3f volumetricOrigin = new Point3f();
   final Vector3f[] volumetricVectors = new Vector3f[3];
@@ -118,22 +121,26 @@
   BufferedReader br;
 
   void setProperty(String propertyName, Object value, BitSet bs) {
+
+    //System.out.println("isosurface setProperty: " + propertyName + " = " + 
value);
     if ("init" == propertyName) {
       fileIndex = 1;
+      nBytes = 0;
       super.setProperty("meshID", null, null);
-      return;  
+      return;
     }
     if ("fileIndex" == propertyName) {
-      fileIndex= ((Integer)value).intValue();
-      if (fileIndex < 1) fileIndex = 1;
-      return;  
+      fileIndex = ((Integer) value).intValue();
+      if (fileIndex < 1)
+        fileIndex = 1;
+      return;
     }
     if ("bufferedReader" == propertyName) {
-      br = (BufferedReader)value;
+      br = (BufferedReader) value;
       if (currentMesh == null)
         allocMesh(null);
       currentMesh.clear("isosurface");
-      readData();
+      readData(false);
       calcVoxelVertexVectors();
       constructTessellatedSurface();
       currentMesh.colix = getDefaultColix();
@@ -141,18 +148,19 @@
       currentMesh.checkForDuplicatePoints(.001f);
       currentMesh.visible = true;
       discardTempData();
+      System.out.println("\n" + getJvxlFile(currentMesh, (iHaveColorData ? 
"mapped" : "")));
       return;
     }
     if ("cutoff" == propertyName) {
-      cutoff = ((Float)value).floatValue();
+      cutoff = ((Float) value).floatValue();
       return;
     }
     if ("rangeMin" == propertyName) {
-      minRange = ((Float)value).floatValue();
+      minRange = ((Float) value).floatValue();
       return;
     }
     if ("rangeMax" == propertyName) {
-      maxRange = ((Float)value).floatValue();
+      maxRange = ((Float) value).floatValue();
       rangeDefined = true;
       return;
     }
@@ -161,30 +169,33 @@
       return;
     }
     if ("colorReader" == propertyName) {
-      System.out.println("colorReader seen!");
-      br = (BufferedReader)value;
-      readData();
-      if (! rangeDefined) {
+      System.out.println("mapping data...");
+      br = (BufferedReader) value;
+      readData(true);
+      if (!rangeDefined) {
         minRange = getMinMappedValue();
         maxRange = getMaxMappedValue();
       }
-      System.out.println(" minRange=" + minRange +
-                         " maxRange=" + maxRange);
+      System.out.println(" minRange=" + minRange + " maxRange=" + maxRange);
       applyColorScale(minRange, maxRange, "roygb");
       discardTempData();
+      System.out.println("\n" + getJvxlFile(currentMesh, "mapped"));
       return;
     }
     super.setProperty(propertyName, value, bs);
   }
 
-  void readData() {
+  boolean isJvxl;
+  void readData(boolean isMapData) {
+    isJvxl = false;
     int nSurfaces = readVolumetricHeader();
     if (nSurfaces < fileIndex) {
-      System.out.println("not enough surfaces in file -- resetting fileIndex 
to " + nSurfaces);
+      System.out.println("not enough surfaces in file -- resetting fileIndex 
to " 
+          + nSurfaces);
       fileIndex = nSurfaces;
     }
     calcVolumetricMatrix();
-    readVolumetricData();
+    readVolumetricData(isMapData);
   }
 
   void calcVolumetricMatrix() {
@@ -237,19 +248,18 @@
     }
   }
 
-  void readVolumetricData() {
+  void readVolumetricData(boolean isMapData) {
     try {
-      readVoxelData();
+      readVoxelData(isMapData);
     } catch (Exception e) {
       e.printStackTrace();
       throw new NullPointerException();
     }
   }
 
-  String jvxlHeader = "";
   void readTitleLines() throws Exception {
-    jvxlHeader = br.readLine() + "\n";
-    jvxlHeader += br.readLine() + "\n";
+    jvxlFileHeader = br.readLine() + "\n";
+    jvxlFileHeader += br.readLine() + "\n";
   }
 
   int atomCount;
@@ -258,18 +268,16 @@
   void readAtomCountAndOrigin() throws Exception {
     String atomLine = line = br.readLine();
     atomCount = parseInt(line);
-    if (atomCount == 0) {
-      atomLine = "-1 " + line.substring(ichNextParse);
-    }
-    jvxlHeader += atomLine + "\n";
+    atomLine = line.substring(ichNextParse);
+    negativeAtomCount = (atomCount < 0);
+    if (negativeAtomCount)
+      atomCount = -atomCount;
+    int jvxlAtoms = (atomCount == 0 ? -1 : -atomCount);
     volumetricOrigin.x = parseFloat(line, ichNextParse);
     volumetricOrigin.y = parseFloat(line, ichNextParse);
     volumetricOrigin.z = parseFloat(line, ichNextParse);
     volumetricOrigin.scale(ANGSTROMS_PER_BOHR);
-    if (atomCount < 0) {
-      atomCount = -atomCount;
-      negativeAtomCount = true;
-    }
+    jvxlFileHeader += jvxlAtoms + " " + atomLine + "\n";
   }
 
   void readVoxelVectors() throws Exception {
@@ -279,7 +287,7 @@
 
   void readVoxelVector(int voxelVectorIndex) throws Exception {
     line = br.readLine();
-    jvxlHeader += line + "\n";
+    jvxlFileHeader += line + "\n";
     Vector3f voxelVector = volumetricVectors[voxelVectorIndex];
     voxelCounts[voxelVectorIndex] = parseInt(line);
     voxelVector.x = parseFloat(line, ichNextParse);
@@ -292,7 +300,7 @@
 
   void readAtoms() throws Exception {
     for (int i = 0; i < atomCount; ++i) {
-      jvxlHeader +=  br.readLine() + "\n";
+      jvxlFileHeader +=  br.readLine() + "\n";
       /*
       Atom atom = atomSetCollection.addNewAtom();
       atom.elementNumber = (byte)parseInt(line);
@@ -303,28 +311,41 @@
       */
     }
     if (atomCount == 0)
-      jvxlHeader += "1 1.0 0.0 0.0 0.0 //BOGUS H ATOM ADDED FOR JVXL FORMAT\n";
+      jvxlFileHeader += "1 1.0 0.0 0.0 0.0 //BOGUS H ATOM ADDED FOR JVXL 
FORMAT\n";
   }
 
-  boolean isJvxl = false;
   int readExtraLine() throws Exception {
     int nSurfaces;
-    jvxlFileData = jvxlHeader;
+    edgeFractionBase = defaultEdgeFractionBase;
+    edgeFractionRange = defaultEdgeFractionRange;          
+    colorFractionBase = defaultColorFractionBase;
+    colorFractionRange = defaultColorFractionRange;
     if (negativeAtomCount) {
       nSurfaces = parseInt(line = br.readLine());
       isJvxl = (nSurfaces < 0);
       if (isJvxl) {
         nSurfaces = -nSurfaces;
-        edgeFractionBase = (char) parseInt(line, ichNextParse);
-        edgeFractionRange = parseFloat(line, ichNextParse);
-        System.out.println("JVXL reading base: " + edgeFractionBase
-            + " range: " + edgeFractionRange);
+        System.out.println("jvxl file surfaces: " + nSurfaces);
+        int ich = parseInt(line, ichNextParse);
+        if (ich == Integer.MIN_VALUE) {
+          System.out.println( "using default edge fraction base and range");
+        } else {
+          edgeFractionBase = (char) ich;
+          edgeFractionRange = parseFloat(line, ichNextParse);
+        }
+        if (ich == Integer.MIN_VALUE) {
+          System.out.println( "using default color fraction base and range");
+        } else {
+          colorFractionBase = (char) ich;
+          colorFractionRange = parseFloat(line, ichNextParse);
+        }
       }
     } else {
       nSurfaces = 1;
     }
-    jvxlFileData += "-1 " + (int) edgeFractionBase + " "
-        + (int) edgeFractionRange + " Jmol voxel format version 0.9a" + "\n";
+    jvxlFileHeader += "-1 " + (int) edgeFractionBase + " "
+    + (int) edgeFractionRange + " " + (int) colorFractionBase + " "
+    + (int) colorFractionRange + " Jmol voxel format version 0.9b\n";
     return nSurfaces;
   }
 
@@ -332,17 +353,18 @@
   int nBytes;
   int nDataPoints;
   String surfaceData;
-  String edgeData;
+  String jvxlFileHeader;
 
-  void readVoxelData() throws Exception {
+  void readVoxelData(boolean isMapData) throws Exception {
     ichNextParse = 0;
     thisValue = Integer.MIN_VALUE;
     nThisValue = 0;
     boolean inside = false;
     int dataCount = 0;
     surfaceData = "";
-    edgeData = "";
-    nBytes = 0;
+    strFractionTemp = "";
+    fractionData = "";
+    iHaveColorData = false;
     thisInside = true;
     nDataPoints = 0;
     int voxelCountX = voxelCounts[0];
@@ -353,8 +375,7 @@
     voxelData = new float[voxelCountX][][];
     skipData(fileIndex - 1);
     if (isJvxl) {
-      br.readLine(); // skip definition line for now
-      System.out.println("jvxl data set: " + line);
+      readJvxlDefinitionLine(true);
       cutoff = 0.5f; // just 0s and 1s here. detail is in the edgeFractions
     }
     line = "";
@@ -368,38 +389,60 @@
           float voxelValue = getNextVoxelValue();
           strip[z] = voxelValue;
           ++nDataPoints;
-          if (!isJvxl) {
-            boolean isInside = ((cutoff > 0 && voxelValue >= cutoff) || 
(cutoff < 0 && voxelValue <= cutoff));
-            if (inside == isInside) {
-              dataCount++;
-            } else {
-              surfaceData += " " + dataCount;
-             dataCount = 1;
-              inside = !inside;
-            }
+          if (isJvxl || isMapData)
+            continue;
+          boolean isInside = ((cutoff > 0 && voxelValue >= cutoff) 
+              || (cutoff < 0 && voxelValue <= cutoff));
+          if (inside == isInside) {
+            dataCount++;
+          } else {
+            surfaceData += " " + dataCount;
+            dataCount = 1;
+            inside = !inside;
           }
         }
       }
     }
-    if (!isJvxl) {
+    if (!isJvxl)
       surfaceData += " " + dataCount + "\n";
-    }
+    if (!isMapData)
+      currentMesh.surfaceData = surfaceData;
     System.out.println("Successfully read " + voxelCountX + " x " + voxelCountY
         + " x " + voxelCountZ + " voxels");
   }
 
+  int nStructureData;
+  int nEdgeData;
+  int nColorData;
+  boolean iHaveColorData;
+  float jvxlCutoff;
+  
+  void readJvxlDefinitionLine(boolean showMsg) throws Exception {
+    line = br.readLine(); // skip definition line for now
+    if (showMsg)
+      System.out.println("reading jvxl data set: " + line);
+    jvxlCutoff = parseFloat(line);
+    nStructureData = parseInt(line, ichNextParse); //nStructure
+    nEdgeData = parseInt(line, ichNextParse); //nEdgeData
+    nColorData = parseInt(line, ichNextParse);
+    iHaveColorData = (nColorData > 0);
+  }
+  
   int thisValue;
   int nThisValue;
   boolean thisInside;
+  
   float getNextVoxelValue() throws Exception {
     if (isJvxl) {
       if (nThisValue == 0) {
         nThisValue = parseInt(line, ichNextParse);
         if (nThisValue == Integer.MIN_VALUE) {
           line = br.readLine();
-          surfaceData += line + "\n"; 
-          if (line == null || (nThisValue = parseInt(line)) == 
Integer.MIN_VALUE) {
-            System.out.println("end of file in JvxlReader? (x,y,z,line):"+ 
line);
+          surfaceData += line + "\n";
+          if (line == null
+              || (nThisValue = parseInt(line)) == Integer.MIN_VALUE) {
+            System.out.println("end of file in JvxlReader? (x,y,z,line):"
+                + line);
             throw new NullPointerException();
           }
           nBytes += line.length() + 1;
@@ -413,7 +456,8 @@
     if (Float.isNaN(voxelValue)) {
       line = br.readLine();
       if (line == null || Float.isNaN(voxelValue = parseFloat(line))) {
-        System.out.println("end of file in CubeReader? nDataPoints="+ 
nDataPoints + " (line):" + line);
+        System.out.println("end of file reading cube voxel data? nDataPoints="
+            + nDataPoints + " (line):" + line);
         throw new NullPointerException();
       }
       nBytes += line.length() + 1;
@@ -425,20 +469,26 @@
     if (n == 0)
       return;
     System.out.println("skipping " + n + " data sets");
-    int nVertices = voxelCountX * voxelCountY * voxelCountZ;     
-    for (int i = 0; i < n; i++)
+    int nVertices = voxelCountX * voxelCountY * voxelCountZ;
+    for (int i = 0; i < n; i++) {
       if (isJvxl)
-        br.readLine(); //skip definition line
-    String line = "";
-    int i=0;
-    while (i < nVertices) {
-        line = br.readLine();
-        int c = countData(line);
-        i += c;
+        readJvxlDefinitionLine(false);
+      skipData(nVertices, true);
+      if (isJvxl) {
+        skipData(nEdgeData, false);
+        if (iHaveColorData)
+          skipData(nColorData, false);
+      }
     }
-    if (isJvxl)
-      br.readLine();
   }
+
+  void skipData(int nPoints, boolean isInt) throws Exception {
+    int iV = 0;
+    while (iV < nPoints) {
+      line = br.readLine();
+      iV += (isInt ? countData(line) : line.length());
+    }
+  }
   
   int countData(String str) {
     int count = 0;
@@ -476,13 +526,12 @@
   final int[] surfacePointIndexes = new int[12];
 
   int voxelCountX, voxelCountY, voxelCountZ;
-  String jvxlFileData;
-  
+
   void constructTessellatedSurface() {
     voxelCountX = voxelData.length - 1;
     voxelCountY = voxelData[0].length - 1;
     voxelCountZ = voxelData[0][0].length - 1;
-    edgeFractions = "";
+    strFractionTemp = "";
     int[][] isoPointIndexes = new int[voxelCountY * voxelCountZ][12];
     for (int i = voxelCountY * voxelCountZ; --i >= 0;)
       isoPointIndexes[i] = new int[12];
@@ -492,71 +541,87 @@
      * ++y) for (int z = 0; z < voxelCountZ; ++z) System.out.println("" + x +
      * "," + y + "," + z + " = " + voxelData[x][y][z]);
      */
+    try {
 
-    int insideCount = 0, outsideCount = 0, surfaceCount = 0;
-    for (int x = voxelCountX; --x >= 0;) {
-      for (int y = voxelCountY; --y >= 0;) {
-        for (int z = voxelCountZ; --z >= 0;) {
-          int insideMask = 0;
-          for (int i = 8; --i >= 0;) {
-            Point3i offset = cubeVertexOffsets[i];
-            float vertexValue = voxelData[x + offset.x][y + offset.y][z
-                + offset.z];
-            vertexValues[i] = vertexValue;
-            if ((cutoff > 0 && vertexValue >= cutoff)
-                || (cutoff < 0 && vertexValue <= cutoff))
-              insideMask |= 1 << i;
-          }
+      int insideCount = 0, outsideCount = 0, surfaceCount = 0;
+      for (int x = voxelCountX; --x >= 0;) {
+        for (int y = voxelCountY; --y >= 0;) {
+          for (int z = voxelCountZ; --z >= 0;) {
+            int insideMask = 0;
+            for (int i = 8; --i >= 0;) {
+              Point3i offset = cubeVertexOffsets[i];
+              float vertexValue = voxelData[x + offset.x][y + offset.y][z
+                  + offset.z];
+              vertexValues[i] = vertexValue;
+              if ((cutoff > 0 && vertexValue >= cutoff)
+                  || (cutoff < 0 && vertexValue <= cutoff))
+                insideMask |= 1 << i;
+            }
 
-          /*
-           * for (int i = 0; i < 8; ++i ) System.out.println("vertexValues[" + 
i +
-           * "]=" + vertexValues[i]); System.out.println("insideMask=" +
-           * Integer.toHexString(insideMask));
-           */
+            /*
+             * for (int i = 0; i < 8; ++i ) System.out.println("vertexValues[" 
+ i +
+             * "]=" + vertexValues[i]); System.out.println("insideMask=" +
+             * Integer.toHexString(insideMask));
+             */
 
-          if (insideMask == 0) {
-            ++outsideCount;
-            continue;
-          }
-          if (insideMask == 0xFF) {
-            ++insideCount;
-            continue;
-          }
-          ++surfaceCount;
-          calcVoxelOrigin(x, y, z);
-          int[] voxelPointIndexes = propogateNeighborPointIndexes(x, y, z,
-              isoPointIndexes);
-          try {
+            if (insideMask == 0) {
+              ++outsideCount;
+              continue;
+            }
+            if (insideMask == 0xFF) {
+              ++insideCount;
+              continue;
+            }
+            ++surfaceCount;
+            calcVoxelOrigin(x, y, z);
+            int[] voxelPointIndexes = propogateNeighborPointIndexes(x, y, z,
+                isoPointIndexes);
             processOneVoxel(insideMask, cutoff, voxelPointIndexes);
-          } catch (Exception e) {
-            e.printStackTrace();
-            throw new NullPointerException();
+
           }
-
         }
       }
+      if (!isJvxl) {
+        fractionData += "\n";
+        currentMesh.nBytes = nBytes;
+      }
+      currentMesh.edgeData = fractionData;
+      currentMesh.jvxlFileHeader = jvxlFileHeader;
+      fractionData = "";
+      strFractionTemp = "";
+      currentMesh.cutoff = (isJvxl ? jvxlCutoff : cutoff);
+      currentMesh.colorData = "";
+      System.out.println("volumetric=" + voxelCountX + "," + voxelCountY + ","
+          + voxelCountZ + "," + " total="
+          + (voxelCountX * voxelCountY * voxelCountZ) + "\n" + " insideCount="
+          + insideCount + " outsideCount=" + outsideCount + " surfaceCount="
+          + surfaceCount + " total="
+          + (insideCount + outsideCount + surfaceCount));
+      if (iHaveColorData) {
+        setJvxlColixes(currentMesh, "roygb");
+        currentMesh.colorData = fractionData;
+      }
+    } catch (Exception e) {
+      e.printStackTrace();
+      throw new NullPointerException();
     }
 
+  }
+
+  String getJvxlFile(Mesh mesh, String msg) {
+    String data = mesh.jvxlFileHeader;
+    data += mesh.cutoff + " " + mesh.surfaceData.length() + " "
+        + (mesh.edgeData.length() - 1) + " " + (mesh.colorData.length() - 1);
     if (!isJvxl)
-      edgeData += "\n";
-    jvxlFileData += cutoff + " " + surfaceData.length() + " " + 
edgeData.length();
-    if (!isJvxl) {
-      jvxlFileData += " compressionRatio="
-          + (nBytes * 1f / (surfaceData.length() + edgeData.length()));
-    }
-    jvxlFileData += "\n" + surfaceData + edgeData;
-    currentMesh.jvxlFileData = jvxlFileData;
-    System.out.println("volumetric=" + voxelCountX + "," + voxelCountY + ","
-        + voxelCountZ + "," + " total="
-        + (voxelCountX * voxelCountY * voxelCountZ) + "\n" + " insideCount="
-        + insideCount + " outsideCount=" + outsideCount + " surfaceCount="
-        + surfaceCount + " total="
-        + (insideCount + outsideCount + surfaceCount));
-    System.out.println("-------start of jvxl file data-------\n" + jvxlFileData
-        + "-------end of jvxl file data-------\n");
-
+      data += " compressionRatio="
+          + (mesh.nBytes * 1f / (mesh.surfaceData.length()
+              + mesh.edgeData.length() + mesh.colorData.length()));
+    data += "\n" + mesh.surfaceData + mesh.edgeData + mesh.colorData;
+    if (msg != null)
+      data += "-------end of jvxl file " + msg + " data-------\n";
+    return data;
   }
-
+  
   final int[] nullNeighbor = {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
 
   int[] propogateNeighborPointIndexes(int x, int y, int z,
@@ -641,28 +706,33 @@
                               voxelPointIndexes[triangles[i + 2]]);
   }
     
-  String edgeFractions = "";
-  char edgeFractionBase = defaultEdgeFractionBase;
-  float edgeFractionRange = defaultEdgeFractionRange;
-  int edgeFractionPtr;
-  float getNextFraction() throws Exception {
-    if (edgeFractions == null)
+  char edgeFractionBase;
+  float edgeFractionRange;
+  char colorFractionBase;
+  float colorFractionRange;
+  int fractionPtr;
+  String strFractionTemp = "";
+  String fractionData = "";
+  float getNextFraction(char base, float range) throws Exception {
+    if (strFractionTemp == null)
       return 0;
-    if (edgeFractionPtr >= edgeFractions.length()) {
-      edgeFractions = br.readLine();
-      edgeData += edgeFractions + "\n";
-      if (edgeFractions == null) {
-        System.out.println("end of file reading edgeFractions");
+    if (fractionPtr >= strFractionTemp.length()) {
+      strFractionTemp = br.readLine();
+      if (strFractionTemp == null) {
+        System.out
+            .println("end of file reading compressed fraction data at point "
+                + fractionData.length());
         throw new NullPointerException();
       }
-      edgeFractionPtr = 0;
+      fractionData += strFractionTemp + "\n";
+      fractionPtr = 0;
     }
-    int ich = (int) edgeFractions.charAt(edgeFractionPtr++);
-    if (ich < edgeFractionBase)
-      ich = 92;    // ! --> \
-    float fraction = (ich - edgeFractionBase + 0.5f) / edgeFractionRange;
+    int ich = (int) strFractionTemp.charAt(fractionPtr++);
+    if (ich < base)
+      ich = 92; // ! --> \
+    float fraction = (ich - base + 0.5f) / range;
     if (logMessages)
-      System.out.println(fraction +" <-- " + ich + " " + (char)ich);
+      System.out.println(fraction + " <-- " + ich + " " + (char) ich);
     return fraction;
   }
 
@@ -670,23 +740,23 @@
       Point3f surfacePoint) throws Exception {
     float fraction;
     if (isJvxl) {
-      fraction = getNextFraction();
+      fraction = getNextFraction(edgeFractionBase, edgeFractionRange);
     } else {
       float diff = valueB - valueA;
       fraction = (cutoff - valueA) / diff;
+      if (Float.isNaN(fraction) || fraction < 0 || fraction > 1) {
+        System.out.println("problem with unusual fraction=" + fraction + " 
cutoff=" + cutoff + " A:"
+            + valueA + " B:" + valueB);
+        fraction = 0;
+      }
       if (! isJvxl) {
         int ich = (int)(fraction * edgeFractionRange + edgeFractionBase);
         if (ich == 92)
           ich = 33;    // \ --> !
         if (logMessages)
           System.out.println(fraction +" --> " + ich + " " + (char)ich);
-        edgeData += (char) (ich);
+        fractionData += (char) (ich);
       }
-      if (Float.isNaN(fraction) || fraction < 0 || fraction > 1) {
-        System.out.println("fraction=" + fraction + " cutoff=" + cutoff + " A:"
-            + valueA + " B:" + valueB);
-        throw new IndexOutOfBoundsException();
-      }
     }
     edgeVector.sub(pointB, pointA);
     surfacePoint.scaleAdd(fraction, edgeVector, pointA);
@@ -752,13 +822,13 @@
   static Vector3f[] voxelVertexVectors = new Vector3f[8];
 
   void calcVoxelVertexVectors() {
-    for (int i = 8; --i >= 0; )
-      voxelVertexVectors[i] =
-        calcVoxelVertexVector(cubeVertexVectors[i]);
-    for (int i = 0; i < 8; ++i) {
-      System.out.println("voxelVertexVectors[" + i + "]=" +
-                         voxelVertexVectors[i]);
-    }
+    for (int i = 8; --i >= 0;)
+      voxelVertexVectors[i] = calcVoxelVertexVector(cubeVertexVectors[i]);
+    if (logMessages)
+      for (int i = 0; i < 8; ++i) {
+        System.out.println("voxelVertexVectors[" + i + "]="
+            + voxelVertexVectors[i]);
+      }
   }
 
   Vector3f calcVoxelVertexVector(Vector3f cubeVectors) {
@@ -1113,16 +1183,40 @@
     return max;
   }
 
+  void setJvxlColixes(Mesh mesh, String scaleName) throws Exception {
+    int vertexCount = mesh.vertexCount;
+    short[] colixes = mesh.vertexColixes;
+    strFractionTemp = "";
+    fractionData = "";
+    if (colixes == null)
+      mesh.vertexColixes = colixes = new short[vertexCount];
+    for (int i = 0; i < vertexCount; i++) {
+      float fraction = getNextFraction(colorFractionBase, colorFractionRange);
+      colixes[i] = viewer.getColixFromPalette(fraction, 0f, 1f, scaleName);
+    }
+  }
+  
   void applyColorScale(Mesh mesh, float min, float max, String scaleName) {
     int vertexCount = mesh.vertexCount;
     Point3f[] vertexes = mesh.vertices;
     short[] colixes = mesh.vertexColixes;
     if (colixes == null)
       mesh.vertexColixes = colixes = new short[vertexCount];
-    for (int i = vertexCount; --i >= 0; ) {
+    float diff = max - min;
+    String list = "";
+    for (int i = 0; i < vertexCount; i++) {
       float value = lookupInterpolatedVoxelValue(vertexes[i]);
+      if (value < min) {
+        value = min + diff * 0.0001f;
+      }
+      if (value >= max) {
+        value = min + diff * 0.9999f;
+      }
+      int ich = (int) ((value - min) / diff * colorFractionRange + 
colorFractionBase);
+      list += (char) ich;
       colixes[i] = viewer.getColixFromPalette(value, min, max, scaleName);
     }
+    mesh.colorData = list + "\n";
   }
 
   float getMinMappedValue(Mesh mesh) {

Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Mesh.java
===================================================================
--- branches/bob200603/Jmol/src/org/jmol/viewer/Mesh.java       2006-05-24 
18:30:06 UTC (rev 5166)
+++ branches/bob200603/Jmol/src/org/jmol/viewer/Mesh.java       2006-05-25 
01:10:38 UTC (rev 5167)
@@ -34,7 +34,15 @@
   Viewer viewer;
 
   String meshID;
-  String jvxlFileData;
+  
+  String jvxlFileHeader;
+  float cutoff;
+  String surfaceData;
+  String edgeData;
+  String colorData;
+  float jvxlCompressionRatio;
+  int nBytes;
+
   boolean visible = true;
   short colix;
   short[] vertexColixes;


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