Author: rozagh
Date: 2012-06-19 16:54:32 -0700 (Tue, 19 Jun 2012)
New Revision: 29631
Added:
core3/impl/trunk/layout-prefuse-impl/src/main/java/prefuse/
core3/impl/trunk/layout-prefuse-impl/src/main/java/prefuse/util/
core3/impl/trunk/layout-prefuse-impl/src/main/java/prefuse/util/force/
Modified:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractPartitionLayoutTask.java
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutEdge.java
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutNode.java
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/PartitionUtil.java
core3/impl/trunk/layout-prefuse-impl/pom.xml
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutContext.java
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutTask.java
Log:
fixes #728 imported the modified prefuse library from 2.8 and make changes
based on the code in 2.8. The behavior needs to be checked for applying force
directed layout on selected only nodes.
Modified:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractPartitionLayoutTask.java
===================================================================
---
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractPartitionLayoutTask.java
2012-06-19 23:51:42 UTC (rev 29630)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/AbstractPartitionLayoutTask.java
2012-06-19 23:54:32 UTC (rev 29631)
@@ -175,7 +175,7 @@
setTaskStatus(1);
// Partitions Requiring Layout
- if (partition.nodeCount() > 1) {
+ /* if (partition.nodeCount() > 1) {
try {
layoutPartion(partition);
} catch (Throwable _e) {
@@ -201,7 +201,40 @@
} else {
continue;
}
+*/
+ // Partitions Requiring Layout
+ if (partition.nodeCount() >= 1) { // LABEL
+ try {
+ layoutPartion(partition);
+ } catch (OutOfMemoryError _e) {
+ System.gc();
+ logger.error("Layout algorithm failed:
Out of memory");
+ return;
+ } catch (Exception _e) {
+ logger.error("Layout algorithm failed:
", (Throwable)_e);
+ return;
+ }
+ if (useAllNodes && !singlePartition) {
+ // logger.debug("Offsetting partition
#"+partition.getPartitionNumber()+" to "+next_x_start+", "+next_y_start);
+ // OFFSET
+ partition.offset(next_x_start,
next_y_start);
+ }
+
+ // single nodes
+ } else if ( partition.nodeCount() == 1 ) { // TODO: do
something with this!!!
+ // Reset our bounds
+ partition.resetNodes();
+
+ // Single node -- get it
+ LayoutNode node = (LayoutNode)
partition.getNodeList().get(0);
+ node.setLocation(next_x_start, next_y_start);
+ partition.moveNodeToLocation(node);
+ } else {
+ logger.info("No nodes in partition
"+partition.getPartitionNumber()+" -- skipping");
+ continue;
+ }
+
double last_max_x = partition.getMaxX();
double last_max_y = partition.getMaxY();
Modified:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutEdge.java
===================================================================
---
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutEdge.java
2012-06-19 23:51:42 UTC (rev 29630)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutEdge.java
2012-06-19 23:54:32 UTC (rev 29631)
@@ -42,7 +42,7 @@
* LayoutNodes that are joined by this edge.
* @CyAPI.Final.Class
*/
-public final class LayoutEdge {
+public final class LayoutEdge implements Comparable<LayoutEdge> {
// instance variables
private LayoutNode v1;
@@ -177,6 +177,15 @@
}
/**
+ * Return the edge's identifier.
+ *
+ * @return String containing the edge's identifier
+ */
+ public String getIdentifier() {
+ return this.edge.getSUID().toString();
+ }
+
+ /**
* Return a string representation for this LayoutEdge.
*
* @return A String containing the name of the Edge, the connecting
LayoutNodes
@@ -185,6 +194,7 @@
public String toString() {
String source = "undefined";
String target = "undefined";
+ String edgeId = "undefined";
if (v1 != null)
source = v1.getIdentifier();
@@ -192,7 +202,15 @@
if (v2 != null)
target = v2.getIdentifier();
- return "Edge " + edge.getSUID() + " connecting " + source + "
and " + target
+ if (this.edge != null)
+ edgeId = getIdentifier();
+
+ return "Edge " + edgeId + " connecting " + source + " and " +
target
+ " with weight " + weight;
}
+
+ @Override
+ public int compareTo(LayoutEdge edgeView) {
+ return getIdentifier().compareTo(edgeView.getIdentifier());
+ }
}
Modified:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutNode.java
===================================================================
---
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutNode.java
2012-06-19 23:51:42 UTC (rev 29630)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutNode.java
2012-06-19 23:54:32 UTC (rev 29631)
@@ -49,7 +49,7 @@
* these are often wrapped by LayoutPartition methods.
* @CyAPI.Final.Class
*/
-public final class LayoutNode {
+public final class LayoutNode implements Comparable<LayoutNode> {
// static (class) variables
private static final double EPSILON = 0.0000001D;
@@ -407,4 +407,9 @@
public String printLocation() {
return "" + x + ", " + y;
}
+
+ @Override
+ public int compareTo(LayoutNode nodeView) {
+ return getIdentifier().compareTo(nodeView.getIdentifier());
+ }
}
Modified:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
===================================================================
---
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
2012-06-19 23:51:42 UTC (rev 29630)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/LayoutPartition.java
2012-06-19 23:54:32 UTC (rev 29631)
@@ -218,6 +218,7 @@
* @param node the LayoutNode to move
*/
public void moveNodeToLocation(LayoutNode node) {
+
// We provide this routine so that we can keep our min/max
values updated
if (node.isLocked())
return;
@@ -507,7 +508,8 @@
edgeList.trimToSize();
}
- private void updateMinMax(final double x, final double y) {
+ private void updateMinMax(final double x, final double y) {
+
minX = Math.min(minX, x);
minY = Math.min(minY, y);
maxX = Math.max(maxX, x);
Modified:
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/PartitionUtil.java
===================================================================
---
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/PartitionUtil.java
2012-06-19 23:51:42 UTC (rev 29630)
+++
core3/api/trunk/layout-api/src/main/java/org/cytoscape/view/layout/PartitionUtil.java
2012-06-19 23:54:32 UTC (rev 29631)
@@ -140,6 +140,9 @@
public int compare(LayoutPartition p1, LayoutPartition
p2) {
return (p2.size() - p1.size());
}
+ public boolean equals(LayoutPartition obj) {
+ return false;
+ }
});
return partitions;
Modified: core3/impl/trunk/layout-prefuse-impl/pom.xml
===================================================================
--- core3/impl/trunk/layout-prefuse-impl/pom.xml 2012-06-19 23:51:42 UTC
(rev 29630)
+++ core3/impl/trunk/layout-prefuse-impl/pom.xml 2012-06-19 23:54:32 UTC
(rev 29631)
@@ -57,8 +57,8 @@
<instructions>
<Bundle-SymbolicName>${bundle.symbolicName}</Bundle-SymbolicName>
<Bundle-Version>${project.version}</Bundle-Version>
-
<Export-Package>!${bundle.namespace}.*</Export-Package>
-
<Private-Package>${bundle.namespace}.*</Private-Package>
+
<Export-Package>!${bundle.namespace}.*,!prefuse.*</Export-Package>
+
<Private-Package>${bundle.namespace}.*,prefuse.*</Private-Package>
<Bundle-Activator>${bundle.namespace}.CyActivator</Bundle-Activator>
</instructions>
</configuration>
@@ -80,10 +80,5 @@
<groupId>org.cytoscape</groupId>
<artifactId>layout-api</artifactId>
</dependency>
- <dependency>
- <groupId>cytoscape-temp</groupId>
- <artifactId>prefuse</artifactId>
- <version>20071021</version>
- </dependency>
</dependencies>
</project>
Modified:
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutContext.java
===================================================================
---
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutContext.java
2012-06-19 23:51:42 UTC (rev 29630)
+++
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutContext.java
2012-06-19 23:54:32 UTC (rev 29631)
@@ -18,6 +18,8 @@
public double defaultSpringLength = 50.0;
@Tunable(description="Default Node Mass")
public double defaultNodeMass = 3.0;
+ @Tunable(description="Force deterministic layouts (slower)")
+ public boolean isDeterministic;
@Tunable(description="Don't partition graph before layout",
groups="Standard settings")
public boolean singlePartition;
Modified:
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutTask.java
===================================================================
---
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutTask.java
2012-06-19 23:51:42 UTC (rev 29630)
+++
core3/impl/trunk/layout-prefuse-impl/src/main/java/org/cytoscape/prefuse/layouts/internal/ForceDirectedLayoutTask.java
2012-06-19 23:54:32 UTC (rev 29631)
@@ -27,8 +27,9 @@
*/
package org.cytoscape.prefuse.layouts.internal;
-
+import java.util.Collections;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -96,11 +97,28 @@
part.calculateEdgeWeights();
// System.out.println("layoutPartion:
"+part.getEdgeList().size()+" edges after calculateEdgeWeights");
- m_fsim.setIntegrator(integrator.getNewIntegrator());
- m_fsim.clear();
+ //m_fsim.setIntegrator(integrator.getNewIntegrator());
+ //m_fsim.clear();
+ m_fsim = new ForceSimulator();
+ m_fsim.addForce(new NBodyForce());
+ m_fsim.addForce(new SpringForce());
+ m_fsim.addForce(new DragForce());
+
+ forceItems.clear();
+
+ List<LayoutNode> nodeList = part.getNodeList();
+ List<LayoutEdge> edgeList = part.getEdgeList();
+
+
+ if(context.isDeterministic){
+ Collections.sort(nodeList);
+ Collections.sort(edgeList);
+ }
+
+
// initialize nodes
- for (LayoutNode ln: part.getNodeList()) {
+ for (LayoutNode ln: nodeList) {
ForceItem fitem = forceItems.get(ln);
if ( fitem == null ) {
fitem = new ForceItem();
@@ -113,7 +131,7 @@
}
// initialize edges
- for (LayoutEdge e: part.getEdgeList()) {
+ for (LayoutEdge e: edgeList) {
LayoutNode n1 = e.getSource();
ForceItem f1 = forceItems.get(n1);
LayoutNode n2 = e.getTarget();
@@ -142,6 +160,7 @@
}
// update positions
+ part.resetNodes(); // reset the nodes so we get the new average
location
for (LayoutNode ln: part.getNodeList()) {
if (!ln.isLocked()) {
ForceItem fitem = forceItems.get(ln);
@@ -150,6 +169,8 @@
part.moveNodeToLocation(ln);
}
}
+
+ /*
// Not quite done, yet. If we're only laying out selected
nodes, we need
// to migrate the selected nodes back to their starting position
double xDelta = 0.0;
@@ -163,6 +184,7 @@
part.moveNodeToLocation(v);
}
}
+ */
}
/**
--
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.