Revision: 20169
          http://sourceforge.net/p/jmol/code/20169
Author:   hansonr
Date:     2014-12-21 19:56:15 +0000 (Sun, 21 Dec 2014)
Log Message:
-----------
minor efficiencies

Modified Paths:
--------------
    trunk/Jmol/src/org/jmol/g3d/Graphics3D.java
    trunk/Jmol/src/org/jmol/g3d/LineRenderer.java
    trunk/Jmol/src/org/jmol/g3d/TriangleRenderer.java

Modified: trunk/Jmol/src/org/jmol/g3d/Graphics3D.java
===================================================================
--- trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2014-12-21 17:30:57 UTC (rev 
20168)
+++ trunk/Jmol/src/org/jmol/g3d/Graphics3D.java 2014-12-21 19:56:15 UTC (rev 
20169)
@@ -311,6 +311,7 @@
     stringCount = 0;
     twoPass = true; //only for testing -- set false to disallow second pass
     isPass2 = false;
+    pass2Flag01 = 0;
     colixCurrent = 0;
     haveTranslucentObjects = false;
     translucentCoverOnly = !translucentMode;
@@ -350,6 +351,7 @@
     if (!haveTranslucentObjects || !currentlyRendering)
       return false;
     isPass2 = true;
+    pass2Flag01 = 1;
     colixCurrent = 0;
     //aap = true;
     if (pbufT == null || antialias2 != antialiasTranslucent) {
@@ -1838,6 +1840,7 @@
 
   private final byte[] shadeIndexes = new byte[normixCount];
   private final byte[] shadeIndexes2Sided = new byte[normixCount];
+  public int pass2Flag01;
     
   public void setRotationMatrix(M3 rotationMatrix) {
     V3[] vertexVectors = Normix.getVertexVectors();

Modified: trunk/Jmol/src/org/jmol/g3d/LineRenderer.java
===================================================================
--- trunk/Jmol/src/org/jmol/g3d/LineRenderer.java       2014-12-21 17:30:57 UTC 
(rev 20168)
+++ trunk/Jmol/src/org/jmol/g3d/LineRenderer.java       2014-12-21 19:56:15 UTC 
(rev 20169)
@@ -47,7 +47,6 @@
 
 import org.jmol.java.BS;
 import org.jmol.util.GData;
-import org.jmol.util.Logger;
 import org.jmol.util.Shader;
 
 final class LineRenderer {
@@ -64,19 +63,30 @@
   private float slope;
   private boolean lineTypeX;
   private int nBits;
-  private int nCached = 0;
-  private int nFound = 0;
+//  private int nCached = 0;
+//  private int nFound = 0;
   //int test = 5;
   private Map<Float, BS> lineCache = new Hashtable<Float, BS>();
   private Float slopeKey;
   
-  void setLineBits(float dx, float dy) { 
+  void setLineBits(float dx, float dy) {
     // from cylinder
-    slope = (dx != 0 ?  dy / dx : dy >= 0 ? Float.MAX_VALUE  : 
-Float.MAX_VALUE);
-    lineTypeX = (slope <=1 && slope >= -1);
+    slope = (dx != 0 ? dy / dx : dy >= 0 ? Float.MAX_VALUE : -Float.MAX_VALUE);
+    lineTypeX = (slope <= 1 && slope >= -1);
     nBits = (lineTypeX ? g3d.width : g3d.height);
-    if (getCachedLine())
+
+    // get cached line bits or create new ones
+
+    slopeKey = Float.valueOf(slope);
+    if (lineCache.containsKey(slopeKey)) {
+      lineBits = lineCache.get(slopeKey);
+      //    if (Logger.debugging) {
+      //      nFound++;
+      //      if (nFound == 1000000)
+      //        Logger.debug("nCached/nFound lines: " + nCached + " " + 
nFound);
+      //    }
       return;
+    }
     lineBits = BS.newN(nBits);
     dy = Math.abs(dy);
     dx = Math.abs(dx);
@@ -93,15 +103,15 @@
         lineBits.set(i);
         twoDError -= twoDx;
       }
-    }    
+    }
     lineCache.put(slopeKey, lineBits);
-    nCached++;
+    //nCached++;
     //if (--test > 0 || ((100-test) % 100 == 0)) System.out.println(test+" 
"+dx + " " + dy + " " + lineBits);
   }
   
   void clearLineCache() {
     lineCache.clear();
-    nCached = 0;
+    //nCached = 0;
   }
   
   void plotLine(int argbA, int argbB, 
@@ -115,9 +125,6 @@
     y2t = yB;
     z1t = zA;
     z2t = zB;
-    //if (xA != 250 && xB != 250)return;
-    //System.out.println("\t\t\t" + xA + "," + yA + " " + xB + "," + yB);
-
     if (clipped)
       switch (getTrimmedLine()) {
       case VISIBILITY_UNCLIPPED:
@@ -210,19 +217,6 @@
         - yA, zB - zA, clipped, run, rise);
   }
 
-  private boolean getCachedLine() {
-    slopeKey = Float.valueOf(slope);
-    if (!lineCache.containsKey(slopeKey))
-      return false;
-    lineBits = lineCache.get(slopeKey);
-    if (Logger.debugging) {
-      nFound++;
-      if (nFound == 1000000)
-        Logger.debug("nCached/nFound lines: " + nCached + " " + nFound);
-    }
-    return true;
-  }
-  
   private final static int VISIBILITY_UNCLIPPED = 0;
   private final static int VISIBILITY_CLIPPED = 1;
   private final static int VISIBILITY_OFFSCREEN = 2;

Modified: trunk/Jmol/src/org/jmol/g3d/TriangleRenderer.java
===================================================================
--- trunk/Jmol/src/org/jmol/g3d/TriangleRenderer.java   2014-12-21 17:30:57 UTC 
(rev 20168)
+++ trunk/Jmol/src/org/jmol/g3d/TriangleRenderer.java   2014-12-21 19:56:15 UTC 
(rev 20169)
@@ -122,20 +122,6 @@
    *
    *==============================================================*/
 
-  void drawfillTriangle(int xA, int yA, int zA, int xB, int yB, int zB, int xC,
-                        int yC, int zC, boolean useGouraud) {
-    ax[0] = xA;
-    ax[1] = xB;
-    ax[2] = xC;
-    ay[0] = yA;
-    ay[1] = yB;
-    ay[2] = yC;
-    az[0] = zA;
-    az[1] = zB;
-    az[2] = zC;
-    fillTriangleB(useGouraud);
-  }
-
   void fillTriangleXYZ(int xScreenA, int yScreenA, int zScreenA, int xScreenB,
                     int yScreenB, int zScreenB, int xScreenC, int yScreenC,
                     int zScreenC, boolean useGouraud) {
@@ -167,7 +153,6 @@
 
   void fillTriangleP3f(P3 screenA, P3 screenB, P3 screenC,
                     boolean useGouraud) {
-    //if (screenA.y > 260)return;
     ax[0] = Math.round(screenA.x);
     ax[1] = Math.round(screenB.x);
     ax[2] = Math.round(screenC.x);
@@ -234,8 +219,15 @@
     int nLines = yMax - yMin + 1;
     if (nLines > g3d.height * 3)
       return;
-    if (nLines > axW.length)
-      reallocRasterArrays(nLines);
+    if (nLines > axW.length) {
+      int n = (nLines + 31) & ~31;
+      axW = new int[n];
+      azW = new int[n];
+      axE = new int[n];
+      azE = new int[n];
+      rgb16sW = reallocRgb16s(rgb16sW, n);
+      rgb16sE = reallocRgb16s(rgb16sE, n);
+    }
     Rgb16[] gouraudW, gouraudE;
     if (useGouraud) {
       gouraudW = rgb16sW;
@@ -321,23 +313,69 @@
       }
     }
     g3d.setZMargin(5);
-    if (useGouraud)
-      fillRasterG(yMin, nLines, isClipped, g3d.isPass2 ? 1 : 0);
-    else
-      fillRaster(yMin, nLines, isClipped, g3d.isPass2 ? 1 : 0);
+    int pass2Row = g3d.pass2Flag01;
+    int pass2Off = 1 - pass2Row;
+    int xW;
+    int i = 0;    
+    if (yMin < 0) {
+      nLines += yMin;
+      i -= yMin;
+      yMin = 0;
+    }
+    if (yMin + nLines > g3d.height)
+      nLines = g3d.height - yMin;
+    if (useGouraud) {
+      if (isClipped) {
+        for (; --nLines >= pass2Row; ++yMin, ++i) {
+          int pixelCount = axE[i] - (xW = axW[i]) + pass2Off;
+          if (pixelCount > 0)
+            g3d.plotPixelsClippedRaster(pixelCount, xW, yMin, azW[i], azE[i], 
rgb16sW[i], rgb16sE[i]);
+        }
+      } else {
+        for (; --nLines >= pass2Row; ++yMin, ++i) {
+          int pixelCount = axE[i] - (xW = axW[i]) + pass2Off;
+          if (pass2Row == 1 && pixelCount < 0) {
+            /*
+             * The issue here is that some very long, narrow triangles can be 
skipped
+             * altogether because axE < axW.
+             * 
+             */
+
+            pixelCount = 1;
+            xW--;
+          }
+          if (pixelCount > 0)
+            g3d.plotPixelsUnclippedRaster(pixelCount, xW, yMin, azW[i], 
azE[i], rgb16sW[i], rgb16sE[i]);
+        }
+      }
+    } else {
+      if (isClipped) {
+        for (; --nLines >= pass2Row; ++yMin, ++i) {
+          int pixelCount = axE[i] - (xW = axW[i]) + pass2Off;
+          if (pixelCount > 0)
+            g3d.plotPixelsClippedRaster(pixelCount, xW, yMin, azW[i], azE[i], 
null, null);
+        }
+      } else {
+        for (; --nLines >= pass2Row; ++yMin, ++i) {
+          int pixelCount = axE[i] - (xW = axW[i]) + pass2Off;
+          if (pass2Row == 1 && pixelCount < 0) {
+            /*
+             * The issue here is that some very long, narrow triangles can be 
skipped
+             * altogether because axE < axW.
+             * 
+             */
+
+            pixelCount = 1;
+            xW--;
+          }
+          if (pixelCount > 0)
+            g3d.plotPixelsUnclippedRaster(pixelCount, xW, yMin, azW[i], 
azE[i], null, null);
+        }
+      }
+    }
     g3d.setZMargin(0);
   }
-
-  private void reallocRasterArrays(int n) {
-    n = (n + 31) & ~31;
-    axW = new int[n];
-    azW = new int[n];
-    axE = new int[n];
-    azE = new int[n];
-    rgb16sW = reallocRgb16s(rgb16sW, n);
-    rgb16sE = reallocRgb16s(rgb16sE, n);
-  }
-
+ 
   private void generateRaster(int dy, int iN, int iS, int[] axRaster,
                               int[] azRaster, int iRaster, Rgb16[] gouraud) {
     int xN = ax[iN], zN = az[iN];
@@ -401,78 +439,4 @@
     }
   }
 
-  private void fillRaster(int y, int numLines,
-                          boolean isClipped, int correction) {
-    int i = 0;
-    if (y < 0) {
-      numLines += y;
-      i -= y;
-      y = 0;
-    }
-    if (y + numLines > g3d.height)
-      numLines = g3d.height - y;
-    if (isClipped) {
-      for (; --numLines >= correction; ++y, ++i) {
-        int xW = axW[i];
-        int pixelCount = axE[i] - xW + 1 - correction;
-        if (pixelCount > 0)
-          g3d.plotPixelsClippedRaster(pixelCount, xW, y, azW[i], azE[i], null, 
null);
-      }
-    } else {
-      int xW;
-      for (; --numLines >= correction; ++y, ++i) {
-        int pixelCount = axE[i] - (xW = axW[i]) + 1 - correction;
-        if (correction == 1 && pixelCount < 0) {
-          /*
-           * The issue here is that some very long, narrow triangles can be 
skipped
-           * altogether because axE < axW.
-           * 
-           */
-
-          pixelCount = 1;
-          xW--;
-        }
-        if (pixelCount > 0)
-          g3d.plotPixelsUnclippedRaster(pixelCount, xW, y, azW[i], azE[i], 
null, null);
-      }
-    }
-  }
-
-  private void fillRasterG(int y, int numLines,
-                          boolean isClipped, int correction) {
-    int i = 0;
-    if (y < 0) {
-      numLines += y;
-      i -= y;
-      y = 0;
-    }
-    if (y + numLines > g3d.height)
-      numLines = g3d.height - y;
-    if (isClipped) {
-      for (; --numLines >= correction; ++y, ++i) {
-        int xW = axW[i];
-        int pixelCount = axE[i] - xW + 1 - correction;
-        if (pixelCount > 0)
-          g3d.plotPixelsClippedRaster(pixelCount, xW, y, azW[i], azE[i], 
rgb16sW[i], rgb16sE[i]);
-      }
-    } else {
-      int xW;
-      for (; --numLines >= correction; ++y, ++i) {
-        int pixelCount = axE[i] - (xW = axW[i]) + 1 - correction;
-        if (correction == 1 && pixelCount < 0) {
-          /*
-           * The issue here is that some very long, narrow triangles can be 
skipped
-           * altogether because axE < axW.
-           * 
-           */
-
-          pixelCount = 1;
-          xW--;
-        }
-        if (pixelCount > 0)
-          g3d.plotPixelsUnclippedRaster(pixelCount, xW, y, azW[i], azE[i], 
rgb16sW[i], rgb16sE[i]);
-      }
-    }
-  }
-
 }

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


------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=164703151&iu=/4140/ostg.clktrk
_______________________________________________
Jmol-commits mailing list
Jmol-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jmol-commits

Reply via email to