Search in sources :

Example 1 with SpacialIndex2D

use of org.cytoscape.spacial.SpacialIndex2D in project cytoscape-impl by cytoscape.

the class DGraphView method renderSubgraph.

int renderSubgraph(GraphGraphics graphics, final GraphLOD lod, Paint bgColor, double xCenter, double yCenter, double scale, LongHash hash, List<CyNode> nodeList, List<CyEdge> edgeList) {
    // the overhead of creating the SpacialIndex2D and CySubNetwork
    if (!largeModel || ((nodeList.size() + edgeList.size()) >= (m_drawPersp.getNodeCount() + m_drawPersp.getEdgeCount()) / 4))
        return renderGraph(graphics, lod, bgColor, xCenter, yCenter, scale, hash);
    // Make a copy of the nodes and edges arrays to avoid a conflict with selection events
    // The assumption here is that these arrays are relatively small
    List<CyNode> nodes = new ArrayList<>(nodeList);
    List<CyEdge> edges = new ArrayList<>(edgeList);
    // Make sure the graphics is initialized
    if (!graphics.isInitialized())
        graphics.clear(bgColor, xCenter, yCenter, scale);
    Color bg = (Color) bgColor;
    if (bg != null)
        bg = new Color(bg.getRed(), bg.getBlue(), bg.getGreen(), 0);
    // Create our private spacial index.
    final SpacialIndex2DFactory spacialFactory = serviceRegistrar.getService(SpacialIndex2DFactory.class);
    SpacialIndex2D sub_spacial = spacialFactory.createSpacialIndex2D();
    // And our private subnetwork
    CySubNetwork net = new MinimalNetwork(SUIDFactory.getNextSUID());
    for (CyEdge edge : edges) {
        nodes.add(edge.getTarget());
        nodes.add(edge.getSource());
    }
    for (CyNode node : nodes) {
        long idx = node.getSUID();
        if (m_spacial.exists(idx, m_extentsBuff, 0)) {
            if (!sub_spacial.exists(idx, new float[4], 0))
                sub_spacial.insert(idx, m_extentsBuff[0], m_extentsBuff[1], m_extentsBuff[2], m_extentsBuff[3], 0.0);
            net.addNode(node);
        }
    }
    for (CyEdge edge : edges) {
        net.addEdge(edge);
    }
    int lastRenderDetail = 0;
    try {
        // final VisualMappingManager vmm = serviceRegistrar.getService(VisualMappingManager.class);
        final Set<VisualPropertyDependency<?>> dependencies = vmm.getVisualStyle(this).getAllVisualPropertyDependencies();
        synchronized (m_lock) {
            lastRenderDetail = GraphRenderer.renderGraph(this, sub_spacial, lod, m_nodeDetails, m_edgeDetails, hash, graphics, null, xCenter, yCenter, scale, haveZOrder, dependencies);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    setContentChanged(false);
    setViewportChanged(false);
    m_visualChanged = true;
    return lastRenderDetail;
}
Also used : Color(java.awt.Color) ArrayList(java.util.ArrayList) CyEdge(org.cytoscape.model.CyEdge) Paint(java.awt.Paint) TexturePaint(java.awt.TexturePaint) IOException(java.io.IOException) SpacialIndex2DFactory(org.cytoscape.spacial.SpacialIndex2DFactory) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) CyNode(org.cytoscape.model.CyNode) SpacialIndex2D(org.cytoscape.spacial.SpacialIndex2D) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Aggregations

Color (java.awt.Color)1 Paint (java.awt.Paint)1 TexturePaint (java.awt.TexturePaint)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNode (org.cytoscape.model.CyNode)1 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)1 SpacialIndex2D (org.cytoscape.spacial.SpacialIndex2D)1 SpacialIndex2DFactory (org.cytoscape.spacial.SpacialIndex2DFactory)1 VisualPropertyDependency (org.cytoscape.view.vizmap.VisualPropertyDependency)1