use of org.eclipse.elk.alg.common.TEdge in project elk by eclipse.
the class Node method distance.
/**
* Distance between two nodes, i.e. how far the other node can be moved in the direction of v without colliding
* with this node.
* @param other the other node
* @param v the direction
* @return the direction dependent distance
*/
public double distance(final Node other, final KVector v) {
double result = Double.POSITIVE_INFINITY;
for (TEdge e1 : Utils.getRectEdges(this.rect)) {
for (TEdge e2 : Utils.getRectEdges(other.rect)) {
double distance = ElkMath.distance(e1.u, e1.v, e2.u, e2.v, v);
result = Math.min(result, distance);
}
}
return result;
}
use of org.eclipse.elk.alg.common.TEdge in project elk by eclipse.
the class Utils method getRectEdges.
/**
* returns a list of the four edges of a rectangle.
* @param r the rectangle
* @return the edges
*/
public static List<TEdge> getRectEdges(final ElkRectangle r) {
List<TEdge> rectEdegs = Lists.newArrayList();
rectEdegs.add(new TEdge(r.getTopLeft(), r.getTopRight()));
rectEdegs.add(new TEdge(r.getTopLeft(), r.getBottomLeft()));
rectEdegs.add(new TEdge(r.getBottomRight(), r.getTopRight()));
rectEdegs.add(new TEdge(r.getBottomRight(), r.getBottomLeft()));
return rectEdegs;
}
use of org.eclipse.elk.alg.common.TEdge in project elk by eclipse.
the class OverlapRemovalLayoutProvider method layout.
@Override
public void layout(final ElkNode layoutGraph, final IElkProgressMonitor progressMonitor) {
// If desired, apply a layout algorithm
if (layoutGraph.hasProperty(SporeCompactionOptions.UNDERLYING_LAYOUT_ALGORITHM)) {
String requestedAlgorithm = layoutGraph.getProperty(SporeOverlapRemovalOptions.UNDERLYING_LAYOUT_ALGORITHM);
LayoutAlgorithmData lad = LayoutMetaDataService.getInstance().getAlgorithmDataBySuffix(requestedAlgorithm);
if (lad != null) {
AbstractLayoutProvider layoutProvider = lad.getInstancePool().fetch();
layoutProvider.layout(layoutGraph, progressMonitor.subTask(1));
}
}
// set algorithm properties
layoutGraph.setProperty(SporeCompactionOptions.PROCESSING_ORDER_ROOT_SELECTION, RootSelection.CENTER_NODE);
layoutGraph.setProperty(SporeCompactionOptions.PROCESSING_ORDER_SPANNING_TREE_COST_FUNCTION, SpanningTreeCostFunction.INVERTED_OVERLAP);
layoutGraph.setProperty(SporeCompactionOptions.PROCESSING_ORDER_TREE_CONSTRUCTION, TreeConstructionStrategy.MINIMUM_SPANNING_TREE);
int maxIterations = layoutGraph.getProperty(SporeOverlapRemovalOptions.OVERLAP_REMOVAL_MAX_ITERATIONS);
progressMonitor.begin("Overlap removal", 1);
// initialize debug output
String debugOutputFile = null;
if (layoutGraph.getProperty(SporeOverlapRemovalOptions.DEBUG_MODE)) {
debugOutputFile = ElkUtil.debugFolderPath("spore") + "45scanlineOverlaps";
}
SVGImage svg = new SVGImage(debugOutputFile);
// set overlap handler and import ElkGraph
Set<TEdge> overlapEdges = Sets.newHashSet();
IOverlapHandler overlapHandler = (n1, n2) -> overlapEdges.add(new TEdge(n1.originalVertex, n2.originalVertex));
IGraphImporter<ElkNode> graphImporter = new ElkGraphImporter();
Graph graph = graphImporter.importGraph(layoutGraph);
boolean overlapsExisted = true;
int iteration = 0;
// repeat overlap removal
while (iteration < maxIterations && overlapsExisted) {
// scanline overlap check
if (layoutGraph.getProperty(SporeOverlapRemovalOptions.OVERLAP_REMOVAL_RUN_SCANLINE)) {
overlapEdges.clear();
new ScanlineOverlapCheck(overlapHandler, svg).sweep(graph.vertices);
if (overlapEdges.isEmpty()) {
// don't bother if nothing overlaps
break;
}
graph.tEdges = overlapEdges;
}
// assembling and executing the algorithm
algorithmAssembler.reset();
algorithmAssembler.setPhase(SPOrEPhases.P1_STRUCTURE, StructureExtractionStrategy.DELAUNAY_TRIANGULATION);
algorithmAssembler.setPhase(SPOrEPhases.P2_PROCESSING_ORDER, graph.treeConstructionStrategy);
algorithmAssembler.setPhase(SPOrEPhases.P3_EXECUTION, OverlapRemovalStrategy.GROW_TREE);
algorithm = algorithmAssembler.build(graph);
for (ILayoutProcessor<Graph> processor : algorithm) {
processor.process(graph, progressMonitor.subTask(1));
}
// update node positions
graphImporter.updateGraph(graph);
overlapsExisted = graph.getProperty(InternalProperties.OVERLAPS_EXISTED);
iteration++;
}
// apply node positions to ElkGraph
graphImporter.applyPositions(graph);
progressMonitor.done();
}
Aggregations