Author: chinmoy
Date: 2009-07-24 13:00:37 -0700 (Fri, 24 Jul 2009)
New Revision: 17556

Modified:
   
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
   
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/cladograms/CircularCladogram.java
Log:
Fixed arc drawing in circular layout algorithms

Modified: 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
===================================================================
--- 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
       2009-07-24 19:20:14 UTC (rev 17555)
+++ 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/CommonFunctions.java
       2009-07-24 20:00:37 UTC (rev 17556)
@@ -293,6 +293,12 @@
                return numLeaves;
        }
        
+       
+       /**
+        * Calculates the optimum factor by which edges must be scaled to 
obtain an optimum view
+        * @param network - the network from which the scaling factor is to be 
calculated
+        * @return - the factor to be multiplied to the branchLengths to obtain 
the optimum view
+        */
        public double getScalingFactor(CyNetwork network)
        {
        
@@ -324,6 +330,9 @@
        
        /**
         * Adds the bends to make the edges look rectangular
+        * * @param network - the network on which the bends are to be added
+        * @param networkView - the networkView on which bends are to be added
+        * @param edge - the edge onto which bends are to be added
         */
        public void addRectangularBends(CyNetwork network, CyNetworkView 
networkView, Edge edge)
        {
@@ -352,6 +361,9 @@
        
        /**
         * Adds the bends to make the edges look circular
+        * @param network - the network on which the bends are to be added
+        * @param networkView - the networkView on which bends are to be added
+        * @param edge - the edge onto which bends are to be added
         */
        public void addCircularBends(CyNetwork network, CyNetworkView 
networkView, Edge edge)
        {
@@ -382,37 +394,52 @@
                                Point2D handlePoint = new 
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle));
                                Point2D sourcePoint = new 
Point2D.Double(sourceX, sourceY);
                                circularBend.addHandle(handlePoint);
-                               
+                       
                                // Algorithm to draw arcs:
+                               // Find the length of the chord from the source 
to the first handle in the bend
+                               // Find the length of the segment that would 
produce an arc of the desired handleInterval
+                               // Divide the length of the chord and the 
subSegment to calculate how many subSegments are required
+                               // Number of subSegments on chord = number of 
handles to produce the arc from the bend
                                
-//                             double distance = 
handlePoint.distance(sourcePoint);
-//                             double handleInterval = 18.0;
-//                             int iterations = 5;
-//                             
-//                                     if(compareAngles(angle,sourceAngle)==0)
-//
-//                                     {
-//                                             for(int i = 0;i<iterations; i 
++)
-//                                             {
-//                                                     angle = 
angle+(Math.PI/handleInterval);
-//                                                     
circularBend.addHandle(new 
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle)));
-//
-//                                             }
-//                                     }
-//                                     else 
if(compareAngles(angle,sourceAngle)==1)
-//                                     {
-//                                             for(int i =0; i<iterations; i++)
-//                                             {
-//                                                     angle = 
angle-(Math.PI/handleInterval);
-//                                                     
circularBend.addHandle(new 
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle)));
-//
-//                                             }
-//                                     }
+                               double chordLength = 
handlePoint.distance(sourcePoint);
                                
+                               double handleInterval = Math.PI/18.0;
+                               double subSegmentLength = 
2*radius*Math.sin(handleInterval/2.0);
+                               
+                               int iterations = 
(int)(chordLength/subSegmentLength);
+                               
+                                       if(compareAngles(angle,sourceAngle)==0)
+
+                                       {
+                                               for(int i = 0;i<iterations; i 
++)
+                                               {
+                                                       angle = 
angle+(handleInterval);
+                                                       
circularBend.addHandle(new 
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle)));
+
+                                               }
+                                       }
+                                       else 
if(compareAngles(angle,sourceAngle)==1)
+                                       {
+                                               for(int i =0; i<iterations; i++)
+                                               {
+                                                       angle = 
angle-(handleInterval);
+                                                       
circularBend.addHandle(new 
Point2D.Double(radius*Math.cos(angle),radius*Math.sin(angle)));
+
+                                               }
+                                       }
+                               
                        }
        }
        
        
+       /**
+        * Important for the functioning of addCircularBends
+        * Given the angle of the initial handle in the bend(arc) and the angle 
of the source node
+        * calculates which one is smaller
+        * @param angle1 - the angle of the initial handle
+        * @param angle2 - the angle of the source node
+        * @return 1 if angle1 is smaller, 0 if angle2 is smaller, 2 if error
+        */
        private int compareAngles(double angle1, double angle2)
        {
                int result = 2;
@@ -425,11 +452,11 @@
                }
                else if(angle1>=0 && angle2<0)
                {
-                       result = 1;
+                       result = 0;
                }
                else if(angle1<0 && angle2>=0)
                {
-                       result = 0;
+                       result = 1;
                }
                
                        return result;

Modified: 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/cladograms/CircularCladogram.java
===================================================================
--- 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/cladograms/CircularCladogram.java
  2009-07-24 19:20:14 UTC (rev 17555)
+++ 
csplugins/trunk/soc/chinmoy/phylotree/src/org/cytoscape/phylotree/layout/cladograms/CircularCladogram.java
  2009-07-24 20:00:37 UTC (rev 17556)
@@ -115,8 +115,7 @@
                {
                        Node node = it.next();
                        
-                       System.out.println(node.getIdentifier()+": 
"+Math.atan2(networkView.getNodeView(node).getYPosition(), 
networkView.getNodeView(node).getXPosition()));
-                       
+               
                        // If leaf position it accordingly
                        
if(network.getAdjacentEdgeIndicesArray(node.getRootGraphIndex(), false, false, 
true).length == 0)
                                positionLeaf(node);


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