Java Code Examples for edu.uci.ics.jung.graph.Graph#getVertices()
The following examples show how to use
edu.uci.ics.jung.graph.Graph#getVertices() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArticulatedEdgeRouter.java From ghidra with Apache License 2.0 | 6 votes |
private Map<V, Rectangle> getVertexBounds() { if (cachedVertexBoundsMap != null) { return cachedVertexBoundsMap; } Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Collection<V> vertices = graph.getVertices(); Map<V, Rectangle> map = new HashMap<>(); for (V v : vertices) { Rectangle vertexBounds = getVertexBoundsInGraphSpace(viewer, v); map.put(v, vertexBounds); } cachedVertexBoundsMap = map; return map; }
Example 2
Source File: BasicEdgeRouter.java From ghidra with Apache License 2.0 | 6 votes |
protected boolean isOccluded(E edge, Shape graphSpaceShape) { Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> graph = layout.getGraph(); Collection<V> vertices = graph.getVertices(); for (V vertex : vertices) { Rectangle vertexBounds = getVertexBoundsInGraphSpace(viewer, vertex); Pair<V> endpoints = graph.getEndpoints(edge); if (vertex == endpoints.getFirst() || vertex == endpoints.getSecond()) { // do we ever care if an edge is occluded by its own vertices? continue; } if (graphSpaceShape.intersects(vertexBounds)) { return true; } } return false; }
Example 3
Source File: GraphViewerUtils.java From ghidra with Apache License 2.0 | 6 votes |
public static <V extends VisualVertex, E extends VisualEdge<V>> Rectangle getTotalGraphSizeInLayoutSpace(VisualizationServer<V, E> viewer) { //@formatter:on Layout<V, E> layout = viewer.getGraphLayout(); Graph<V, E> theGraph = layout.getGraph(); Collection<V> vertices = theGraph.getVertices(); Collection<E> edges = theGraph.getEdges(); Function<V, Rectangle> vertexToBounds = createVertexToBoundsTransformer(viewer); if (!layoutUsesEdgeArticulations(layout)) { Rectangle bounds = getBoundsForVerticesInLayoutSpace(vertices, vertexToBounds); return bounds; } Function<E, List<Point2D>> edgeToArticulations = e -> e.getArticulationPoints(); return getTotalGraphSizeInLayoutSpace(vertices, edges, vertexToBounds, edgeToArticulations); }
Example 4
Source File: DependencyGraph.java From baleen with Apache License 2.0 | 6 votes |
/** Find and remove simple loops (e.g. a → b → a) from a Jung graph */ public static <V, E> void removeLoops(Graph<V, E> graph) { for (V v : graph.getVertices()) { for (E e : graph.getOutEdges(v)) { V dest = graph.getDest(e); E returnEdge = graph.findEdge(dest, v); if (returnEdge != null) { LOGGER.warn( "Loop detected between {} and {}. Original order will be preserved.", getName(v), getName(dest)); graph.removeEdge(returnEdge); } } } }
Example 5
Source File: FunctionGraphVertexAttributes.java From ghidra with Apache License 2.0 | 6 votes |
private Map<FGVertex, Point> getVertexLocationsFromPropertyMaps(FunctionGraph functionGraph, ObjectPropertyMap vertexLocationPropertyMap, ObjectPropertyMap groupVertexLocationPropertyMap) { Map<FGVertex, Point> map = new HashMap<>(); Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); for (FGVertex vertex : vertices) { SaveablePoint saveablePoint = getPointFromPropertyMap(vertex, vertexLocationPropertyMap, groupVertexLocationPropertyMap); if (saveablePoint != null) { Point point = saveablePoint.getPoint(); map.put(vertex, point); } } return map; }
Example 6
Source File: SelectByScopedFlowPlugin.java From ghidra with Apache License 2.0 | 6 votes |
private CodeBlockVertex getVertex(ProgramLocation location, Graph<CodeBlockVertex, CodeBlockEdge> graph) { CodeBlockVertex from = null; Collection<CodeBlockVertex> vertices = graph.getVertices(); for (CodeBlockVertex vertex : vertices) { CodeBlock codeBlock = vertex.getCodeBlock(); Address address = location.getAddress(); if (codeBlock.contains(address)) { from = vertex; break; } } if (from == null) { throw new AssertException("supplied location is not within supplied function"); } return from; }
Example 7
Source File: FGViewUpdater.java From ghidra with Apache License 2.0 | 6 votes |
/** * Ungroups all {@link GroupedFunctionGraphVertex group vertices} found in the graph. This * method is recursive in that it will keep running until no group vertices remain. * * @param controller The controller in use with the current function graph */ public void ungroupAllVertices(final FGController controller) { FGData functionGraphData = controller.getFunctionGraphData(); FunctionGraph functionGraph = functionGraphData.getFunctionGraph(); Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); Set<GroupedFunctionGraphVertex> groupVertices = new HashSet<>(); for (FGVertex vertex : vertices) { if (vertex instanceof GroupedFunctionGraphVertex) { groupVertices.add((GroupedFunctionGraphVertex) vertex); } } if (groupVertices.size() == 0) { return; // nothing left to ungroup } ungroupVertex(controller, groupVertices.iterator().next(), true); // this follow-up job will call this method again until all groups are gone scheduleViewChangeJob(new UngroupAllVertexFunctionGraphJob(controller)); }
Example 8
Source File: FGViewUpdater.java From ghidra with Apache License 2.0 | 6 votes |
public FGVertex updateEdgeVertexForUngrouping(FunctionGraph functionGraph, GroupedFunctionGraphVertex groupedVertex, FGVertex originalVertex) { Graph<FGVertex, FGEdge> graph = functionGraph; if (graph.containsVertex(originalVertex)) { return originalVertex; } // // Look through the vertices to find the vertex that contains the given address. We may // have multiple vertices that contain the address, as is the case when we are // transitioning from a group vertex that contains a group vertex that contains the // given address. // Address address = originalVertex.getVertexAddress(); Collection<FGVertex> vertices = graph.getVertices(); for (FGVertex vertex : vertices) { if (vertex.containsAddress(address) && !vertex.equals(groupedVertex)) { return vertex; } } // should never happen throw new AssertException("Cannot find any vertex for address: " + address); }
Example 9
Source File: GroupedFunctionGraphVertex.java From ghidra with Apache License 2.0 | 6 votes |
private Map<FGVertex, Point2D> getCurrentVertexLocations() { FGController fgController = getController(); FGView view = fgController.getView(); VisualizationViewer<FGVertex, FGEdge> viewer = view.getPrimaryGraphViewer(); Layout<FGVertex, FGEdge> graphLayout = viewer.getGraphLayout(); Graph<FGVertex, FGEdge> graph = graphLayout.getGraph(); Collection<FGVertex> currentVertices = graph.getVertices(); Map<FGVertex, Point2D> map = new HashMap<>(); for (FGVertex vertex : currentVertices) { if (vertex == this) { // not sure if we need to do this, but, conceptually, we are getting the locations // in the graph before this group node is installed continue; } Point2D point2D = graphLayout.apply(vertex); map.put(vertex, new Point((int) point2D.getX(), (int) point2D.getY())); } return map; }
Example 10
Source File: PageRank.java From AGDISTIS with GNU Affero General Public License v3.0 | 5 votes |
@SuppressWarnings("rawtypes") private double computeDistance(Graph g) { Node n; double distance = 0; for (Object o : g.getVertices()) { n = (Node) o; distance += Math.abs(n.getPageRank() - n.getPageRankNew()); } return distance; }
Example 11
Source File: FunctionGraphPluginScreenShots.java From ghidra with Apache License 2.0 | 5 votes |
private Image captureGraph() { FGController controller = getFunctionGraphController(); FGView view = controller.getView(); VisualizationViewer<FGVertex, FGEdge> viewer = view.getPrimaryGraphViewer(); FunctionGraph functionGraph = getFunctionGraph(); Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); Rectangle layoutBounds = GraphViewerUtils.getBoundsForVerticesInLayoutSpace(viewer, vertices); Rectangle viewBounds = GraphViewerUtils.translateRectangleFromLayoutSpaceToViewSpace(viewer, layoutBounds); // add some padding int padding = 40; viewBounds.x -= padding; viewBounds.y -= padding; viewBounds.width += (2 * padding); viewBounds.height += (2 * padding); FGProvider provider = screen.getProvider(FGProvider.class); JComponent parent = provider.getComponent(); DockableComponent dc = getDockableComponent(parent); viewBounds = SwingUtilities.convertRectangle(provider.getComponent(), viewBounds, dc); captureProvider(); screen.crop(viewBounds); return screen.image; }
Example 12
Source File: FunctionGraphGroupVertices1Test.java From ghidra with Apache License 2.0 | 5 votes |
@Test public void testUngroupAll() { // // Group some vertices and then group that vertex with some vertices to create a // recursively/nested grouping. Also create a second top-level group. Make sure the // ungroup all action will restore the original graph. // FGData graphData = graphFunction("01002cf5"); FunctionGraph functionGraph = graphData.getFunctionGraph(); Graph<FGVertex, FGEdge> graph = functionGraph; Set<FGVertex> originalVertices = new HashSet<>(graph.getVertices()); Set<FGVertex> ungroupedVertices = selectVertices(functionGraph, "01002d2b" /* Another Local*/, "01002d1f" /* MyLocal */); group(ungroupedVertices); Set<FGVertex> outerUngroupedVertices = selectVertices(functionGraph, "01002d0f" /* LAB_01002d0f */, "01002d1f" /* Grouped Vertex */); group(outerUngroupedVertices); Set<FGVertex> secondUngroupedVertices = selectVertices(functionGraph, "01002d11" /* LAB_01002d11*/, "01002d06" /* 01002d06 */); group(secondUngroupedVertices); Assert.assertNotEquals(originalVertices.size(), graph.getVertices().size()); ungroupAll(); // don't use assertEQuals() with the different sets, as the sets may be of differing types // that do not correctly compare as equal Collection<FGVertex> vertices = graph.getVertices(); assertEquals(originalVertices.size(), vertices.size()); for (FGVertex originalVertex : originalVertices) { assertTrue("Original vertex not in ungrouped group: " + originalVertex, vertices.contains(originalVertex)); } }
Example 13
Source File: GroupVertexSerializer.java From ghidra with Apache License 2.0 | 5 votes |
public static Element getXMLForGroupedVertices(FunctionGraph functionGraph) { Element element = new Element(GROUP_VERTICES_ELEMENT_NAME); Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); for (FGVertex vertex : vertices) { if (vertex instanceof GroupedFunctionGraphVertex) { GroupedVertexInfo info = new GroupedVertexInfo((GroupedFunctionGraphVertex) vertex, functionGraph); element.addContent(info.toXML()); } } return element; }
Example 14
Source File: GroupHistoryInfo.java From ghidra with Apache License 2.0 | 5 votes |
private static Map<AddressHasher, FGVertex> hashVerticesByStartAndEndAddress( FunctionGraph functionGraph) { Map<AddressHasher, FGVertex> map = new HashMap<>(); Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); for (FGVertex vertex : vertices) { AddressSetView addresses = vertex.getAddresses(); Address minAddress = addresses.getMinAddress(); Address maxAddress = addresses.getMaxAddress(); map.put(new AddressHasher(minAddress, maxAddress), vertex); } return map; }
Example 15
Source File: FGView.java From ghidra with Apache License 2.0 | 5 votes |
void refreshDisplayWithoutRebuilding() { FunctionGraph functionGraph = functionGraphData.getFunctionGraph(); Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); for (FGVertex vertex : vertices) { vertex.refreshDisplay(); } }
Example 16
Source File: FunctionGraphVertexAttributes.java From ghidra with Apache License 2.0 | 5 votes |
private void clearMap(ObjectPropertyMap propertyMap, FunctionGraph functionGraph) { if (propertyMap == null) { return; // nothing to do } Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); for (FGVertex vertex : vertices) { AddressSetView codeBlock = vertex.getAddresses(); Address minAddress = codeBlock.getMinAddress(); propertyMap.remove(minAddress); } }
Example 17
Source File: FunctionGraphVertexAttributes.java From ghidra with Apache License 2.0 | 5 votes |
public Map<FGVertex, Color> getVertexColors(FunctionGraph functionGraph) { ObjectPropertyMap propertyMap = programUserData.getObjectProperty(FunctionGraphPlugin.class.getSimpleName(), COLOR_PROPERTY_NAME, SaveableColor.class, false); if (propertyMap == null) { return Collections.emptyMap(); } Map<FGVertex, Color> map = new HashMap<>(); Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); for (FGVertex vertex : vertices) { AddressSetView codeBlock = vertex.getAddresses(); Address minAddress = codeBlock.getMinAddress(); SaveableColor saveableColor = (SaveableColor) propertyMap.getObject(minAddress); if (saveableColor != null) { Color color = saveableColor.getColor(); map.put(vertex, color); } } return map; }
Example 18
Source File: JungWrappingVisualGraphLayoutAdapter.java From ghidra with Apache License 2.0 | 5 votes |
private void syncVertexLocationsToLayout() { Graph<V, E> g = getGraph(); Collection<V> vertices = g.getVertices(); for (V v : vertices) { v.setLocation(apply(v)); } }
Example 19
Source File: FGActionManager.java From ghidra with Apache License 2.0 | 4 votes |
private Set<FGVertex> getAllVertices() { FGData functionGraphData = controller.getFunctionGraphData(); FunctionGraph functionGraph = functionGraphData.getFunctionGraph(); Graph<FGVertex, FGEdge> graph = functionGraph; return new HashSet<>(graph.getVertices()); }
Example 20
Source File: LazyGraphGroupSaveableXML.java From ghidra with Apache License 2.0 | 4 votes |
@Override public boolean isEmpty() { Graph<FGVertex, FGEdge> graph = functionGraph; Collection<FGVertex> vertices = graph.getVertices(); return !vertices.stream().anyMatch(v -> v instanceof GroupedFunctionGraphVertex); }