Search in sources :

Example 1 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class VCellGraphToContainedGraphMapper method updateContainedGraphFromVCellGraph.

public void updateContainedGraphFromVCellGraph() {
    containedGraph.clear();
    for (Shape shape : vcellGraph.getShapes()) {
        GraphContainerLayout containerLayout = vcellGraph.getContainerLayout();
        if (containerLayout.isContainerForAutomaticLayout(shape)) {
            Rectangle boundary = containerLayout.getBoundaryForAutomaticLayout(shape);
            Container container = containedGraph.addContainer(shape, boundary.getX(), boundary.getY(), boundary.getWidth(), boundary.getHeight());
            for (Shape child : shape.getChildren()) {
                if (containerLayout.isNodeForAutomaticLayout(child)) {
                    Point absLoc = child.getSpaceManager().getAbsLoc();
                    Dimension size = child.getSpaceManager().getSize();
                    containedGraph.addNode(child, container, absLoc.getX(), absLoc.getY(), size.getWidth(), size.getHeight());
                }
            }
        }
    }
    for (Shape shape : vcellGraph.getShapes()) {
        if (shape instanceof EdgeShape) {
            EdgeShape edgeShape = (EdgeShape) shape;
            Node nodeStart = containedGraph.getNode(edgeShape.getStartShape());
            Node nodeEnd = containedGraph.getNode(edgeShape.getEndShape());
            if (nodeStart != null && nodeEnd != null) {
                containedGraph.addEdge(edgeShape, nodeStart, nodeEnd);
            }
        }
    }
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) Node(org.vcell.util.graphlayout.ContainedGraph.Node) Rectangle(java.awt.Rectangle) Point(java.awt.Point) Dimension(java.awt.Dimension)

Example 2 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class VCellGraphToContainedGraphMapper method updateVCellGraphFromContainedGraph.

public void updateVCellGraphFromContainedGraph() {
    for (Node node : containedGraph.getNodes()) {
        Object object = node.getObject();
        if (object instanceof Shape) {
            Shape shape = (Shape) object;
            shape.getSpaceManager().setAbsLoc((int) node.getX(), (int) node.getY());
        }
    }
}
Also used : Node(org.vcell.util.graphlayout.ContainedGraph.Node)

Example 3 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class SimpleElipticalLayouter method layout.

// 
// 
// 
// protected static JungNode getOrAddInternalNode(ContainerContext cc, Node node) {
// JungNode glgNode = cc.getIntNodeMap().get(node);
// if(glgNode == null) {
// glgNode = new JungNode(node, false);	// internal
// cc.jungGraph.addVertex(glgNode);
// cc.intNodeMap.put(node, glgNode);
// double posX = node.getCenterX();
// double posY = node.getCenterY();
// cc.jungLayout.setLocation(glgNode, posX, posY);	// TODO: here
// }
// return glgNode;
// }
// 
// // inode - internal, already dealt with
// // enode - our external candidate
// protected static JungNode getOrAddExternalNode(ContainerContext cc, Node enode, Node inode) {
// JungNode glgNode = cc.getExtNodeMap().get(enode);
// if(glgNode == null) {
// glgNode = new JungNode(enode, true);	// external
// cc.jungGraph.addVertex(glgNode);
// cc.extNodeMap.put(enode, glgNode);
// double posX = enode.getCenterX() - inode.getCenterX();
// double posY = enode.getCenterY() - inode.getCenterY();
// cc.jungLayout.setLocation(glgNode, posX, posY);			// TODO: here
// cc.jungLayout.lock(glgNode, true);
// }
// return glgNode;
// }
// 
// protected static void getOrAddEdge(ContainerContext cc, Edge edge) {
// Node node1 = edge.getNode1();
// Node node2 = edge.getNode2();
// Container container = cc.getContainer();
// if(container.equals(node1.getContainer()) && container.equals(node2.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNode1 = getOrAddInternalNode(cc, node1);
// JungNode glgNode2 = getOrAddInternalNode(cc, node2);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode1, glgNode2);
// cc.edgeMap.put(edge, jungEdge);
// }
// } else if(container.equals(node1.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNode1 = getOrAddInternalNode(cc, node1);
// JungNode glgNodeExternal2 = getOrAddExternalNode(cc, node2, node1);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode1, glgNodeExternal2);
// cc.edgeMap.put(edge, jungEdge);
// }
// } else if(container.equals(node2.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNodeExternal1 = getOrAddExternalNode(cc, node1, node2);
// JungNode glgNode2 = getOrAddInternalNode(cc, node2);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode2, glgNodeExternal1);
// cc.edgeMap.put(edge, jungEdge);
// }
// }
// }
@Override
public void layout(ContainedGraph graph) {
    for (Container container : graph.getContainers()) {
        // ContainerContext containerContext = new ContainerContext(container);
        // int edgeCount = 0;
        // ContainerContext containerContext = new ContainerContext(container);
        // DirectedSparseMultigraph<String, Number> dag = new DirectedSparseMultigraph<>();
        // Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
        // Map<String, Node> speciesNodesMap = new HashMap<>();
        // ReactionContainerShape rcs = (ReactionContainerShape)container.getObject();
        // Structure structure = rcs.getStructure();
        // for(Node node : containerNodes) {
        // if(node.object instanceof SpeciesContextShape) {
        // SpeciesContextShape scs = (SpeciesContextShape)node.object;
        // SpeciesContext sc = (SpeciesContext)(scs.getModelObject());
        // dag.addVertex(sc.getName());
        // speciesNodesMap.put(sc.getName(), node);
        // }
        // }
        // for(Node node : containerNodes) {
        // if(node.object instanceof ReactionStepShape) {
        // ReactionStepShape rss = (ReactionStepShape)node.object;
        // ReactionStep rs = (ReactionStep)(rss.getModelObject());
        // for(ReactionParticipant rp1 : rs.getReactionParticipants()) {
        // for(ReactionParticipant rp2 : rs.getReactionParticipants()) {
        // if(structure == rp1.getStructure() && structure == rp2.getStructure()) {
        // if(rp1 instanceof Reactant && rp2 instanceof Product) {		// edges from reactants to products
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Catalyst && rp2 instanceof Reactant) {	// edges from catalysts to reactants
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Reactant && rp2 instanceof Reactant && rp1 != rp2) {	// edges between reactants
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // dag.addEdge(edgeCount, rp2.getName(), rp1.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Product && rp2 instanceof Product && rp1 != rp2) {	// edges between products
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // dag.addEdge(edgeCount, rp2.getName(), rp1.getName());
        // edgeCount++;
        // }
        // }
        // }
        // }
        // }
        // }
        // SpringLayout<String, Number> layout = new SpringLayout<String, Number>(dag);
        // layout.setSize(new Dimension((int)container.width,(int)container.height));
        // 
        // for(String v : dag.getVertices()) {
        // Node node = speciesNodesMap.get(v);
        // layout.setLocation(v, node.getCenterX(), node.getCenterY());
        // }
        // 
        // int step = 0;
        // while (!springIterate(layout) && step < 1000) {
        // step++;
        // }
        // 
        // // position the nodes on the new locations
        // for(String v : dag.getVertices()) {
        // Node node = speciesNodesMap.get(v);
        // double x = layout.getX(v);
        // double y = layout.getY(v);
        // node.setCenter(x, y);
        // }
        // 
        // // place all the reaction nodes in the center of mass of its reactants
        // for(Node node : containerNodes) {
        // if(node.object instanceof ReactionStepShape) {
        // int count = 0;
        // double x = 0;
        // double y = 0;
        // ReactionStepShape rss = (ReactionStepShape)node.object;
        // ReactionStep rs = (ReactionStep)(rss.getModelObject());
        // for(ReactionParticipant rp : rs.getReactionParticipants()) {
        // if(structure == rp.getStructure()) {
        // x += layout.getX(rp.getName());
        // y += layout.getY(rp.getName());
        // count++;
        // } else {		// reactant is in another structure
        // x += 5;		// just shift it a little
        // y += 5;
        // // TODO: make big correction as if it's far away to the left or to the right
        // // depending on the order of structures in the diagram
        // count++;
        // }
        // }
        // if(count > 0) {
        // node.setCenter(x/count, y/count);
        // }
        // }
        // }
        double centerX = container.getX() + container.getWidth() / 2;
        double centerY = container.getY() + container.getHeight() / 2;
        double quartaxisX = container.getWidth() / 3;
        double quartaxisY = container.getHeight() / 3;
        double semiaxisX = container.getWidth() / 2;
        double semiaxisY = container.getHeight() / 2;
        Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
        int nNodes = containerNodes.size();
        int iNode = 0;
        for (Node node : containerNodes) {
            if (node.object instanceof SpeciesContextShape || node.object instanceof RuleParticipantSignatureDiagramShape) {
                double angle = 2 * Math.PI * (((double) iNode) / ((double) nNodes));
                node.setCenter(centerX + quartaxisX * Math.cos(angle), centerY + quartaxisY * Math.sin(angle));
            } else if (node.object instanceof ReactionStepShape || node.object instanceof ReactionRuleDiagramShape) {
                double angle = 2 * Math.PI * (((double) iNode) / ((double) nNodes));
                node.setCenter(centerX + semiaxisX * Math.cos(angle), centerY + semiaxisY * Math.sin(angle));
            }
            ++iNode;
        }
    }
    stretchLayouter.layout(graph);
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) Node(org.vcell.util.graphlayout.ContainedGraph.Node) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape)

Example 4 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class AllNodePairsEnergyTermFactory method generateTerms.

public Set<EnergyTerm> generateTerms(ContainedGraph graph) {
    Set<SetOfTwo<Node>> nodePairs = new HashSet<SetOfTwo<Node>>();
    for (Node node1 : graph.getNodes()) {
        for (Node node2 : graph.getNodes()) {
            if (node1 != node2 && (acrossContainers || node1.getContainer() == node2.getContainer())) {
                SetOfTwo<Node> nodePair = new SetOfTwo<Node>(node1, node2);
                if (!nodePairs.contains(nodePair)) {
                    nodePairs.add(nodePair);
                }
            }
        }
    }
    HashSet<EnergyTerm> terms = new HashSet<EnergyTerm>();
    for (SetOfTwo<Node> nodePair : nodePairs) {
        terms.add(new EnergyTerm.Default(new ListOfTwo<Node>(nodePair.getElement1(), nodePair.getElement2()), function));
    }
    return terms;
}
Also used : EnergyTerm(org.vcell.util.graphlayout.energybased.EnergySum.EnergyTerm) SetOfTwo(org.sbpax.util.sets.SetOfTwo) ListOfTwo(org.vcell.sybil.util.lists.ListOfTwo) Node(org.vcell.util.graphlayout.ContainedGraph.Node) HashSet(java.util.HashSet)

Example 5 with Node

use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.

the class EdgeTugLayouter method layout.

@Override
public void layout(ContainedGraph graph) {
    for (Node node : graph.getNodes()) {
        node.move(random.nextInt(3) - 1, random.nextInt(3) - 1);
        Collection<? extends Edge> nodeEdges = graph.getNodeEdges(node);
        for (Edge edge : nodeEdges) {
            Node node2 = edge.getNode1().equals(node) ? edge.getNode2() : edge.getNode1();
            node.move(Math.signum(node2.getCenterX() - node.getCenterX()), Math.signum(node2.getCenterY() - node.getCenterY()));
        }
        List<Node> closestNodes = new ArrayList<Node>();
        int closestNodesCount = nodeEdges.size();
        if (closestNodesCount > 0) {
            for (Node node2 : graph.getNodes()) {
                if (closestNodes.size() < closestNodesCount) {
                    closestNodes.add(node2);
                } else if (distanceSquared(node, node2) < distanceSquared(node, closestNodes.get(closestNodesCount - 1))) {
                    closestNodes.set(closestNodesCount - 1, node2);
                }
                for (int i = closestNodes.size() - 1; i > 0; --i) {
                    if (distanceSquared(node, closestNodes.get(i)) < distanceSquared(node, closestNodes.get(i - 1))) {
                        Collections.swap(closestNodes, i, i - 1);
                    } else {
                        break;
                    }
                }
            }
            for (Node closeNode : closestNodes) {
                node.move(Math.signum(node.getCenterX() - closeNode.getCenterX()), Math.signum(node.getCenterY() - closeNode.getCenterY()));
            }
        }
    }
    stretchLayouter.layout(graph);
}
Also used : Node(org.vcell.util.graphlayout.ContainedGraph.Node) ArrayList(java.util.ArrayList) Edge(org.vcell.util.graphlayout.ContainedGraph.Edge)

Aggregations

Node (org.vcell.util.graphlayout.ContainedGraph.Node)11 Container (org.vcell.util.graphlayout.ContainedGraph.Container)5 ContainedGraph (org.vcell.util.graphlayout.ContainedGraph)2 Edge (org.vcell.util.graphlayout.ContainedGraph.Edge)2 NodesShift (org.vcell.util.graphlayout.NodesShift)2 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)1 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)1 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)1 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)1 Dimension (java.awt.Dimension)1 Point (java.awt.Point)1 Rectangle (java.awt.Rectangle)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 SetOfTwo (org.sbpax.util.sets.SetOfTwo)1 ListOfTwo (org.vcell.sybil.util.lists.ListOfTwo)1 Vector2D (org.vcell.util.geometry2d.Vector2D)1 EnergyTerm (org.vcell.util.graphlayout.energybased.EnergySum.EnergyTerm)1