Search in sources :

Example 1 with ArrowShape

use of org.cytoscape.view.presentation.property.values.ArrowShape in project cytoscape-impl by cytoscape.

the class DEdgeView method applyVisualProperty.

/**
 * This method sets a mapped value.  NOT Defaults.
 */
@SuppressWarnings("unchecked")
@Override
protected <T, V extends T> void applyVisualProperty(final VisualProperty<? extends T> vpOriginal, V value) {
    VisualProperty<?> vp = vpOriginal;
    // Check to make sure our view hasn't gotten disconnected somewhere along the line
    if (graphView.getEdgeView(this.getModel()) == null)
        return;
    // If value is null, simply use the VP's default value.
    if (value == null)
        value = (V) vp.getDefault();
    if (vp == DVisualLexicon.EDGE_STROKE_SELECTED_PAINT) {
        setSelectedPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_STROKE_UNSELECTED_PAINT) {
        setUnselectedPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_WIDTH) {
        final float w = ((Number) value).floatValue();
        setStrokeWidth(w);
        setStroke(DLineType.getDLineType(lineType).getStroke(w));
    } else if (vp == DVisualLexicon.EDGE_LINE_TYPE) {
        lineType = (LineType) value;
        final Stroke newStroke = DLineType.getDLineType(lineType).getStroke(graphView.m_edgeDetails.getWidth(model));
        setStroke(newStroke);
    } else if (vp == DVisualLexicon.EDGE_TRANSPARENCY) {
        setTransparency(((Number) value).intValue());
    } else if (vp == DVisualLexicon.EDGE_LABEL_TRANSPARENCY) {
        final int labelTransparency = ((Number) value).intValue();
        setLabelTransparency(labelTransparency);
    } else if (vp == DVisualLexicon.EDGE_SOURCE_ARROW_SELECTED_PAINT) {
        setSourceEdgeEndSelectedPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_TARGET_ARROW_SELECTED_PAINT) {
        setTargetEdgeEndSelectedPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_SOURCE_ARROW_UNSELECTED_PAINT) {
        setSourceEdgeEndPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_TARGET_ARROW_UNSELECTED_PAINT) {
        setTargetEdgeEndPaint((Paint) value);
    } else if (vp == DVisualLexicon.EDGE_SOURCE_ARROW_SIZE) {
        setSourceArrowSize(((Number) value).doubleValue());
    } else if (vp == DVisualLexicon.EDGE_TARGET_ARROW_SIZE) {
        setTargetArrowSize(((Number) value).doubleValue());
    } else if (vp == BasicVisualLexicon.EDGE_SELECTED) {
        setSelected((Boolean) value);
    } else if (vp == BasicVisualLexicon.EDGE_TARGET_ARROW_SHAPE) {
        final ArrowShape shape = (ArrowShape) value;
        final String shapeID = shape.getSerializableString();
        setTargetEdgeEnd(DArrowShape.parseArrowText(shapeID).getPresentationShape());
    } else if (vp == BasicVisualLexicon.EDGE_SOURCE_ARROW_SHAPE) {
        final ArrowShape shape = (ArrowShape) value;
        final String shapeID = shape.getSerializableString();
        setSourceEdgeEnd(DArrowShape.parseArrowText(shapeID).getPresentationShape());
    } else if (vp == BasicVisualLexicon.EDGE_LABEL) {
        setText(value.toString());
    } else if (vp == BasicVisualLexicon.EDGE_LABEL_WIDTH) {
        setLabelWidth(((Number) value).doubleValue());
    } else if (vp == DVisualLexicon.EDGE_TOOLTIP) {
        setToolTip(value.toString());
    } else if (vp == DVisualLexicon.EDGE_LABEL_FONT_FACE) {
        Font newFont = (Font) value;
        final Font f = getFont();
        if (f != null)
            newFont = f.deriveFont((float) f.getSize());
        setFont(newFont);
    } else if (vp == DVisualLexicon.EDGE_LABEL_FONT_SIZE) {
        float fontSize = ((Number) value).floatValue();
        final Font f = getFont();
        if (f != null)
            setFont(f.deriveFont(fontSize));
    } else if (vp == BasicVisualLexicon.EDGE_LABEL_COLOR) {
        setTextPaint((Paint) value);
    } else if (vp == BasicVisualLexicon.EDGE_VISIBLE) {
        if (((Boolean) value).booleanValue()) {
            graphView.showGraphObject(this);
            isVisible = true;
        } else {
            graphView.hideGraphObject(this);
            isVisible = false;
        }
    } else if (vp == DVisualLexicon.EDGE_CURVED) {
        final Boolean curved = (Boolean) value;
        if (curved)
            setLineCurved(EdgeView.CURVED_LINES);
        else
            setLineCurved(EdgeView.STRAIGHT_LINES);
    } else if (vp == DVisualLexicon.EDGE_BEND) {
        setBend((Bend) value);
    }
}
Also used : Stroke(java.awt.Stroke) AnimatedStroke(org.cytoscape.ding.impl.strokes.AnimatedStroke) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) DArrowShape(org.cytoscape.ding.DArrowShape) Bend(org.cytoscape.view.presentation.property.values.Bend) Paint(java.awt.Paint) LineType(org.cytoscape.view.presentation.property.values.LineType) Font(java.awt.Font)

Example 2 with ArrowShape

use of org.cytoscape.view.presentation.property.values.ArrowShape in project cytoscape-impl by cytoscape.

the class InnerCanvas method computeEdgesIntersecting.

// Puts [last drawn] edges intersecting onto stack; as RootGraph indices.
// Depends on the state of several member variables, such as m_hash.
// Clobbers m_stack and m_ptBuff.
// The rectangle extents are in component coordinate space.
// IMPORTANT: Code that calls this method should be holding m_lock.
final void computeEdgesIntersecting(final int xMini, final int yMini, final int xMaxi, final int yMaxi, final LongStack stack) {
    m_ptBuff[0] = xMini;
    m_ptBuff[1] = yMini;
    m_view.xformComponentToNodeCoords(m_ptBuff);
    final double xMin = m_ptBuff[0];
    final double yMin = m_ptBuff[1];
    m_ptBuff[0] = xMaxi;
    m_ptBuff[1] = yMaxi;
    m_view.xformComponentToNodeCoords(m_ptBuff);
    final double xMax = m_ptBuff[0];
    final double yMax = m_ptBuff[1];
    // Positive.
    LongEnumerator edgeNodesEnum = m_hash.elements();
    m_stack.empty();
    final int edgeNodesCount = edgeNodesEnum.numRemaining();
    for (int i = 0; i < edgeNodesCount; i++) m_stack.push(edgeNodesEnum.nextLong());
    m_hash.empty();
    edgeNodesEnum = m_stack.elements();
    stack.empty();
    final CyNetwork graph = m_view.m_drawPersp;
    if ((m_lastRenderDetail & GraphRenderer.LOD_HIGH_DETAIL) == 0) {
        // We won't need to look up arrows and their sizes.
        for (int i = 0; i < edgeNodesCount; i++) {
            // Positive.
            final long node = edgeNodesEnum.nextLong();
            final CyNode nodeObj = graph.getNode(node);
            if (!m_view.m_spacial.exists(node, m_view.m_extentsBuff, 0))
                // Will happen if e.g. node was removed.
                continue;
            final float nodeX = (m_view.m_extentsBuff[0] + m_view.m_extentsBuff[2]) / 2;
            final float nodeY = (m_view.m_extentsBuff[1] + m_view.m_extentsBuff[3]) / 2;
            final Iterable<CyEdge> touchingEdges = graph.getAdjacentEdgeIterable(nodeObj, CyEdge.Type.ANY);
            for (CyEdge e : touchingEdges) {
                final long edge = e.getSUID();
                final long otherNode = node ^ e.getSource().getSUID().longValue() ^ e.getTarget().getSUID().longValue();
                if (m_hash.get(otherNode) < 0) {
                    m_view.m_spacial.exists(otherNode, m_view.m_extentsBuff, 0);
                    final float otherNodeX = (m_view.m_extentsBuff[0] + m_view.m_extentsBuff[2]) / 2;
                    final float otherNodeY = (m_view.m_extentsBuff[1] + m_view.m_extentsBuff[3]) / 2;
                    m_line.setLine(nodeX, nodeY, otherNodeX, otherNodeY);
                    if (m_line.intersects(xMin, yMin, xMax - xMin, yMax - yMin))
                        stack.push(edge);
                }
            }
            m_hash.put(node);
        }
    } else {
        // Last render high detail.
        for (int i = 0; i < edgeNodesCount; i++) {
            // Positive.
            final long node = edgeNodesEnum.nextLong();
            final CyNode nodeObj = graph.getNode(node);
            if (!m_view.m_spacial.exists(node, m_view.m_extentsBuff, 0))
                continue;
            /* Will happen if e.g. node was removed. */
            final byte nodeShape = m_view.m_nodeDetails.getShape(nodeObj);
            final Iterable<CyEdge> touchingEdges = graph.getAdjacentEdgeIterable(nodeObj, CyEdge.Type.ANY);
            for (CyEdge edge : touchingEdges) {
                // final int edge = e.getIndex(); // Positive.
                final double segThicknessDiv2 = m_view.m_edgeDetails.getWidth(edge) / 2.0d;
                final long otherNode = node ^ edge.getSource().getSUID().longValue() ^ edge.getTarget().getSUID().longValue();
                final CyNode otherNodeObj = graph.getNode(otherNode);
                if (m_hash.get(otherNode) < 0) {
                    m_view.m_spacial.exists(otherNode, m_extentsBuff2, 0);
                    final byte otherNodeShape = m_view.m_nodeDetails.getShape(otherNodeObj);
                    final byte srcShape;
                    final byte trgShape;
                    final float[] srcExtents;
                    final float[] trgExtents;
                    if (node == edge.getSource().getSUID().longValue()) {
                        srcShape = nodeShape;
                        trgShape = otherNodeShape;
                        srcExtents = m_view.m_extentsBuff;
                        trgExtents = m_extentsBuff2;
                    } else {
                        // node == graph.edgeTarget(edge).
                        srcShape = otherNodeShape;
                        trgShape = nodeShape;
                        srcExtents = m_extentsBuff2;
                        trgExtents = m_view.m_extentsBuff;
                    }
                    final ArrowShape srcArrow;
                    final ArrowShape trgArrow;
                    final float srcArrowSize;
                    final float trgArrowSize;
                    if ((m_lastRenderDetail & GraphRenderer.LOD_EDGE_ARROWS) == 0) {
                        srcArrow = trgArrow = ArrowShapeVisualProperty.NONE;
                        srcArrowSize = trgArrowSize = 0.0f;
                    } else {
                        srcArrow = m_view.m_edgeDetails.getSourceArrowShape(edge);
                        trgArrow = m_view.m_edgeDetails.getTargetArrowShape(edge);
                        srcArrowSize = ((srcArrow == ArrowShapeVisualProperty.NONE) ? 0.0f : m_view.m_edgeDetails.getSourceArrowSize(edge));
                        trgArrowSize = ((trgArrow == ArrowShapeVisualProperty.NONE) ? 0.0f : m_view.m_edgeDetails.getTargetArrowSize(edge));
                    }
                    final EdgeAnchors anchors = (((m_lastRenderDetail & GraphRenderer.LOD_EDGE_ANCHORS) == 0) ? null : m_view.m_edgeDetails.getAnchors(edge));
                    if (!GraphRenderer.computeEdgeEndpoints(m_grafx, srcExtents, srcShape, srcArrow, srcArrowSize, anchors, trgExtents, trgShape, trgArrow, trgArrowSize, m_floatBuff1, m_floatBuff2))
                        continue;
                    m_grafx.getEdgePath(srcArrow, srcArrowSize, trgArrow, trgArrowSize, m_floatBuff1[0], m_floatBuff1[1], anchors, m_floatBuff2[0], m_floatBuff2[1], m_path);
                    GraphRenderer.computeClosedPath(m_path.getPathIterator(null), m_path2);
                    if (m_path2.intersects(xMin - segThicknessDiv2, yMin - segThicknessDiv2, (xMax - xMin) + (segThicknessDiv2 * 2), (yMax - yMin) + (segThicknessDiv2 * 2)))
                        stack.push(edge.getSUID().longValue());
                }
            }
            m_hash.put(node);
        }
    }
}
Also used : EdgeAnchors(org.cytoscape.graph.render.immed.EdgeAnchors) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) Point(java.awt.Point) LongEnumerator(org.cytoscape.util.intr.LongEnumerator) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) CyNode(org.cytoscape.model.CyNode)

Example 3 with ArrowShape

use of org.cytoscape.view.presentation.property.values.ArrowShape in project cytoscape-impl by cytoscape.

the class DEdgeDetails method getSourceArrowShape.

@Override
public ArrowShape getSourceArrowShape(final CyEdge edge) {
    // Check bypass
    final DEdgeView dev = dGraphView.getDEdgeView(edge);
    if (dev.isValueLocked(EDGE_SOURCE_ARROW_SHAPE)) {
        final ArrowShape tgtArrow = dev.getVisualProperty(EDGE_SOURCE_ARROW_SHAPE);
        final String shapeID = tgtArrow.getSerializableString();
        return DArrowShape.parseArrowText(shapeID).getPresentationShape();
    }
    final ArrowShape arrow = m_sourceArrows.get(edge);
    if (arrow == null)
        return m_sourceArrowDefault == null ? super.getSourceArrowShape(edge) : m_sourceArrowDefault;
    return arrow;
}
Also used : DArrowShape(org.cytoscape.ding.DArrowShape) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape)

Example 4 with ArrowShape

use of org.cytoscape.view.presentation.property.values.ArrowShape in project cytoscape-impl by cytoscape.

the class GraphGraphics method getEdgePath.

/**
 * Computes the path that an edge takes; this method is useful if a user
 * interface would allow user selection of edges, for example. The returned
 * path is the path along the center of the edge segment, extending to the
 * points which specify the arrow locations. Note that this path therefore
 * disregards edge thickness and arrow outline. Use the same parameter
 * values that were used to render corresponding edge.
 *
 * @param arrow0Type
 *            the type of arrow shape used for drawing the arrow at point
 *            (x0, y0); this value must be one of the ARROW_* constants.
 * @param arrow0Size
 *            the size of arrow at point (x0, y0).
 * @param arrow1Type
 *            the type of arrow shape used for drawing the arrow at point
 *            (x1, y1); this value must be one of the ARROW_* constants.
 * @param arrow1Size
 *            the size of arrow at point (x1, y1).
 * @param x0
 *            the X coordinate of the first edge endpoint.
 * @param y0
 *            the Y coordinate of the first edge endpoint.
 * @param anchors
 *            anchor points between the two edge endpoints; null is an
 *            acceptable value to indicate no edge anchors.
 * @param x1
 *            the X coordinate of the second edge endpoint.
 * @param y1
 *            the Y coordinate of the second edge endpoint.
 * @param path
 *            the computed path is returned in this parameter; the computed
 *            path's coordinate system is the node coordinate system; the
 *            computed path is not closed.
 * @return true if and only if the specified edge would be drawn (which is
 *         if and only if any two points from the edge anchor set plus the
 *         beginning and end point are distinct); if false is returned, the
 *         path parameter is not modified.
 * @exception IllegalArgumentException
 *                if any one of the edge arrow criteria specified in
 *                drawEdgeFull() is not satisfied.
 */
public final boolean getEdgePath(final ArrowShape arrow0Type, final float arrow0Size, final ArrowShape arrow1Type, final float arrow1Size, final float x0, final float y0, EdgeAnchors anchors, final float x1, final float y1, final GeneralPath path) {
    final double curveFactor = CURVE_ELLIPTICAL;
    if (anchors == null) {
        anchors = m_noAnchors;
    }
    if (m_debug) {
        checkDispatchThread();
        if (!arrows.containsKey(arrow0Type))
            throw new IllegalArgumentException("arrow0Type is not recognized");
        if (!arrows.containsKey(arrow1Type))
            throw new IllegalArgumentException("arrow1Type is not recognized");
        if (anchors.numAnchors() > MAX_EDGE_ANCHORS) {
            throw new IllegalArgumentException("at most MAX_EDGE_ANCHORS (" + MAX_EDGE_ANCHORS + ") edge anchors can be specified");
        }
    }
    ArrowShape arrow0 = arrow0Type;
    ArrowShape arrow1 = arrow1Type;
    if (!computeCubicPolyEdgePath(arrow0, (arrow0 == ArrowShapeVisualProperty.NONE) ? 0.0f : arrow0Size, arrow1, (arrow1 == ArrowShapeVisualProperty.NONE) ? 0.0f : arrow1Size, x0, y0, anchors, x1, y1, curveFactor)) {
        // 3 total.
        if (m_edgePtsCount == 2) {
            path.reset();
            path.moveTo((float) m_edgePtsBuff[0], (float) m_edgePtsBuff[1]);
            path.lineTo((float) m_edgePtsBuff[2], (float) m_edgePtsBuff[3]);
            return true;
        }
        return false;
    }
    path.reset();
    path.moveTo((float) m_edgePtsBuff[0], (float) m_edgePtsBuff[1]);
    path.lineTo((float) m_edgePtsBuff[2], (float) m_edgePtsBuff[3]);
    int inx = 4;
    final int count = ((m_edgePtsCount - 1) * 6) - 2;
    while (inx < count) {
        path.curveTo((float) m_edgePtsBuff[inx++], (float) m_edgePtsBuff[inx++], (float) m_edgePtsBuff[inx++], (float) m_edgePtsBuff[inx++], (float) m_edgePtsBuff[inx++], (float) m_edgePtsBuff[inx++]);
    }
    path.lineTo((float) m_edgePtsBuff[count], (float) m_edgePtsBuff[count + 1]);
    return true;
}
Also used : ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint)

Example 5 with ArrowShape

use of org.cytoscape.view.presentation.property.values.ArrowShape in project cytoscape-impl by cytoscape.

the class GraphRenderer method renderGraph.

/**
 * Renders a graph.
 * @param netView the network view; nodes in this graph must correspond to
 *   objKeys in nodePositions (the SpacialIndex2D parameter) and vice versa.
 * @param nodePositions defines the positions and extents of nodes in graph;
 *   each entry (objKey) in this structure must correspond to a node in graph
 *   (the CyNetwork parameter) and vice versa; the order in which nodes are
 *   rendered is defined by a non-reversed overlap query on this structure.
 * @param lod defines the different levels of detail; an appropriate level
 *   of detail is chosen based on the results of method calls on this
 *   object.
 * @param nodeDetails defines details of nodes such as colors, node border
 *   thickness, and shape; the node arguments passed to methods on this
 *   object will be nodes in the graph parameter.
 * @param edgeDetails defines details of edges such as colors, thickness,
 *   and arrow type; the edge arguments passed to methods on this
 *   object will be edges in the graph parameter.
 * @param nodeBuff this is a computational helper that is required in the
 *   implementation of this method; when this method returns, nodeBuff is
 *   in a state such that an edge in graph has been rendered by this method
 *   if and only if it touches at least one node in this nodeBuff set;
 *   no guarantee made regarding edgeless nodes.
 * @param grafx the graphics context that is to render this graph.
 * @param bgPaint the background paint to use when calling grafx.clear().
 * @param xCenter the xCenter parameter to use when calling grafx.clear().
 * @param yCenter the yCenter parameter to use when calling grafx.clear().
 * @param scaleFactor the scaleFactor parameter to use when calling
 *   grafx.clear().
 * @param dependencies
 * @return bits representing the level of detail that was rendered; the
 *   return value is a bitwise-or'ed value of the LOD_* constants.
 */
public static final int renderGraph(final CyNetworkView netView, final SpacialIndex2D nodePositions, final GraphLOD lod, final NodeDetails nodeDetails, final EdgeDetails edgeDetails, final LongHash nodeBuff, final GraphGraphics grafx, final Paint bgPaint, final double xCenter, final double yCenter, final double scaleFactor, final boolean haveZOrder, final Set<VisualPropertyDependency<?>> dependencies) {
    // Make sure we keep our promise.
    nodeBuff.empty();
    if (grafx == null || grafx.image == null)
        return 0;
    final CyNetwork graph = netView.getModel();
    // Define the visible window in node coordinate space.
    final float xMin;
    // Define the visible window in node coordinate space.
    final float yMin;
    // Define the visible window in node coordinate space.
    final float xMax;
    // Define the visible window in node coordinate space.
    final float yMax;
    xMin = (float) (xCenter - ((0.5d * grafx.image.getWidth(null)) / scaleFactor));
    yMin = (float) (yCenter - ((0.5d * grafx.image.getHeight(null)) / scaleFactor));
    xMax = (float) (xCenter + ((0.5d * grafx.image.getWidth(null)) / scaleFactor));
    yMax = (float) (yCenter + ((0.5d * grafx.image.getHeight(null)) / scaleFactor));
    // Define buffers.  These are of the few objects we're instantiating
    // directly in this method.
    final float[] floatBuff1;
    // Define buffers.  These are of the few objects we're instantiating
    // directly in this method.
    final float[] floatBuff2;
    // Define buffers.  These are of the few objects we're instantiating
    // directly in this method.
    final float[] floatBuff3;
    // Define buffers.  These are of the few objects we're instantiating
    // directly in this method.
    final float[] floatBuff4;
    // Define buffers.  These are of the few objects we're instantiating
    // directly in this method.
    final float[] floatBuff5;
    final double[] doubleBuff1;
    final double[] doubleBuff2;
    final GeneralPath path2d;
    floatBuff1 = new float[4];
    floatBuff2 = new float[4];
    floatBuff3 = new float[2];
    floatBuff4 = new float[2];
    floatBuff5 = new float[8];
    doubleBuff1 = new double[4];
    doubleBuff2 = new double[2];
    path2d = new GeneralPath();
    // Determine the number of nodes and edges that we are about to render.
    final int renderNodeCount;
    final int renderEdgeCount;
    final byte renderEdges;
    long start = System.currentTimeMillis();
    {
        final SpacialEntry2DEnumerator nodeHits = nodePositions.queryOverlap(xMin, yMin, xMax, yMax, null, 0, false);
        final int visibleNodeCount = nodeHits.numRemaining();
        final int totalNodeCount = graph.getNodeCount();
        final int totalEdgeCount = graph.getEdgeCount();
        renderEdges = lod.renderEdges(visibleNodeCount, totalNodeCount, totalEdgeCount);
        if (renderEdges > 0) {
            int runningNodeCount = 0;
            for (int i = 0; i < visibleNodeCount; i++) {
                nodeHits.nextExtents(floatBuff1, 0);
                if ((floatBuff1[0] != floatBuff1[2]) && (floatBuff1[1] != floatBuff1[3]))
                    runningNodeCount++;
            }
            renderNodeCount = runningNodeCount;
            renderEdgeCount = totalEdgeCount;
        } else if (renderEdges < 0) {
            int runningNodeCount = 0;
            for (int i = 0; i < visibleNodeCount; i++) {
                nodeHits.nextExtents(floatBuff1, 0);
                if ((floatBuff1[0] != floatBuff1[2]) && (floatBuff1[1] != floatBuff1[3]))
                    runningNodeCount++;
            }
            renderNodeCount = runningNodeCount;
            renderEdgeCount = 0;
        } else {
            int runningNodeCount = 0;
            int runningEdgeCount = 0;
            for (int i = 0; i < visibleNodeCount; i++) {
                final long node = nodeHits.nextExtents(floatBuff1, 0);
                if ((floatBuff1[0] != floatBuff1[2]) && (floatBuff1[1] != floatBuff1[3]))
                    runningNodeCount++;
                final Iterable<CyEdge> touchingEdges = graph.getAdjacentEdgeIterable(graph.getNode(node), CyEdge.Type.ANY);
                for (CyEdge e : touchingEdges) {
                    if (!edgeDetails.isVisible(e))
                        continue;
                    final long edge = e.getSUID();
                    final long otherNode = node ^ e.getSource().getSUID() ^ e.getTarget().getSUID();
                    if (nodeBuff.get(otherNode) < 0)
                        runningEdgeCount++;
                }
                nodeBuff.put(node);
            }
            renderNodeCount = runningNodeCount;
            renderEdgeCount = runningEdgeCount;
            nodeBuff.empty();
        }
    }
    // System.out.println("renderEdgeCount: "+renderEdgeCount);
    // System.out.println("time: "+(System.currentTimeMillis()-start)+"ms");
    // Based on number of objects we are going to render, determine LOD.
    final int lodBits;
    {
        int lodTemp = 0;
        if (lod.detail(renderNodeCount, renderEdgeCount)) {
            lodTemp |= LOD_HIGH_DETAIL;
            if (lod.nodeBorders(renderNodeCount, renderEdgeCount))
                lodTemp |= LOD_NODE_BORDERS;
            if (lod.nodeLabels(renderNodeCount, renderEdgeCount))
                lodTemp |= LOD_NODE_LABELS;
            if (lod.edgeArrows(renderNodeCount, renderEdgeCount))
                lodTemp |= LOD_EDGE_ARROWS;
            if (lod.dashedEdges(renderNodeCount, renderEdgeCount))
                lodTemp |= LOD_DASHED_EDGES;
            if (lod.edgeAnchors(renderNodeCount, renderEdgeCount))
                lodTemp |= LOD_EDGE_ANCHORS;
            if (lod.edgeLabels(renderNodeCount, renderEdgeCount))
                lodTemp |= LOD_EDGE_LABELS;
            if ((((lodTemp & LOD_NODE_LABELS) != 0) || ((lodTemp & LOD_EDGE_LABELS) != 0)) && lod.textAsShape(renderNodeCount, renderEdgeCount))
                lodTemp |= LOD_TEXT_AS_SHAPE;
            if (lod.customGraphics(renderNodeCount, renderEdgeCount))
                lodTemp |= LOD_CUSTOM_GRAPHICS;
        }
        lodBits = lodTemp;
    }
    // Clear the background.
    {
        if (bgPaint != null)
            grafx.clear(bgPaint, xCenter, yCenter, scaleFactor);
    }
    // on top of the edge it belongs to.
    if (renderEdges >= 0) {
        final SpacialEntry2DEnumerator nodeHits;
        if (renderEdges > 0)
            // We want to render edges in the same order (back to front) that
            // we would use to render just edges on visible nodes; this is assuming
            // that our spacial index has the subquery order-preserving property.
            nodeHits = nodePositions.queryOverlap(Float.NEGATIVE_INFINITY, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, null, 0, false);
        else
            nodeHits = nodePositions.queryOverlap(xMin, yMin, xMax, yMax, null, 0, false);
        if ((lodBits & LOD_HIGH_DETAIL) == 0) {
            // Low detail.
            final int nodeHitCount = nodeHits.numRemaining();
            for (int i = 0; i < nodeHitCount; i++) {
                final long node = nodeHits.nextExtents(floatBuff1, 0);
                // Casting to double and then back we could achieve better accuracy
                // at the expense of performance.
                final float nodeX = (floatBuff1[0] + floatBuff1[2]) / 2;
                final float nodeY = (floatBuff1[1] + floatBuff1[3]) / 2;
                Iterable<CyEdge> touchingEdges = graph.getAdjacentEdgeIterable(graph.getNode(node), CyEdge.Type.ANY);
                for (CyEdge edge : touchingEdges) {
                    if (!edgeDetails.isVisible(edge))
                        continue;
                    final long otherNode = node ^ edge.getSource().getSUID() ^ edge.getTarget().getSUID();
                    if (nodeBuff.get(otherNode) < 0) {
                        // Has not yet been rendered.
                        nodePositions.exists(otherNode, floatBuff2, 0);
                        grafx.drawEdgeLow(nodeX, nodeY, // accuracy and performance.
                        (floatBuff2[0] + floatBuff2[2]) / 2, (floatBuff2[1] + floatBuff2[3]) / 2, edgeDetails.getColorLowDetail(edge));
                    }
                }
                nodeBuff.put(node);
            }
        } else {
            // High detail.
            while (nodeHits.numRemaining() > 0) {
                final long node = nodeHits.nextExtents(floatBuff1, 0);
                final CyNode cyNode = graph.getNode(node);
                final byte nodeShape = nodeDetails.getShape(cyNode);
                Iterable<CyEdge> touchingEdges = graph.getAdjacentEdgeIterable(cyNode, CyEdge.Type.ANY);
                for (final CyEdge edge : touchingEdges) {
                    if (!edgeDetails.isVisible(edge))
                        continue;
                    final long otherNode = node ^ edge.getSource().getSUID() ^ edge.getTarget().getSUID();
                    final CyNode otherCyNode = graph.getNode(otherNode);
                    if (nodeBuff.get(otherNode) < 0) {
                        if (!nodePositions.exists(otherNode, floatBuff2, 0))
                            continue;
                        // throw new IllegalStateException("nodePositions not recognizing node that exists in graph: "+otherCyNode.toString());
                        final byte otherNodeShape = nodeDetails.getShape(otherCyNode);
                        // Compute node shapes, center positions, and extents.
                        final byte srcShape;
                        // Compute node shapes, center positions, and extents.
                        final byte trgShape;
                        final float[] srcExtents;
                        final float[] trgExtents;
                        if (node == edge.getSource().getSUID()) {
                            srcShape = nodeShape;
                            trgShape = otherNodeShape;
                            srcExtents = floatBuff1;
                            trgExtents = floatBuff2;
                        } else {
                            // node == graph.edgeTarget(edge).
                            srcShape = otherNodeShape;
                            trgShape = nodeShape;
                            srcExtents = floatBuff2;
                            trgExtents = floatBuff1;
                        }
                        // Compute visual attributes that do not depend on LOD.
                        final float thickness = edgeDetails.getWidth(edge);
                        final Stroke edgeStroke = edgeDetails.getStroke(edge);
                        final Paint segPaint = edgeDetails.getPaint(edge);
                        // Compute arrows.
                        final ArrowShape srcArrow;
                        final ArrowShape trgArrow;
                        final float srcArrowSize;
                        final float trgArrowSize;
                        final Paint srcArrowPaint;
                        final Paint trgArrowPaint;
                        if ((lodBits & LOD_EDGE_ARROWS) == 0) {
                            // Not rendering arrows.
                            trgArrow = srcArrow = ArrowShapeVisualProperty.NONE;
                            trgArrowSize = srcArrowSize = 0.0f;
                            trgArrowPaint = srcArrowPaint = null;
                        } else {
                            // Rendering edge arrows.
                            srcArrow = edgeDetails.getSourceArrowShape(edge);
                            trgArrow = edgeDetails.getTargetArrowShape(edge);
                            srcArrowSize = ((srcArrow == ArrowShapeVisualProperty.NONE) ? 0.0f : edgeDetails.getSourceArrowSize(edge));
                            trgArrowSize = ((trgArrow == ArrowShapeVisualProperty.NONE) ? 0.0f : edgeDetails.getTargetArrowSize(edge));
                            srcArrowPaint = ((srcArrow == ArrowShapeVisualProperty.NONE) ? null : edgeDetails.getSourceArrowPaint(edge));
                            trgArrowPaint = ((trgArrow == ArrowShapeVisualProperty.NONE) ? null : edgeDetails.getTargetArrowPaint(edge));
                        }
                        // Compute the anchors to use when rendering edge.
                        final EdgeAnchors anchors = (((lodBits & LOD_EDGE_ANCHORS) == 0) ? null : edgeDetails.getAnchors(edge));
                        if (!computeEdgeEndpoints(grafx, srcExtents, srcShape, srcArrow, srcArrowSize, anchors, trgExtents, trgShape, trgArrow, trgArrowSize, floatBuff3, floatBuff4))
                            continue;
                        final float srcXAdj = floatBuff3[0];
                        final float srcYAdj = floatBuff3[1];
                        final float trgXAdj = floatBuff4[0];
                        final float trgYAdj = floatBuff4[1];
                        grafx.drawEdgeFull(srcArrow, srcArrowSize, srcArrowPaint, trgArrow, trgArrowSize, trgArrowPaint, srcXAdj, srcYAdj, anchors, trgXAdj, trgYAdj, thickness, edgeStroke, segPaint);
                        // Take care of edge anchor rendering.
                        if (anchors != null) {
                            for (int k = 0; k < anchors.numAnchors(); k++) {
                                final float anchorSize;
                                if ((anchorSize = edgeDetails.getAnchorSize(edge, k)) > 0.0f) {
                                    anchors.getAnchor(k, floatBuff4, 0);
                                    grafx.drawNodeFull(GraphGraphics.SHAPE_RECTANGLE, (float) (floatBuff4[0] - (anchorSize / 2.0d)), (float) (floatBuff4[1] - (anchorSize / 2.0d)), (float) (floatBuff4[0] + (anchorSize / 2.0d)), (float) (floatBuff4[1] + (anchorSize / 2.0d)), edgeDetails.getAnchorPaint(edge, k), 0.0f, null, null);
                                }
                            }
                        }
                        // Take care of label rendering.
                        if ((lodBits & LOD_EDGE_LABELS) != 0) {
                            final int labelCount = edgeDetails.getLabelCount(edge);
                            for (int labelInx = 0; labelInx < labelCount; labelInx++) {
                                final String text = edgeDetails.getLabelText(edge, labelInx);
                                final Font font = edgeDetails.getLabelFont(edge, labelInx);
                                final double fontScaleFactor = edgeDetails.getLabelScaleFactor(edge, labelInx);
                                final Paint paint = edgeDetails.getLabelPaint(edge, labelInx);
                                final Position textAnchor = edgeDetails.getLabelTextAnchor(edge, labelInx);
                                final Position edgeAnchor = edgeDetails.getLabelEdgeAnchor(edge, labelInx);
                                final float offsetVectorX = edgeDetails.getLabelOffsetVectorX(edge, labelInx);
                                final float offsetVectorY = edgeDetails.getLabelOffsetVectorY(edge, labelInx);
                                final Justification justify;
                                if (text.indexOf('\n') >= 0)
                                    justify = edgeDetails.getLabelJustify(edge, labelInx);
                                else
                                    justify = Justification.JUSTIFY_CENTER;
                                final double edgeAnchorPointX;
                                final double edgeAnchorPointY;
                                final double edgeLabelWidth = edgeDetails.getLabelWidth(edge);
                                // in any case.
                                if (edgeAnchor == Position.WEST) {
                                    edgeAnchorPointX = srcXAdj;
                                    edgeAnchorPointY = srcYAdj;
                                } else if (edgeAnchor == Position.EAST) {
                                    edgeAnchorPointX = trgXAdj;
                                    edgeAnchorPointY = trgYAdj;
                                } else if (edgeAnchor == Position.CENTER) {
                                    if (!grafx.getEdgePath(srcArrow, srcArrowSize, trgArrow, trgArrowSize, srcXAdj, srcYAdj, anchors, trgXAdj, trgYAdj, path2d)) {
                                        continue;
                                    }
                                    // Count the number of path segments.  This count
                                    // includes the initial SEG_MOVETO.  So, for example, a
                                    // path composed of 2 cubic curves would have a numPaths
                                    // of 3.  Note that numPaths will be at least 2 in all
                                    // cases.
                                    final int numPaths;
                                    {
                                        final PathIterator pathIter = path2d.getPathIterator(null);
                                        int numPathsTemp = 0;
                                        while (!pathIter.isDone()) {
                                            // pathIter.currentSegment().
                                            numPathsTemp++;
                                            pathIter.next();
                                        }
                                        numPaths = numPathsTemp;
                                    }
                                    // Compute "midpoint" of edge.
                                    if ((numPaths % 2) != 0) {
                                        final PathIterator pathIter = path2d.getPathIterator(null);
                                        for (int i = numPaths / 2; i > 0; i--) pathIter.next();
                                        final int subPathType = pathIter.currentSegment(floatBuff5);
                                        if (subPathType == PathIterator.SEG_LINETO) {
                                            edgeAnchorPointX = floatBuff5[0];
                                            edgeAnchorPointY = floatBuff5[1];
                                        } else if (subPathType == PathIterator.SEG_QUADTO) {
                                            edgeAnchorPointX = floatBuff5[2];
                                            edgeAnchorPointY = floatBuff5[3];
                                        } else if (subPathType == PathIterator.SEG_CUBICTO) {
                                            edgeAnchorPointX = floatBuff5[4];
                                            edgeAnchorPointY = floatBuff5[5];
                                        } else
                                            throw new IllegalStateException("got unexpected PathIterator segment type: " + subPathType);
                                    } else {
                                        // numPaths % 2 == 0.
                                        final PathIterator pathIter = path2d.getPathIterator(null);
                                        for (int i = numPaths / 2; i > 0; i--) {
                                            if (i == 1) {
                                                final int subPathType = pathIter.currentSegment(floatBuff5);
                                                if ((subPathType == PathIterator.SEG_MOVETO) || (subPathType == PathIterator.SEG_LINETO)) {
                                                    floatBuff5[6] = floatBuff5[0];
                                                    floatBuff5[7] = floatBuff5[1];
                                                } else if (subPathType == PathIterator.SEG_QUADTO) {
                                                    floatBuff5[6] = floatBuff5[2];
                                                    floatBuff5[7] = floatBuff5[3];
                                                } else if (subPathType == PathIterator.SEG_CUBICTO) {
                                                    floatBuff5[6] = floatBuff5[4];
                                                    floatBuff5[7] = floatBuff5[5];
                                                } else
                                                    throw new IllegalStateException("got unexpected PathIterator segment type: " + subPathType);
                                            }
                                            pathIter.next();
                                        }
                                        final int subPathType = pathIter.currentSegment(floatBuff5);
                                        if (subPathType == PathIterator.SEG_LINETO) {
                                            edgeAnchorPointX = (0.5d * floatBuff5[6]) + (0.5d * floatBuff5[0]);
                                            edgeAnchorPointY = (0.5d * floatBuff5[7]) + (0.5d * floatBuff5[1]);
                                        } else if (subPathType == PathIterator.SEG_QUADTO) {
                                            edgeAnchorPointX = (0.25d * floatBuff5[6]) + (0.5d * floatBuff5[0]) + (0.25d * floatBuff5[2]);
                                            edgeAnchorPointY = (0.25d * floatBuff5[7]) + (0.5d * floatBuff5[1]) + (0.25d * floatBuff5[3]);
                                        } else if (subPathType == PathIterator.SEG_CUBICTO) {
                                            edgeAnchorPointX = (0.125d * floatBuff5[6]) + (0.375d * floatBuff5[0]) + (0.375d * floatBuff5[2]) + (0.125d * floatBuff5[4]);
                                            edgeAnchorPointY = (0.125d * floatBuff5[7]) + (0.375d * floatBuff5[1]) + (0.375d * floatBuff5[3]) + (0.125d * floatBuff5[5]);
                                        } else
                                            throw new IllegalStateException("got unexpected PathIterator segment type: " + subPathType);
                                    }
                                } else
                                    throw new IllegalStateException("encountered an invalid EDGE_ANCHOR_* constant: " + edgeAnchor);
                                final MeasuredLineCreator measuredText = new MeasuredLineCreator(text, font, grafx.getFontRenderContextFull(), fontScaleFactor, (lodBits & LOD_TEXT_AS_SHAPE) != 0, edgeLabelWidth);
                                doubleBuff1[0] = -0.5d * measuredText.getMaxLineWidth();
                                doubleBuff1[1] = -0.5d * measuredText.getTotalHeight();
                                doubleBuff1[2] = 0.5d * measuredText.getMaxLineWidth();
                                doubleBuff1[3] = 0.5d * measuredText.getTotalHeight();
                                lemma_computeAnchor(textAnchor, doubleBuff1, doubleBuff2);
                                final double textXCenter = edgeAnchorPointX - doubleBuff2[0] + offsetVectorX;
                                final double textYCenter = edgeAnchorPointY - doubleBuff2[1] + offsetVectorY;
                                TextRenderingUtils.renderHorizontalText(grafx, measuredText, font, fontScaleFactor, (float) textXCenter, (float) textYCenter, justify, paint, (lodBits & LOD_TEXT_AS_SHAPE) != 0);
                            }
                        }
                    }
                }
                nodeBuff.put(node);
            }
        }
    }
    // Render nodes and labels.  A label is not necessarily on top of every
    // node; it is only on top of the node it belongs to.
    {
        final SpacialEntry2DEnumerator nodeHits = nodePositions.queryOverlap(xMin, yMin, xMax, yMax, null, 0, false);
        if ((lodBits & LOD_HIGH_DETAIL) == 0) {
            // Low detail.
            final int nodeHitCount = nodeHits.numRemaining();
            for (int i = 0; i < nodeHitCount; i++) {
                final CyNode node = graph.getNode(nodeHits.nextExtents(floatBuff1, 0));
                if ((floatBuff1[0] != floatBuff1[2]) && (floatBuff1[1] != floatBuff1[3]))
                    grafx.drawNodeLow(floatBuff1[0], floatBuff1[1], floatBuff1[2], floatBuff1[3], nodeDetails.getColorLowDetail(node));
            }
        } else {
            // High detail.
            SpacialEntry2DEnumerator zHits = nodeHits;
            if (haveZOrder) {
                zHits = new SpacialEntry2DEnumeratorZSort(nodePositions, nodeHits);
            }
            while (zHits.numRemaining() > 0) {
                final long node = zHits.nextExtents(floatBuff1, 0);
                final CyNode cyNode = graph.getNode(node);
                renderNodeHigh(netView, grafx, cyNode, floatBuff1, doubleBuff1, doubleBuff2, nodeDetails, lodBits, dependencies);
                // Take care of label rendering.
                if ((lodBits & LOD_NODE_LABELS) != 0) {
                    // Potential label rendering.
                    final int labelCount = nodeDetails.getLabelCount(cyNode);
                    for (int labelInx = 0; labelInx < labelCount; labelInx++) {
                        final String text = nodeDetails.getLabelText(cyNode, labelInx);
                        final Font font = nodeDetails.getLabelFont(cyNode, labelInx);
                        final double fontScaleFactor = nodeDetails.labelScaleFactor(cyNode, labelInx);
                        final Paint paint = nodeDetails.getLabelPaint(cyNode, labelInx);
                        final Position textAnchor = nodeDetails.getLabelTextAnchor(cyNode, labelInx);
                        final Position nodeAnchor = nodeDetails.getLabelNodeAnchor(cyNode, labelInx);
                        final float offsetVectorX = nodeDetails.getLabelOffsetVectorX(cyNode, labelInx);
                        final float offsetVectorY = nodeDetails.getLabelOffsetVectorY(cyNode, labelInx);
                        final Justification justify;
                        if (text.indexOf('\n') >= 0)
                            justify = nodeDetails.getLabelJustify(cyNode, labelInx);
                        else
                            justify = Justification.JUSTIFY_CENTER;
                        final double nodeLabelWidth = nodeDetails.getLabelWidth(cyNode);
                        doubleBuff1[0] = floatBuff1[0];
                        doubleBuff1[1] = floatBuff1[1];
                        doubleBuff1[2] = floatBuff1[2];
                        doubleBuff1[3] = floatBuff1[3];
                        lemma_computeAnchor(nodeAnchor, doubleBuff1, doubleBuff2);
                        final double nodeAnchorPointX = doubleBuff2[0];
                        final double nodeAnchorPointY = doubleBuff2[1];
                        final MeasuredLineCreator measuredText = new MeasuredLineCreator(text, font, grafx.getFontRenderContextFull(), fontScaleFactor, (lodBits & LOD_TEXT_AS_SHAPE) != 0, nodeLabelWidth);
                        doubleBuff1[0] = -0.5d * measuredText.getMaxLineWidth();
                        doubleBuff1[1] = -0.5d * measuredText.getTotalHeight();
                        doubleBuff1[2] = 0.5d * measuredText.getMaxLineWidth();
                        doubleBuff1[3] = 0.5d * measuredText.getTotalHeight();
                        lemma_computeAnchor(textAnchor, doubleBuff1, doubleBuff2);
                        final double textXCenter = nodeAnchorPointX - doubleBuff2[0] + offsetVectorX;
                        final double textYCenter = nodeAnchorPointY - doubleBuff2[1] + offsetVectorY;
                        TextRenderingUtils.renderHorizontalText(grafx, measuredText, font, fontScaleFactor, (float) textXCenter, (float) textYCenter, justify, paint, (lodBits & LOD_TEXT_AS_SHAPE) != 0);
                    }
                }
            }
        }
    }
    // System.out.println("total time: "+(System.currentTimeMillis()-start)+"ms");
    return lodBits;
}
Also used : EdgeAnchors(org.cytoscape.graph.render.immed.EdgeAnchors) GeneralPath(java.awt.geom.GeneralPath) PathIterator(java.awt.geom.PathIterator) CyNetwork(org.cytoscape.model.CyNetwork) Font(java.awt.Font) CyNode(org.cytoscape.model.CyNode) Justification(org.cytoscape.view.presentation.property.values.Justification) Stroke(java.awt.Stroke) Position(org.cytoscape.view.presentation.property.values.Position) SpacialEntry2DEnumerator(org.cytoscape.spacial.SpacialEntry2DEnumerator) TexturePaint(java.awt.TexturePaint) Paint(java.awt.Paint) CyEdge(org.cytoscape.model.CyEdge) TexturePaint(java.awt.TexturePaint) Paint(java.awt.Paint) ArrowShape(org.cytoscape.view.presentation.property.values.ArrowShape)

Aggregations

ArrowShape (org.cytoscape.view.presentation.property.values.ArrowShape)12 Paint (java.awt.Paint)6 DArrowShape (org.cytoscape.ding.DArrowShape)5 BasicStroke (java.awt.BasicStroke)3 Font (java.awt.Font)3 Stroke (java.awt.Stroke)3 TexturePaint (java.awt.TexturePaint)3 Color (java.awt.Color)2 Shape (java.awt.Shape)2 EdgeAnchors (org.cytoscape.graph.render.immed.EdgeAnchors)2 DiamondNodeShape (org.cytoscape.graph.render.immed.nodeshape.DiamondNodeShape)2 EllipseNodeShape (org.cytoscape.graph.render.immed.nodeshape.EllipseNodeShape)2 HexagonNodeShape (org.cytoscape.graph.render.immed.nodeshape.HexagonNodeShape)2 LegacyCustomNodeShape (org.cytoscape.graph.render.immed.nodeshape.LegacyCustomNodeShape)2 NodeShape (org.cytoscape.graph.render.immed.nodeshape.NodeShape)2 OctagonNodeShape (org.cytoscape.graph.render.immed.nodeshape.OctagonNodeShape)2 ParallelogramNodeShape (org.cytoscape.graph.render.immed.nodeshape.ParallelogramNodeShape)2 RectangleNodeShape (org.cytoscape.graph.render.immed.nodeshape.RectangleNodeShape)2 RoundedRectangleNodeShape (org.cytoscape.graph.render.immed.nodeshape.RoundedRectangleNodeShape)2 TriangleNodeShape (org.cytoscape.graph.render.immed.nodeshape.TriangleNodeShape)2