use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.
the class FRLayoutTest method testFRLayout.
@Test
public void testFRLayout() {
Graph g = m_graphContainer.getGraph();
List<Vertex> vertices = new ArrayList<>(g.getDisplayVertices());
TopoFRLayout<VertexRef, EdgeRef> layout = runFRLayout(g, g.getLayout(), vertices);
Vertex v1 = vertices.get(0);
Vertex v2 = vertices.get(1);
Vertex v3 = vertices.get(2);
double distance = calcDistance(layout, v1, v2);
double distance2 = calcDistance(layout, v2, v3);
double distance3 = calcDistance(layout, v1, v3);
LOG.info("distance: " + distance);
LOG.info("distance2: " + distance2);
LOG.info("distance3: " + distance3);
// Run again then refactor
TopoFRLayout<VertexRef, EdgeRef> layout2 = runFRLayout(g, g.getLayout(), vertices);
distance = calcDistance(layout2, v1, v2);
distance2 = calcDistance(layout2, v2, v3);
distance3 = calcDistance(layout2, v1, v3);
LOG.info("distance: " + distance);
LOG.info("distance2: " + distance2);
LOG.info("distance3: " + distance3);
TopoFRLayout<VertexRef, EdgeRef> layout3 = runFRLayout(g, g.getLayout(), vertices);
distance = calcDistance(layout3, v1, v2);
distance2 = calcDistance(layout3, v2, v3);
distance3 = calcDistance(layout3, v1, v3);
LOG.info("distance: " + distance);
LOG.info("distance2: " + distance2);
LOG.info("distance3: " + distance3);
}
use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.
the class DefaultSelectionContext method setSelectedEdgeRefs.
@Override
public boolean setSelectedEdgeRefs(Collection<? extends EdgeRef> edgeRefs) {
Set<EdgeRef> oldSet = new HashSet<>();
oldSet.addAll(getSelectedEdgeRefs());
doDeselectAll();
for (EdgeRef edgeRef : edgeRefs) {
setEdgeRefSelected(edgeRef, true);
}
if (oldSet.equals(getSelectedEdgeRefs())) {
return false;
} else {
return true;
}
}
use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.
the class TopoFRLayoutAlgorithm 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());
}
TopoFRLayout<VertexRef, EdgeRef> layout = new TopoFRLayout<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)));
}
}
use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.
the class RealUltimateLayoutAlgorithm method doSpringLayout.
private static void doSpringLayout(final Layout graphLayout, SparseGraph<VertexRef, EdgeRef> jungGraph, Dimension size, int repulsion) {
SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
layout.setRepulsionRange(repulsion);
layout.setInitializer(initializer(graphLayout));
layout.setSize(size);
int count = 0;
while (!layout.done() && count < 700) {
layout.step();
count++;
}
for (VertexRef v : jungGraph.getVertices()) {
graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
}
}
use of org.opennms.features.topology.api.topo.EdgeRef in project opennms by OpenNMS.
the class SpringLayoutAlgorithm method updateLayout.
@Override
public void updateLayout(final Graph graph) {
final Layout graphLayout = graph.getLayout();
SparseGraph<VertexRef, EdgeRef> jungGraph = new SparseGraph<VertexRef, EdgeRef>();
Collection<? extends Vertex> vertices = graph.getDisplayVertices();
for (VertexRef v : vertices) {
jungGraph.addVertex(v);
}
Collection<? extends Edge> edges = graph.getDisplayEdges();
for (Edge e : edges) {
jungGraph.addEdge(e, e.getSource().getVertex(), e.getTarget().getVertex());
}
SpringLayout<VertexRef, EdgeRef> layout = new SpringLayout<VertexRef, EdgeRef>(jungGraph);
layout.setForceMultiplier(SPRING_FORCE_MULTIPLIER);
layout.setRepulsionRange(SPRING_LAYOUT_REPULSION);
layout.setInitializer(initializer(graphLayout));
layout.setSize(selectLayoutSize(graph));
int count = 0;
while (!layout.done() && count < 700) {
layout.step();
count++;
}
for (VertexRef v : vertices) {
graphLayout.setLocation(v, new Point(layout.getX(v), layout.getY(v)));
}
}
Aggregations