use of org.eclipse.elk.alg.common.spore.IOverlapHandler 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