Revision: 21518
          http://sourceforge.net/p/jmol/code/21518
Author:   hansonr
Date:     2017-04-14 04:36:53 +0000 (Fri, 14 Apr 2017)
Log Message:
-----------
Jmol.___JmolVersion="14.14.1"

new feature: set jmolInJSpecView  
  -- allows Jmol window to NOT be embedded in JSpecView when JSpecView is 
opened in Jmol
  -- default TRUE
  
new feature: WRITE ISOMESH "t.pmesh"; WRITE ISOMESHBIN "t.pmb"
  -- isosurface contour only (for now)
  -- creates ASCII/BINARY .pmesh/.pmb file
  -- read back into Jmol using ISOSURFACE PMESH "t.pmesh"/"t.pmb"
  -- note that binary files are NOT RECOMMENDED for JSmol because some 
platforms cannot read them locally
  -- example:
  
  load $methane
  isosurface plane {0 0 0 1} map vdw contours 20
  write ISOMESHBIN contour.pmb
  isosurface PMESH contour.pmb
  

bug fix: mesh capper producing gaps
bug fix: CIP chirality fixed for rule ordering; validated for IUPAC Rules 1, 2, 
and 3 (though still some questions about Rule 3)
bug fix: print getProperty("cifinfo") without file name fails
 
 

Modified Paths:
--------------
    trunk/Jmol/src/javajs/util/OC.java
    trunk/Jmol/src/javajs/util/T3.java
    trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java
    trunk/Jmol/src/org/jmol/scriptext/CmdExt.java
    trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java
    trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java
    trunk/Jmol/src/org/jmol/util/MeshSurface.java
    trunk/Jmol/src/org/jmol/viewer/Jmol.properties

Modified: trunk/Jmol/src/javajs/util/OC.java
===================================================================
--- trunk/Jmol/src/javajs/util/OC.java  2017-04-13 16:27:44 UTC (rev 21517)
+++ trunk/Jmol/src/javajs/util/OC.java  2017-04-14 04:36:53 UTC (rev 21518)
@@ -440,4 +440,8 @@
     }
   }
 
+  public void writeFloat(float x) {
+    writeInt(x == 0 ? 0 : Float.floatToIntBits(x));
+  }
+
 }

Modified: trunk/Jmol/src/javajs/util/T3.java
===================================================================
--- trunk/Jmol/src/javajs/util/T3.java  2017-04-13 16:27:44 UTC (rev 21517)
+++ trunk/Jmol/src/javajs/util/T3.java  2017-04-14 04:36:53 UTC (rev 21518)
@@ -304,7 +304,7 @@
     return (int) (bits ^ (bits >> 32));
   }
 
-  static int floatToIntBits(float x) {
+  public static int floatToIntBits(float x) {
     return (x == 0 ? 0 : Float.floatToIntBits(x));
   }
 

Modified: trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java
===================================================================
--- trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java       2017-04-13 
16:27:44 UTC (rev 21517)
+++ trunk/Jmol/src/org/jmol/jvxl/readers/PmeshReader.java       2017-04-14 
04:36:53 UTC (rev 21518)
@@ -41,7 +41,7 @@
  3.0000 3.0000 1.0000
  2.3333 3.0000 1.0000
  ...(98 more like this)
- 81
+ 81 <-- polygonCount may be -1
  5
  0
  10
@@ -49,6 +49,7 @@
  1
  0
  ...(80 more sets like this)
+ <-- may be 0 if polygonCount = -1
 
  * The first line defines the number of grid points 
  *   defining the surface (integer, n)
@@ -58,9 +59,9 @@
  * The next m sets of numbers, one number per line, 
  *   define the polygons. In each set, the first number, p, specifies 
  *   the number of points in each set. Currently this number must be either 
- *   4 (for triangles) or 5 (for quadrilaterals). The next p numbers specify 
+ *   1 (points), 2 (edges), 3 (triangles), 4 (for closed triangles) or 5 (for 
closed quadrilaterals). The next p numbers specify 
  *   indexes into the list of data points (starting with 0). 
- *   The first and last of these numbers must be identical in order to 
+ *   For p > 3, the first and last of these numbers must be identical in order 
to 
  *   "close" the polygon. 
  *   
  *   If the number of points in a set is negative, it indicates that a color 
follows:
@@ -81,10 +82,9 @@
  * note that there is NO redundant extra vertex in this format 
  *
  *  4 bytes: P M \1 \0 
- *  4 bytes: ignored
  *  4 bytes: (int) 1 -- first byte used to determine big(==0) or little(!=0) 
endian
  *  4 bytes: (int) nVertices
- *  4 bytes: (int) nPolygons
+ *  4 bytes: (int) nPolygons -- may be -1
  * 64 bytes: reserved
  *  ------------------------------
  *  float[nVertices*3]vertices {x,y,z}
@@ -92,7 +92,7 @@
  *  --each polygon--
  *    4 bytes: (int)nVertices (1,2,3, or 4)
  *    [4 bytes * nVertices] int[nVertices]
- *    
+ *    optional 4 bytes (int)0 -- end of file 
  *
  */
 
@@ -233,19 +233,25 @@
     pmeshError = type  + " ERROR: polygon count must be zero or positive";
     if (!isBinary)
       nPolygons = getInt();
-    if (nPolygons < 0) {
-      pmeshError += " (" + nPolygons + ")";
-      return false;
-    }
+//    if (nPolygons < 0) {
+//      pmeshError += " (" + nPolygons + ")";
+//      return false;
+//    }
     if (onePerLine)
       iToken = Integer.MAX_VALUE;
     int[] vertices = new int[5];
+    if (nPolygons == -1)
+      nPolygons = Integer.MAX_VALUE;
+    int nread = 0;
     for (int iPoly = 0; iPoly < nPolygons; iPoly++) {
       int intCount = (fixedCount == 0 ? getInt() : fixedCount);
+      if (intCount == 0)
+        break;
+      nread++;
       boolean haveColor = (intCount < 0);
       if (haveColor)
         intCount = -intCount;
-      int vertexCount = intCount - (isClosedFace ? 1 : 0);
+      int vertexCount = intCount - (intCount > 3 && isClosedFace ? 1 : 0);
       // (we will ignore the redundant extra vertex when not binary and not 
msms)
       if (vertexCount < 1 || vertexCount > 4) {
         pmeshError = type  + " ERROR: bad polygon (must have 1-4 vertices) at 
#"
@@ -271,10 +277,14 @@
           vertices[i] = vertices[i - 1];
       int color = 0;
       if (haveColor) {
-        String c = nextToken();
-        color = parseIntStr(c);
-        if (color == Integer.MIN_VALUE)
-          color = CU.getArgbFromString(c);
+        if (isBinary) {
+         color = getInt(); 
+        } else {
+          String c = nextToken();
+          color = parseIntStr(c);
+          if (color == Integer.MIN_VALUE)
+            color = CU.getArgbFromString(c);
+        }
         color |= 0xFF000000;
       }
       // check: 1 (ab) | 2(bc) | 4(ac)
@@ -299,6 +309,7 @@
     }
     if (isBinary)
       nBytes = binarydoc.getPosition();
+    nPolygons = nread;
     return true;
   }
 

Modified: trunk/Jmol/src/org/jmol/scriptext/CmdExt.java
===================================================================
--- trunk/Jmol/src/org/jmol/scriptext/CmdExt.java       2017-04-13 16:27:44 UTC 
(rev 21517)
+++ trunk/Jmol/src/org/jmol/scriptext/CmdExt.java       2017-04-14 04:36:53 UTC 
(rev 21518)
@@ -3754,6 +3754,7 @@
       // quality|PNG|PPM|SPT] "filename"
       // write script "filename"
       // write isosurface t.jvxl
+      // write isosurface t.pmesh
 
       if (type.equals("IMAGE")
           && PT.isOneOf(val.toLowerCase(), JC.IMAGE_OR_SCENE)) {
@@ -3862,7 +3863,7 @@
         && !PT
             .isOneOf(
                 type,
-                
";SCENE;JMOL;ZIP;ZIPALL;SPT;HISTORY;MO;NBO;ISOSURFACE;MESH;PMESH;VAR;FILE;FUNCTION;CIF;CML;JSON;XYZ;XYZRN;XYZVIB;MENU;MOL;MOL67;PDB;PGRP;PQR;QUAT;RAMA;SDF;V2000;V3000;INLINE;"))
+                
";SCENE;JMOL;ZIP;ZIPALL;SPT;HISTORY;MO;NBO;ISOSURFACE;MESH;PMESH;PMB;ISOMESHBIN;ISOMESH;VAR;FILE;FUNCTION;CIF;CML;JSON;XYZ;XYZRN;XYZVIB;MENU;MOL;MOL67;PDB;PGRP;PQR;QUAT;RAMA;SDF;V2000;V3000;INLINE;"))
       eval.errorStr2(
           ScriptError.ERROR_writeWhat,
           
"COORDS|FILE|FUNCTIONS|HISTORY|IMAGE|INLINE|ISOSURFACE|JMOL|MENU|MO|NBO|POINTGROUP|QUATERNION
 [w,x,y,z] [derivative]"
@@ -4011,11 +4012,19 @@
         data = getMoJvxl(Integer.MAX_VALUE, data == "NBO");
         type = "XJVXL";
       } else if (data == "PMESH") {
-        if ((data = getIsosurfaceJvxl(true, JC.SHAPE_PMESH)) == null)
+        if ((data = (String) getIsosurfaceJvxl(JC.SHAPE_PMESH, data)) == null)
           error(ScriptError.ERROR_noData);
         type = "XJVXL";
+      } else if (data == "ISOMESH") {
+        if ((data = (String) getIsosurfaceJvxl(JC.SHAPE_ISOSURFACE, data)) == 
null)
+          error(ScriptError.ERROR_noData);
+        type = "PMESH";
+      } else if (data == "ISOMESHBIN" || data == "PMB") {
+        if ((bytes = getIsosurfaceJvxl(JC.SHAPE_ISOSURFACE, "ISOMESHBIN")) == 
null)
+          error(ScriptError.ERROR_noData);
+        type = "PMB";
       } else if (data == "ISOSURFACE" || data == "MESH") {
-        if ((data = getIsosurfaceJvxl(data == "MESH", JC.SHAPE_ISOSURFACE)) == 
null)
+        if ((data = (String) getIsosurfaceJvxl(JC.SHAPE_ISOSURFACE, data)) == 
null)
           error(ScriptError.ERROR_noData);
         type = (data.indexOf("<?xml") >= 0 ? "XJVXL" : "JVXL");
         if (!showOnly)
@@ -5192,9 +5201,11 @@
     return sb.toString();
   }
 
-  private String getIsosurfaceJvxl(boolean asMesh, int iShape) {
-    return (chk ? "" : (String) getShapeProperty(iShape, asMesh ? "jvxlMeshX"
-        : "jvxlDataXml"));
+  private Object getIsosurfaceJvxl(int iShape, String type) {
+   type = (type == "PMESH" || type == "MESH" ? "jvxlMeshX" : 
+     type == "ISOMESH" ? "pmesh" : type == "ISOMESHBIN" ? "pmeshbin" 
+        : "jvxlDataXml");   
+    return (chk ? "" : getShapeProperty(iShape, type));
   }
 
   @SuppressWarnings("unchecked")

Modified: trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java
===================================================================
--- trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java        2017-04-13 
16:27:44 UTC (rev 21517)
+++ trunk/Jmol/src/org/jmol/shapesurface/Isosurface.java        2017-04-14 
04:36:53 UTC (rev 21518)
@@ -925,6 +925,8 @@
       return jvxlData.jvxlPlane;
     if (property == "contours")
       return thisMesh.getContours();
+    if (property == "pmesh" || property == "pmeshbin")
+      return thisMesh.getPmeshData(property == "pmeshbin"); 
     if (property == "jvxlDataXml" || property == "jvxlMeshXml") {
       MeshData meshData = null;
       jvxlData.slabInfo = null;

Modified: trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java
===================================================================
--- trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java    2017-04-13 
16:27:44 UTC (rev 21517)
+++ trunk/Jmol/src/org/jmol/shapesurface/IsosurfaceMesh.java    2017-04-14 
04:36:53 UTC (rev 21518)
@@ -43,6 +43,7 @@
 
 import javajs.util.CU;
 import javajs.util.M4;
+import javajs.util.OC;
 import javajs.util.P3;
 import javajs.util.P3i;
 import javajs.util.PT;
@@ -292,6 +293,152 @@
     return jvxlData.vContours = vContours;
   }
 
+  public Object getPmeshData(boolean isBinary) {
+    MeshWriter mw = new MeshWriter(isBinary);
+    return mw.write();
+  }
+
+  private class MeshWriter {
+    boolean isBinary;
+    private OC oc;
+
+   MeshWriter(boolean isBinary) {
+      this.isBinary = isBinary;
+      oc = vwr.getOutputChannel(null, null);
+      if (isBinary) {
+        oc.writeByteAsInt(80);
+        oc.writeByteAsInt(77);
+        oc.writeByteAsInt(1);
+        oc.writeByteAsInt(0);
+        oc.writeInt(1);
+        oc.writeInt(vc);
+        oc.writeInt(-1);
+        for (int i = 0; i < 16; i++)
+          oc.writeInt(0); 
+      }
+    }
+   
+    Object write() {
+      boolean fill = false;
+      int[][] polygonIndexes = pis;
+      short cx = (!fill && meshColix != 0 ? meshColix : colix);
+      short[] vertexColixes = (!fill && meshColix != 0 ? null : vcs);
+      boolean colorSolid = (vertexColixes == null);
+      boolean noColor = (vertexColixes == null || !fill && meshColix != 0);
+      boolean colorArrayed = (colorSolid && pcs != null);
+      if (colorArrayed && !fill && fillTriangles)
+        colorArrayed = false;
+      short[] contourColixes = jvxlData.contourColixes;
+      boolean haveBsDisplay = (bsDisplay != null);
+      boolean selectedPolyOnly = (bsSlabDisplay != null);
+      BS bsPolygons = (selectedPolyOnly ? bsSlabDisplay : null);
+      int i0 = 0;
+      int color = 0;
+      if (!isBinary)
+        outputInt(vc);
+      for (int i = 0; i < vc; i++)
+        outputXYZ(vs[i]);
+      if (!isBinary)
+        outputInt(-1); // null-terminated
+      for (int i = pc; --i >= i0;) {
+        int[] polygon = polygonIndexes[i];
+        if (polygon == null || selectedPolyOnly && !bsPolygons.get(i))
+          continue;
+        int iA = polygon[0];
+        int iB = polygon[1];
+        int iC = polygon[2];
+        if (jvxlData.thisSet >= 0 && vertexSets != null
+            && vertexSets[iA] != jvxlData.thisSet)
+          continue;
+        if (haveBsDisplay
+            && (!bsDisplay.get(iA) || !bsDisplay.get(iB) || 
!bsDisplay.get(iC)))
+          continue;
+        if (colorSolid) {
+          if (colorArrayed && i < pcs.length) {
+            short c = pcs[i];
+            if (c == 0)
+              continue;
+            cx = c;
+          }
+        } else {
+          cx = vertexColixes[iA];
+        }
+        color = C.getArgb(cx);
+        if (fill) {
+          if (iB == iC) {
+            if (iA == iB)
+              outputPoint(iA, color);
+            else
+              outputEdge(iA, iB, color);
+          } else if (colorsExplicit) {
+            color = polygon[MeshSurface.P_EXPLICIT_COLOR];
+            outputTriangle(iA, iB, iC, color, 7);
+          } else {
+            outputTriangle(iA, iB, iC, color, 7);
+          }
+        } else {
+          // mesh only
+          // check: 1 (ab) | 2(bc) | 4(ac)
+          int check = 7 & polygon[MeshSurface.P_CHECK];
+          if (check == 0)
+            continue;
+          if (noColor) {
+          } else if (colorArrayed) {
+            color = C.getArgb(fillTriangles ? C.BLACK
+                : contourColixes[polygon[MeshSurface.P_CONTOUR]
+                    % contourColixes.length]);
+          }
+          outputTriangle(iA, iB, iC, color, check);
+        }
+      }
+      if (isBinary)
+        oc.writeInt(0);
+      else
+        oc.append("0\n");
+      oc.closeChannel();
+      return (isBinary ? oc.toByteArray() : oc.toString());
+    }
+
+    private void outputInt(int i) {
+      if (isBinary)
+        oc.writeInt(i);
+      else
+        oc.append("" + i + "\n");
+    }
+
+    private int outputPoint(int iA, int color) {
+      outputInt(-1);
+      outputInt(iA);
+      outputInt(color);
+      return 1;
+    }
+
+    private void outputXYZ(T3 pt) {
+      if (isBinary) {
+        oc.writeFloat(pt.x);
+        oc.writeFloat(pt.y);
+        oc.writeFloat(pt.z);
+      } else {
+        oc.append(pt.x + " " + pt.y + " " + pt.z + "\n");
+      }
+    }
+
+    private void outputEdge(int iA, int iB, int color) {
+      outputInt(-2);
+      outputInt(iA);
+      outputInt(iB);
+      outputInt(color);
+    }
+
+    private void outputTriangle(int iA, int iB, int iC, int color, int check) {
+      if ((check & 1) != 0)
+        outputEdge(iA, iB, color);
+      if ((check & 2) != 0)
+        outputEdge(iB, iC, color);
+      if ((check & 4) != 0)
+        outputEdge(iC, iA, color);
+    }
+  }
   private static void get3dContour(IsosurfaceMesh m, Lst<Object> v, float 
value, short colix) {
     BS bsContour = BS.newN(m.pc);
     SB fData = new SB();

Modified: trunk/Jmol/src/org/jmol/util/MeshSurface.java
===================================================================
--- trunk/Jmol/src/org/jmol/util/MeshSurface.java       2017-04-13 16:27:44 UTC 
(rev 21517)
+++ trunk/Jmol/src/org/jmol/util/MeshSurface.java       2017-04-14 04:36:53 UTC 
(rev 21518)
@@ -21,7 +21,7 @@
   public static final int P_CONTOUR = 4;
   public static final int P_EXPLICIT_COLOR = 4;
 
-  protected Viewer vwr;
+  public Viewer vwr;
   
   private MeshSlicer slicer;
   

Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2017-04-13 16:27:44 UTC 
(rev 21517)
+++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2017-04-14 04:36:53 UTC 
(rev 21518)
@@ -55,6 +55,19 @@
   -- allows Jmol window to NOT be embedded in JSpecView when JSpecView is 
opened in Jmol
   -- default TRUE
   
+new feature: WRITE ISOMESH "t.pmesh"; WRITE ISOMESHBIN "t.pmb"
+  -- isosurface contour only (for now)
+  -- creates ASCII/BINARY .pmesh/.pmb file
+  -- read back into Jmol using ISOSURFACE PMESH "t.pmesh"/"t.pmb"
+  -- note that binary files are NOT RECOMMENDED for JSmol because some 
platforms cannot read them locally
+  -- example:
+  
+  load $methane
+  isosurface plane {0 0 0 1} map vdw contours 20
+  write ISOMESHBIN contour.pmb
+  isosurface PMESH contour.pmb
+  
+
 bug fix: mesh capper producing gaps
 bug fix: CIP chirality fixed for rule ordering; validated for IUPAC Rules 1, 
2, and 3 (though still some questions about Rule 3)
 bug fix: print getProperty("cifinfo") without file name fails

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


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to