Search in sources :

Example 1 with DCComponent

use of org.eclipse.elk.alg.disco.graph.DCComponent in project elk by eclipse.

the class DisCoPolyominoCompactor method createPolyominoes.

/**
 * Creates {@link DCPolyomino polyominoes} from all {@link DCComponent DCComponents} of the {@link DCGraph} to
 * compact. Initializes an underlying grid structure to represent the polyomino based layout. Prerequisite:
 * {@link #computeCellSize(DCGraph)} must have been called before this method.
 */
private void createPolyominoes() {
    DCPolyomino poly;
    Set<DCComponent> comps = cmpGraph.getComponents();
    for (DCComponent comp : comps) {
        poly = new DCPolyomino(comp, gridCellSizeX, gridCellSizeY);
        polys.add(poly);
    }
}
Also used : DCPolyomino(org.eclipse.elk.alg.disco.structures.DCPolyomino) DCComponent(org.eclipse.elk.alg.disco.graph.DCComponent)

Example 2 with DCComponent

use of org.eclipse.elk.alg.disco.graph.DCComponent in project elk by eclipse.

the class DisCoGraphRenderer method renderComponentGraph.

// added by mic
/**
 * Paints all elements of the DCGraph that fall into the given dirty area.
 *
 * @param componentGraph
 *            The DCGraph to paint
 * @param graphics
 *            the graphics context used to paint
 * @param area
 *            dirty area that needs painting
 * @param offset
 *            offset to be added to relative coordinates
 * @param nodeAlpha
 *            alpha value for nodes
 * @param fillingAlpha
 *            alpha value for node fillings
 */
private void renderComponentGraph(final ElkNode parent, final DCGraph componentGraph, final GC graphics, final Rectangle area, final KVector offset, final int nodeAlpha, final int fillingAlpha, final int levelNumber) {
    KVector boundaries = new KVector(parent.getWidth(), parent.getHeight());
    for (DCComponent comp : componentGraph.getComponents()) {
        for (DCElement el : comp.getElements()) {
            PaintPolygon poly = polygonMap.get(el);
            if (poly == null) {
                poly = new PaintPolygon(el, offset, getScale());
                polygonMap.put(el, poly);
            }
            if (!poly.painted && poly.intersects(area)) {
                // paint this node
                graphics.setAlpha(fillingAlpha);
                if (configurator.getDCElementFillColor() != null) {
                    graphics.setBackground(configurator.getDCElementFillColor());
                    graphics.fillPolygon(poly.coordsScaledAndRounded);
                }
                graphics.setAlpha(nodeAlpha);
                if (configurator.getDCElementBorderTextColor() != null) {
                    graphics.setForeground(configurator.getDCElementBorderTextColor());
                    graphics.drawPolygon(poly.coordsScaledAndRounded);
                    if (configurator.getNodeLabelFont() != null) {
                        graphics.setFont(configurator.getNodeLabelFont());
                    }
                    if (state.drawLabels()) {
                        String levelprefix = levelNumber + "_";
                        if (state.removeLvl()) {
                            levelprefix = "";
                        }
                        graphics.drawString(levelprefix + Integer.toString(comp.getId()), poly.coordsScaledAndRounded[0], poly.coordsScaledAndRounded[1], true);
                    }
                }
                poly.painted = true;
            }
            ElkRectangle bounds = el.getBounds();
            Rectangle2D.Double elementBounding = new Rectangle2D.Double(bounds.x, bounds.y, bounds.width, bounds.height);
            double offsetX = elementBounding.getX() + el.getOffset().x;
            double offsetY = elementBounding.getY() + el.getOffset().y;
            elementBounding = new Rectangle2D.Double(offsetX, offsetY, elementBounding.getWidth(), elementBounding.getHeight());
            for (DCExtension ext : el.getExtensions()) {
                PaintRectangle rect = dcExtensionMap.get(ext);
                if (rect == null) {
                    rect = new PaintRectangle(ext, elementBounding, boundaries, offset, getScale());
                    dcExtensionMap.put(ext, rect);
                }
                if (!rect.painted && rect.intersects(area)) {
                    graphics.setAlpha(fillingAlpha);
                    // CHECKSTYLEOFF MagicNumber
                    if (configurator.getDCElementExternalFillColor() != null) {
                        graphics.setBackgroundPattern(patterns.getDCExtensionPattern(state.makeSolid() ? 255 : fillingAlpha));
                        graphics.fillRectangle(rect.x, rect.y, rect.width, rect.height);
                    }
                    // CHECKSTYLEON MagicNumber
                    graphics.setAlpha(nodeAlpha);
                    if (configurator.getNodeBorderColor() != null) {
                        graphics.setForeground(configurator.getDCElementExternalBorderTextColor());
                        graphics.drawRectangle(rect.x, rect.y, rect.width, rect.height);
                    }
                    if (configurator.getDCElementExternalBorderTextColor() != null) {
                        graphics.setForeground(configurator.getDCElementExternalBorderTextColor());
                        if (configurator.getNodeLabelFont() != null) {
                            graphics.setFont(configurator.getNodeLabelFont());
                        }
                        if (state.drawLabels()) {
                            String levelprefix = levelNumber + "_";
                            if (state.removeLvl()) {
                                levelprefix = "";
                            }
                            graphics.drawString(levelprefix + Integer.toString(comp.getId()), rect.x, rect.y, true);
                        }
                    }
                    rect.painted = true;
                }
            }
        }
    }
}
Also used : DCComponent(org.eclipse.elk.alg.disco.graph.DCComponent) DCExtension(org.eclipse.elk.alg.disco.graph.DCExtension) Rectangle2D(java.awt.geom.Rectangle2D) DCElement(org.eclipse.elk.alg.disco.graph.DCElement) KVector(org.eclipse.elk.core.math.KVector) ElkRectangle(org.eclipse.elk.core.math.ElkRectangle)

Example 3 with DCComponent

use of org.eclipse.elk.alg.disco.graph.DCComponent in project elk by eclipse.

the class DisCoPolyominoCompactor method computeCellSize.

// /////////////////////////////////////////////////////////////////////////////
// Private submethods
/**
 * <p>
 * Computes the optimal step size for the polyomino grid, satisfying this equation from the paper.
 * </p>
 *
 * <p>
 * (c*n-1)*l² - (Σ from i=1 to n: (W_i + H_i) * l) - (Σ from i=1 to n: W_i * H_i) = 0
 * </p>
 *
 * <p>
 * with
 * <ul>
 * <li>c: upper bound on the avarage size of a polyomino (given as 100 in the paper based on experiments regarding
 * computation time and quality resulting layout)</li>
 * <li>l: grid step (result of this method)</li>
 * <li>n: number of connected components of the {@link DCGraph}</li>
 * <li>W_i: width of {@link DCComponent} i</li>
 * <li>H_i: height of {@link DCComponent} i</li>
 * </ul>
 * </p>
 *
 * @param graph
 *            input graph to compute optimal step size for
 * @return optimal step size (number of spatial units of the {@link DCGraph} covered by the witdh or height of a
 *         discrete grid cell used for creating {@link DCPolyomino polyominoes})
 */
private double computeCellSize(final DCGraph graph) {
    double sumTerm = 0.0;
    double prodTerm = 0.0;
    Set<DCComponent> comps = graph.getComponents();
    int numOfComps = comps.size();
    for (DCComponent comp : comps) {
        KVector bounds = comp.getDimensionsOfBoundingRectangle();
        double width = bounds.x;
        double height = bounds.y;
        sumTerm += width + height;
        prodTerm += width * height;
    }
    // Numerator of positive solution of quadratic equation (the negative solution is is not interesting for us, as
    // step size should be positive)
    final double four = 4.0;
    double numerator = Math.sqrt(four * upperBound * numOfComps * prodTerm - four * prodTerm + sumTerm * sumTerm) + sumTerm;
    double denominator = 2 * (upperBound * numOfComps - 1.0);
    // Shouldn't happen with reasonable values for parameter "bound", ignore denominator just in case
    if (denominator == 0.0) {
        return numerator;
    }
    return numerator / denominator;
}
Also used : DCComponent(org.eclipse.elk.alg.disco.graph.DCComponent) KVector(org.eclipse.elk.core.math.KVector)

Aggregations

DCComponent (org.eclipse.elk.alg.disco.graph.DCComponent)3 KVector (org.eclipse.elk.core.math.KVector)2 Rectangle2D (java.awt.geom.Rectangle2D)1 DCElement (org.eclipse.elk.alg.disco.graph.DCElement)1 DCExtension (org.eclipse.elk.alg.disco.graph.DCExtension)1 DCPolyomino (org.eclipse.elk.alg.disco.structures.DCPolyomino)1 ElkRectangle (org.eclipse.elk.core.math.ElkRectangle)1