Search in sources :

Example 1 with TEdge

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;
}
Also used : TEdge(org.eclipse.elk.alg.common.TEdge)

Example 2 with TEdge

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;
}
Also used : TEdge(org.eclipse.elk.alg.common.TEdge)

Example 3 with TEdge

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();
}
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)

Aggregations

TEdge (org.eclipse.elk.alg.common.TEdge)3 Sets (com.google.common.collect.Sets)1 List (java.util.List)1 Set (java.util.Set)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 Graph (org.eclipse.elk.alg.spore.graph.Graph)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 StructureExtractionStrategy (org.eclipse.elk.alg.spore.options.StructureExtractionStrategy)1 TreeConstructionStrategy (org.eclipse.elk.alg.spore.options.TreeConstructionStrategy)1 AbstractLayoutProvider (org.eclipse.elk.core.AbstractLayoutProvider)1 AlgorithmAssembler (org.eclipse.elk.core.alg.AlgorithmAssembler)1 ILayoutProcessor (org.eclipse.elk.core.alg.ILayoutProcessor)1 LayoutAlgorithmData (org.eclipse.elk.core.data.LayoutAlgorithmData)1