use of org.eclipse.elk.core.AbstractLayoutProvider in project elk by eclipse.
the class AlgorithmFactory method create.
@Override
public AbstractLayoutProvider create() {
try {
AbstractLayoutProvider algorithm = clazz.newInstance();
algorithm.initialize(parameter);
return algorithm;
} catch (InstantiationException exception) {
throw new WrappedException(exception);
} catch (IllegalAccessException exception) {
throw new WrappedException(exception);
}
}
use of org.eclipse.elk.core.AbstractLayoutProvider in project elk by eclipse.
the class DisCoLayoutProvider method layout.
// /////////////////////////////////////////////////////////////////////////////
// Layout
/*
* (non-Javadoc)
*/
@Override
public void layout(final ElkNode layoutGraph, final IElkProgressMonitor progressMonitor) {
progressMonitor.begin("Connected Components Compaction", 1);
componentSpacing = layoutGraph.getProperty(DisCoOptions.SPACING_COMPONENT_COMPONENT);
// If desired, apply a layout algorithm to the connected components themselves
if (layoutGraph.hasProperty(DisCoOptions.COMPONENT_COMPACTION_COMPONENT_LAYOUT_ALGORITHM)) {
String requestedAlgorithm = layoutGraph.getProperty(DisCoOptions.COMPONENT_COMPACTION_COMPONENT_LAYOUT_ALGORITHM);
LayoutAlgorithmData lad = LayoutMetaDataService.getInstance().getAlgorithmDataBySuffix(requestedAlgorithm);
if (lad != null) {
AbstractLayoutProvider layoutProvider = lad.getInstancePool().fetch();
layoutProvider.layout(layoutGraph, progressMonitor.subTask(1));
}
}
// 1.) Transform given KGraph into DCGraph
ElkGraphTransformer transformer = new ElkGraphTransformer(componentSpacing);
result = transformer.importGraph(layoutGraph);
// 2.) Choose strategy and compact the DCGraph (only polyomino compaction at the moment)
switch(layoutGraph.getProperty(DisCoMetaDataProvider.COMPONENT_COMPACTION_STRATEGY)) {
// components
case POLYOMINO:
new DisCoPolyominoCompactor().compact(result);
// Only for debugging purposes, see org.eclipse.elk.alg.disco.debug.views.DisCoGraphRenderer
layoutGraph.setProperty(DisCoOptions.DEBUG_DISCO_POLYS, result.getProperty(DisCoOptions.DEBUG_DISCO_POLYS));
break;
default:
System.out.println("DisCo: no compaction strategy used for connected components.");
}
// 3.) Apply new layout to input graph
transformer.applyLayout();
// Only for debugging purposes, see org.eclipse.elk.alg.disco.debug.views.DisCoGraphRenderer
layoutGraph.setProperty(DisCoOptions.DEBUG_DISCO_GRAPH, result);
progressMonitor.done();
}
use of org.eclipse.elk.core.AbstractLayoutProvider 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();
}
use of org.eclipse.elk.core.AbstractLayoutProvider in project elk by eclipse.
the class ShrinkTreeLayoutProvider 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(SporeCompactionOptions.UNDERLYING_LAYOUT_ALGORITHM);
LayoutAlgorithmData lad = LayoutMetaDataService.getInstance().getAlgorithmDataBySuffix(requestedAlgorithm);
if (lad != null) {
AbstractLayoutProvider layoutProvider = lad.getInstancePool().fetch();
layoutProvider.layout(layoutGraph, progressMonitor.subTask(1));
}
}
IGraphImporter<ElkNode> graphImporter = new ElkGraphImporter();
Graph graph = graphImporter.importGraph(layoutGraph);
shrinktree.shrink(graph, progressMonitor.subTask(1));
graphImporter.applyPositions(graph);
}
use of org.eclipse.elk.core.AbstractLayoutProvider in project elk by eclipse.
the class LayoutTestRunner method initializeAlgorithms.
/**
* Loads all algorithms configured in the test class.
*/
private void initializeAlgorithms(final TestClass testClass, final List<Throwable> errors) {
testAlgorithms.addAll(TestAlgorithm.fromTestClass(testClass, errors));
// If we have whitebox tests, we need to check stuff
if (!whiteboxTests.isEmpty()) {
// Ensure that there is at least one specific layout algorithm
if (testAlgorithms.isEmpty() || testAlgorithms.get(0).getAlgorithmData() == null) {
errors.add(new Exception("Whitebox tests require explicit @Algorithm annotations."));
} else {
// Ensure that all algorithms are whitebox testable
for (TestAlgorithm algorithm : testAlgorithms) {
LayoutAlgorithmData algorithmData = algorithm.getAlgorithmData();
AbstractLayoutProvider layoutProvider = algorithmData.getInstancePool().fetch();
if (!(layoutProvider instanceof IWhiteBoxTestable)) {
errors.add(new Exception("Algorithm " + algorithmData.getId() + " is not whitebox testable."));
}
algorithmData.getInstancePool().release(layoutProvider);
}
}
}
if (testAlgorithms.isEmpty()) {
testAlgorithms.add(TestAlgorithm.identity());
}
}
Aggregations