Author: paperwing
Date: 2012-02-07 14:54:50 -0800 (Tue, 07 Feb 2012)
New Revision: 28209

Modified:
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.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/WindBirdsEyeRenderingEngine.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindRenderingEngine.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/NetworkChangeInputHandler.java
   
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/tools/GeometryToolkit.java
   
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
Log:
Added 2D node label rendering, using orthogonal labels that have persistent 
size. This uses JOGL's TextRenderer class, along with a function that 
transforms 3D coordinates to screen coordinates.

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
  2012-02-07 20:45:44 UTC (rev 28208)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/BirdsEyeGraphicsHandler.java
  2012-02-07 22:54:50 UTC (rev 28209)
@@ -78,6 +78,9 @@
                for (ReadOnlyGraphicsProcedure renderProcedure : 
renderProcedures) {
                        renderProcedure.execute(graphicsData);
                }
+               
+               
+//             System.out.println(graphicsData.getFramesElapsed());
        }
 
        @Override

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-02-07 20:45:44 UTC (rev 28208)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/MainGraphicsHandler.java
      2012-02-07 22:54:50 UTC (rev 28209)
@@ -53,6 +53,8 @@
                renderProcedures.add(new RenderNodesProcedure());
                renderProcedures.add(new RenderArcEdgesProcedure());
                renderProcedures.add(new RenderSelectionBoxProcedure());
+               
+               renderProcedures.add(new RenderNodeLabelsProcedure());
        }
        
        @Override

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindBirdsEyeRenderingEngine.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindBirdsEyeRenderingEngine.java
      2012-02-07 20:45:44 UTC (rev 28208)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindBirdsEyeRenderingEngine.java
      2012-02-07 22:54:50 UTC (rev 28209)
@@ -43,6 +43,8 @@
        public WindBirdsEyeRenderingEngine(Object container, View<CyNetwork> 
viewModel,
                        VisualLexicon visualLexicon) {
                super(container, viewModel, visualLexicon);
+               
+//             System.out.println("wind bird's eye created for network: " + 
viewModel);
        }
 
        @Override

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindRenderingEngine.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindRenderingEngine.java
      2012-02-07 20:45:44 UTC (rev 28208)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/WindRenderingEngine.java
      2012-02-07 22:54:50 UTC (rev 28209)
@@ -145,6 +145,8 @@
                                setUpAnimatorStarting(focus, animator);
                                
                                active = true;
+                               
+//                             System.out.println("placed in canvas");
                        }
                }
        }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/NetworkChangeInputHandler.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/NetworkChangeInputHandler.java
  2012-02-07 20:45:44 UTC (rev 28208)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/input/NetworkChangeInputHandler.java
  2012-02-07 22:54:50 UTC (rev 28209)
@@ -10,6 +10,7 @@
 import org.cytoscape.paperwing.internal.data.GraphicsData;
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 import org.cytoscape.paperwing.internal.tools.GeometryToolkit;
+import org.cytoscape.paperwing.internal.tools.RenderToolkit;
 import org.cytoscape.paperwing.internal.tools.SimpleCamera;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.View;
@@ -43,7 +44,9 @@
                        Vector3 projection = GeometryToolkit.convertScreenTo3d(
                                        mouse.x(), mouse.y(), 
graphicsData.getScreenWidth(),
                                        graphicsData.getScreenHeight(), 
NODE_PLACEMENT_DISTANCE, camera);
-                               
+                       
+//                     System.out.println("Input window coordinates: " + 
mouse.x() + ", " + mouse.y());
+                       
                        CyNode added = networkView.getModel().addNode();
                        networkView.updateView();
 
@@ -68,6 +71,8 @@
                                // through some way other than the mouse
                                // 
graphicsData.getSelectionData().setHoverNodeIndex(added.getIndex());
                        }
+                       
+//                     System.out.println("Node created, window coordinates: " 
+ RenderToolkit.convert3dToScreen(graphicsData.getGlContext(), projection));
                }
        }
        

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-02-07 20:45:44 UTC (rev 28208)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/rendering/RenderNodeLabelsProcedure.java
      2012-02-07 22:54:50 UTC (rev 28209)
@@ -13,6 +13,7 @@
 import 
org.cytoscape.paperwing.internal.rendering.shapes.ScalableShapeDrawer.ShapeType;
 import org.cytoscape.paperwing.internal.rendering.text.StringRenderer;
 import org.cytoscape.paperwing.internal.tools.RenderColor;
+import org.cytoscape.paperwing.internal.tools.RenderToolkit;
 import org.cytoscape.view.model.CyNetworkView;
 import org.cytoscape.view.model.View;
 import org.cytoscape.view.presentation.property.MinimalVisualLexicon;
@@ -26,10 +27,10 @@
        private static final Vector3 TEXT_OFFSET = new Vector3 (0, 0.04, 0);
        
        private static final float TEXT_CHARACTER_WIDTH = 0.612f;
-       private static final int TEXT_FONT_SIZE = 72;
+       private static final int TEXT_FONT_SIZE = 9;
        
        private TextRenderer textRenderer;
-       private Font defaultFont = new Font("Trebuchet MS", Font.PLAIN, 
TEXT_FONT_SIZE);
+       private Font defaultFont = new Font("SansSerif", Font.PLAIN, 
TEXT_FONT_SIZE);
        
        public RenderNodeLabelsProcedure() {
                textRenderer = new TextRenderer(defaultFont);
@@ -40,7 +41,7 @@
                GL2 gl = graphicsData.getGlContext();
                
                // Increase rendering efficiency; can set to true if desired
-               textRenderer.setSmoothing(false);
+//             textRenderer.setSmoothing(false);
        }
 
        @Override
@@ -51,12 +52,21 @@
                float distanceScale = graphicsData.getDistanceScale();
                float x, y, z;
 
+               // Store the current modelview, projection, and viewport 
matrices
+               double modelView[] = new double[16];
+               double projection[] = new double[16];
+               int viewPort[] = new int[4];
+               
+        gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, modelView, 0);
+        gl.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projection, 0);
+        gl.glGetIntegerv(GL2.GL_VIEWPORT, viewPort, 0);
+               
                String text;
                
                textRenderer.setColor(Color.BLACK);
                
                gl.glPushMatrix();
-               textRenderer.begin3DRendering();
+               textRenderer.beginRendering(graphicsData.getScreenWidth(), 
graphicsData.getScreenHeight(), true);
                
                for (View<CyNode> nodeView : networkView.getNodeViews()) {
                        x = 
nodeView.getVisualProperty(RichVisualLexicon.NODE_X_LOCATION)
@@ -86,11 +96,19 @@
                                        // textRenderer.drawCenteredText(gl, 
"aac");
                                        
 //                                     text = "test" + nodeView.getSUID();
-                                       textRenderer.draw3D(text, 
-                                                       x + (float) 
TEXT_OFFSET.x() - text.length() * (TEXT_CHARACTER_WIDTH / TEXT_FONT_SIZE), 
-                                                       y + (float) 
TEXT_OFFSET.y(), 
-                                                       z + (float) 
TEXT_OFFSET.z(), 
-                                                       TEXT_SCALE);
+//                                     textRenderer.draw3D(text, 
+//                                                     x + (float) 
TEXT_OFFSET.x(), 
+//                                                     y + (float) 
TEXT_OFFSET.y(), 
+//                                                     z + (float) 
TEXT_OFFSET.z(), 
+//                                                     TEXT_SCALE);
+                                       
+                                       
+                                       Vector3 screenCoordinates = 
RenderToolkit.convert3dToScreen(gl, new Vector3(x, y, z), modelView, 
projection, viewPort);
+//                                     System.out.println("Node label " + (new 
Vector3(x, y, z)) + " mapped to: " + screenCoordinates);
+                                       
+                                       textRenderer.draw(text, (int) 
screenCoordinates.x() - findTextScreenWidth(text) / 2, (int) 
screenCoordinates.y());
+                                       
+//                                     textRenderer.draw(text, 300, 300);
                                }
                        }
                }
@@ -101,4 +119,14 @@
                gl.glPopMatrix();
                
        }
+       
+       private int findTextScreenWidth(String text) {
+               int width = 0;
+               
+               for (int i = 0; i < text.length(); i++) {
+                       width += textRenderer.getCharWidth(text.charAt(i));
+               }
+               
+               return width;
+       }
 }

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/GeometryToolkit.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/GeometryToolkit.java
    2012-02-07 20:45:44 UTC (rev 28208)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/GeometryToolkit.java
    2012-02-07 22:54:50 UTC (rev 28209)
@@ -36,6 +36,7 @@
                //   fov = 45 deg
                //   nearDist = 0.2
                
+               // TODO: Allow a variable field of view, unlike here, to be 
specified as a parameter
                double fieldOfView = Math.PI / 4;
                double nearDistance = 0.2;
                

Modified: 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
===================================================================
--- 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
      2012-02-07 20:45:44 UTC (rev 28208)
+++ 
csplugins/trunk/toronto/yuedong/paperwing-impl/src/main/java/org/cytoscape/paperwing/internal/tools/RenderToolkit.java
      2012-02-07 22:54:50 UTC (rev 28209)
@@ -1,6 +1,7 @@
 package org.cytoscape.paperwing.internal.tools;
 
 import javax.media.opengl.GL2;
+import javax.media.opengl.glu.GLU;
 
 import org.cytoscape.paperwing.internal.geometric.Vector3;
 
@@ -45,4 +46,38 @@
                                (float) normalized.y(),
                                (float) normalized.z());
        }
+       
+       public static Vector3 convert3dToScreen(GL2 gl, Vector3 position) {
+               GLU glu = GLU.createGLU(gl);
+               
+               double modelView[] = new double[16];
+               double projection[] = new double[16];
+               int viewPort[] = new int[4];
+               
+        gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, modelView, 0);
+        gl.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projection, 0);
+        gl.glGetIntegerv(GL2.GL_VIEWPORT, viewPort, 0);
+        
+        double result[] = new double[4];
+        
+               glu.gluProject(position.x(), position.y(), position.z(), 
+                               modelView, 0, projection, 0, viewPort, 0, 
result, 0);
+               
+               return new Vector3(result[0],
+                               result[1],
+                               result[2]);
+       }
+       
+       public static Vector3 convert3dToScreen(GL2 gl, Vector3 position, 
double[] modelView, double[] projection, int[] viewPort) {
+               GLU glu = GLU.createGLU(gl);
+               
+        double result[] = new double[4];
+        
+               glu.gluProject(position.x(), position.y(), position.z(), 
+                               modelView, 0, projection, 0, viewPort, 0, 
result, 0);
+               
+               return new Vector3(result[0],
+                               result[1],
+                               result[2]);
+       }
 }

-- 
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