Search in sources :

Example 1 with AbstractLayoutProvider

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);
    }
}
Also used : AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider)

Example 2 with AbstractLayoutProvider

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();
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) ElkGraphTransformer(org.eclipse.elk.alg.disco.transform.ElkGraphTransformer) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider)

Example 3 with AbstractLayoutProvider

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();
}
Also used : TEdge(org.eclipse.elk.alg.common.TEdge) ScanlineOverlapCheck(org.eclipse.elk.alg.common.spore.ScanlineOverlapCheck) RootSelection(org.eclipse.elk.alg.spore.options.RootSelection) AlgorithmAssembler(org.eclipse.elk.core.alg.AlgorithmAssembler) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider) LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) IElkProgressMonitor(org.eclipse.elk.core.util.IElkProgressMonitor) Set(java.util.Set) Graph(org.eclipse.elk.alg.spore.graph.Graph) TreeConstructionStrategy(org.eclipse.elk.alg.spore.options.TreeConstructionStrategy) OverlapRemovalStrategy(org.eclipse.elk.alg.spore.options.OverlapRemovalStrategy) ElkNode(org.eclipse.elk.graph.ElkNode) SpanningTreeCostFunction(org.eclipse.elk.alg.spore.options.SpanningTreeCostFunction) ILayoutProcessor(org.eclipse.elk.core.alg.ILayoutProcessor) Sets(com.google.common.collect.Sets) SporeCompactionOptions(org.eclipse.elk.alg.spore.options.SporeCompactionOptions) ElkUtil(org.eclipse.elk.core.util.ElkUtil) SVGImage(org.eclipse.elk.alg.common.utils.SVGImage) List(java.util.List) SporeOverlapRemovalOptions(org.eclipse.elk.alg.spore.options.SporeOverlapRemovalOptions) IOverlapHandler(org.eclipse.elk.alg.common.spore.IOverlapHandler) StructureExtractionStrategy(org.eclipse.elk.alg.spore.options.StructureExtractionStrategy) LayoutMetaDataService(org.eclipse.elk.core.data.LayoutMetaDataService) InternalProperties(org.eclipse.elk.alg.common.spore.InternalProperties) ScanlineOverlapCheck(org.eclipse.elk.alg.common.spore.ScanlineOverlapCheck) ElkNode(org.eclipse.elk.graph.ElkNode) IOverlapHandler(org.eclipse.elk.alg.common.spore.IOverlapHandler) SVGImage(org.eclipse.elk.alg.common.utils.SVGImage) LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) TEdge(org.eclipse.elk.alg.common.TEdge) Graph(org.eclipse.elk.alg.spore.graph.Graph) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider)

Example 4 with AbstractLayoutProvider

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);
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) Graph(org.eclipse.elk.alg.spore.graph.Graph) ElkNode(org.eclipse.elk.graph.ElkNode) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider)

Example 5 with AbstractLayoutProvider

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());
    }
}
Also used : LayoutAlgorithmData(org.eclipse.elk.core.data.LayoutAlgorithmData) TestAlgorithm(org.eclipse.elk.alg.test.framework.algorithm.TestAlgorithm) IWhiteBoxTestable(org.eclipse.elk.core.testing.IWhiteBoxTestable) AbstractLayoutProvider(org.eclipse.elk.core.AbstractLayoutProvider)

Aggregations

AbstractLayoutProvider (org.eclipse.elk.core.AbstractLayoutProvider)6 LayoutAlgorithmData (org.eclipse.elk.core.data.LayoutAlgorithmData)4 ElkNode (org.eclipse.elk.graph.ElkNode)3 Graph (org.eclipse.elk.alg.spore.graph.Graph)2 IElkProgressMonitor (org.eclipse.elk.core.util.IElkProgressMonitor)2 Sets (com.google.common.collect.Sets)1 List (java.util.List)1 Set (java.util.Set)1 TEdge (org.eclipse.elk.alg.common.TEdge)1 IOverlapHandler (org.eclipse.elk.alg.common.spore.IOverlapHandler)1 InternalProperties (org.eclipse.elk.alg.common.spore.InternalProperties)1 ScanlineOverlapCheck (org.eclipse.elk.alg.common.spore.ScanlineOverlapCheck)1 SVGImage (org.eclipse.elk.alg.common.utils.SVGImage)1 ElkGraphTransformer (org.eclipse.elk.alg.disco.transform.ElkGraphTransformer)1 LayeredLayoutProvider (org.eclipse.elk.alg.layered.LayeredLayoutProvider)1 OverlapRemovalStrategy (org.eclipse.elk.alg.spore.options.OverlapRemovalStrategy)1 RootSelection (org.eclipse.elk.alg.spore.options.RootSelection)1 SpanningTreeCostFunction (org.eclipse.elk.alg.spore.options.SpanningTreeCostFunction)1 SporeCompactionOptions (org.eclipse.elk.alg.spore.options.SporeCompactionOptions)1 SporeOverlapRemovalOptions (org.eclipse.elk.alg.spore.options.SporeOverlapRemovalOptions)1