graph = graphModel.getHierarchicalGraphVisible();
graph.readLock();
Node[] nodes = graph.getNodes().toArray();
for (Node n : nodes) {
if (n.getNodeData().getLayoutData() == null || !(n.getNodeData().getLayoutData() instanceof ForceVector)) {
n.getNodeData().setLayoutData(new ForceVector());
}
}
// Evaluates n^2 inter node forces using BarnesHut.
QuadTree tree = QuadTree.buildTree(graph, getQuadTreeMaxLevel());
// double electricEnergy = 0; ///////////////////////
// double springEnergy = 0; ///////////////////////
BarnesHut barnes = new BarnesHut(getNodeForce());
barnes.setTheta(getBarnesHutTheta());
for (Node node : nodes) {
NodeData data = node.getNodeData();
ForceVector layoutData = data.getLayoutData();
ForceVector f = barnes.calculateForce(data, tree);
layoutData.add(f);
// electricEnergy += f.getEnergy();
}
// Apply edge forces.
for (Edge e : graph.getEdgesAndMetaEdges()) {
if (!e.getSource().equals(e.getTarget())) {
NodeData n1 = e.getSource().getNodeData();
NodeData n2 = e.getTarget().getNodeData();
ForceVector f1 = n1.getLayoutData();
ForceVector f2 = n2.getLayoutData();
ForceVector f = getEdgeForce().calculateForce(n1, n2);
f1.add(f);
f2.subtract(f);
}
}
// Calculate energy and max force.
energy0 = energy;
energy = 0;
double maxForce = 1;
for (Node n : nodes) {
NodeData data = n.getNodeData();
ForceVector force = data.getLayoutData();
energy += force.getNorm();
maxForce = Math.max(maxForce, force.getNorm());
}
// Apply displacements on nodes.
for (Node n : nodes) {
NodeData data = n.getNodeData();
if (!data.isFixed()) {
ForceVector force = data.getLayoutData();
force.multiply((float) (1.0 / maxForce));
getDisplacement().moveNode(data, force);
}
}
postAlgo();
// springEnergy = energy - electricEnergy;