Search in sources :

Example 6 with LayoutNode

use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.

the class ISOMLayoutTask method getClosestPosition.

/**
 * @return the index of the closest NodeView to these coords.
 */
public long getClosestPosition(double x, double y) {
    double minDistance = Double.MAX_VALUE;
    long closest = 0;
    Iterator nodeIter = partition.nodeIterator();
    while (nodeIter.hasNext()) {
        LayoutNode node = (LayoutNode) nodeIter.next();
        long rootGraphIndex = node.getNode().getSUID();
        nodeIndexToLayoutIndex.put(rootGraphIndex, node.getIndex());
        double dx = node.getX();
        double dy = node.getY();
        double dist = (dx * dx) + (dy * dy);
        if (dist < minDistance) {
            minDistance = dist;
            closest = rootGraphIndex;
        }
    }
    return closest;
}
Also used : LayoutNode(org.cytoscape.view.layout.LayoutNode) Iterator(java.util.Iterator)

Example 7 with LayoutNode

use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.

the class ISOMLayoutTask method adjustVertex.

/**
 *  DOCUMENT ME!
 *
 * @param v DOCUMENT ME!
 */
public void adjustVertex(long v) {
    q.clear();
    ISOMVertexData ivd = getISOMVertexData(v);
    ivd.distance = 0;
    ivd.visited = true;
    q.add(v);
    long current;
    List<LayoutNode> nodeList = partition.getNodeList();
    while (!q.isEmpty()) {
        current = q.get(0);
        q.remove(0);
        int layoutIndex = nodeIndexToLayoutIndex.get(current);
        LayoutNode currentNode = (LayoutNode) nodeList.get(layoutIndex);
        ISOMVertexData currData = getISOMVertexData(current);
        double current_x = currentNode.getX();
        double current_y = currentNode.getY();
        double dx = globalX - current_x;
        double dy = globalY - current_y;
        // possible mod
        double factor = adaption / Math.pow(2, currData.distance);
        currentNode.setX(current_x + (factor * dx));
        currentNode.setY(current_y + (factor * dy));
        partition.moveNodeToLocation(currentNode);
        if (currData.distance < context.radius) {
            long[] neighbors = neighborsArray(network, currentNode.getNode());
            for (int neighbor_index = 0; neighbor_index < neighbors.length; ++neighbor_index) {
                ISOMVertexData childData = getISOMVertexData(neighbors[neighbor_index]);
                if (!childData.visited) {
                    childData.visited = true;
                    childData.distance = currData.distance + 1;
                    q.add(neighbors[neighbor_index]);
                }
            }
        }
    }
// Add check to make sure we don't put nodes on top of each other
}
Also used : LayoutNode(org.cytoscape.view.layout.LayoutNode)

Example 8 with LayoutNode

use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.

the class BioLayoutFRAlgorithmTask method layoutPartition.

/**
 * Perform a layout
 */
public void layoutPartition(LayoutPartition partition) {
    this.partition = partition;
    LayoutPoint initialLocation = null;
    /* Get all of our profiles */
    /*
		        initProfile = new Profile();
		        iterProfile = new Profile();
		        repulseProfile = new Profile();
		        attractProfile = new Profile();
		        updateProfile = new Profile();

		        initProfile.start();
		*/
    // Calculate a bounded rectangle for our
    // layout.  This is roughly the area of all
    // nodes * 2
    calculateSize();
    // System.out.println("BioLayoutFR Algorithm.  Laying out " + partition.nodeCount()
    // + " nodes and " + partition.edgeCount() + " edges: ");
    // Initialize our temperature
    double temp;
    if (context.temperature == 0) {
        temp = Math.sqrt(this.width * this.height) / 2;
    } else {
        temp = Math.sqrt(this.width * this.height) * this.context.temperature / 100;
    }
    // Figure out our starting point
    initialLocation = partition.getAverageLocation();
    // outside of our bounds
    if (context.randomize)
        partition.randomizeLocations(context.layout3D);
    // Calculate our force constant
    calculateForces();
    // Calculate our edge weights
    partition.calculateEdgeWeights();
    // initProfile.done("Initialization completed in ");
    taskMonitor.setStatusMessage("Calculating new node positions");
    taskMonitor.setProgress(0.01);
    // Main algorithm
    // iterProfile.start();
    int iteration = 0;
    for (iteration = 0; (iteration < context.nIterations) && !cancelled; iteration++) {
        if ((temp = doOneIteration(iteration, temp)) == 0)
            break;
        if (debug || ((context.update_iterations > 0) && ((iteration % context.update_iterations) == 0))) {
            if (iteration > 0) {
                // Actually move the pieces around
                for (LayoutNode v : partition.getNodeList()) {
                    // if this is locked, the move just resets X and Y
                    if (context.layout3D)
                        v.moveToLocation3D();
                    else
                        v.moveToLocation();
                }
                // This fires events to presentation layer.
                networkView.updateView();
            }
            if (debug) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                }
            }
        }
        taskMonitor.setStatusMessage("Calculating new node positions - " + iteration);
        taskMonitor.setProgress(iteration / context.nIterations);
    }
    // iterProfile.done("Iterations complete in ");
    // System.out.println("Attraction calculation portion of iterations took "+attractProfile.getTotalTime()+"ms");
    // System.out.println("Repulsion calculation portion of iterations took "+repulseProfile.getTotalTime()+"ms");
    // System.out.println("Update portion of iterations took "+updateProfile.getTotalTime()+"ms");
    taskMonitor.setStatusMessage("Updating display");
    // Actually move the pieces around
    // Note that we reset our min/max values before we start this
    // so we can get an accurate min/max for paritioning
    partition.resetNodes();
    for (LayoutNode v : partition.getNodeList()) {
        if (context.layout3D)
            partition.moveNodeToLocation3D(v);
        else
            partition.moveNodeToLocation(v);
    }
    // Not quite done, yet.  If we're only laying out selected nodes, we need
    // to migrate the selected nodes back to their starting position
    double xDelta = 0.0;
    double yDelta = 0.0;
    double zDelta = 0.0;
    final LayoutPoint finalLocation = partition.getAverageLocation();
    xDelta = finalLocation.getX() - initialLocation.getX();
    yDelta = finalLocation.getY() - initialLocation.getY();
    if (context.layout3D)
        zDelta = finalLocation.getZ() - initialLocation.getZ();
    partition.resetNodes();
    for (LayoutNode v : partition.getNodeList()) {
        if (!v.isLocked()) {
            v.decrement(xDelta, yDelta, zDelta);
            if (context.layout3D)
                partition.moveNodeToLocation3D(v);
            else
                partition.moveNodeToLocation(v);
        }
    }
// System.out.println("Layout complete after " + iteration + " iterations");
}
Also used : LayoutNode(org.cytoscape.view.layout.LayoutNode) LayoutPoint(org.cytoscape.view.layout.LayoutPoint) LayoutPoint(org.cytoscape.view.layout.LayoutPoint)

Example 9 with LayoutNode

use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.

the class BioLayoutFRAlgorithmTask method calculateRepulsion.

/**
 * calculate the repulsive forces and offsets for
 * each vertex.
 *
 * @param v LayoutNode we're calculating repulsive forces for
 */
private void calculateRepulsion(LayoutNode v) {
    // / v.disp := 0;
    v.setDisp(0, 0, 0);
    double radius = v.getWidth() / 2;
    // / for u in V do
    for (LayoutNode u : partition.getNodeList()) {
        double dx = v.getX() - u.getX();
        double dy = v.getY() - u.getY();
        double dz = v.getZ() - u.getZ();
        // / if (u # v) then begin
        if (v == u)
            continue;
        // Get the
        // double xSign = Math.signum(v.getX() - u.getX());
        // double ySign = Math.signum(v.getY() - u.getY());
        // / delta := v.pos - u.pos
        // Get our euclidean distance
        double deltaDistance = context.layout3D ? v.distance3D(u) : v.distance(u);
        if (deltaDistance == 0.0)
            deltaDistance = EPSILON;
        double fr = forceR(repulsion_constant, deltaDistance);
        // If its too close, increase the force by a constant
        if (deltaDistance < (radius + (u.getWidth() / 2))) {
            // System.out.println("Applying conflict_avoidance force: "+conflict_avoidance);
            fr += context.conflict_avoidance;
        }
        if (Double.isNaN(fr)) {
            fr = 500;
        }
        /*
			            System.out.println("Repulsive force between "+v.getIdentifier()
			                             +" and "+u.getIdentifier()+" is "+fr);
			            System.out.println("   distance = "+deltaDistance);
			            System.out.println("   incrementing "+v.getIdentifier()+" by ("+
		                                     fr+", "+fr+")");
			*/
        // Adjust the displacement.  In the case of doing selectedOnly,
        // we increase the force to enhance the discrimination power.
        // Also note that we only update the displacement of the movable
        // node since the other node won't move anyways.
        // / v.disp := v.disp + (delta/abs(delta)) * fr(abs(delta))
        double xVector = dx * fr / deltaDistance;
        double yVector = dy * fr / deltaDistance;
        double zVector = context.layout3D ? dz * fr / deltaDistance : 0;
        if (v.isLocked()) {
            // shouldn't happen
            return;
        } else if (u.isLocked()) {
            v.incrementDisp(xVector * 2, yVector * 2, zVector * 2);
        } else {
            v.incrementDisp(xVector, yVector, zVector);
        }
    }
}
Also used : LayoutNode(org.cytoscape.view.layout.LayoutNode)

Example 10 with LayoutNode

use of org.cytoscape.view.layout.LayoutNode in project cytoscape-impl by cytoscape.

the class BioLayoutFRAlgorithmTask method calculateAttraction.

/**
 * calculate the attractive forces and offsets for
 * each vertex based on their connecting edges and the
 * corresponding edge weights.
 *
 * @param e Edge we're calculating attractive forces for
 */
private void calculateAttraction(LayoutEdge e) {
    LayoutNode v = e.getSource();
    LayoutNode u = e.getTarget();
    double dx = v.getX() - u.getX();
    double dy = v.getY() - u.getY();
    double dz = v.getZ() - u.getZ();
    // / delta := e.v.pos - e.u.pos
    double deltaDistance = context.layout3D ? v.distance3D(u) : v.distance(u);
    double fa = forceA(attraction_constant, deltaDistance, e.getWeight());
    if (Double.isNaN(fa)) {
        fa = EPSILON;
    }
    // Adjust the displacement.  In the case of doing selectedOnly,
    // we increase the force to enhance the discrimination power.
    // Also note that we only update the displacement of the movable
    // node since the other node won't move anyways.
    // / e.v.disp := e.v.disp - (delta/abs(delta)) * fa(abs(delta))
    // / e.u.disp := e.u.disp + (delta/abs(delta)) * fa(abs(delta))
    double xVector = dx * fa;
    double yVector = dy * fa;
    double zVector = context.layout3D ? dz * fa : 0;
    if (u.isLocked() && v.isLocked()) {
        // shouldn't happen
        return;
    } else if (u.isLocked()) {
        v.decrementDisp(xVector * 2, yVector * 2, zVector * 2);
    } else if (v.isLocked()) {
        u.incrementDisp(xVector * 2, yVector * 2, zVector * 2);
    } else {
        v.decrementDisp(xVector, yVector, zVector);
        u.incrementDisp(xVector, yVector, zVector);
    }
}
Also used : LayoutNode(org.cytoscape.view.layout.LayoutNode)

Aggregations

LayoutNode (org.cytoscape.view.layout.LayoutNode)16 LayoutPoint (org.cytoscape.view.layout.LayoutPoint)5 CyNode (org.cytoscape.model.CyNode)4 LayoutEdge (org.cytoscape.view.layout.LayoutEdge)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 LinkedList (java.util.LinkedList)2 LGraph (org.ivis.layout.LGraph)2 LGraphManager (org.ivis.layout.LGraphManager)2 LNode (org.ivis.layout.LNode)2 Profile (csapps.layout.Profile)1 Edge (csapps.layout.algorithms.hierarchicalLayout.Edge)1 Graph (csapps.layout.algorithms.hierarchicalLayout.Graph)1 CyGroup (org.cytoscape.group.CyGroup)1 CyGroupManager (org.cytoscape.group.CyGroupManager)1 CyColumn (org.cytoscape.model.CyColumn)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyTable (org.cytoscape.model.CyTable)1