use of prefuse.util.force.SpringForce in project jo-client-platform by jo-source.
the class LayoutManager method createForceSimulator.
private static ForceSimulator createForceSimulator() {
final ForceSimulator result = new ForceSimulator();
result.addForce(new DragForce(0.03f));
result.addForce(new NBodyForce(-10, 320, 0));
result.addForce(new SpringForce(1E-4f, 250));
return result;
}
use of prefuse.util.force.SpringForce in project cytoscape-impl by cytoscape.
the class ForceDirectedLayoutTask method layoutPartition.
public void layoutPartition(LayoutPartition part) {
LayoutPoint initialLocation = null;
// System.out.println("layoutPartion: "+part.getEdgeList().size()+" edges");
// Calculate our edge weights
part.calculateEdgeWeights();
// System.out.println("layoutPartion: "+part.getEdgeList().size()+" edges after calculateEdgeWeights");
// 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 : nodeList) {
ForceItem fitem = forceItems.get(ln);
if (fitem == null) {
fitem = new ForceItem();
forceItems.put(ln, fitem);
}
fitem.mass = getMassValue(ln);
fitem.location[0] = 0f;
fitem.location[1] = 0f;
m_fsim.addItem(fitem);
}
// initialize edges
for (LayoutEdge e : edgeList) {
LayoutNode n1 = e.getSource();
ForceItem f1 = forceItems.get(n1);
LayoutNode n2 = e.getTarget();
ForceItem f2 = forceItems.get(n2);
if (f1 == null || f2 == null)
continue;
m_fsim.addSpring(f1, f2, getSpringCoefficient(e), getSpringLength(e));
}
// setTaskStatus(5); // This is a rough approximation, but probably good enough
if (taskMonitor != null) {
taskMonitor.setStatusMessage("Initializing partition " + part.getPartitionNumber());
}
// Figure out our starting point
initialLocation = part.getAverageLocation();
// perform layout
long timestep = 1000L;
for (int i = 0; i < context.numIterations && !cancelled; i++) {
timestep *= (1.0 - i / (double) context.numIterations);
long step = timestep + 50;
m_fsim.runSimulator(step);
setTaskStatus((int) (((double) i / (double) context.numIterations) * 90. + 5));
}
// update positions
// reset the nodes so we get the new average location
part.resetNodes();
for (LayoutNode ln : part.getNodeList()) {
if (!ln.isLocked()) {
ForceItem fitem = forceItems.get(ln);
ln.setX(fitem.location[0]);
ln.setY(fitem.location[1]);
part.moveNodeToLocation(ln);
}
}
}
Aggregations