use of org.cytoscape.model.subnetwork.CyRootNetwork in project clusterMaker2 by RBVI.
the class ViewUtils method createClusterImage.
/**
* Convert a network to an image. This is used by the MCODEResultsPanel.
*
* @param clusterManager the clusterManager (used to get services)
* @param vs the VisualStyle to use
* @param network the network
* @param cluster Input network to convert to an image
* @param height Height that the resulting image should be
* @param width Width that the resulting image should be
* @param layouter Reference to the layout algorithm
* @param layoutNecessary Determinant of cluster size growth or shrinkage, the former requires layout
* @return The resulting image
*/
public static Image createClusterImage(final ClusterManager clusterManager, final VisualStyle vs, final CyNetwork network, final NodeCluster cluster, final int height, final int width, SpringEmbeddedLayouter layouter, boolean layoutNecessary) {
// System.out.println("CCI: inside method");
final CyRootNetwork root = clusterManager.getService(CyRootNetworkManager.class).getRootNetwork(network);
final NetworkImageFactory networkImageFactory = clusterManager.getService(NetworkImageFactory.class);
// need to create a method get the subnetwork for a cluster
final CyNetwork net = cluster.getSubNetwork(network, root, SavePolicy.DO_NOT_SAVE);
// System.out.println("CCI: after getting root and network ");
// Progress reporters.
// There are three basic tasks, the progress of each is calculated and then combined
// using the respective weighting to get an overall progress global progress
// setting up the nodes and edges is deemed as 25% of the whole task
int weightSetupNodes = 20;
int weightSetupEdges = 5;
// layout it is 70%
double weightLayout = 75.0;
double goalTotal = weightSetupNodes + weightSetupEdges;
if (layoutNecessary) {
goalTotal += weightLayout;
}
// keeps track of progress as a percent of the totalGoal
double progress = 0;
// System.out.println("CCI: after getClusterStyle");
final CyNetworkView clusterView = createNetworkView(clusterManager, net, vs);
// System.out.println("CCI: after createNetworkView");
clusterView.setVisualProperty(NETWORK_WIDTH, new Double(width));
clusterView.setVisualProperty(NETWORK_HEIGHT, new Double(height));
for (View<CyNode> nv : clusterView.getNodeViews()) {
/*
if (interrupted) {
//logger.debug("Interrupted: Node Setup");
// before we short-circuit the method we reset the interruption so that the method can run without
// problems the next time around
if (layouter != null) layouter.resetDoLayout();
resetLoading();
return null;
}
*/
// Node position
final double x;
final double y;
// first prevents the program from throwing a null pointer exception in the second condition)
if (cluster.getView() != null && cluster.getView().getNodeView(nv.getModel()) != null) {
// If it does, then we take the layout position that was already generated for it
x = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_X_LOCATION);
y = cluster.getView().getNodeView(nv.getModel()).getVisualProperty(NODE_Y_LOCATION);
} else {
// Otherwise, randomize node positions before layout so that they don't all layout in a line
// (so they don't fall into a local minimum for the SpringEmbedder)
// If the SpringEmbedder implementation changes, this code may need to be removed
// size is small for many default drawn graphs, thus +100
x = (clusterView.getVisualProperty(NETWORK_WIDTH) + 100) * Math.random();
y = (clusterView.getVisualProperty(NETWORK_HEIGHT) + 100) * Math.random();
if (!layoutNecessary) {
goalTotal += weightLayout;
progress /= (goalTotal / (goalTotal - weightLayout));
layoutNecessary = true;
}
}
nv.setVisualProperty(NODE_X_LOCATION, x);
nv.setVisualProperty(NODE_Y_LOCATION, y);
}
if (layoutNecessary) {
if (layouter == null) {
layouter = new SpringEmbeddedLayouter();
}
layouter.setGraphView(clusterView);
// The doLayout method should return true if the process completes without interruption
if (!layouter.doLayout(weightLayout, goalTotal, progress)) {
// Otherwise, if layout is not completed, set the interruption to false, and return null, not an image
return null;
}
}
// final Image image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
final Image image = networkImageFactory.createImage(clusterView, width, height);
return image;
}
Aggregations