Search in sources :

Example 1 with ForceSimulator

use of prefuse.util.force.ForceSimulator 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;
}
Also used : NBodyForce(prefuse.util.force.NBodyForce) SpringForce(prefuse.util.force.SpringForce) DragForce(prefuse.util.force.DragForce) ForceSimulator(prefuse.util.force.ForceSimulator)

Example 2 with ForceSimulator

use of prefuse.util.force.ForceSimulator 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);
        }
    }
}
Also used : LayoutNode(org.cytoscape.view.layout.LayoutNode) NBodyForce(prefuse.util.force.NBodyForce) SpringForce(prefuse.util.force.SpringForce) DragForce(prefuse.util.force.DragForce) LayoutPoint(org.cytoscape.view.layout.LayoutPoint) ForceSimulator(prefuse.util.force.ForceSimulator) LayoutPoint(org.cytoscape.view.layout.LayoutPoint) LayoutEdge(org.cytoscape.view.layout.LayoutEdge) ForceItem(prefuse.util.force.ForceItem)

Aggregations

DragForce (prefuse.util.force.DragForce)2 ForceSimulator (prefuse.util.force.ForceSimulator)2 NBodyForce (prefuse.util.force.NBodyForce)2 SpringForce (prefuse.util.force.SpringForce)2 LayoutEdge (org.cytoscape.view.layout.LayoutEdge)1 LayoutNode (org.cytoscape.view.layout.LayoutNode)1 LayoutPoint (org.cytoscape.view.layout.LayoutPoint)1 ForceItem (prefuse.util.force.ForceItem)1