Revision: 20465
          http://sourceforge.net/p/jmol/code/20465
Author:   hansonr
Date:     2015-04-30 13:17:17 +0000 (Thu, 30 Apr 2015)
Log Message:
-----------
Jmol.___JmolVersion="14.3.13_2015.04.30"

bug fix: POV-Ray fixed for perspective and orthographic cameras using new 
z-depth formula.

Modified Paths:
--------------
    trunk/Jmol/src/org/jmol/export/Export3D.java
    trunk/Jmol/src/org/jmol/export/_PovrayExporter.java
    trunk/Jmol/src/org/jmol/export/_TachyonExporter.java
    trunk/Jmol/src/org/jmol/export/__CartesianExporter.java
    trunk/Jmol/src/org/jmol/export/__RayTracerExporter.java
    trunk/Jmol/src/org/jmol/export/___Exporter.java
    trunk/Jmol/src/org/jmol/g3d/CircleRenderer.java
    trunk/Jmol/src/org/jmol/g3d/Graphics3D.java
    trunk/Jmol/src/org/jmol/viewer/Jmol.properties
    trunk/Jmol/src/org/jmol/viewer/TransformManager.java

Modified: trunk/Jmol/src/org/jmol/export/Export3D.java
===================================================================
--- trunk/Jmol/src/org/jmol/export/Export3D.java        2015-04-30 03:09:00 UTC 
(rev 20464)
+++ trunk/Jmol/src/org/jmol/export/Export3D.java        2015-04-30 13:17:17 UTC 
(rev 20465)
@@ -548,10 +548,8 @@
     // from Draw arrow and NucleicMonomer
     if (diameter <= 0)
       return;
-    if (!exporter.isCartesian) {
-      ptA.set(pointA.x, pointA.y, pointA.z);
-      ptB.set(pointB.x, pointB.y, pointB.z);
-    }
+    ptA.set(pointA.x, pointA.y, pointA.z);
+    ptB.set(pointB.x, pointB.y, pointB.z);
     exporter.fillCylinderScreen(colix, endcaps, diameter, ptA, ptB, pt0f, pt1f,
         radius);
   }
@@ -651,7 +649,7 @@
       // shouldn't be here, because that uses renderIsosurface
       return;
     }
-    exporter.fillTriangle(colixA, pA, pB, pC, false, false);
+    exporter.fillTriangle(colixA, pA, pB, pC, false);
   }
 
   @Override
@@ -666,7 +664,7 @@
     ptA.set(pointA.x, pointA.y, pointA.z);
     ptB.set(pointB.x, pointB.y, pointB.z);
     ptC.set(pointC.x, pointC.y, pointC.z);
-    exporter.fillTriangle(colixA, ptA, ptB, ptC, false, false);
+    exporter.fillTriangle(colixA, ptA, ptB, ptC, false);
   }
 
   @Override
@@ -678,27 +676,23 @@
     ptA.set(xpointA, ypointA, zpointA);
     ptB.set(xpointB, ypointB, zpointB);
     ptC.set(xpointC, ypointC, zpointC);
-    exporter.fillTriangle(colix, ptA, ptB, ptC, true, false);
+    exporter.fillTriangle(colix, ptA, ptB, ptC, true);
   }
 
   @Override
   public void fillTriangle3f(P3 pointA, P3 pointB, P3 pointC, boolean 
setNoisy) {
     // rockets
-    exporter.fillTriangle(colix, pointA, pointB, pointC, false, false);
+    exporter.fillTriangle(colix, pointA, pointB, pointC, false);
   }
 
   @Override
   public void fillTriangle3i(P3i screenA, P3i screenB, P3i screenC, T3 ptA0,
                              T3 ptB0, T3 ptC0, boolean doShade) {
     // cartoon only, for nucleic acid bases
-    if (exporter.isCartesian) {
-      exporter.fillTriangle(colix, ptA0, ptB0, ptC0, true, true);
-    } else {
       ptA.set(screenA.x, screenA.y, screenA.z);
       ptB.set(screenB.x, screenB.y, screenB.z);
       ptC.set(screenC.x, screenC.y, screenC.z);
-      exporter.fillTriangle(colix, ptA, ptB, ptC, true, false);
-    }
+      exporter.fillTriangle(colix, ptA, ptB, ptC, true);
   }
 
   /*
@@ -728,8 +722,8 @@
   @Override
   public void fillQuadrilateral(P3 pointA, P3 pointB, P3 pointC, P3 pointD) {
     // hermite, rockets, cartoons
-    exporter.fillTriangle(colix, pointA, pointB, pointC, false, false);
-    exporter.fillTriangle(colix, pointA, pointC, pointD, false, false);
+    exporter.fillTriangle(colix, pointA, pointB, pointC, false);
+    exporter.fillTriangle(colix, pointA, pointC, pointD, false);
   }
 
   @Override
@@ -737,12 +731,6 @@
     exporter.drawSurface(meshSurface, colix);
   }
 
-//  @Override
-//  public short[] getBgColixes(short[] bgcolixes) {
-//    // 3D exporters cannot do background labels
-//    return exporter.exportType == GData.EXPORT_CARTESIAN ? null : bgcolixes;
-//  }
-
   @Override
   public void fillEllipsoid(P3 center, P3[] points, int x, int y, int z,
                             int diameter, M3 mToEllipsoidal, double[] coef,

Modified: trunk/Jmol/src/org/jmol/export/_PovrayExporter.java
===================================================================
--- trunk/Jmol/src/org/jmol/export/_PovrayExporter.java 2015-04-30 03:09:00 UTC 
(rev 20464)
+++ trunk/Jmol/src/org/jmol/export/_PovrayExporter.java 2015-04-30 13:17:17 UTC 
(rev 20465)
@@ -44,10 +44,23 @@
  * Jmol 11.3.30
  * Oct 2008
  * 
+ * Note added by Bob Hanson 4/30/2015
+ * 
+ * Previously we were just writing the exact perspective scene from Jmol
+ * using an orthographic camera. However, the problem with z not being linear
+ * in this mode caused both Jmol and POV-Ray to incorrectly place the z value
+ * of pixels, which was particularly noticeable for large triangles.
+ * (See org.jmol.g3d/PrecisionRenderer.java) 
+ * 
+ *  The solution is to temporarily set the Jmol renderer to orthographic mode 
after
+ *  getting the needed constants.
+ * 
  */
 
 public class _PovrayExporter extends __RayTracerExporter {
   
+  private String perspective;
+
   public _PovrayExporter() {
     commentChar = "// ";
   }
@@ -60,6 +73,7 @@
 
   @Override
   protected void outputHeader() {
+    perspective = getJmolPerspective();
     initVars();
     output("// ******************************************************\n");
     output("// Created by Jmol " + Viewer.getJmolVersion() + "\n");
@@ -67,11 +81,13 @@
     output("// This script was generated on " + getExportDate() + "\n");
     output("// ******************************************************\n");
     try {
-    output(vwr.getWrappedStateScript());
+      output(vwr.getWrappedStateScript());
     } catch (Exception e) {
       // tough luck
     }
     output("\n");
+     output(perspective);
+    output("\n");
     output("// ******************************************************\n");
     output("// Declare the resolution, camera, and light sources.\n");
     output("// ******************************************************\n");
@@ -86,29 +102,39 @@
     output("#declare showBonds = true;\n");
     output("#declare noShadows = true;\n");
     output("camera{\n");
-    output("  orthographic\n");
-    output("  location < " + screenWidth / 2f + ", " + screenHeight / 2f
-        + ", 0>\n" + "\n");
-    output("  // Negative right for a right hand coordinate system.\n");
-    output("\n");
+    float offsetX, offsetY, f;
+    if (wasPerspective) {
+      offsetX = vwr.tm.getTranslationXPercent() / 100 * screenWidth;
+      offsetY = vwr.tm.getTranslationYPercent() / 100 * screenHeight;
+      f = 1f/vwr.tm.getPerspectiveFactor(2500);
+      output("  perspective\n");
+      output("  angle " + aperatureAngle + "\n");
+      output("  right < " + screenWidth + ", 0, 0>\n");
+      output("  up < 0, " + -screenHeight + ", 0 >\n");
+    } else {
+      offsetX = offsetY = f = 0;
+      output("  orthographic\n");
+      output("  right < " + -screenWidth + ", 0, 0>\n");
+      output("  up < 0, " + screenHeight + ", 0 >\n");
+    }
     output("  sky < 0, -1, 0 >\n");
-    output("  right < -" + screenWidth + ", 0, 0>\n");
-    output("  up < 0, " + screenHeight + ", 0 >\n");
-    output("  look_at < " + screenWidth / 2f + ", " + screenHeight / 2f
+    output("  location < " + (screenWidth / 2f + offsetX) + ", " + 
(screenHeight / 2f + offsetY)
+        + ", 0>\n");
+    output("  look_at < " + (screenWidth / 2f + f * offsetX) + ", " + 
(screenHeight / 2f + f * offsetY)
         + ", 1000 >\n");
     output("}\n");
     output("\n");
 
-    output("background { color rgb <" + 
-        rgbFractionalFromColix(backgroundColix)
+    output("background { color rgb <" + rgbFractionalFromColix(backgroundColix)
         + "> }\n");
     output("\n");
 
     // light source
 
     float distance = Math.max(screenWidth, screenHeight);
-    output("light_source { <" + lightSource.x * distance + "," + lightSource.y 
* distance
-        + ", " + (-1 * lightSource.z * distance) + "> " + " rgb <0.6,0.6,0.6> 
}\n");
+    output("light_source { <" + lightSource.x * distance + "," + lightSource.y
+        * distance + ", " + (-1 * lightSource.z * distance) + "> "
+        + " rgb <0.6,0.6,0.6> }\n");
     output("\n");
     output("\n");
 

Modified: trunk/Jmol/src/org/jmol/export/_TachyonExporter.java
===================================================================
--- trunk/Jmol/src/org/jmol/export/_TachyonExporter.java        2015-04-30 
03:09:00 UTC (rev 20464)
+++ trunk/Jmol/src/org/jmol/export/_TachyonExporter.java        2015-04-30 
13:17:17 UTC (rev 20465)
@@ -48,7 +48,6 @@
 
 public class _TachyonExporter extends __RayTracerExporter {
 
-  boolean wasPerspectiveDepth;
   String lighting;
   String phong;
   
@@ -60,8 +59,6 @@
  
   @Override
   boolean initializeOutput(Viewer vwr, double privateKey, GData gdata, 
Map<String, Object> params) {
-    //wasPerspectiveDepth = vwr.getPerspectiveDepth();
-    //vwr.setPerspectiveDepth(false);
     getLightingInfo();
     return initOutput(vwr, privateKey, gdata, params);    
   }

Modified: trunk/Jmol/src/org/jmol/export/__CartesianExporter.java
===================================================================
--- trunk/Jmol/src/org/jmol/export/__CartesianExporter.java     2015-04-30 
03:09:00 UTC (rev 20464)
+++ trunk/Jmol/src/org/jmol/export/__CartesianExporter.java     2015-04-30 
13:17:17 UTC (rev 20465)
@@ -349,16 +349,10 @@
 
   @Override
   protected void fillTriangle(short colix, T3 ptA, T3 ptB,
-                              T3 ptC, boolean twoSided, boolean isCartesian) {
-    if (isCartesian) {
-      tempP1.setT(ptA);
-      tempP2.setT(ptB);
-      tempP3.setT(ptC);
-    } else {
+                              T3 ptC, boolean twoSided) {
       tm.unTransformPoint(ptA, tempP1);
       tm.unTransformPoint(ptB, tempP2);
       tm.unTransformPoint(ptC, tempP3);
-    }
     outputTriangle(tempP1, tempP2, tempP3, colix);
     if (twoSided)
       outputTriangle(tempP1, tempP3, tempP2, colix);

Modified: trunk/Jmol/src/org/jmol/export/__RayTracerExporter.java
===================================================================
--- trunk/Jmol/src/org/jmol/export/__RayTracerExporter.java     2015-04-30 
03:09:00 UTC (rev 20464)
+++ trunk/Jmol/src/org/jmol/export/__RayTracerExporter.java     2015-04-30 
13:17:17 UTC (rev 20465)
@@ -26,8 +26,11 @@
 package org.jmol.export;
 
 
+import java.util.Map;
+
 import org.jmol.modelset.Atom;
 import org.jmol.util.GData;
+import org.jmol.viewer.Viewer;
 
 import javajs.util.M3;
 import javajs.util.M4;
@@ -45,6 +48,7 @@
 
   protected boolean isSlabEnabled;
   protected int minScreenDimension;
+  protected boolean wasPerspective;
   
   public __RayTracerExporter() {
     exportType = GData.EXPORT_RAYTRACER;
@@ -52,6 +56,25 @@
   }
 
   @Override
+  protected boolean initOutput(Viewer vwr, double privateKey, GData g3d,
+                               Map<String, Object> params) {
+    wasPerspective = vwr.tm.perspectiveDepth;
+    if (super.initOutput(vwr, privateKey, g3d, params)) {
+      vwr.tm.perspectiveDepth = false;
+      if (wasPerspective)
+        vwr.shm.finalizeAtoms(null, null);
+      return true;
+    }
+    return false; 
+  }
+    
+  @Override
+  protected String finalizeOutput2() {
+    vwr.tm.perspectiveDepth = wasPerspective;
+    return super.finalizeOutput2();    
+  }
+  
+  @Override
   protected void outputVertex(T3 pt, T3 offset) {
     setTempVertex(pt, offset, tempP1);
     tm.transformPt3f(tempP1, tempP1);
@@ -196,11 +219,11 @@
   @Override
   void fillCylinderScreenMad(short colix, byte endcaps, int diameter, 
                                P3 screenA, P3 screenB) {
+    if (diameter == 0)
+      return;
+    if (diameter < 1)
+      diameter = 1;
     float radius = diameter / 2f;
-    if (radius == 0)
-      return;
-    if (radius < 1)
-      radius = 1;
     if (screenA.distance(screenB) == 0) {
       outputSphere(screenA.x, screenA.y, screenA.z, radius, colix);
       return;
@@ -226,7 +249,7 @@
   }
   
   @Override
-  protected void fillTriangle(short colix, T3 ptA, T3 ptB, T3 ptC, boolean 
twoSided, boolean isCartesian) {
+  protected void fillTriangle(short colix, T3 ptA, T3 ptB, T3 ptC, boolean 
twoSided) {
     outputTriangle(ptA, ptB, ptC, colix);
   }
 

Modified: trunk/Jmol/src/org/jmol/export/___Exporter.java
===================================================================
--- trunk/Jmol/src/org/jmol/export/___Exporter.java     2015-04-30 03:09:00 UTC 
(rev 20464)
+++ trunk/Jmol/src/org/jmol/export/___Exporter.java     2015-04-30 13:17:17 UTC 
(rev 20465)
@@ -144,8 +144,6 @@
   protected String fileName;
   protected String commandLineOptions;
   
-  public boolean isCartesian;
-  
   protected GData gdata;
 
   protected short backgroundColix;
@@ -205,7 +203,7 @@
     this.vwr = vwr;
     tm = vwr.tm;
     isWebGL = params.get("type").equals("JS");
-    this.gdata = g3d;
+    gdata = g3d;
     this.privateKey = privateKey;
     backgroundColix = vwr.getObjectColix(StateManager.OBJ_BACKGROUND);
     center.setT(tm.fixedRotationCenter);
@@ -324,6 +322,10 @@
     return rgbFractionalFromArgb(gdata.getColorArgbOrGray(colix));
   }
 
+  protected String getTriadC(T3 t) {
+    return  getTriad(t);
+  }
+  
   protected String getTriad(T3 t) {
     return round(t.x) + " " + round(t.y) + " " + round(t.z); 
   }
@@ -337,7 +339,7 @@
     tempC.set(red == 0 ? 0 : (red + 1)/ 256f, 
         green == 0 ? 0 : (green + 1) / 256f, 
         blue == 0 ? 0 : (blue + 1) / 256f);
-    return getTriad(tempC);
+    return getTriadC(tempC);
   }
 
   protected static String translucencyFractionalFromColix(short colix) {
@@ -563,7 +565,7 @@
   abstract void fillSphere(short colix, int diameter, P3 pt);
   
   //cartoons, rockets, polyhedra:
-  protected abstract void fillTriangle(short colix, T3 ptA0, T3 ptB0, T3 ptC0, 
boolean twoSided, boolean isCartesian);
+  protected abstract void fillTriangle(short colix, T3 ptA0, T3 ptB0, T3 ptC0, 
boolean twoSided);
   
   
   private int nText;

Modified: trunk/Jmol/src/org/jmol/g3d/CircleRenderer.java
===================================================================
--- trunk/Jmol/src/org/jmol/g3d/CircleRenderer.java     2015-04-30 03:09:00 UTC 
(rev 20464)
+++ trunk/Jmol/src/org/jmol/g3d/CircleRenderer.java     2015-04-30 13:17:17 UTC 
(rev 20465)
@@ -155,13 +155,13 @@
     Pixelator p = g.pixel;
 
     while (x >= y) {
-      g.plotPixelsClipped(c, 2 * x + 1 - sizeCorrection, xCenter - x, yCenter
+      plotPixelsClipped(c, 2 * x + 1 - sizeCorrection, xCenter - x, yCenter
           + y - sizeCorrection, zCenter, width, height, zbuf, p);
-      g.plotPixelsClipped(c, 2 * x + 1 - sizeCorrection, xCenter - x, yCenter
+      plotPixelsClipped(c, 2 * x + 1 - sizeCorrection, xCenter - x, yCenter
           - y, zCenter, width, height, zbuf, p);
-      g.plotPixelsClipped(c, 2 * y + 1 - sizeCorrection, xCenter - y, yCenter
+      plotPixelsClipped(c, 2 * y + 1 - sizeCorrection, xCenter - y, yCenter
           + x - sizeCorrection, zCenter, width, height, zbuf, p);
-      g.plotPixelsClipped(c, 2 * y + 1 - sizeCorrection, xCenter - y, yCenter
+      plotPixelsClipped(c, 2 * y + 1 - sizeCorrection, xCenter - y, yCenter
           - x, zCenter, width, height, zbuf, p);
       ++y;
       radiusError += yChange;
@@ -174,6 +174,29 @@
     }
   }
 
+  private void plotPixelsClipped(int argb, int count, int x, int y, int z, int 
width,
+                         int height, int[] zbuf, Pixelator p) {
+    // for circle only; i.e. halo 
+    // simple Z/window clip
+    if (y < 0 || y >= height || x >= width)
+      return;
+    if (x < 0) {
+      count += x; // x is negative, so this is subtracting -x
+      x = 0;
+    }
+    if (count + x > width)
+      count = width - x;
+    if (count <= 0)
+      return;
+    int offsetPbuf = y * width + x;
+    int offsetMax = offsetPbuf + count;
+    while (offsetPbuf < offsetMax) {
+      if (z < zbuf[offsetPbuf])
+        p.addPixel(offsetPbuf, z, argb);
+      offsetPbuf++;// += step;
+    }
+  }
+
   void plotFilledCircleCenteredUnclipped(int xCenter, int yCenter, int zCenter,
                                          int diameter) {
     // for halo only

Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java
===================================================================
--- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2015-04-30 03:09:00 UTC (rev 
20464)
+++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2015-04-30 13:17:17 UTC (rev 
20465)
@@ -1610,29 +1610,6 @@
     }
   }
 
-  void plotPixelsClipped(int argb, int count, int x, int y, int z, int width,
-                         int height, int[] zbuf, Pixelator p) {
-    // for circle only; i.e. halo 
-    // simple Z/window clip
-    if (y < 0 || y >= height || x >= width)
-      return;
-    if (x < 0) {
-      count += x; // x is negative, so this is subtracting -x
-      x = 0;
-    }
-    if (count + x > width)
-      count = width - x;
-    if (count <= 0)
-      return;
-    int offsetPbuf = y * width + x;
-    int offsetMax = offsetPbuf + count;
-    while (offsetPbuf < offsetMax) {
-      if (z < zbuf[offsetPbuf])
-        p.addPixel(offsetPbuf, z, argb);
-      offsetPbuf++;// += step;
-    }
-  }
-
   void plotPixelsClippedRaster(int count, int x, int y, int zAtLeft,
                                int zPastRight, Rgb16 rgb16Left, Rgb16 
rgb16Right) {
     // cylinder3d.renderFlatEndcap, triangle3d.fillRaster

Modified: trunk/Jmol/src/org/jmol/viewer/Jmol.properties
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-04-30 03:09:00 UTC 
(rev 20464)
+++ trunk/Jmol/src/org/jmol/viewer/Jmol.properties      2015-04-30 13:17:17 UTC 
(rev 20465)
@@ -14,9 +14,12 @@
 
 TODO: remove HTML5 dependency on synchronous file loading (check SCRIPT 
command for problems)
 
+Jmol.___JmolVersion="14.3.13_2015.04.30"
 
-Jmol.___JmolVersion="14.3.13_2015.04.29"
+bug fix: POV-Ray fixed for perspective and orthographic cameras using new 
z-depth formula.
 
+JmolVersion="14.3.13_2015.04.29"
+
 bug fix: perspective renderer was using the wrong formula for calculating Z 
depth of pixels:
 
  * Note added 4/2015 BH:

Modified: trunk/Jmol/src/org/jmol/viewer/TransformManager.java
===================================================================
--- trunk/Jmol/src/org/jmol/viewer/TransformManager.java        2015-04-30 
03:09:00 UTC (rev 20464)
+++ trunk/Jmol/src/org/jmol/viewer/TransformManager.java        2015-04-30 
13:17:17 UTC (rev 20465)
@@ -1149,7 +1149,6 @@
    * This method returns data needed by the VRML, X3D, and IDTF/U3D exporters.
    * It also should serve as a valuable resource for anyone adapting Jmol and
    * wanting to know how the Jmol 11+ camera business works.
-   * 
    * @return a set of camera data
    */
   public P3[] getCameraFactors() {

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


------------------------------------------------------------------------------
One dashboard for servers and applications across Physical-Virtual-Cloud 
Widest out-of-the-box monitoring support with 50+ applications
Performance metrics, stats and reports that give you Actionable Insights
Deep dive visibility with transaction tracing using APM Insight.
http://ad.doubleclick.net/ddm/clk/290420510;117567292;y
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to