Search in sources :

Example 1 with RectangleD

use of org.ivis.util.RectangleD in project cytoscape-impl by cytoscape.

the class SbgnPDLayout method calculateBounds.

/**
 * This method returns the bounding rectangle of the given set of nodes with
 * or without the margins
 */
protected RectangleD calculateBounds(boolean isMarginIncluded, ArrayList<SbgnPDNode> nodes) {
    int boundLeft = Integer.MAX_VALUE;
    int boundRight = Integer.MIN_VALUE;
    int boundTop = Integer.MAX_VALUE;
    int boundBottom = Integer.MIN_VALUE;
    int nodeLeft;
    int nodeRight;
    int nodeTop;
    int nodeBottom;
    Iterator<SbgnPDNode> itr = nodes.iterator();
    while (itr.hasNext()) {
        LNode lNode = itr.next();
        nodeLeft = (int) (lNode.getLeft());
        nodeRight = (int) (lNode.getRight());
        nodeTop = (int) (lNode.getTop());
        nodeBottom = (int) (lNode.getBottom());
        if (boundLeft > nodeLeft)
            boundLeft = nodeLeft;
        if (boundRight < nodeRight)
            boundRight = nodeRight;
        if (boundTop > nodeTop)
            boundTop = nodeTop;
        if (boundBottom < nodeBottom)
            boundBottom = nodeBottom;
    }
    if (isMarginIncluded) {
        return new RectangleD(boundLeft - SbgnPDConstants.COMPLEX_MEM_MARGIN, boundTop - SbgnPDConstants.COMPLEX_MEM_MARGIN, boundRight - boundLeft + 2 * SbgnPDConstants.COMPLEX_MEM_MARGIN, boundBottom - boundTop + 2 * SbgnPDConstants.COMPLEX_MEM_MARGIN);
    } else {
        return new RectangleD(boundLeft, boundTop, boundRight - boundLeft, boundBottom - boundTop);
    }
}
Also used : RectangleD(org.ivis.util.RectangleD) LNode(org.ivis.layout.LNode)

Example 2 with RectangleD

use of org.ivis.util.RectangleD in project cytoscape-impl by cytoscape.

the class SbgnPDLayout method applyPolyomino.

/**
 * This method tiles the given list of nodes by using polyomino packing
 * algorithm.
 */
private void applyPolyomino(SbgnPDNode parent) {
    RectangleD r;
    LGraph childGr = parent.getChild();
    if (childGr == null) {
        System.out.println("Child graph is empty (Polyomino)");
    } else {
        // packing takes the input as an array. put the members in an array.
        SbgnPDNode[] mpArray = new SbgnPDNode[childGr.getNodes().size()];
        for (int i = 0; i < childGr.getNodes().size(); i++) {
            SbgnPDNode s = (SbgnPDNode) childGr.getNodes().get(i);
            mpArray[i] = s;
        }
        // pack rectangles
        RectProc.packRectanglesMino(SbgnPDConstants.COMPLEX_MEM_HORIZONTAL_BUFFER, mpArray.length, mpArray);
        // apply compaction
        Compaction c = new Compaction((ArrayList<SbgnPDNode>) childGr.getNodes());
        c.perform();
        // get the resulting rectangle and set parent's (complex) width &
        // height
        r = calculateBounds(true, (ArrayList<SbgnPDNode>) childGr.getNodes());
        parent.setWidth(r.getWidth());
        parent.setHeight(r.getHeight());
    }
}
Also used : RectangleD(org.ivis.util.RectangleD) ArrayList(java.util.ArrayList) LGraph(org.ivis.layout.LGraph)

Example 3 with RectangleD

use of org.ivis.util.RectangleD in project cytoscape-impl by cytoscape.

the class VisibilityGraph method sweepIntersectedArea.

/**
 * Starting from the intersection area between p and q, walk on a line
 * perpendicular to the desired direction. If there is an edge that does not
 * intersect with any other nodes, this is a valid edge.
 *
 * @return true if an edge exists. false otherwise.
 */
private boolean sweepIntersectedArea(SbgnPDNode p, SbgnPDNode q) {
    RectangleD edge;
    boolean isValid;
    int start = 0, end = 0, result;
    // find the sweep line borders
    if (direction == CompactionDirection.VERTICAL) {
        start = (int) q.getLeft();
        end = (int) Math.min(p.getRight(), q.getRight());
    } else if (direction == CompactionDirection.HORIZONTAL) {
        start = (int) q.getTop();
        end = (int) Math.min(p.getBottom(), q.getBottom());
    }
    // if they intersect only on the borders, immediately return false.
    if (start == end)
        return false;
    // check for all intersected area
    for (int sweepPoint = start; sweepPoint <= end; sweepPoint++) {
        isValid = true;
        edge = tryConstructingEdge(p, q, sweepPoint);
        // if an edge is constructed, check its validity
        if (edge != null) {
            result = checkIntermediateNodes(p, q, edge, sweepPoint);
            if (sweepPoint == result)
                isValid = true;
            else {
                sweepPoint = result;
                isValid = false;
            }
        }
        if (isValid)
            return true;
    }
    return false;
}
Also used : RectangleD(org.ivis.util.RectangleD)

Example 4 with RectangleD

use of org.ivis.util.RectangleD in project cytoscape-impl by cytoscape.

the class LNode method calcOverlap.

/**
 * This method returns true if two LNodes overlap along with the overlap
 * amount in x and y directions. Method returns false if there is no overlap.
 */
public boolean calcOverlap(LNode nodeB, double[] overlapAmount) {
    RectangleD rectA = this.getRect();
    RectangleD rectB = nodeB.getRect();
    // System.out.println("In LNODE OVERLAPS");
    if (rectA.intersects(rectB)) // two nodes overlap
    {
        // calculate separation amount in x and y directions
        IGeometry.calcSeparationAmount(rectA, rectB, overlapAmount, FDLayoutConstants.DEFAULT_EDGE_LENGTH / 2.0);
        return true;
    } else {
        return false;
    }
}
Also used : RectangleD(org.ivis.util.RectangleD)

Example 5 with RectangleD

use of org.ivis.util.RectangleD in project cytoscape-impl by cytoscape.

the class SbgnPDLayout method adjustLocation.

/**
 * Adjust locations of children of given complex wrt. the location of the
 * complex
 */
private void adjustLocation(SbgnPDNode comp, LGraph chGr) {
    RectangleD rect = calculateBounds(false, (ArrayList<SbgnPDNode>) chGr.getNodes());
    int differenceX = (int) (rect.x - comp.getLeft());
    int differenceY = (int) (rect.y - comp.getTop());
    // if the parent graph is a compound, add compound margins
    if (!comp.type.equals(SbgnPDConstants.COMPLEX)) {
        differenceX -= LayoutConstants.COMPOUND_NODE_MARGIN;
        differenceY -= LayoutConstants.COMPOUND_NODE_MARGIN;
    }
    for (int j = 0; j < chGr.getNodes().size(); j++) {
        SbgnPDNode s = (SbgnPDNode) chGr.getNodes().get(j);
        s.setLocation(s.getLeft() - differenceX + SbgnPDConstants.COMPLEX_MEM_HORIZONTAL_BUFFER, s.getTop() - differenceY + SbgnPDConstants.COMPLEX_MEM_VERTICAL_BUFFER);
        if (s.getChild() != null)
            adjustLocation(s, s.getChild());
    }
}
Also used : RectangleD(org.ivis.util.RectangleD)

Aggregations

RectangleD (org.ivis.util.RectangleD)5 ArrayList (java.util.ArrayList)1 LGraph (org.ivis.layout.LGraph)1 LNode (org.ivis.layout.LNode)1