Author: paperwing
Date: 2012-03-14 15:58:36 -0700 (Wed, 14 Mar 2012)
New Revision: 28538

Added:
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/FrameRateTracker.java
Modified:
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindVisualLexicon.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/Light.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/picking/DefaultShapePickingProcessor.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodeLabelsProcedure.java
Log:
refs #678 The use of the TextRenderer was modified to move the flush() call to 
outside the text loop, resulting in an approximate 50% gain in framerate (from 
20 to 30 for a network with 400 nodes and 1100 edges). Pressing "K" now toggles 
frames-per-second display at bottom left corner of screen. Re-using display 
lists for drawing all nodes and edges at once is disabled due to interference 
with node selection.

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
 2012-03-14 20:15:08 UTC (rev 28537)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/Graphics.java
 2012-03-14 22:58:36 UTC (rev 28538)
@@ -183,14 +183,12 @@
                handler.drawScene(graphicsData);
                
                graphicsData.setFramesElapsed(graphicsData.getFramesElapsed() + 
1);
+               graphicsData.getFrameRateTracker().advanceFrame();
        }
 
        @Override
        public void dispose(GLAutoDrawable autoDrawable) {
                coordinatorProcessor.unlinkCoordinator(coordinator);
-               
-               GL2 gl = autoDrawable.getGL().getGL2();
-               gl.glDeleteLists(graphicsData.getSceneList(), 1);
        }
 
        /** Initialize the Graphics object, performing certain
@@ -228,8 +226,6 @@
                handler.setupLighting(graphicsData);
                
                shapePickingProcessor.initialize(graphicsData);
-               
-               graphicsData.setSceneList(gl.glGenLists(1));
        }
 
 

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-03-14 20:15:08 UTC (rev 28537)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-03-14 22:58:36 UTC (rev 28538)
@@ -70,15 +70,15 @@
                renderProcedures.add(new RenderArcEdgesProcedure());
                renderProcedures.add(new RenderSelectionBoxProcedure());
                
-               // renderProcedures.add(new RenderNodeLabelsProcedure());
+               renderProcedures.add(new RenderNodeLabelsProcedure());
                renderProcedures.add(new RenderLightsProcedure());
                
                // Initialize the dictionary of display lists to be used for 
rendering procedures that can be
                // compiled into a re-usable display list
                renderProcedureLists = new HashMap<Class<? extends 
ReadOnlyGraphicsProcedure>, Integer>();
                
-               renderProcedureLists.put(RenderNodesProcedure.class, null);
-               renderProcedureLists.put(RenderArcEdgesProcedure.class, null);
+//             renderProcedureLists.put(RenderNodesProcedure.class, null);
+//             renderProcedureLists.put(RenderArcEdgesProcedure.class, null);
        }
        
        @Override

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindVisualLexicon.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindVisualLexicon.java
        2012-03-14 20:15:08 UTC (rev 28537)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindVisualLexicon.java
        2012-03-14 22:58:36 UTC (rev 28538)
@@ -85,13 +85,13 @@
        // =======================
        
        public static final VisualProperty<Double> LIGHT_X_LOCATION = new 
DoubleVisualProperty(
-                       0.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_X_LOCATION", "Light 
X Location", CyNetwork.class);
+                       1.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_X_LOCATION", "Light 
X Location", CyNetwork.class);
        
        public static final VisualProperty<Double> LIGHT_Y_LOCATION = new 
DoubleVisualProperty(
-                       0.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_Y_LOCATION", "Light 
Y Location", CyNetwork.class);
+                       1.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_Y_LOCATION", "Light 
Y Location", CyNetwork.class);
        
        public static final VisualProperty<Double> LIGHT_Z_LOCATION = new 
DoubleVisualProperty(
-                       0.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_Z_LOCATION", "Light 
Z Location", CyNetwork.class);
+                       -1.0, ARBITRARY_DOUBLE_RANGE, "LIGHT_Z_LOCATION", 
"Light Z Location", CyNetwork.class);
        
        public static final VisualProperty<Boolean> LIGHT_ENABLED = new 
BooleanVisualProperty(
                        true, "LIGHT_ENABLED", "Light Enabled", 
CyNetwork.class);

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
        2012-03-14 20:15:08 UTC (rev 28537)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/data/GraphicsData.java
        2012-03-14 22:58:36 UTC (rev 28538)
@@ -2,6 +2,7 @@
 
 import java.awt.Component;
 import java.util.Map;
+import java.util.Queue;
 import java.util.Set;
 
 import javax.media.opengl.GL2;
@@ -12,6 +13,7 @@
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 import org.cytoscape.paperwing.internal.geometric.ViewingVolume;
 import org.cytoscape.paperwing.internal.task.TaskFactoryListener;
+import org.cytoscape.paperwing.internal.tools.FrameRateTracker;
 import org.cytoscape.paperwing.internal.tools.SimpleCamera;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.VisualLexicon;
@@ -71,9 +73,6 @@
        /** A boolean to disable real-time shape picking to improve framerate */
        private boolean disableHovering;
        
-       /** The display list for drawing the entire scene, minus the 
transformations performed to setup the scene */
-       private int sceneList = 0;
-       
        /** Whether the scene has been updated and needs to be redrawn */
        private boolean updateScene = false;
        
@@ -82,10 +81,13 @@
        
        private Component container;
        
+       /** A framerate tracker used to calculate the current number of frames 
per second. */
+       private FrameRateTracker frameRateTracker;
+       
        /** A {@link TaskFactoryListener} object that can be used to obtain the 
current set of task factories */
        private TaskFactoryListener taskFactoryListener;
        
-       /** A task manager that can be used to execute tasks ccreated by 
TaskFactory objects */
+       /** A task manager that can be used to execute tasks created by 
TaskFactory objects */
        private DialogTaskManager taskManager;
        
        private SubmenuTaskManager submenuTaskManager;
@@ -132,6 +134,7 @@
                
                camera = new SimpleCamera();
                viewingVolume = new ViewingVolume();
+               frameRateTracker = new FrameRateTracker();
        }
        
        public void setNetworkView(CyNetworkView networkView) {
@@ -326,14 +329,6 @@
                return updateScene;
        }
 
-       public void setSceneList(int sceneList) {
-               this.sceneList = sceneList;
-       }
-
-       public int getSceneList() {
-               return sceneList;
-       }
-
        public void setShowFPS(boolean showFPS) {
                this.showFPS = showFPS;
        }
@@ -341,5 +336,9 @@
        public boolean getShowFPS() {
                return showFPS;
        }
+
+       public FrameRateTracker getFrameRateTracker() {
+               return frameRateTracker;
+       }
        
 }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/Light.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/Light.java
   2012-03-14 20:15:08 UTC (rev 28537)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/lighting/Light.java
   2012-03-14 22:58:36 UTC (rev 28538)
@@ -3,7 +3,7 @@
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 
 /**
- * This class represents a light described by the Phong illumination model
+ * This class represents a light described by its position and its ambient, 
diffuse, and specular light components.
  */
 public class Light {
 

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/picking/DefaultShapePickingProcessor.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/picking/DefaultShapePickingProcessor.java
     2012-03-14 20:15:08 UTC (rev 28537)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/picking/DefaultShapePickingProcessor.java
     2012-03-14 22:58:36 UTC (rev 28538)
@@ -3,6 +3,9 @@
 import java.nio.ByteBuffer;
 import java.nio.ByteOrder;
 import java.nio.IntBuffer;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
 
 import javax.media.opengl.GL;
 import javax.media.opengl.GL2;
@@ -15,6 +18,8 @@
 import org.cytoscape.paperwing.internal.input.KeyboardMonitor;
 import org.cytoscape.paperwing.internal.input.MouseMonitor;
 import org.cytoscape.paperwing.internal.rendering.ReadOnlyGraphicsProcedure;
+import org.cytoscape.paperwing.internal.rendering.RenderArcEdgesProcedure;
+import org.cytoscape.paperwing.internal.rendering.RenderNodesProcedure;
 import org.cytoscape.paperwing.internal.tools.SimpleCamera;
 
 public class DefaultShapePickingProcessor implements ShapePickingProcessor {
@@ -34,7 +39,6 @@
        public static final int NO_INDEX = -1; // Value representing that no 
node
                                                                                
        // or edge index is being held
 
-       
        private ReadOnlyGraphicsProcedure drawNodesProcedure;
        private ReadOnlyGraphicsProcedure drawEdgesProcedure;
        
@@ -45,6 +49,8 @@
        
        @Override
        public void initialize(GraphicsData graphicsData) {
+               GL2 gl = graphicsData.getGlContext();
+               
                drawNodesProcedure.initialize(graphicsData);
                drawEdgesProcedure.initialize(graphicsData);
        }
@@ -174,7 +180,7 @@
 
                // Render nodes for picking
                drawNodesProcedure.execute(graphicsData);
-
+               
                gl.glPopName();
                gl.glPopName();
 
@@ -183,7 +189,7 @@
 
                // Render edges for picking
                drawEdgesProcedure.execute(graphicsData);
-
+               
                gl.glPopName();
                gl.glPopName();
        }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodeLabelsProcedure.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodeLabelsProcedure.java
      2012-03-14 20:15:08 UTC (rev 28537)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodeLabelsProcedure.java
      2012-03-14 22:58:36 UTC (rev 28538)
@@ -2,6 +2,7 @@
 
 import java.awt.Color;
 import java.awt.Font;
+import java.text.DecimalFormat;
 
 import javax.media.opengl.GL2;
 
@@ -121,16 +122,19 @@
                                                                
                                                
textRenderer.setColor(textColor);
                                                textRenderer.draw(text, (int) 
screenCoordinates.x() - findTextScreenWidth(text) / 2, (int) 
screenCoordinates.y());              
-                                               textRenderer.flush();
+                                               
                                        }
                                }
                        }
                }
                
                if (graphicsData.getShowFPS()) {
+                       double frameRate = 
graphicsData.getFrameRateTracker().getFrameRate();
 
+                       textRenderer.draw("FPS: " + (int) frameRate, 1, 1);
                }
                
+               textRenderer.flush();
                textRenderer.endRendering();
                gl.glPopMatrix();
                

Added: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/FrameRateTracker.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/FrameRateTracker.java
                           (rev 0)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/FrameRateTracker.java
   2012-03-14 22:58:36 UTC (rev 28538)
@@ -0,0 +1,57 @@
+package org.cytoscape.paperwing.internal.tools;
+
+import java.util.LinkedList;
+import java.util.Queue;
+
+/**
+ * This class represents a framerate tracker, which is capable of keeping track
+ * of a set of frame times in order to calculate the average framerate.
+ */
+public class FrameRateTracker {
+       
+       public static int DEFAULT_FRAMES_TRACKED = 30;
+       
+       private int framesTracked = DEFAULT_FRAMES_TRACKED;
+
+       private Queue<Long> frameTimes;
+       
+       public FrameRateTracker() {
+               frameTimes = new LinkedList<Long>();
+       }
+       
+       /**
+        * Set the number of frames used to perform the frames-per-second 
calculation.
+        * @param framesTracked The number of frames before the current frame 
to use for calculating framerate.
+        */
+       public void setFramesTracked(int framesTracked) {
+               this.framesTracked = framesTracked;
+               
+               while (frameTimes.size() > framesTracked) {
+                       frameTimes.remove();
+               }
+       }
+       
+       public void advanceFrame() {
+               frameTimes.add(System.nanoTime());
+               
+               while (frameTimes.size() > framesTracked) {
+                       frameTimes.remove();
+               }
+       }
+       
+       /**
+        * Return the average framerate over the tracked number of frames.
+        * @return The average framerate over the currently tracked number of 
frames.
+        */
+       public double getFrameRate() {
+               Long startTime = frameTimes.peek();
+               Long endTime = ((LinkedList<Long>) frameTimes).peekLast();
+
+               if (startTime == endTime) {
+                       // Prevent division by 0
+                       return 0;
+               } else {
+                       return frameTimes.size() / ((double) (endTime - 
startTime) / 1000000000);
+               }
+       }
+}


Property changes on: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/FrameRateTracker.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to