Search in sources :

Example 86 with CyRootNetwork

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;
}
Also used : CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) NetworkImageFactory(org.cytoscape.view.presentation.NetworkImageFactory) CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) Image(java.awt.Image) BufferedImage(java.awt.image.BufferedImage) CyNetworkView(org.cytoscape.view.model.CyNetworkView) Paint(java.awt.Paint) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)86 CyNetwork (org.cytoscape.model.CyNetwork)39 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)38 CyNode (org.cytoscape.model.CyNode)29 CyEdge (org.cytoscape.model.CyEdge)15 CyRow (org.cytoscape.model.CyRow)15 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)15 Test (org.junit.Test)14 ArrayList (java.util.ArrayList)13 CyTable (org.cytoscape.model.CyTable)11 CyNetworkView (org.cytoscape.view.model.CyNetworkView)11 CyGroup (org.cytoscape.group.CyGroup)7 HashSet (java.util.HashSet)6 Dimension (java.awt.Dimension)4 IOException (java.io.IOException)4 CyNetworkManager (org.cytoscape.model.CyNetworkManager)4 Image (java.awt.Image)3 BufferedImage (java.awt.image.BufferedImage)3 CyApplicationManager (org.cytoscape.application.CyApplicationManager)3 CyEventHelper (org.cytoscape.event.CyEventHelper)3