Search in sources :

Example 1 with LongStack

use of org.cytoscape.util.intr.LongStack in project cytoscape-impl by cytoscape.

the class DGraphView method getPickedNodeView.

/**
 * utility that returns the nodeView that is located at input point
 *
 * @param pt
 */
@Override
public NodeView getPickedNodeView(Point2D pt) {
    DNodeView nv = null;
    double[] locn = new double[2];
    locn[0] = pt.getX();
    locn[1] = pt.getY();
    long chosenNode = 0;
    xformComponentToNodeCoords(locn);
    final LongStack nodeStack = new LongStack();
    getNodesIntersectingRectangle((float) locn[0], (float) locn[1], (float) locn[0], (float) locn[1], (m_networkCanvas.getLastRenderDetail() & GraphRenderer.LOD_HIGH_DETAIL) == 0, nodeStack);
    // Sort the nodeStack by Z
    if (nodeStack.size() > 0) {
        LongEnumerator le = nodeStack.elements();
        while (le.numRemaining() > 0) {
            DNodeView dnv = getDNodeView(le.nextLong());
            if (nv == null || dnv.getZPosition() > nv.getZPosition())
                nv = dnv;
        }
    }
    return nv;
}
Also used : LongEnumerator(org.cytoscape.util.intr.LongEnumerator) LongStack(org.cytoscape.util.intr.LongStack)

Example 2 with LongStack

use of org.cytoscape.util.intr.LongStack in project cytoscape-impl by cytoscape.

the class DGraphView method getPickedEdgeView.

@Override
public EdgeView getPickedEdgeView(Point2D pt) {
    EdgeView ev = null;
    final LongStack edgeStack = new LongStack();
    queryDrawnEdges((int) pt.getX(), (int) pt.getY(), (int) pt.getX(), (int) pt.getY(), edgeStack);
    long chosenEdge = 0;
    chosenEdge = (edgeStack.size() > 0) ? edgeStack.peek() : -1;
    if (chosenEdge >= 0) {
        ev = getDEdgeView(chosenEdge);
    }
    return ev;
}
Also used : LongStack(org.cytoscape.util.intr.LongStack) EdgeView(org.cytoscape.ding.EdgeView)

Example 3 with LongStack

use of org.cytoscape.util.intr.LongStack in project cytoscape-impl by cytoscape.

the class RTree method queryOverlap.

/*
	 * Returns the number of entries under n that overlap specified query
	 * rectangle.  Nodes are added to the node stack - internal nodes added
	 * recursively contain only overlapping entries, and leaf nodes added
	 * should be iterated through to find overlapping entries.
	 * (In fact internal nodes added to the node
	 * stack are completely contained within specified query rectangle.)
	 * An important property is that every node on the returned node stack
	 * will recursively contain at least one entry that overlaps the
	 * query rectangle, unless n is completely empty.  If n is completely
	 * empty, it is expected that its MBR [represented by xMinN, yMinN,
	 * xMaxN, and yMaxN] be the infinite inverted rectangle (that is, its
	 * min values should all be Float.POSITIVE_INFINITY and its max values
	 * should all be Float.NEGATIVE_INFINITY).
	 * I'd like to discuss stackStack.  Objects of type IntStack are tossed onto
	 * this stack (in other words, stackStack is a stack of IntStack).  For every
	 * leaf node on nodeStack, stackStack will contain
	 * a corresponding IntStack - if the IntStack is null,
	 * then every entry in that leaf node overlaps the query rectangle; if
	 * the IntStack is of positive length, then the IntStack contains indices of
	 * entries that overlap the query rectangle.
	 */
private static final int queryOverlap(final ObjStack unprocessedNodes, final float[] extStack, final ObjStack nodeStack, final ObjStack stackStack, final float xMinQ, final float yMinQ, final float xMaxQ, final float yMaxQ, final float[] extents, final int off, final boolean reverse) {
    // Depth first search.
    final int incr = reverse ? (-1) : 1;
    int count = 0;
    // Into extStack.
    int extOff = 4;
    while (unprocessedNodes.size() > 0) {
        final Node n = (Node) unprocessedNodes.pop();
        extOff -= 4;
        if (// Rectangle Q contains
        (xMinQ <= extStack[extOff]) && // rectangle N - trivially
        (xMaxQ >= extStack[extOff + 2]) && // include node.
        (yMinQ <= extStack[extOff + 1]) && (yMaxQ >= extStack[extOff + 3])) {
            if (isLeafNode(n)) {
                count += n.entryCount;
                stackStack.push(null);
            } else {
                count += n.data.deepCount;
            }
            nodeStack.push(n);
            if (extents != null) {
                extents[off] = Math.min(extents[off], extStack[extOff]);
                extents[off + 1] = Math.min(extents[off + 1], extStack[extOff + 1]);
                extents[off + 2] = Math.max(extents[off + 2], extStack[extOff + 2]);
                extents[off + 3] = Math.max(extents[off + 3], extStack[extOff + 3]);
            }
        } else {
            if (isLeafNode(n)) {
                final LongStack stack = new LongStack();
                for (int cntr = n.entryCount, i = reverse ? 0 : (n.entryCount - 1); cntr > 0; cntr--, i -= incr) {
                    // Overlaps test of two rectangles.
                    if ((Math.max(xMinQ, n.xMins[i]) <= Math.min(xMaxQ, n.xMaxs[i])) && (Math.max(yMinQ, n.yMins[i]) <= Math.min(yMaxQ, n.yMaxs[i]))) {
                        stack.push(i);
                        if (extents != null) {
                            extents[off] = Math.min(extents[off], n.xMins[i]);
                            extents[off + 1] = Math.min(extents[off + 1], n.yMins[i]);
                            extents[off + 2] = Math.max(extents[off + 2], n.xMaxs[i]);
                            extents[off + 3] = Math.max(extents[off + 3], n.yMaxs[i]);
                        }
                    }
                }
                if (stack.size() > 0) {
                    count += stack.size();
                    stackStack.push(stack);
                    nodeStack.push(n);
                }
            } else {
                for (int cntr = n.entryCount, i = reverse ? (n.entryCount - 1) : 0; cntr > 0; cntr--, i += incr) {
                    // Overlaps test of two rectangles.
                    if ((Math.max(xMinQ, n.xMins[i]) <= Math.min(xMaxQ, n.xMaxs[i])) && (Math.max(yMinQ, n.yMins[i]) <= Math.min(yMaxQ, n.yMaxs[i]))) {
                        unprocessedNodes.push(n.data.children[i]);
                        extStack[extOff++] = n.xMins[i];
                        extStack[extOff++] = n.yMins[i];
                        extStack[extOff++] = n.xMaxs[i];
                        extStack[extOff++] = n.yMaxs[i];
                    }
                }
            }
        }
    }
    return count;
}
Also used : LongStack(org.cytoscape.util.intr.LongStack)

Aggregations

LongStack (org.cytoscape.util.intr.LongStack)3 EdgeView (org.cytoscape.ding.EdgeView)1 LongEnumerator (org.cytoscape.util.intr.LongEnumerator)1