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);
}
}
}
}
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());
}
}
}
use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.
the class StretchToBoundaryLayouter method layout.
public void layout(ContainedGraph graph, Container container) {
Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
if (!containerNodes.isEmpty()) {
Iterator<? extends Node> nodeIter = containerNodes.iterator();
Node firstNode = nodeIter.next();
double xMin = firstNode.getX();
double yMin = firstNode.getY();
double xMax = firstNode.getX() + firstNode.getWidth();
double yMax = firstNode.getY() + firstNode.getHeight();
if (containerNodes.size() > 2) {
while (nodeIter.hasNext()) {
Node node = nodeIter.next();
double xMinNode = node.getX();
double yMinNode = node.getY();
double xMaxNode = node.getX() + node.getWidth();
double yMaxNode = node.getY() + node.getHeight();
if (xMinNode < xMin) {
xMin = xMinNode;
}
if (yMinNode < yMin) {
yMin = yMinNode;
}
if (xMaxNode > xMax) {
xMax = xMaxNode;
}
if (yMaxNode > yMax) {
yMax = yMaxNode;
}
}
double xRange = xMax - xMin;
if (xRange > 0) {
for (Node node : containerNodes) {
double spaceNew = container.getWidth() - node.getWidth();
double spaceOld = xRange - node.getWidth();
if (spaceNew >= 0) {
node.setX(container.getX() + ((node.getX() - xMin) * spaceNew) / spaceOld);
}
}
}
double yRange = yMax - yMin;
if (yRange > 0) {
for (Node node : containerNodes) {
double spaceNew = container.getHeight() - node.getHeight();
double spaceOld = yRange - node.getHeight();
if (spaceNew >= 0) {
node.setY(container.getY() + (int) (((node.getY() - yMin) * spaceNew) / spaceOld));
}
}
}
} else {
for (Node node : containerNodes) {
if (node.getX() < container.getX()) {
node.setX(container.getX());
} else {
double xMaxNode = container.getNodeMaxX(node);
if (node.getX() > xMaxNode) {
node.setX(xMaxNode);
}
}
if (node.getY() < container.getY()) {
node.setY(container.getY());
} else {
double yMaxNode = container.getNodeMaxY(node);
if (node.getY() > yMaxNode) {
node.setY(yMaxNode);
}
}
}
}
}
}
use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.
the class GenericLogicGraphLayouter method getOrAddEdge.
protected static void getOrAddEdge(ContainerContext context, Edge edge) {
Node node1 = edge.getNode1();
Node node2 = edge.getNode2();
Container container = context.getContainer();
if (container.equals(node1.getContainer()) && container.equals(node2.getContainer())) {
GlgGraphEdge glgEdge = context.getEdgeMap().get(edge);
if (glgEdge == null) {
GlgGraphNode glgNode1 = getOrAddInternalNode(context, node1);
GlgGraphNode glgNode2 = getOrAddInternalNode(context, node2);
if (!context.getGlgGraph().NodesConnected(glgNode1, glgNode2)) {
glgEdge = context.getGlgGraph().AddEdge(glgNode1, glgNode2, edge);
context.getEdgeMap().put(edge, glgEdge);
}
}
} else if (container.equals(node1.getContainer())) {
GlgGraphEdge glgEdge = context.getEdgeMap().get(edge);
if (glgEdge == null) {
GlgGraphNode glgNode1 = getOrAddInternalNode(context, node1);
GlgGraphNode glgNodeExternal2 = getOrAddExternalNode(context, node2, node1);
if (!context.getGlgGraph().NodesConnected(glgNode1, glgNodeExternal2)) {
glgEdge = context.getGlgGraph().AddEdge(glgNode1, glgNodeExternal2, edge);
context.getEdgeMap().put(edge, glgEdge);
}
}
} else if (container.equals(node2.getContainer())) {
GlgGraphEdge glgEdge = context.getEdgeMap().get(edge);
if (glgEdge == null) {
GlgGraphNode glgNodeExternal1 = getOrAddExternalNode(context, node1, node2);
GlgGraphNode glgNode2 = getOrAddInternalNode(context, node2);
if (!context.getGlgGraph().NodesConnected(glgNodeExternal1, glgNode2)) {
glgEdge = context.getGlgGraph().AddEdge(glgNode2, glgNodeExternal1, edge);
context.getEdgeMap().put(edge, glgEdge);
}
}
}
}
use of org.vcell.util.graphlayout.ContainedGraph.Node in project vcell by virtualcell.
the class ShootAndCutMinimizer method minimize.
public void minimize(EnergySum energySum) {
ContainedGraph graph = energySum.getGraph();
for (Node node : graph.getNodes()) {
double shiftX = ContainedGraphUtil.getRandomShiftX(node, random);
double shiftY = ContainedGraphUtil.getRandomShiftY(node, random);
while (Math.abs(shiftX) + Math.abs(shiftY) > 0.3) {
NodesShift nodesShift = new NodesShift.SingleNode(graph, node, shiftX, shiftY);
if (energySum.getDifference(nodesShift) < 0) {
nodesShift.apply();
break;
}
shiftX = (1 - cut) * shiftX;
shiftY = (1 - cut) * shiftY;
}
}
}
Aggregations