Author: ghuck
Date: 2011-06-26 14:22:37 -0700 (Sun, 26 Jun 2011)
New Revision: 25946

Added:
   
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/OldLayoutExample.java.nocompile
   
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/StarLayout.java
Removed:
   
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/CircleLayout.java.nocompile
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/cytoscape/plugins/igraph/layouts/CircleLayout.java
   csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
   csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
Log:
Added Star Layout. TODO: Fix issue when only laying out selected nodes

Deleted: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/CircleLayout.java.nocompile
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/CircleLayout.java.nocompile
     2011-06-26 14:52:56 UTC (rev 25945)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/CircleLayout.java.nocompile
     2011-06-26 21:22:37 UTC (rev 25946)
@@ -1,393 +0,0 @@
-/**************************************************************************************
-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;
-
-import cytoscape.Cytoscape;
-import cytoscape.layout.AbstractLayout;
-import cytoscape.layout.LayoutProperties;
-import cytoscape.layout.Tunable;
-import cytoscape.CyNode;
-import cytoscape.logger.CyLogger;
-
-import cytoscape.view.CyNetworkView;
-import cytoscape.data.CyAttributes;
-
-import csplugins.layout.LayoutPartition;
-import csplugins.layout.LayoutEdge;
-import csplugins.layout.LayoutNode;
-import csplugins.layout.EdgeWeighter;
-import csplugins.layout.algorithms.graphPartition.*;
-
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-
-import java.awt.Dimension;
-import java.awt.GridLayout;
-import java.util.*;
-
-public class CircleLayout extends AbstractGraphPartition
-{
-    private String message;
-    private LayoutProperties layoutProperties;
-
-
-    /**
-     * Creates a new layout object.
-     */
-    public CircleLayout() {
-       super();
-
-       logger = CyLogger.getLogger(CircleLayout.class);
-       // logger.setDebug(true);
-
-       layoutProperties = new LayoutProperties(getName());
-       initialize_properties();
-    }
-
-
-    /**
-     * This plugin supports laying out only selected nodes
-     */
-    public boolean supportsSelectedOnly() {
-               return true;
-    }
-    
-    /**
-     * Adds tunable objects for adjusting plugin parameters
-     * Initializes default values for those parameters
-     */
-    protected void initialize_properties() {
-       
-       // Add new properties to layout 
-       
-       // Initialize layout properties
-       layoutProperties.initializeProperties();
-       
-       // Force the settings update
-       updateSettings(true);
-    }
-    
-    /**
-     * getName is used to construct property strings
-     * for this layout.
-     */
-    public  String getName() {
-       return "Igraph Circle Layout";
-    }
-    
-    /**
-     * toString is used to get the user-visible name
-     * of the layout
-     */
-    public  String toString(){
-       return "Circle Layout";
-    }
-    
-    /**
-     * Overload updateSettings for using it without arguments
-     */
-    public void updateSettings() {
-       updateSettings(false);
-    }
-    
-    /**
-     * Get new values from tunables and update parameters
-     */
-    public void updateSettings(boolean force) {
-       layoutProperties.updateValues();        
-    }
-    
-    /**
-     * Get the settings panel for this layout
-     */
-    public JPanel getSettingsPanel() {
-       JPanel panel = new JPanel(new GridLayout(1, 1));
-       panel.add(layoutProperties.getTunablePanel());
-       
-       return panel;
-    }
-    
-    /**
-     * Revert previous settings
-     */
-    public void revertSettings() {
-       layoutProperties.revertProperties();
-    }    
-    
-    /**
-     * Get layout properties
-     */
-    public LayoutProperties getSettings() {
-       return layoutProperties;
-    }
-       
-    
-    /**
-     * 
-     */
-    public void layoutPartition (LayoutPartition part) {
-
-       // Check whether it has been canceled by the user
-       if (canceled)
-           return;
-
-       // Show message on the task monitor
-       taskMonitor.setStatus("Initializing: Partition: " + 
part.getPartitionNumber());
-       
-       // The completed percentage is indeterminable
-       taskMonitor.setPercentCompleted(-1);
-
-       // Figure out our starting point if we are only laying out selected 
nodes
-       Dimension initialLocation = null;
-       if (selectedOnly) {
-           initialLocation = part.getAverageLocation();
-       }
-
-       // Get the number of edges and nodes
-       int numNodes = part.nodeCount();
-
-       // Allocate memory for storing graph edges information (to be used as 
arguments for JNI call)
-       double[] x = new double[numNodes];
-       double[] y = new double[numNodes];      
-
-       // Load graph into native library
-       HashMap<Integer,Integer> mapping = loadGraphPartition(part, 
selectedOnly);
-
-       // Check whether it has been canceled by the user
-       if (canceled)
-           return;
-
-       // Show message on the task monitor
-       taskMonitor.setStatus("Calling native code: Partition: " + 
part.getPartitionNumber());
-
-       // Simplify graph
-       IgraphInterface.simplify();
-       
-       // Make native method call
-       IgraphInterface.layoutCircle(x, y);
-
-       // Check whether it has been canceled by the user
-       if (canceled)
-           return;
-
-       // Show message on the task monitor
-       taskMonitor.setStatus("Updating display");      
-       
-       updateDisplay(part, mapping, x, y, initialLocation, selectedOnly);
-
-    }// layoutPartion(LayoutPartition part)
-
-
-
-    protected void updateDisplay(LayoutPartition part, 
HashMap<Integer,Integer> mapping, double[] x, double[] y, Dimension 
initialLocation, boolean selectedOnly) {
-       // Find which ratio is required to 'scale up' the node positions so 
that nodes don't overlap
-       double upRatio = 0.0;
-       double actualRatio = 0.0;
-
-       for (LayoutEdge edge: part.getEdgeList()) {
-           LayoutNode n1 = edge.getSource();
-           LayoutNode n2 = edge.getTarget();
-
-           if (n1.isLocked() || n2.isLocked())
-               continue;
-
-           double n1Size = Math.max(n1.getHeight(), n1.getWidth());
-           double n2Size = Math.max(n2.getHeight(), n2.getWidth());
-
-           double edgeSize = Math.sqrt( Math.pow(x[mapping.get(n1.getIndex())] 
- x[mapping.get(n2.getIndex())], 2)
-                                      + Math.pow(y[mapping.get(n1.getIndex())] 
- y[mapping.get(n2.getIndex())], 2)
-                                      );
-           // Check if edgeSize is not zero
-           if (edgeSize > 0.0){
-           
-               // actualRatio = minimun_desired_length / actual_length
-               actualRatio = (n1Size + n2Size) / edgeSize;
-               
-               // Update upRatio if necessary
-               if (actualRatio > upRatio)
-                   upRatio = actualRatio;
-           }
-
-       }
-       
-       // Check whether the ratio is not zero
-       if (upRatio < 1.0){   
-           upRatio = 1.0;
-       }
-
-       double oldUpRatio = upRatio;
-
-
-       // Move nodes to their position
-       boolean success = false;
-       while (!success){
-           
-           try{
-               // We will keep track of the offset of the whole part so that 
we can eliminate it
-               double minX = x[0];
-               double minY = y[0];
-               
-               // Get the 'offset' of the whole partition, so that we can 
eliminate it
-               for (int i = 1; i < mapping.size(); i++) {
-                   
-                   if (x[i] < minX)
-                       minX = x[i];
-
-                   if (y[i] < minY)
-                       minY = y[i];
-               }
-
-               minX = upRatio * minX;
-               minY = upRatio * minY;
-               
-               // Reset the nodes so we get the new average location
-               part.resetNodes(); 
-               
-               // Create an iterator for processing the nodes
-               Iterator<LayoutNode> iterator2 = part.getNodeList().iterator();
-                               
-               while (iterator2.hasNext()){
-                   
-                   // Get next node
-                   LayoutNode node = (LayoutNode) iterator2.next();
-
-                   // If it is locked, skip it
-                   if (!node.isLocked()) {                     
-
-                       // Set node's X and Y positions
-                       node.setX(upRatio * x[mapping.get(node.getIndex())] - 
minX);
-                       node.setY(upRatio * y[mapping.get(node.getIndex())] - 
minY);
-
-                       // Move node to desired location
-                       part.moveNodeToLocation(node);
-                   }
-               }
-       
-       
-               // Not quite done, yet.  If we're only laying out selected 
nodes, we need
-               // to migrate the selected nodes back to their starting position
-               if (selectedOnly) {
-                   double xDelta = 0.0;
-                   double yDelta = 0.0;
-                   Dimension finalLocation = part.getAverageLocation();
-                   xDelta = finalLocation.getWidth()  - 
initialLocation.getWidth();
-                   yDelta = finalLocation.getHeight() - 
initialLocation.getHeight();
-                   for (LayoutNode v: part.getNodeList()) {
-                       if (!v.isLocked()) {
-                           v.decrement(xDelta, yDelta);
-                           part.moveNodeToLocation(v);
-                       }
-                   }
-               }
-               
-               success = true;
-
-           }
-           catch(Exception excep){
-
-               upRatio = upRatio / 10.0;
-               if (upRatio <= 0.0){
-                   message = "Sorry, cannot produce layout";
-                   JOptionPane.showMessageDialog(Cytoscape.getDesktop(), 
message);
-                   return;
-               }
-               success = false;
-           }
-
-       }//while(!success)
-
-    } //updateDisplay
-
-
-    /**
-     * This function loads a partition into igraph
-     *
-     */    
-    public static HashMap<Integer,Integer> loadGraphPartition(LayoutPartition 
part, boolean selectedOnly){
-
-       CyLogger logger = CyLogger.getLogger(CircleLayout.class);           
-       
-       // Create a reverse mapping
-       int nodeCount = part.nodeCount();
-
-       HashMap<Integer, Integer> nodeIdMapping;
-       if (selectedOnly) 
-           nodeIdMapping = new HashMap<Integer, Integer>(nodeCount - 
part.lockedNodeCount());
-       else
-           nodeIdMapping = new HashMap<Integer, Integer>(nodeCount);
-       int j = 0;
-
-       Iterator<LayoutNode> nodeIt = part.nodeIterator();      
-       if (selectedOnly) {
-           while(nodeIt.hasNext()) {            
-               LayoutNode node = (LayoutNode) nodeIt.next();
-               if (!node.isLocked()) {
-                   nodeIdMapping.put(node.getIndex(), j);
-                   j++;
-               }
-           }
-       } else {
-           while(nodeIt.hasNext()) {            
-               LayoutNode node = (LayoutNode) nodeIt.next();
-               nodeIdMapping.put(node.getIndex(), j);
-               j++;
-           }
-       }
-               
-       // Write edges (as pairs of consecutive nodes) in edgeArray
-       int[] edgeArray = new int[part.edgeCount() * 2];
-       int i = 0;
-       
-       Iterator<LayoutEdge> it = part.getEdgeList().iterator();
-
-       if (selectedOnly) {     
-           while (it.hasNext()) {
-               LayoutEdge e = (LayoutEdge) it.next();
-
-               LayoutNode source = e.getSource();
-               LayoutNode target = e.getTarget();
-
-               if (source.isLocked() || target.isLocked())
-                   continue;
-
-               edgeArray[i]     = nodeIdMapping.get(source.getIndex());
-               edgeArray[i + 1] = nodeIdMapping.get(target.getIndex());
-               i += 2;     
-           }
-       } else {
-           while (it.hasNext()) {
-               LayoutEdge e = (LayoutEdge) it.next();
-
-               LayoutNode source = e.getSource();
-               LayoutNode target = e.getTarget();
-
-               edgeArray[i]     = nodeIdMapping.get(source.getIndex());
-               edgeArray[i + 1] = nodeIdMapping.get(target.getIndex());
-               i += 2;     
-           }
-       }
-
-       IgraphInterface.createGraph(edgeArray, i);
-
-       return nodeIdMapping;
-    } // loadGraphPartition()
-
-
-}
\ No newline at end of file

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-26 14:52:56 UTC (rev 25945)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
    2011-06-26 21:22:37 UTC (rev 25946)
@@ -17,8 +17,9 @@
        Native.register("igraphWrapper"); 
     }
     
-    public static native int nativeAdd(int a, int b);    
-    
+//     public static native int nativeAdd(int a, int b);
+   
+    // Create an igraph's graph
     public static native void createGraph(int edgeArray[], int length);
     
     // Test whether the graph is connected
@@ -29,5 +30,18 @@
 
     // Circle layout
     public static native void layoutCircle(double x[], double y[]);
+
+    // Star Layout
+    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);
     
 }
\ 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-26 14:52:56 UTC (rev 25945)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
       2011-06-26 21:22:37 UTC (rev 25946)
@@ -73,6 +73,8 @@
        // Layouts
        CyLayouts.addLayout(new CircleLayout(), "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-26 14:52:56 UTC (rev 25945)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
       2011-06-26 21:22:37 UTC (rev 25946)
@@ -65,7 +65,10 @@
     /**
      * Do the layout on a graph alrealy loaded into igraph
      */
-    public abstract int layout(double[] x, double[] y);
+    public abstract int layout(double[] x, 
+                              double[] y, 
+                              LayoutPartition part, 
+                              HashMap<Integer,Integer> mapping);
 
     /**
      * getName is used to construct property strings
@@ -184,7 +187,7 @@
        taskMonitor.setStatus("Calling native code: Partition: " + 
part.getPartitionNumber());
 
        // Do Layout
-       layout(x,y);
+       layout(x,y, part, mapping);
 
        // Check whether it has been canceled by the user
        if (canceled)

Modified: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/CircleLayout.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/CircleLayout.java
       2011-06-26 14:52:56 UTC (rev 25945)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/CircleLayout.java
       2011-06-26 21:22:37 UTC (rev 25946)
@@ -22,7 +22,9 @@
 import cytoscape.plugins.igraph.*;
 import cytoscape.logger.CyLogger;
 import cytoscape.layout.LayoutProperties;
+import csplugins.layout.LayoutPartition;
 
+import java.util.*;
 
 public class CircleLayout extends AbstractIgraphLayout {
 
@@ -37,7 +39,10 @@
     /**
      * Do the layout on a graph alrealy loaded into igraph
      */
-    public int layout(double[] x, double[] y) {
+    public int layout(double[] x, 
+                     double[] y, 
+                     LayoutPartition part, 
+                     HashMap<Integer,Integer> mapping) {
        // Simplify graph
        IgraphInterface.simplify();
        

Copied: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/OldLayoutExample.java.nocompile
 (from rev 25942, 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/CircleLayout.java.nocompile)
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/OldLayoutExample.java.nocompile
                         (rev 0)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/OldLayoutExample.java.nocompile
 2011-06-26 21:22:37 UTC (rev 25946)
@@ -0,0 +1,395 @@
+/**************************************************************************************
+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.Cytoscape;
+import cytoscape.layout.AbstractLayout;
+import cytoscape.layout.LayoutProperties;
+import cytoscape.layout.Tunable;
+import cytoscape.CyNode;
+import cytoscape.logger.CyLogger;
+
+import cytoscape.view.CyNetworkView;
+import cytoscape.data.CyAttributes;
+
+import csplugins.layout.LayoutPartition;
+import csplugins.layout.LayoutEdge;
+import csplugins.layout.LayoutNode;
+import csplugins.layout.EdgeWeighter;
+import csplugins.layout.algorithms.graphPartition.*;
+
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+
+import java.awt.Dimension;
+import java.awt.GridLayout;
+import java.util.*;
+
+public class CircleLayout extends AbstractGraphPartition
+{
+    private String message;
+    private LayoutProperties layoutProperties;
+
+
+    /**
+     * Creates a new layout object.
+     */
+    public CircleLayout() {
+       super();
+
+       logger = CyLogger.getLogger(CircleLayout.class);
+       // logger.setDebug(true);
+
+       layoutProperties = new LayoutProperties(getName());
+       initialize_properties();
+    }
+
+
+    /**
+     * This plugin supports laying out only selected nodes
+     */
+    public boolean supportsSelectedOnly() {
+               return true;
+    }
+    
+    /**
+     * Adds tunable objects for adjusting plugin parameters
+     * Initializes default values for those parameters
+     */
+    protected void initialize_properties() {
+       
+       // Add new properties to layout 
+       
+       // Initialize layout properties
+       layoutProperties.initializeProperties();
+       
+       // Force the settings update
+       updateSettings(true);
+    }
+    
+    /**
+     * getName is used to construct property strings
+     * for this layout.
+     */
+    public  String getName() {
+       return "Igraph Circle Layout";
+    }
+    
+    /**
+     * toString is used to get the user-visible name
+     * of the layout
+     */
+    public  String toString(){
+       return "Circle Layout";
+    }
+    
+    /**
+     * Overload updateSettings for using it without arguments
+     */
+    public void updateSettings() {
+       updateSettings(false);
+    }
+    
+    /**
+     * Get new values from tunables and update parameters
+     */
+    public void updateSettings(boolean force) {
+       layoutProperties.updateValues();        
+    }
+    
+    /**
+     * Get the settings panel for this layout
+     */
+    public JPanel getSettingsPanel() {
+       JPanel panel = new JPanel(new GridLayout(1, 1));
+       panel.add(layoutProperties.getTunablePanel());
+       
+       return panel;
+    }
+    
+    /**
+     * Revert previous settings
+     */
+    public void revertSettings() {
+       layoutProperties.revertProperties();
+    }    
+    
+    /**
+     * Get layout properties
+     */
+    public LayoutProperties getSettings() {
+       return layoutProperties;
+    }
+       
+    
+    /**
+     * 
+     */
+    public void layoutPartition (LayoutPartition part) {
+
+       // Check whether it has been canceled by the user
+       if (canceled)
+           return;
+
+       // Show message on the task monitor
+       taskMonitor.setStatus("Initializing: Partition: " + 
part.getPartitionNumber());
+       
+       // The completed percentage is indeterminable
+       taskMonitor.setPercentCompleted(-1);
+
+       // Figure out our starting point if we are only laying out selected 
nodes
+       Dimension initialLocation = null;
+       if (selectedOnly) {
+           initialLocation = part.getAverageLocation();
+       }
+
+       // Get the number of edges and nodes
+       int numNodes = part.nodeCount();
+
+       // Allocate memory for storing graph edges information (to be used as 
arguments for JNI call)
+       double[] x = new double[numNodes];
+       double[] y = new double[numNodes];      
+
+       // Load graph into native library
+       HashMap<Integer,Integer> mapping = loadGraphPartition(part, 
selectedOnly);
+
+       // Check whether it has been canceled by the user
+       if (canceled)
+           return;
+
+       // Show message on the task monitor
+       taskMonitor.setStatus("Calling native code: Partition: " + 
part.getPartitionNumber());
+
+       // Simplify graph
+       IgraphInterface.simplify();
+       
+       // Make native method call
+       IgraphInterface.layoutCircle(x, y);
+
+       // Check whether it has been canceled by the user
+       if (canceled)
+           return;
+
+       // Show message on the task monitor
+       taskMonitor.setStatus("Updating display");      
+       
+       updateDisplay(part, mapping, x, y, initialLocation, selectedOnly);
+
+    }// layoutPartion(LayoutPartition part)
+
+
+
+    protected void updateDisplay(LayoutPartition part, 
HashMap<Integer,Integer> mapping, double[] x, double[] y, Dimension 
initialLocation, boolean selectedOnly) {
+       // Find which ratio is required to 'scale up' the node positions so 
that nodes don't overlap
+       double upRatio = 0.0;
+       double actualRatio = 0.0;
+
+       for (LayoutEdge edge: part.getEdgeList()) {
+           LayoutNode n1 = edge.getSource();
+           LayoutNode n2 = edge.getTarget();
+
+           if (n1.isLocked() || n2.isLocked())
+               continue;
+
+           double n1Size = Math.max(n1.getHeight(), n1.getWidth());
+           double n2Size = Math.max(n2.getHeight(), n2.getWidth());
+
+           double edgeSize = Math.sqrt( Math.pow(x[mapping.get(n1.getIndex())] 
- x[mapping.get(n2.getIndex())], 2)
+                                      + Math.pow(y[mapping.get(n1.getIndex())] 
- y[mapping.get(n2.getIndex())], 2)
+                                      );
+           // Check if edgeSize is not zero
+           if (edgeSize > 0.0){
+           
+               // actualRatio = minimun_desired_length / actual_length
+               actualRatio = (n1Size + n2Size) / edgeSize;
+               
+               // Update upRatio if necessary
+               if (actualRatio > upRatio)
+                   upRatio = actualRatio;
+           }
+
+       }
+       
+       // Check whether the ratio is not zero
+       if (upRatio < 1.0){   
+           upRatio = 1.0;
+       }
+
+       double oldUpRatio = upRatio;
+
+
+       // Move nodes to their position
+       boolean success = false;
+       while (!success){
+           
+           try{
+               // We will keep track of the offset of the whole part so that 
we can eliminate it
+               double minX = x[0];
+               double minY = y[0];
+               
+               // Get the 'offset' of the whole partition, so that we can 
eliminate it
+               for (int i = 1; i < mapping.size(); i++) {
+                   
+                   if (x[i] < minX)
+                       minX = x[i];
+
+                   if (y[i] < minY)
+                       minY = y[i];
+               }
+
+               minX = upRatio * minX;
+               minY = upRatio * minY;
+               
+               // Reset the nodes so we get the new average location
+               part.resetNodes(); 
+               
+               // Create an iterator for processing the nodes
+               Iterator<LayoutNode> iterator2 = part.getNodeList().iterator();
+                               
+               while (iterator2.hasNext()){
+                   
+                   // Get next node
+                   LayoutNode node = (LayoutNode) iterator2.next();
+
+                   // If it is locked, skip it
+                   if (!node.isLocked()) {                     
+
+                       // Set node's X and Y positions
+                       node.setX(upRatio * x[mapping.get(node.getIndex())] - 
minX);
+                       node.setY(upRatio * y[mapping.get(node.getIndex())] - 
minY);
+
+                       // Move node to desired location
+                       part.moveNodeToLocation(node);
+                   }
+               }
+       
+       
+               // Not quite done, yet.  If we're only laying out selected 
nodes, we need
+               // to migrate the selected nodes back to their starting position
+               if (selectedOnly) {
+                   double xDelta = 0.0;
+                   double yDelta = 0.0;
+                   Dimension finalLocation = part.getAverageLocation();
+                   xDelta = finalLocation.getWidth()  - 
initialLocation.getWidth();
+                   yDelta = finalLocation.getHeight() - 
initialLocation.getHeight();
+                   for (LayoutNode v: part.getNodeList()) {
+                       if (!v.isLocked()) {
+                           v.decrement(xDelta, yDelta);
+                           part.moveNodeToLocation(v);
+                       }
+                   }
+               }
+               
+               success = true;
+
+           }
+           catch(Exception excep){
+
+               upRatio = upRatio / 10.0;
+               if (upRatio <= 0.0){
+                   message = "Sorry, cannot produce layout";
+                   JOptionPane.showMessageDialog(Cytoscape.getDesktop(), 
message);
+                   return;
+               }
+               success = false;
+           }
+
+       }//while(!success)
+
+    } //updateDisplay
+
+
+    /**
+     * This function loads a partition into igraph
+     *
+     */    
+    public static HashMap<Integer,Integer> loadGraphPartition(LayoutPartition 
part, boolean selectedOnly){
+
+       CyLogger logger = CyLogger.getLogger(CircleLayout.class);           
+       
+       // Create a reverse mapping
+       int nodeCount = part.nodeCount();
+
+       HashMap<Integer, Integer> nodeIdMapping;
+       if (selectedOnly) 
+           nodeIdMapping = new HashMap<Integer, Integer>(nodeCount - 
part.lockedNodeCount());
+       else
+           nodeIdMapping = new HashMap<Integer, Integer>(nodeCount);
+       int j = 0;
+
+       Iterator<LayoutNode> nodeIt = part.nodeIterator();      
+       if (selectedOnly) {
+           while(nodeIt.hasNext()) {            
+               LayoutNode node = (LayoutNode) nodeIt.next();
+               if (!node.isLocked()) {
+                   nodeIdMapping.put(node.getIndex(), j);
+                   j++;
+               }
+           }
+       } else {
+           while(nodeIt.hasNext()) {            
+               LayoutNode node = (LayoutNode) nodeIt.next();
+               nodeIdMapping.put(node.getIndex(), j);
+               j++;
+           }
+       }
+               
+       // Write edges (as pairs of consecutive nodes) in edgeArray
+       int[] edgeArray = new int[part.edgeCount() * 2];
+       int i = 0;
+       
+       Iterator<LayoutEdge> it = part.getEdgeList().iterator();
+
+       if (selectedOnly) {     
+           while (it.hasNext()) {
+               LayoutEdge e = (LayoutEdge) it.next();
+
+               LayoutNode source = e.getSource();
+               LayoutNode target = e.getTarget();
+
+               if (source.isLocked() || target.isLocked())
+                   continue;
+
+               edgeArray[i]     = nodeIdMapping.get(source.getIndex());
+               edgeArray[i + 1] = nodeIdMapping.get(target.getIndex());
+               i += 2;     
+           }
+       } else {
+           while (it.hasNext()) {
+               LayoutEdge e = (LayoutEdge) it.next();
+
+               LayoutNode source = e.getSource();
+               LayoutNode target = e.getTarget();
+
+               edgeArray[i]     = nodeIdMapping.get(source.getIndex());
+               edgeArray[i + 1] = nodeIdMapping.get(target.getIndex());
+               i += 2;     
+           }
+       }
+
+       IgraphInterface.createGraph(edgeArray, i);
+
+       return nodeIdMapping;
+    } // loadGraphPartition()
+
+
+}
\ No newline at end of file

Added: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/StarLayout.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/StarLayout.java
                         (rev 0)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/StarLayout.java
 2011-06-26 21:22:37 UTC (rev 25946)
@@ -0,0 +1,72 @@
+/**************************************************************************************
+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 java.util.*;
+
+public class StarLayout extends AbstractIgraphLayout {
+
+    public StarLayout() {
+       super();
+       logger = CyLogger.getLogger(StarLayout.class);
+       
+       layoutProperties = new LayoutProperties(getName());
+       initialize_properties();
+    }
+
+    /**
+     * Do the layout on a graph alrealy loaded into igraph
+     */
+    public int layout(double[] x, 
+                     double[] y, 
+                     LayoutPartition part, 
+                     HashMap<Integer,Integer> mapping) {
+
+       // Simplify graph
+       IgraphInterface.simplify();
+       
+       // Make native method call
+       IgraphInterface.starLayout(x, y, mapping.keySet().iterator().next());
+
+       return 1;
+    }
+
+    /**
+     * getName is used to construct property strings
+     * for this layout.
+     */
+    public String getName() {
+       return "Igraph Star Layout";
+    }
+    
+    /**
+     * toString is used to get the user-visible name
+     * of the layout
+     */
+    public String toString() {
+       return "Star Layout";
+    }
+
+}
\ No newline at end of file

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp      
2011-06-26 14:52:56 UTC (rev 25945)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp      
2011-06-26 21:22:37 UTC (rev 25946)
@@ -12,12 +12,12 @@
 using namespace std;
 
 
-//Testing passing of an integer
-//Try global variables just in case
+// Testing passing of an integer
+// Try global variables just in case
 int count = 0;
 
-//use a global graph object
-//Make sure there's only one active graph @ a time to reduce confusions
+// Use a global graph object
+// Make sure there's only one active graph @ a time to reduce confusions
 igraph_t g;
 int existsGraph = 0;
 
@@ -43,14 +43,6 @@
   igraph_vector_destroy(&v);
 }
 
-//Boolean, test whether the current graph is simple
-//Can only be called when a graph has been loaded
-// bool isSimple(){
-//     igraph_bool_t simple;
-//     igraph_is_simple(&g, &simple);
-//     return (bool)simple;
-//     //return 1;
-// }
 
 bool isConnected(){
        igraph_bool_t connected;
@@ -61,7 +53,89 @@
 void simplify(){
   igraph_simplify(&g, 1, 1, 0);
 }
+
+
+
+void layoutCircle(double x[], double y[]){
+       igraph_matrix_t locs;
+       igraph_matrix_init(&locs, 0, 0);
+
+       // Execute layout
+       igraph_layout_circle(&g, &locs);
+       
+       long int nRow = igraph_matrix_nrow(&locs);
+       long int nCol = igraph_matrix_ncol(&locs);
+       for(int i=0; i<nRow; i++){
+               x[i] = MATRIX(locs, i, 0);
+               y[i] = MATRIX(locs, i, 1);
+       }
+}
+
+void starLayout(double x[], double y[], int centerId) {
+
+       igraph_matrix_t locs;
+       igraph_matrix_init(&locs, 0, 0);
+
+       // Execute layout
+       igraph_layout_star(&g, &locs, centerId, NULL);
+
+       long int nRow = igraph_matrix_nrow(&locs);
+       long int nCol = igraph_matrix_ncol(&locs);
+       for(int i=0; i<nRow; i++){
+               x[i] = MATRIX(locs, i, 0);
+               y[i] = MATRIX(locs, i, 1);
+       }
+
+
+}
+
+// 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);
+//     }       
+// }
+
+
+
+
 //////////////////////////////
+
+//Boolean, test whether the current graph is simple
+//Can only be called when a graph has been loaded
+// bool isSimple(){
+//     igraph_bool_t simple;
+//     igraph_is_simple(&g, &simple);
+//     return (bool)simple;
+//     //return 1;
+// }
+
+
 // void clusters(int membership[], int csize[], int* numCluster){
 //     igraph_vector_t membership_v;
 //     igraph_vector_t csize_v;
@@ -311,21 +385,17 @@
 // }
 
 
-void layoutCircle(double x[], double y[]){
-       igraph_matrix_t locs;
-       igraph_matrix_init(&locs, 0, 0);
 
-       igraph_layout_circle(&g, &locs);
-       
-       long int nRow = igraph_matrix_nrow(&locs);
-       long int nCol = igraph_matrix_ncol(&locs);
-       for(int i=0; i<nRow; i++){
-               x[i] = MATRIX(locs, i, 0);
-               y[i] = MATRIX(locs, i, 1);
-       }
-}
 
 
+// int igraph_layout_fruchterman_reingold(const igraph_t *graph, 
igraph_matrix_t *res,
+//                                    igraph_integer_t niter, igraph_real_t 
maxdelta,
+//                                    igraph_real_t area, igraph_real_t 
coolexp, 
+//                                    igraph_real_t repulserad, igraph_bool_t 
use_seed,
+//                                    const igraph_vector_t *weight);
+
+
+
 // void layoutRandom(double x[], double y[]){
 //     igraph_matrix_t locs;
 //     igraph_matrix_init(&locs, 0, 0);
@@ -408,23 +478,7 @@
        
 // }
 
-// ///
-// 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);
-//     }       
-// }
-
 // //
 // void layoutKamadaKawai(double x[], double y[], int iter, double sigma, 
double initTemp, double coolExp, double kkConsts, bool useSeed){
 //     long int vcount = igraph_vcount(&g);

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h        
2011-06-26 14:52:56 UTC (rev 25945)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h        
2011-06-26 21:22:37 UTC (rev 25946)
@@ -4,26 +4,30 @@
 
 extern "C"
 {
-  //test functions
-  int nativeAdd( int a, int b );
-/*   void nativeIncrement(int* iptr); */
-/*   int nativeArrayReset(int data[], int length); */
-/*   int nativeCountAdd(int value); */
-/*   void nativeArrayTest(int data[]); */
-/*   void nativeMemoryAllocate(int **data, int *length); //pointer to pointer 
reference */
-/*   void nativePointerMemoryAllocate(int *data, int *length); //single 
pointer reference */
-/*   void nativeListAllocate(int*** data, int** list_lengths, int* 
data_length); //Return a zig-zag type */
-/*   void nativeMatrixAllocate(int** data, int* nrow, int* ncol); */
 
-  //igraph functions
+
+  // Igraph functions
   void createGraph(int edgeArray[], int length);
-/*   bool isSimple(); */
   bool isConnected();
   void simplify();
-/*   void clusters(int membership[], int csize[], int* numCluster); */
   int nodeCount();
-/*   int edgeCount(); */
+  /*   bool isSimple(); */
+  /*   int edgeCount(); */
+  /*   void clusters(int membership[], int csize[], int* numCluster); */
 
+  // 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 fastGreedy(int membership[], double* modularity, int csize[], int * 
numCluster); */
 /*   void labelPropagation(int membership[], double* modularity); */
 /*   void walkTrap(int membership[], double*modularity, int csize[], int * 
numCluster); */
@@ -32,6 +36,16 @@
 /*   void spinGlassSingle(int target, int community[], int* community_size); 
//only compute community close to the target id */
   //Can also make a function to compute an array of ids, if possible in later 
versions.
 
-  void layoutCircle(double x[], double y[]);
 
+  //test functions
+/*   int nativeAdd( int a, int b ); */
+/*   void nativeIncrement(int* iptr); */
+/*   int nativeArrayReset(int data[], int length); */
+/*   int nativeCountAdd(int value); */
+/*   void nativeArrayTest(int data[]); */
+/*   void nativeMemoryAllocate(int **data, int *length); //pointer to pointer 
reference */
+/*   void nativePointerMemoryAllocate(int *data, int *length); //single 
pointer reference */
+/*   void nativeListAllocate(int*** data, int** list_lengths, int* 
data_length); //Return a zig-zag type */
+/*   void nativeMatrixAllocate(int** data, int* nrow, int* ncol); */
+
 }

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