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;
}
Aggregations