Revision: 5169
Author:   hansonr
Date:     2006-05-24 22:45:51 -0700 (Wed, 24 May 2006)
ViewCVS:  http://svn.sourceforge.net/jmol/?rev=5169&view=rev

Log Message:
-----------
bob200603 isosurfaces Phase III complete: planes
defined as Point4f in Eval: {a b c d} for ax + by + cz + d = 0.

Modified Paths:
--------------
    branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java
    branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java
Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java
===================================================================
--- branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java       2006-05-25 
03:47:48 UTC (rev 5168)
+++ branches/bob200603/Jmol/src/org/jmol/viewer/Eval.java       2006-05-25 
05:45:51 UTC (rev 5169)
@@ -32,6 +32,7 @@
 import java.util.Hashtable;
 import javax.vecmath.Point3f;
 import javax.vecmath.Vector3f;
+import javax.vecmath.Point4f;
 
 class Context {
   String filename;
@@ -1423,6 +1424,31 @@
     return pt;
   }
 
+  Point4f getPoint4f(int i) throws ScriptException {
+    coordinatesAreFractional = false;
+    if (statement[i++].tok != Token.leftbrace)
+      coordinateExpected();
+    Point4f pt = new Point4f();
+    for (int j = i; j + 1 < statement.length; j++) {
+      switch (statement[j].tok) {
+      case Token.slash:
+        coordinatesAreFractional = true;
+      case Token.rightbrace:
+        break;
+      }
+    }
+    if (coordinatesAreFractional)
+      evalError("fractional coordinates are not allowed in this context");
+    pt.x = coordinateValue(i);
+    pt.y = coordinateValue(++pcLastExpressionInstruction);
+    pt.z = coordinateValue(++pcLastExpressionInstruction);
+    pt.w = coordinateValue(++pcLastExpressionInstruction);
+       if (statement[++pcLastExpressionInstruction].tok != Token.rightbrace)
+      coordinateExpected();
+    return pt;
+  }
+
+
   float coordinateValue(int i) throws ScriptException {
     // includes support for fractional coordinates
     float val = floatParameter(i++);
@@ -3914,12 +3940,20 @@
     viewer.loadShape(JmolConstants.SHAPE_ISOSURFACE);
     viewer.setShapeProperty(JmolConstants.SHAPE_ISOSURFACE, "init", null);
     boolean colorSeen = false;
+    boolean iHavePlane = false;
     int colorRangeStage = 0;
     for (int i = 1; i < statementLength; ++i) {
       String propertyName = null;
       Object propertyValue = null;
       Token token = statement[i];
       switch (token.tok) {
+      case Token.leftbrace:
+        // {X, Y, Z, W}
+        propertyName = "plane";
+        propertyValue = getPoint4f(i);
+        i = pcLastExpressionInstruction;
+        iHavePlane = true;
+        break;
       case Token.identifier:
         if (((String) token.value).equalsIgnoreCase("fileIndex")) {
           fileIndexPt = i + 1;
@@ -3938,10 +3972,19 @@
             .getUnzippedBufferedReaderOrErrorMessageFromName(filename);
         if (t instanceof String)
           fileNotFoundException(filename + ":" + t);
+        if (iHavePlane) {
+          //dual pass when there is a plane defined
+          viewer.setShapeProperty(JmolConstants.SHAPE_ISOSURFACE, 
"bufferedReader",
+              t);
+          t = null;
+          t = viewer.getUnzippedBufferedReaderOrErrorMessageFromName(filename);
+          colorSeen = true;
+          iHavePlane = false;
+        }
         propertyName = colorSeen ? "colorReader" : "bufferedReader";
-        propertyValue = t;
         if (colorSeen && colorRangeStage != 0 && colorRangeStage != 3)
           invalidArgument();
+        propertyValue = t;
         break;
       case Token.decimal:
         if (colorRangeStage == 0) {

Modified: branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java
===================================================================
--- branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java 2006-05-25 
03:47:48 UTC (rev 5168)
+++ branches/bob200603/Jmol/src/org/jmol/viewer/Isosurface.java 2006-05-25 
05:45:51 UTC (rev 5169)
@@ -79,6 +79,7 @@
 import java.util.BitSet;
 import java.io.BufferedReader;
 import javax.vecmath.Point3f;
+import javax.vecmath.Point4f;
 import javax.vecmath.Point3i;
 import javax.vecmath.Vector3f;
 import javax.vecmath.Matrix3f;
@@ -118,14 +119,18 @@
   float cutoff = 0.02f;
   boolean rangeDefined = false;
   float minRange, maxRange;
+  
+  Point4f thePlane;
+  
   BufferedReader br;
 
   void setProperty(String propertyName, Object value, BitSet bs) {
 
-    //System.out.println("isosurface setProperty: " + propertyName + " = " + 
value);
+    System.out.println("isosurface setProperty: " + propertyName + " = " + 
value);
     if ("init" == propertyName) {
       fileIndex = 1;
       nBytes = 0;
+      thePlane = null;
       super.setProperty("meshID", null, null);
       return;
     }
@@ -135,6 +140,7 @@
         fileIndex = 1;
       return;
     }
+
     if ("bufferedReader" == propertyName) {
       br = (BufferedReader) value;
       if (currentMesh == null)
@@ -142,6 +148,7 @@
       currentMesh.clear("isosurface");
       readData(false);
       calcVoxelVertexVectors();
+      thePlane = null;
       constructTessellatedSurface();
       currentMesh.colix = getDefaultColix();
       currentMesh.initialize();
@@ -151,6 +158,11 @@
       System.out.println("\n" + getJvxlFile(currentMesh, (iHaveColorData ? 
"mapped" : "")));
       return;
     }
+    if ("plane" == propertyName) {
+      thePlane = (Point4f) value;
+      cutoff = 0f;
+      return;
+    }
     if ("cutoff" == propertyName) {
       cutoff = ((Float) value).floatValue();
       return;
@@ -379,6 +391,12 @@
       cutoff = 0.5f; // just 0s and 1s here. detail is in the edgeFractions
     }
     line = "";
+    if (thePlane != null) {
+      if (thePlane.x + thePlane.y + thePlane.z == 0)
+        thePlane.z = 1; //{0 0 0 w} becomes {0 0 1 w}
+      vTemp.set(thePlane.x, thePlane.y, thePlane.z);
+      vTempMag = vTemp.length();
+    }
     for (int x = 0; x < voxelCountX; ++x) {
       float[][] plane = new float[voxelCountY][];
       voxelData[x] = plane;
@@ -387,16 +405,19 @@
         plane[y] = strip;
         for (int z = 0; z < voxelCountZ; ++z) {
           float voxelValue = getNextVoxelValue();
+          if (thePlane != null)
+            voxelValue = calcVoxelPlaneDistance(x, y, z);
           strip[z] = voxelValue;
           ++nDataPoints;
           if (isJvxl || isMapData)
             continue;
           boolean isInside = ((cutoff > 0 && voxelValue >= cutoff) 
-              || (cutoff < 0 && voxelValue <= cutoff));
+              || (cutoff <= 0 && voxelValue <= cutoff));
           if (inside == isInside) {
             dataCount++;
           } else {
-            surfaceData += " " + dataCount;
+            if (dataCount != 0)
+              surfaceData += " " + dataCount;
             dataCount = 1;
             inside = !inside;
           }
@@ -411,6 +432,18 @@
         + " x " + voxelCountZ + " voxels");
   }
 
+  float calcVoxelPlaneDistance(int x, int y, int z) {
+    calcVoxelOrigin(x, y, z);
+    return distancePointToPlane(voxelOrigin, thePlane);
+  }
+
+  final Vector3f vTemp = new Vector3f();
+  float vTempMag;
+  float distancePointToPlane(Point3f pt, Point4f plane) {
+    return (plane.x * pt.x + plane.y * pt.y + plane.z * pt.z + plane.w) / 
vTempMag;    
+  }
+  
+  
   int nStructureData;
   int nEdgeData;
   int nColorData;
@@ -418,7 +451,7 @@
   float jvxlCutoff;
   
   void readJvxlDefinitionLine(boolean showMsg) throws Exception {
-    line = br.readLine(); // skip definition line for now
+    while ((line = br.readLine()).length() == 0 || line.charAt(0) == '#') {}
     if (showMsg)
       System.out.println("reading jvxl data set: " + line);
     jvxlCutoff = parseFloat(line);
@@ -554,7 +587,7 @@
                   + offset.z];
               vertexValues[i] = vertexValue;
               if ((cutoff > 0 && vertexValue >= cutoff)
-                  || (cutoff < 0 && vertexValue <= cutoff))
+                  || (cutoff <= 0 && vertexValue <= cutoff))
                 insideMask |= 1 << i;
             }
 


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