Search in sources :

Example 1 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class FRLayoutTest method runFRLayout.

private TopoFRLayout<VertexRef, EdgeRef> runFRLayout(Graph g, Layout graphLayout, List<Vertex> vertices) {
    TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<>(createJungGraph(g));
    Dimension size = selectLayoutSize(m_graphContainer);
    //layout.setRepulsionMultiplier(3/8.0);
    //layout.setAttractionMultiplier(3/8.0);
    layout.setInitializer(initializer(graphLayout, size));
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    LOG.info("/******** FRLayout Run **********/");
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - size.getWidth() / 2.0, layout.getY(v) - size.getHeight() / 2.0));
        LOG.info("layout.getX(): " + layout.getX(v) + " layout.getY(): " + layout.getY(v));
    }
    LOG.info("/******** End FRLayout Run **********/");
    return layout;
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 2 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class BreadcrumbPathCalculator method findPath.

static PathTree findPath(TopologyServiceClient topologyServiceClient, Collection<VertexRef> vertices) {
    Objects.requireNonNull(topologyServiceClient);
    Objects.requireNonNull(vertices);
    final Map<VertexRef, EdgeRef> incomingEdgeMap = getIncomingEdgeMap(topologyServiceClient);
    final PathTree pathTree = new PathTree();
    for (VertexRef eachVertex : vertices) {
        List<VertexRef> path = findPath(incomingEdgeMap, eachVertex);
        pathTree.addPath(path);
    }
    return pathTree;
}
Also used : EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 3 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class FRLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(final Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    FRLayout<VertexRef, EdgeRef> layout = new FRLayout<VertexRef, EdgeRef>(jungGraph);
    // Initialize the vertex positions to the last known positions from the layout
    Dimension size = selectLayoutSize(graph);
    layout.setInitializer(initializer(graphLayout, (int) size.getWidth() / 2, (int) size.getHeight() / 2));
    // Resize the graph to accommodate the number of vertices
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    // Store the new positions in the layout
    for (Vertex v : vertices) {
        graphLayout.setLocation(v, new Point(layout.getX(v) - (size.getWidth() / 2), (int) layout.getY(v) - (size.getHeight() / 2)));
    }
}
Also used : Vertex(org.opennms.features.topology.api.topo.Vertex) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) Dimension(java.awt.Dimension) Point(org.opennms.features.topology.api.Point) SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Layout(org.opennms.features.topology.api.Layout) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Example 4 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class RealUltimateLayoutAlgorithm method doFRLayout.

private static void doFRLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, final int xOffset, final int yOffset) {
    FRLayout<VertexRef, EdgeRef> layout = new FRLayout<VertexRef, EdgeRef>(jungGraph);
    layout.setInitializer(initializer(graphLayout, xOffset, yOffset));
    layout.setSize(size);
    while (!layout.done()) {
        layout.step();
    }
    for (VertexRef v : jungGraph.getVertices()) {
        graphLayout.setLocation(v, new Point(layout.getX(v) + xOffset, layout.getY(v) + yOffset));
    }
}
Also used : FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Point(org.opennms.features.topology.api.Point) VertexRef(org.opennms.features.topology.api.topo.VertexRef)

Example 5 with EdgeRef

use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.

the class RealUltimateLayoutAlgorithm method updateLayout.

@Override
public void updateLayout(Graph graph) {
    final Layout graphLayout = graph.getLayout();
    SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
    Collection<? extends Vertex> vertices = graph.getDisplayVertices();
    for (Vertex v : vertices) {
        jungGraph.addVertex(v);
    }
    Collection<? extends Edge> edges = graph.getDisplayEdges();
    for (Edge e : edges) {
        jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
    }
    Dimension size = selectLayoutSize(graph);
    Dimension paddedSize = new Dimension((int) (size.getWidth() * .75), (int) (size.getHeight() * .75));
    doISOMLayout(graphLayout, jungGraph, size);
    doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION);
    doFRLayout(graphLayout, jungGraph, paddedSize, (int) (size.getWidth() / 8.0), (int) (size.getHeight() / 8.0));
    doSpringLayout(graphLayout, jungGraph, size, SPRING_LAYOUT_REPULSION);
}
Also used : SparseGraph(edu.uci.ics.jung.graph.SparseGraph) Vertex(org.opennms.features.topology.api.topo.Vertex) NonStupidISOMLayout(org.opennms.features.topology.app.internal.jung.ISOMLayoutAlgorithm.NonStupidISOMLayout) Layout(org.opennms.features.topology.api.Layout) FRLayout(edu.uci.ics.jung.algorithms.layout.FRLayout) SpringLayout(edu.uci.ics.jung.algorithms.layout.SpringLayout) EdgeRef(org.opennms.features.topology.api.topo.EdgeRef) Dimension(java.awt.Dimension) VertexRef(org.opennms.features.topology.api.topo.VertexRef) Edge(org.opennms.features.topology.api.topo.Edge)

Aggregations

EdgeRef (org.opennms.features.topology.api.topo.EdgeRef)29 VertexRef (org.opennms.features.topology.api.topo.VertexRef)18 Vertex (org.opennms.features.topology.api.topo.Vertex)14 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 Edge (org.opennms.features.topology.api.topo.Edge)11 SparseGraph (edu.uci.ics.jung.graph.SparseGraph)10 Status (org.opennms.features.topology.api.topo.Status)10 Point (org.opennms.features.topology.api.Point)9 Dimension (java.awt.Dimension)6 Layout (org.opennms.features.topology.api.Layout)6 FRLayout (edu.uci.ics.jung.algorithms.layout.FRLayout)3 SpringLayout (edu.uci.ics.jung.algorithms.layout.SpringLayout)3 AbstractVertex (org.opennms.features.topology.api.topo.AbstractVertex)3 Graph (org.opennms.features.topology.api.Graph)2 Lists (com.google.common.collect.Lists)1 ISOMLayout (edu.uci.ics.jung.algorithms.layout.ISOMLayout)1 UnweightedShortestPath (edu.uci.ics.jung.algorithms.shortestpath.UnweightedShortestPath)1 DirectedSparseGraph (edu.uci.ics.jung.graph.DirectedSparseGraph)1 FileWriter (java.io.FileWriter)1