Author: ghuck
Date: 2011-07-03 08:21:41 -0700 (Sun, 03 Jul 2011)
New Revision: 26014

Modified:
   csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml
   
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/FruchtermanReingoldLayout.java
   csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
   csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
Log:
Support for weighted layout added on the C side

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml    2011-07-02 14:07:24 UTC 
(rev 26013)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/build.xml    2011-07-03 15:21:41 UTC 
(rev 26014)
@@ -152,7 +152,15 @@
     </exec>
   </target>
 
+  <!-- =================================================================== -->
+  <!-- Clean up libraries extracted in plugins folder                      -->
+  <!-- =================================================================== -->
+  <target name="clean-libs" depends="init">
+    <delete file="${cytoscape.plugin.dir}/libigraphWrapper.dylib"/>
+    <delete file="${cytoscape.plugin.dir}/libigraph.0.dylib"/>
+  </target>
 
+
 </project>
 
 <!-- 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-07-02 14:07:24 UTC (rev 26013)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphInterface.java
    2011-07-03 15:21:41 UTC (rev 26014)
@@ -17,7 +17,7 @@
        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);
@@ -42,6 +42,9 @@
                                                double area, 
                                                double coolExp, 
                                                double repulserad, 
-                                               boolean useSeed);
+                                               boolean useSeed,
+                                               boolean isWeighted,
+                                               double weights[]);
     
-}
\ 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-07-02 14:07:24 UTC (rev 26013)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
       2011-07-03 15:21:41 UTC (rev 26014)
@@ -55,10 +55,10 @@
        checkLib("igraph.0");
 
         String userDir = System.getProperty("user.dir"); 
-//     JOptionPane.showMessageDialog( Cytoscape.getDesktop(), "user dir:"+ 
userDir);   
+       // JOptionPane.showMessageDialog( Cytoscape.getDesktop(), "user dir:"+ 
userDir);        
        NativeLibrary.addSearchPath("igraphWrapper", userDir + "/plugins");
 
-//     JOptionPane.showMessageDialog(Cytoscape.getDesktop(), 
IgraphInterface.nativeAdd(10, 20));          
+       // JOptionPane.showMessageDialog(Cytoscape.getDesktop(), 
IgraphInterface.nativeAdd(10, 20));       
 
        // Create Igraph object
        IgraphAPI igraph = new IgraphAPI();
@@ -123,54 +123,54 @@
     } // checkLib
 
 
-    protected boolean loadIgraph() {
+//     protected boolean loadIgraph() {
 
-       boolean res = true;
+//     boolean res = true;
 
-       // Reset the "sys_paths" field of the ClassLoader to null.
-       Class clazz = ClassLoader.class;
-       Field field;
-       try {
-           field = clazz.getDeclaredField("sys_paths");
-           boolean accessible = field.isAccessible();
-           if (!accessible)
-               field.setAccessible(true);
-           Object original = field.get(clazz);
+//     // Reset the "sys_paths" field of the ClassLoader to null.
+//     Class clazz = ClassLoader.class;
+//     Field field;
+//     try {
+//         field = clazz.getDeclaredField("sys_paths");
+//         boolean accessible = field.isAccessible();
+//         if (!accessible)
+//             field.setAccessible(true);
+//         Object original = field.get(clazz);
 
-           // Get original PATH
-           String orig_path = System.getProperty("java.library.path");
+//         // Get original PATH
+//         String orig_path = System.getProperty("java.library.path");
            
-           // Reset it to null so that whenever "System.loadLibrary" is 
called, it will be reconstructed with the changed value
-           field.set(clazz, null);
-           try {
-               // Change the value and load the library.
-               System.setProperty("java.library.path", "./plugins"  + ":" + 
orig_path);
-               //              System.loadLibrary("igraph.0");
-               System.loadLibrary("igraphWrapper");
-           }
+//         // Reset it to null so that whenever "System.loadLibrary" is 
called, it will be reconstructed with the changed value
+//         field.set(clazz, null);
+//         try {
+//             // Change the value and load the library.
+//             System.setProperty("java.library.path", "./plugins"  + ":" + 
orig_path);
+//             //              System.loadLibrary("igraph.0");
+//             System.loadLibrary("igraphWrapper");
+//         }
 
-           catch (UnsatisfiedLinkError error) {
-               String message = "Problem detected while loading library.\n"    
            
-                   + error.getMessage() 
-                   + "\nPlease check your plugins folder.";
-               JOptionPane.showMessageDialog(Cytoscape.getDesktop(), message);
+//         catch (UnsatisfiedLinkError error) {
+//             String message = "Problem detected while loading library.\n"    
            
+//                 + error.getMessage() 
+//                 + "\nPlease check your plugins folder.";
+//             JOptionPane.showMessageDialog(Cytoscape.getDesktop(), message);
                                
-               res = false;
-           }           
+//             res = false;
+//         }           
 
-           finally {
-               // Revert back the changes
-               field.set(clazz, original);
-               field.setAccessible(accessible);   
-           }
-       }
-       catch (Exception exception) {
-           res = false;
-       }
+//         finally {
+//             // Revert back the changes
+//             field.set(clazz, original);
+//             field.setAccessible(accessible);   
+//         }
+//     }
+//     catch (Exception exception) {
+//         res = false;
+//     }
 
-       finally {
-           return res;
-       }
-    }
+//     finally {
+//         return res;
+//     }
+//     }
         
 }
\ No newline at end of file

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-07-02 14:07:24 UTC (rev 26013)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/AbstractIgraphLayout.java
       2011-07-03 15:21:41 UTC (rev 26014)
@@ -187,9 +187,6 @@
        // Load graph into native library
        HashMap<Integer,Integer> mapping = loadGraphPartition(part, 
selectedOnly);
 
-       // Store current node positions
-       loadPositions(part, mapping, x, y);
-
        // Check whether it has been canceled by the user
        if (canceled)
            return;
@@ -341,6 +338,8 @@
 
        CyLogger logger = CyLogger.getLogger(AbstractIgraphLayout.class);       
    
        
+       // JOptionPane.showMessageDialog(Cytoscape.getDesktop(), "Load graph 
called!");    
+
        // Create a reverse mapping
        int nodeCount = part.nodeCount();
 

Modified: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
  2011-07-02 14:07:24 UTC (rev 26013)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/layouts/FruchtermanReingoldLayout.java
  2011-07-03 15:21:41 UTC (rev 26014)
@@ -132,15 +132,6 @@
 
     }
 
-//     /**
-//      * 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
@@ -151,9 +142,17 @@
                      HashMap<Integer,Integer> mapping) {
 
        
-       double maxDelta   = maxDeltaCoefficient * part.nodeCount();
-       double area       = areaCoefficient * part.nodeCount() * 
part.nodeCount();
-       double repulseRad = repulseRadCoefficient * area * part.nodeCount();
+       int numNodes = mapping.size();
+
+       double maxDelta   = maxDeltaCoefficient * numNodes;
+       double area       = areaCoefficient * numNodes * numNodes;
+       double repulseRad = repulseRadCoefficient * area * numNodes;
+       double[] weights = new double[numNodes];
+
+       // Store current node positions if necessary
+       if (!randomize) {
+           loadPositions(part, mapping, x, y);
+       }
        
        // Make native method call
        IgraphInterface.layoutFruchterman(x, 
@@ -163,7 +162,9 @@
                                          area, 
                                          coolExp, 
                                          repulseRad, 
-                                         !randomize);
+                                         !randomize,
+                                         false,
+                                         weights);
        
        return 1;
     }

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp      
2011-07-02 14:07:24 UTC (rev 26013)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.cpp      
2011-07-03 15:21:41 UTC (rev 26014)
@@ -69,6 +69,8 @@
                x[i] = MATRIX(locs, i, 0);
                y[i] = MATRIX(locs, i, 1);
        }
+       // Clean up
+       igraph_matrix_destroy(&locs);
 }
 
 void starLayout(double x[], double y[], int centerId) {
@@ -85,8 +87,9 @@
                x[i] = MATRIX(locs, i, 0);
                y[i] = MATRIX(locs, i, 1);
        }
-
-
+       
+       // Clean up
+       igraph_matrix_destroy(&locs);
 }
 
 //Fruchterman - Reingold Layout
@@ -97,35 +100,76 @@
                       double area, 
                       double coolExp, 
                       double repulserad, 
-                      bool useSeed){
+                      bool useSeed, 
+                      bool isWeighted,
+                      double weights[]){
+
        long int vcount = igraph_vcount(&g);
+
        igraph_matrix_t locs;
        igraph_matrix_init(&locs, vcount, 2); 
-       for(int i = 0; i < vcount; i++){
+       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, // weights 
-                                          0, 
-                                          0);
+       igraph_vector_t weights_vector;
+       if (isWeighted) {
+         igraph_vector_init(&weights_vector, vcount);
+         for (int i = 0; i < vcount; i++){
+           VECTOR(weights_vector)[i] = weights[i];
+         } 
+       }
+
+
+       if (isWeighted) {
+         igraph_layout_fruchterman_reingold(&g, 
+                                            &locs, 
+                                            iter, 
+                                            maxDelta, 
+                                            area, 
+                                            coolExp, 
+                                            repulserad, 
+                                            useSeed, 
+                                            &weights_vector,
+                                            0, 
+                                            0);
+
+       } else {
+         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);
        }       
+
+       // Clean up
+       igraph_matrix_destroy(&locs);
+       igraph_vector_destroy(&weights_vector); 
 }
 
+extern "C"{
+  //Simple adding of two integers
+  int nativeAdd(int a, int b)
+  {
+    return( a + b );
+  }
+}
 
 
 
+
 //////////////////////////////
 
 //Boolean, test whether the current graph is simple
@@ -628,13 +672,6 @@
 // }
 
 
-extern "C"{
-//Simple adding of two integers
-  int nativeAdd( int a, int b )
-  {
-    return( a + b );
-  }
-}
 // //Add one to the passed integer via pointer
 // void nativeIncrement(int* iptr){
 //     *iptr += 1;

Modified: csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h
===================================================================
--- csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h        
2011-07-02 14:07:24 UTC (rev 26013)
+++ csplugins/trunk/soc/ghuck/IgraphPlugin/src/igraphWrapper/igraphJNA.h        
2011-07-03 15:21:41 UTC (rev 26014)
@@ -25,7 +25,9 @@
                         double area,
                         double coolExp,
                         double repulserad,
-                        bool useSeed);
+                        bool useSeed,
+                        bool isWeighted,
+                        double weights[]);
 
 
 /*   void fastGreedy(int membership[], double* modularity, int csize[], int * 
numCluster); */
@@ -34,11 +36,10 @@
 /*   void edgeBetweenness(int membership[], double*modularity, int csize[], 
int * numCluster); */
 /*   void spinGlass(int membership[], double* modularity, int csize[], int* 
numCluster); */
 /*   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.
+  
 
-
   //test functions
-/*   int nativeAdd( int a, int b ); */
+  int nativeAdd(int a, int b);
 /*   void nativeIncrement(int* iptr); */
 /*   int nativeArrayReset(int data[], int length); */
 /*   int nativeCountAdd(int value); */

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