Search in sources :

Example 1 with ForceVector

use of org.gephi.layout.plugin.force.ForceVector in project gephi by gephi.

the class YifanHuLayout method initAlgo.

@Override
public void initAlgo() {
    if (graphModel == null) {
        return;
    }
    graph = graphModel.getGraphVisible();
    graph.readLock();
    try {
        energy = Float.POSITIVE_INFINITY;
        for (Node n : graph.getNodes()) {
            n.setLayoutData(new ForceVector());
        }
        progress = 0;
        setConverged(false);
        setStep(initialStep);
    } finally {
        graph.readUnlockAll();
    }
}
Also used : Node(org.gephi.graph.api.Node) ForceVector(org.gephi.layout.plugin.force.ForceVector)

Example 2 with ForceVector

use of org.gephi.layout.plugin.force.ForceVector in project gephi by gephi.

the class BarnesHut method calculateForce.

/* Calculates the ForceVector on node against every other node represented
     * in the tree with respect to force.
     */
public ForceVector calculateForce(Node node, QuadTree tree) {
    if (tree.mass() <= 0) {
        return null;
    }
    float distance = ForceVectorUtils.distance(node, tree);
    if (tree.isIsLeaf() || tree.mass() == 1) {
        // this is probably the case where tree has only the node.
        if (distance < 1e-8) {
            return null;
        }
        return force.calculateForce(node, tree);
    }
    if (distance * theta > tree.size()) {
        ForceVector f = force.calculateForce(node, tree, distance);
        f.multiply(tree.mass());
        return f;
    }
    ForceVector f = new ForceVector();
    for (QuadTree child : tree.getChildren()) {
        f.add(calculateForce(node, child));
    }
    return f;
}
Also used : ForceVector(org.gephi.layout.plugin.force.ForceVector)

Example 3 with ForceVector

use of org.gephi.layout.plugin.force.ForceVector in project gephi by gephi.

the class YifanHuLayout method goAlgo.

@Override
public void goAlgo() {
    graph = graphModel.getGraphVisible();
    graph.readLock();
    try {
        Node[] nodes = graph.getNodes().toArray();
        for (Node n : nodes) {
            if (n.getLayoutData() == null || !(n.getLayoutData() instanceof ForceVector)) {
                n.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) {
            ForceVector layoutData = node.getLayoutData();
            ForceVector f = barnes.calculateForce(node, tree);
            layoutData.add(f);
        //            electricEnergy += f.getEnergy();
        }
        // Apply edge forces.
        for (Edge e : graph.getEdges()) {
            if (!e.getSource().equals(e.getTarget())) {
                Node n1 = e.getSource();
                Node n2 = e.getTarget();
                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) {
            ForceVector force = n.getLayoutData();
            energy += force.getNorm();
            maxForce = Math.max(maxForce, force.getNorm());
        }
        // Apply displacements on nodes.
        for (Node n : nodes) {
            if (!n.isFixed()) {
                ForceVector force = n.getLayoutData();
                force.multiply((float) (1.0 / maxForce));
                getDisplacement().moveNode(n, force);
            }
        }
        postAlgo();
    } finally {
        graph.readUnlockAll();
    }
}
Also used : QuadTree(org.gephi.layout.plugin.force.quadtree.QuadTree) Node(org.gephi.graph.api.Node) BarnesHut(org.gephi.layout.plugin.force.quadtree.BarnesHut) ForceVector(org.gephi.layout.plugin.force.ForceVector) Edge(org.gephi.graph.api.Edge)

Aggregations

ForceVector (org.gephi.layout.plugin.force.ForceVector)3 Node (org.gephi.graph.api.Node)2 Edge (org.gephi.graph.api.Edge)1 BarnesHut (org.gephi.layout.plugin.force.quadtree.BarnesHut)1 QuadTree (org.gephi.layout.plugin.force.quadtree.QuadTree)1