Search in sources :

Example 1 with Relaxer

use of edu.rpi.graphdrawing.Relaxer in project vcell by virtualcell.

the class WorkflowCartoonTool method layout.

public void layout(String layoutName) throws Exception {
    Blackboard bb = new Blackboard();
    HashMap<String, Shape> nodeShapeMap = new HashMap<String, Shape>();
    // add nodes
    boolean bHasSelections = getGraphModel().getSelectedShape() != null;
    ArrayList<Shape> vcellShapeList = new ArrayList<Shape>();
    for (Shape shape : getGraphModel().getShapes()) {
        vcellShapeList.add(shape);
        edu.rpi.graphdrawing.Node newNode = null;
        if (ShapeUtil.isMovable(shape)) {
            if (!bHasSelections || shape.isSelected()) {
                String shapeIndexStr = "node" + Integer.toString(vcellShapeList.indexOf(shape));
                newNode = bb.addNode(shapeIndexStr);
            }
        }
        // initialize node location to current absolute position
        if (newNode != null) {
            newNode.XY(shape.getSpaceManager().getAbsLoc().x, shape.getSpaceManager().getAbsLoc().y);
            nodeShapeMap.put(newNode.label(), shape);
        }
    }
    for (Shape shape : getGraphModel().getShapes()) {
        if (shape instanceof EdgeShape) {
            EdgeShape eShape = (EdgeShape) shape;
            Shape node1Shape = eShape.getStartShape();
            Shape node2Shape = eShape.getEndShape();
            if (!bHasSelections || (node1Shape.isSelected() && node2Shape.isSelected())) {
                String node1IndexStr = "node" + Integer.toString(vcellShapeList.indexOf(node1Shape));
                String node2IndexStr = "node" + Integer.toString(vcellShapeList.indexOf(node2Shape));
                bb.addEdge(node1IndexStr, node2IndexStr);
            }
        }
    }
    bb.setArea(0, 0, getGraphPane().getWidth(), getGraphPane().getHeight());
    bb.globals.D(20);
    bb.addEmbedder(GraphLayoutManager.OldLayouts.ANNEALER, new Annealer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.CIRCULARIZER, new Circularizer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.CYCLEIZER, new Cycleizer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.FORCEDIRECT, new ForceDirect(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.LEVELLER, new Leveller(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.RANDOMIZER, new Randomizer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.RELAXER, new Relaxer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.STABILIZER, new Stabilizer(bb));
    bb.setEmbedding(layoutName);
    @SuppressWarnings("unchecked") List<Node> nodeList = bb.nodes();
    for (int i = 0; i < nodeList.size(); i++) {
        Node node = nodeList.get(i);
        System.out.println("Node " + node.label() + " @ (" + node.x() + "," + node.y() + ")");
    }
    bb.PreprocessNodes();
    Embedder embedder = bb.embedder();
    embedder.Init();
    for (int i = 0; i < 1000; i++) {
        embedder.Embed();
    }
    bb.removeDummies();
    @SuppressWarnings("unchecked") Vector<Node> nodes = bb.nodes();
    nodeList = nodes;
    // 
    // calculate offset and scaling so that resulting graph fits on canvas
    // 
    double lowX = 100000;
    double highX = -100000;
    double lowY = 100000;
    double highY = -100000;
    for (int i = 0; i < nodeList.size(); i++) {
        Node node = nodeList.get(i);
        lowX = Math.min(lowX, node.x());
        highX = Math.max(highX, node.x());
        lowY = Math.min(lowY, node.y());
        highY = Math.max(highY, node.y());
    }
    double scaleX = getGraphPane().getWidth() / (1.5 * (highX - lowX));
    double scaleY = getGraphPane().getHeight() / (1.5 * (highY - lowY));
    int offsetX = getGraphPane().getWidth() / 6;
    int offsetY = getGraphPane().getHeight() / 6;
    for (int i = 0; i < nodeList.size(); i++) {
        Node node = nodeList.get(i);
        Shape shape = nodeShapeMap.get(node.label());
        Point parentLoc = shape.getParent().getSpaceManager().getAbsLoc();
        shape.getSpaceManager().setAbsLoc(new Point((int) (scaleX * (node.x() - lowX)) + offsetX + parentLoc.x, (int) ((scaleY * (node.y() - lowY)) + offsetY + parentLoc.y)));
        System.out.println("Shape " + shape.getLabel() + " @ " + shape.getSpaceManager().getAbsLoc());
    }
    getGraphPane().repaint();
}
Also used : Randomizer(edu.rpi.graphdrawing.Randomizer) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) NodeShape(cbit.gui.graph.NodeShape) EdgeShape(cbit.gui.graph.EdgeShape) ContainerShape(cbit.gui.graph.ContainerShape) Shape(cbit.gui.graph.Shape) HashMap(java.util.HashMap) Node(edu.rpi.graphdrawing.Node) ArrayList(java.util.ArrayList) Cycleizer(edu.rpi.graphdrawing.Cycleizer) Embedder(edu.rpi.graphdrawing.Embedder) Annealer(edu.rpi.graphdrawing.Annealer) ForceDirect(edu.rpi.graphdrawing.ForceDirect) EdgeShape(cbit.gui.graph.EdgeShape) Circularizer(edu.rpi.graphdrawing.Circularizer) Relaxer(edu.rpi.graphdrawing.Relaxer) Node(edu.rpi.graphdrawing.Node) Point(java.awt.Point) Point(java.awt.Point) Stabilizer(edu.rpi.graphdrawing.Stabilizer) Leveller(edu.rpi.graphdrawing.Leveller) Blackboard(edu.rpi.graphdrawing.Blackboard)

Example 2 with Relaxer

use of edu.rpi.graphdrawing.Relaxer in project vcell by virtualcell.

the class GraphLayoutManager method layoutRPI.

public void layoutRPI(Client client) throws Exception {
    Blackboard bb = new Blackboard();
    HashMap<String, Shape> nodeShapeMap = new HashMap<String, Shape>();
    for (Shape shape : client.getGraphModel().getShapes()) {
        Node newNode = null;
        if (ShapeUtil.isMovable(shape)) {
            newNode = bb.addNode(shape.getLabel());
        }
        // initialize node location to current absolute position
        if (newNode != null) {
            newNode.XY(shape.getSpaceManager().getAbsLoc().x, shape.getSpaceManager().getAbsLoc().y);
            nodeShapeMap.put(newNode.label(), shape);
        }
    }
    for (Shape shape : client.getGraphModel().getShapes()) {
        if (shape instanceof EdgeShape) {
            EdgeShape edgeShape = (EdgeShape) shape;
            Shape startShape = edgeShape.getStartShape();
            Shape endShape = edgeShape.getEndShape();
            if (edgeShape.isDirectedForward()) {
                bb.addEdge(startShape.getLabel(), endShape.getLabel());
            } else {
                bb.addEdge(endShape.getLabel(), startShape.getLabel());
            }
        }
    }
    bb.setArea(0, 0, client.getWidth(), client.getHeight());
    bb.globals.D(20);
    bb.addEmbedder(GraphLayoutManager.OldLayouts.ANNEALER, new Annealer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.CIRCULARIZER, new Circularizer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.CYCLEIZER, new Cycleizer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.FORCEDIRECT, new ForceDirect(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.LEVELLER, new Leveller(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.RANDOMIZER, new Randomizer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.RELAXER, new Relaxer(bb));
    bb.addEmbedder(GraphLayoutManager.OldLayouts.STABILIZER, new Stabilizer(bb));
    bb.setEmbedding(client.getLayoutName());
    @SuppressWarnings("unchecked") List<Node> nodeList = bb.nodes();
    bb.PreprocessNodes();
    Embedder embedder = bb.embedder();
    embedder.Init();
    for (int i = 0; i < 1000; i++) {
        embedder.Embed();
    }
    bb.removeDummies();
    @SuppressWarnings("unchecked") List<Node> nodesRaw = bb.nodes();
    nodeList = nodesRaw;
    for (int i = 0; i < nodeList.size(); i++) {
        Node node = nodeList.get(i);
        Shape shape = nodeShapeMap.get(node.label());
        if (shape != null) {
            shape.setAbsPos((int) node.x(), (int) node.y());
        }
    }
    new StretchToBoundaryLayouter().layout(client);
}
Also used : Randomizer(edu.rpi.graphdrawing.Randomizer) Circularizer(edu.rpi.graphdrawing.Circularizer) HashMap(java.util.HashMap) Relaxer(edu.rpi.graphdrawing.Relaxer) Node(edu.rpi.graphdrawing.Node) Cycleizer(edu.rpi.graphdrawing.Cycleizer) Embedder(edu.rpi.graphdrawing.Embedder) Stabilizer(edu.rpi.graphdrawing.Stabilizer) Annealer(edu.rpi.graphdrawing.Annealer) Leveller(edu.rpi.graphdrawing.Leveller) StretchToBoundaryLayouter(org.vcell.util.graphlayout.StretchToBoundaryLayouter) ForceDirect(edu.rpi.graphdrawing.ForceDirect) Blackboard(edu.rpi.graphdrawing.Blackboard)

Aggregations

Annealer (edu.rpi.graphdrawing.Annealer)2 Blackboard (edu.rpi.graphdrawing.Blackboard)2 Circularizer (edu.rpi.graphdrawing.Circularizer)2 Cycleizer (edu.rpi.graphdrawing.Cycleizer)2 Embedder (edu.rpi.graphdrawing.Embedder)2 ForceDirect (edu.rpi.graphdrawing.ForceDirect)2 Leveller (edu.rpi.graphdrawing.Leveller)2 Node (edu.rpi.graphdrawing.Node)2 Randomizer (edu.rpi.graphdrawing.Randomizer)2 Relaxer (edu.rpi.graphdrawing.Relaxer)2 Stabilizer (edu.rpi.graphdrawing.Stabilizer)2 HashMap (java.util.HashMap)2 ContainerShape (cbit.gui.graph.ContainerShape)1 EdgeShape (cbit.gui.graph.EdgeShape)1 NodeShape (cbit.gui.graph.NodeShape)1 RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)1 Shape (cbit.gui.graph.Shape)1 Point (java.awt.Point)1 ArrayList (java.util.ArrayList)1 StretchToBoundaryLayouter (org.vcell.util.graphlayout.StretchToBoundaryLayouter)1