use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.
the class BioLayoutFRAlgorithmTask method doOneIteration.
/**
* This executes a single iteration of the FR algorithm.
*
* @param iteration The current interation.
* @param temp The current temperature factor.
* @return an updated temperature factor.
*/
public double doOneIteration(int iteration, double temp) {
double xAverage = 0;
double yAverage = 0;
double zAverage = 0;
// Calculate repulsive forces
for (LayoutNode v : partition.getNodeList()) {
if (!v.isLocked()) {
xAverage += v.getX() / partition.nodeCount();
yAverage += v.getY() / partition.nodeCount();
zAverage += v.getZ() / partition.nodeCount();
}
}
for (LayoutNode v : partition.getNodeList()) {
if (!v.isLocked()) {
calculateRepulsion(v);
if (gravity_constant != 0)
calculateGravity(v, xAverage, yAverage, zAverage);
}
}
// / for e in E do begin
for (LayoutEdge e : partition.getEdgeList()) {
calculateAttraction(e);
}
// / end
// attractProfile.checkpoint();
// Dump the current displacements
// print_disp();
// Dampen & update
double xDispTotal = 0;
double yDispTotal = 0;
// / for v in V do begin
for (LayoutNode v : partition.getNodeList()) {
if (v.isLocked())
continue;
calculatePosition(v, temp);
xDispTotal += Math.abs(v.getXDisp());
yDispTotal += Math.abs(v.getYDisp());
}
// hit our completion criteria
if (complete(xDispTotal, yDispTotal))
return 0;
// t := cool(t)
return cool(temp, iteration);
}
use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.
the class BioLayoutKKAlgorithmTask method simpleMoveNode.
private void simpleMoveNode(PartialDerivatives partials) {
LayoutNode node = partials.node;
if (node.isLocked()) {
return;
}
double denominator = ((partials.xx * partials.yy) - (partials.xy * partials.xy));
if (((float) denominator) == 0.0) {
return;
// throw new RuntimeException("denominator too close to 0 for node "+node);
}
// System.out.println(partials.printPartial());
double deltaX = (((-partials.x * partials.yy) - (-partials.y * partials.xy)) / denominator);
double deltaY = (((-partials.y * partials.xx) - (-partials.x * partials.xy)) / denominator);
/* System.out.println("Moving node "+node.getIdentifier()+" from "+node.getX()+", "+node.getY()+
" to "+(node.getX()+deltaX)+", "+(node.getY()+deltaY)); */
node.setLocation(node.getX() + deltaX, node.getY() + deltaY);
}
use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.
the class BioLayoutKKAlgorithmTask method calculateNodeDistances.
private int[][] calculateNodeDistances() {
int[][] distances = new int[m_nodeCount][];
LinkedList<Integer> queue = new LinkedList<Integer>();
boolean[] completedNodes = new boolean[m_nodeCount];
int toNode;
int fromNode;
int neighbor;
int toNodeDistance;
int neighborDistance;
for (LayoutNode v : partition.getNodeList()) {
fromNode = v.getIndex();
if (distances[fromNode] == null)
distances[fromNode] = new int[m_nodeCount];
Arrays.fill(distances[fromNode], Integer.MAX_VALUE);
distances[fromNode][fromNode] = 0;
Arrays.fill(completedNodes, false);
queue.add(Integer.valueOf(fromNode));
while (!(queue.isEmpty())) {
int index = ((Integer) queue.removeFirst()).intValue();
if (completedNodes[index])
continue;
completedNodes[index] = true;
toNode = index;
toNodeDistance = distances[fromNode][index];
if (index < fromNode) {
// Oh boy. We've already got every distance from/to this node.
int distanceThroughToNode;
for (int i = 0; i < m_nodeCount; i++) {
if (distances[index][i] == Integer.MAX_VALUE)
continue;
distanceThroughToNode = toNodeDistance + distances[index][i];
if (distanceThroughToNode <= distances[fromNode][i]) {
// calculated from fromNode never will, and is thus complete.
if (distances[index][i] == 1)
completedNodes[i] = true;
distances[fromNode][i] = distanceThroughToNode;
}
}
// the previous calculation.
continue;
}
// End if toNode has already had all of its distances calculated.
List<LayoutNode> neighborList = v.getNeighbors();
for (LayoutNode neighbor_v : neighborList) {
neighbor = neighbor_v.getIndex();
// We've already done everything we can here.
if (completedNodes[neighbor])
continue;
neighborDistance = distances[fromNode][neighbor];
if ((toNodeDistance != Integer.MAX_VALUE) && (neighborDistance > (toNodeDistance + 1))) {
distances[fromNode][neighbor] = toNodeDistance + 1;
queue.addLast(Integer.valueOf(neighbor));
}
}
}
}
return distances;
}
use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.
the class CoSELayoutAlgorithmTask method layoutPartition.
@Override
public void layoutPartition(final LayoutPartition partition) {
if (cancelled)
return;
final CyGroupManager groupManager = serviceRegistrar.getService(CyGroupManager.class);
final CyNetwork network = networkView.getModel();
// Create the CoSE model
// (see http://www.cs.bilkent.edu.tr/~ivis/chilay/ChiLay-2.0-PG.pdf)
cose = new CoSELayout();
cose.addProgressListener(new ProgressListener() {
@Override
public void update(double value) {
taskMonitor.setProgress(value);
}
});
final LGraphManager gm = cose.getGraphManager();
final LGraph root = gm.addRoot();
// Index all LayoutNodes by CyNode for future reference
final Map<CyNode, LayoutNode> layoutNodeMap = new HashMap<>();
for (LayoutNode n : partition.getNodeList()) layoutNodeMap.put(n.getNode(), n);
// Create all CoSE nodes
final Map<CyNode, LNode> lNodeMap = new HashMap<>();
for (LayoutNode n : partition.getNodeList()) {
// If this node does not belong to a CyGroup, let's traverse its potential compound node tree.
if (groupManager.getGroupsForNode(n.getNode(), network).isEmpty())
traverseLNodeTree(n, root, cose, lNodeMap, layoutNodeMap, groupManager);
}
if (cancelled)
return;
// Create all CoSE edges
final Map<CyEdge, LEdge> lEdgeMap = new HashMap<>();
final Iterator<LayoutEdge> edgeIter = partition.edgeIterator();
while (edgeIter.hasNext() && !cancelled) {
final LayoutEdge e = edgeIter.next();
createLEdge(e, cose, lNodeMap, lEdgeMap);
}
if (cancelled)
return;
// Run the layout
try {
cose.runLayout();
} catch (Exception e) {
logger.error("Error running CoSE Layout", e);
return;
}
if (cancelled)
return;
// Move all Node Views to the new positions
for (LayoutNode n : partition.getNodeList()) partition.moveNodeToLocation(n);
}
use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.
the class CoSELayoutAlgorithmTask method traverseLNodeTree.
private void traverseLNodeTree(final LayoutNode layoutNode, final LGraph graph, final CoSELayout cose, final Map<CyNode, LNode> lNodeMap, final Map<CyNode, LayoutNode> layoutNodeMap, final CyGroupManager groupManager) {
if (lNodeMap.containsKey(layoutNode.getNode()))
// This node has already been visited!
return;
final LNode ln = createLNode(layoutNode, graph, cose, lNodeMap);
if (groupManager.isGroup(layoutNode.getNode(), networkView.getModel())) {
final CyGroup group = groupManager.getGroup(layoutNode.getNode(), networkView.getModel());
if (group != null) {
final LGraphManager gm = cose.getGraphManager();
final LGraph subGraph = gm.add(cose.newGraph("G" + group.getGroupNetwork().getSUID()), ln);
for (CyNode childNode : group.getNodeList()) {
final LayoutNode childLayoutNode = layoutNodeMap.get(childNode);
if (childLayoutNode != null)
traverseLNodeTree(childLayoutNode, subGraph, cose, lNodeMap, layoutNodeMap, groupManager);
}
}
}
}
Aggregations