Author: ghuck
Date: 2011-06-28 08:02:18 -0700 (Tue, 28 Jun 2011)
New Revision: 25958

Added:
   
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
Modified:
   
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
   
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
   
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
   csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
   csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
Log:
Added Fruchterman-Reignolds layout

Modified: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
    2011-06-28 14:58:25 UTC (rev 25957)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
    2011-06-28 15:02:18 UTC (rev 25958)
@@ -35,13 +35,13 @@
     public static native void starLayout(double x[], double y[], int centerId);
 
     // Fruchterman - Reingold Layout
-//     public static native void layoutFruchterman(double x[], 
-//                                             double y[], 
-//                                             int iter, 
-//                                             double maxDelta, 
-//                                             double area, 
-//                                             double coolExp, 
-//                                             double repulserad, 
-//                                             boolean useSeed);
+    public static native void layoutFruchterman(double x[], 
+                                               double y[], 
+                                               int iter, 
+                                               double maxDelta, 
+                                               double area, 
+                                               double coolExp, 
+                                               double repulserad, 
+                                               boolean useSeed);
     
 }
\ No newline at end of file

Modified: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
       2011-06-28 14:58:25 UTC (rev 25957)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
       2011-06-28 15:02:18 UTC (rev 25958)
@@ -71,10 +71,10 @@
        
Cytoscape.getDesktop().getCyMenus().addCytoscapeAction((CytoscapeAction) 
isConnectedAction2);
 
        // Layouts
-       CyLayouts.addLayout(new CircleLayout(), "Igraph");
+       CyLayouts.addLayout(new CircleLayout()             , "Igraph");
+       CyLayouts.addLayout(new StarLayout()               , "Igraph");
+       CyLayouts.addLayout(new FruchtermanReingoldLayout(), "Igraph");
 
-       CyLayouts.addLayout(new StarLayout(), "Igraph");
-
                
     }
 

Modified: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
       2011-06-28 14:58:25 UTC (rev 25957)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
       2011-06-28 15:02:18 UTC (rev 25958)
@@ -109,10 +109,10 @@
     }
 
     /**
-     * Overload updateSettings for using it without arguments
+     * Get new values from tunables and update parameters
      */
-    public void updateSettings() {
-       updateSettings(false);
+    public void updateSettings(boolean force) {
+       layoutProperties.updateValues();        
     }
 
     /**
@@ -128,10 +128,10 @@
     // END OF METHODS WHICH MAY BE OVERRIDEN         
 
     /**
-     * Get new values from tunables and update parameters
+     * Overload updateSettings for using it without arguments
      */
-    public void updateSettings(boolean force) {
-       layoutProperties.updateValues();        
+    public void updateSettings() {
+       updateSettings(false);
     }
         
     /**

Added: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
                          (rev 0)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
  2011-06-28 15:02:18 UTC (rev 25958)
@@ -0,0 +1,190 @@
+/**************************************************************************************
+Copyright (C) Gerardo Huck, 2011
+
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+**************************************************************************************/
+
+package cytoscape.plugins.igraph.layout;
+
+import cytoscape.plugins.igraph.*;
+import cytoscape.logger.CyLogger;
+import cytoscape.layout.LayoutProperties;
+import csplugins.layout.LayoutPartition;
+import cytoscape.layout.Tunable;
+
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import java.awt.GridLayout;
+
+import java.util.*;
+
+public class FruchtermanReingoldLayout extends AbstractIgraphLayout {
+
+    private int iterNumber               = 500;   // Number of iterations
+    private double maxDeltaCoefficient   = 1.0;   // Maximum distance to move 
a node in each iteration
+    private double areaCoefficient       = 1.0;   // Area parameter
+    private double coolExp               = 1.5;   // The cooling exponent of 
the simulated annealing
+    private double repulseRadCoefficient = 1.0;   // Determines the radius at 
which vertex-vertex repulsion cancels out attraction of adjacent vertices
+    private boolean randomize            = true;  // Randomize node position 
before layout
+
+
+    public FruchtermanReingoldLayout() {
+       super();
+       logger = CyLogger.getLogger(FruchtermanReingoldLayout.class);
+       
+       layoutProperties = new LayoutProperties(getName());
+       initialize_properties();
+    }
+
+    /**
+     * Adds tunable objects for adjusting plugin parameters
+     * Initializes default values for those parameters
+     */
+    protected void initialize_properties() {
+       
+       // Add new properties to layout 
+       layoutProperties.add(new Tunable("iterNumber", 
+                                        "Number of Iterations", 
+                                        Tunable.INTEGER, 
+                                        new Integer(iterNumber)));     
+
+       layoutProperties.add(new Tunable("maxDeltaCoefficient", 
+                                        "Distance to move nodes in each 
iteration", 
+                                        Tunable.DOUBLE, 
+                                        new Double(maxDeltaCoefficient)));
+
+       layoutProperties.add(new Tunable("areaCoefficient", 
+                                        "Area to use in layout", 
+                                        Tunable.DOUBLE, 
+                                        new Double(areaCoefficient)));
+
+       layoutProperties.add(new Tunable("coolExp", 
+                                        "Cooling exponent of the simulated 
annealing", 
+                                        Tunable.DOUBLE, 
+                                        new Double(coolExp)));
+
+       layoutProperties.add(new Tunable("repulseRadCoefficient", 
+                                        "Radius at which vertex-vertex 
repulsion cancels out attraction of adjacent vertices", 
+                                        Tunable.DOUBLE, 
+                                        new Double(repulseRadCoefficient)));
+
+       layoutProperties.add(new Tunable("randomize",
+                                        "Randomize node locations before 
laying out nodes",
+                                        Tunable.BOOLEAN, 
+                                        new Boolean(randomize)));
+
+       // Initialize layout properties
+       layoutProperties.initializeProperties();
+       
+       // Force the settings update
+       updateSettings(true);
+    }
+
+    /**
+     * Get new values from tunables and update parameters
+     */
+    public void updateSettings(boolean force) {
+       layoutProperties.updateValues();        
+
+       // Get initialNoIterations
+       Tunable t1 = layoutProperties.get("iterNumber");
+       if ((t1 != null) && (t1.valueChanged() || force))
+           iterNumber = ((Integer) t1.getValue()).intValue();
+
+       // Get maxDeltaCoefficient
+       Tunable t2 = layoutProperties.get("maxDeltaCoefficient");
+       if ((t2 != null) && (t2.valueChanged() || force))
+           maxDeltaCoefficient = ((Double) t2.getValue()).doubleValue();
+
+       // Get areaCoefficient
+       Tunable t3 = layoutProperties.get("areaCoefficient");
+       if ((t3 != null) && (t3.valueChanged() || force))
+           areaCoefficient = ((Double) t3.getValue()).doubleValue();
+
+       // Get coolExp
+       Tunable t4 = layoutProperties.get("coolExp");
+       if ((t4 != null) && (t4.valueChanged() || force))
+           coolExp = ((Double) t4.getValue()).doubleValue();
+
+       // Get repulseRadCoefficient
+       Tunable t5 = layoutProperties.get("repulseRadCoefficient");
+       if ((t5 != null) && (t5.valueChanged() || force))
+           repulseRadCoefficient = ((Double) t5.getValue()).doubleValue();
+
+       // Get randomize
+       Tunable t6 = layoutProperties.get("randomize");
+       if ((t6 != null) && (t6.valueChanged() || force))
+           randomize = ((Boolean) t6.getValue()).booleanValue();
+
+    }
+
+//     /**
+//      * Get the settings panel for this layout
+//      */
+//     public JPanel getSettingsPanel() {
+//     JPanel panel = new JPanel(new GridLayout(1, 1));
+//     panel.add(layoutProperties.getTunablePanel());
+       
+//     return panel;
+//     }
+
+    /**
+     * Do the layout on a graph alrealy loaded into igraph
+     */
+    public int layout(double[] x, 
+                     double[] y, 
+                     LayoutPartition part, 
+                     HashMap<Integer,Integer> mapping) {
+
+       
+       double maxDelta   = maxDeltaCoefficient * part.nodeCount();
+       double area       = areaCoefficient * part.nodeCount() * 
part.nodeCount();
+       double repulseRad = repulseRadCoefficient * area * part.nodeCount();
+       
+       // Make native method call
+       IgraphInterface.layoutFruchterman(x, 
+                                         y, 
+                                         iterNumber, 
+                                         maxDelta, 
+                                         area, 
+                                         coolExp, 
+                                         repulseRad, 
+                                         !randomize);
+       
+       return 1;
+    }
+
+    /**
+     * getName is used to construct property strings
+     * for this layout.
+     */
+    public String getName() {
+       return "Igraph Fruchterman-Reingold Layout";
+    }
+    
+    /**
+     * toString is used to get the user-visible name
+     * of the layout
+     */
+    public String toString() {
+       return "Fruchterman-Reingold Layout";
+    }
+
+}
+
+
+

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp      
2011-06-28 14:58:25 UTC (rev 25957)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp      
2011-06-28 15:02:18 UTC (rev 25958)
@@ -89,37 +89,39 @@
 
 }
 
-// Fruchterman - Reingold Layout
-// void layoutFruchterman(double x[], 
-//                    double y[], 
-//                    int iter, 
-//                    double maxDelta, 
-//                    double area, 
-//                    double coolExp, 
-//                    double repulserad, 
-//                    bool useSeed){
-//     long int vcount = igraph_vcount(&g);
-//     igraph_matrix_t locs;
-//     igraph_matrix_init(&locs, vcount, 2); 
-//     for(int i=0; i<vcount; i++){
-//             MATRIX(locs, i, 0) = x[i];
-//             MATRIX(locs, i, 1) = y[i];
-//     }
+//Fruchterman - Reingold Layout
+void layoutFruchterman(double x[], 
+                      double y[], 
+                      int iter, 
+                      double maxDelta, 
+                      double area, 
+                      double coolExp, 
+                      double repulserad, 
+                      bool useSeed){
+       long int vcount = igraph_vcount(&g);
+       igraph_matrix_t locs;
+       igraph_matrix_init(&locs, vcount, 2); 
+       for(int i = 0; i < vcount; i++){
+               MATRIX(locs, i, 0) = x[i];
+               MATRIX(locs, i, 1) = y[i];
+       }
 
-//     igraph_layout_fruchterman_reingold(&g, 
-//                                        &locs, 
-//                                        iter, 
-//                                        maxDelta, 
-//                                        area, 
-//                                        coolExp, 
-//                                        repulserad, 
-//                                        useSeed, 
-//                                        0);
-//     for(int i=0; i<vcount; i++){
-//             x[i] = MATRIX(locs, i, 0);
-//             y[i] = MATRIX(locs, i, 1);
-//     }       
-// }
+       igraph_layout_fruchterman_reingold(&g, 
+                                          &locs, 
+                                          iter, 
+                                          maxDelta, 
+                                          area, 
+                                          coolExp, 
+                                          repulserad, 
+                                          useSeed, 
+                                          0, // weights 
+                                          0, 
+                                          0);
+       for(int i=0; i<vcount; i++){
+               x[i] = MATRIX(locs, i, 0);
+               y[i] = MATRIX(locs, i, 1);
+       }       
+}
 
 
 

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h        
2011-06-28 14:58:25 UTC (rev 25957)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h        
2011-06-28 15:02:18 UTC (rev 25958)
@@ -18,14 +18,14 @@
   // Layouts
   void layoutCircle(double x[], double y[]);
   void starLayout(double x[], double y[], int centerId);
-/*   void layoutFruchterman(double x[],  */
-/*                      double y[],  */
-/*                      int iter,  */
-/*                      double maxDelta,  */
-/*                      double area,  */
-/*                      double coolExp,  */
-/*                      double repulserad,  */
-/*                      bool useSeed); */
+  void layoutFruchterman(double x[],
+                        double y[],
+                        int iter,
+                        double maxDelta,
+                        double area,
+                        double coolExp,
+                        double repulserad,
+                        bool useSeed);
 
 
 /*   void fastGreedy(int membership[], double* modularity, int csize[], int * 
numCluster); */

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