Search in sources :

Example 1 with ReactionCartoonFull

use of cbit.vcell.graph.ReactionCartoonFull in project vcell by virtualcell.

the class ITextWriter method generateDocReactionsImage.

public static BufferedImage generateDocReactionsImage(Model model, Integer width) throws Exception {
    // if (model == null || !isValidResolutionSetting(resolution)) {
    // throw new IllegalArgumentException("Invalid parameters for generating reactions image for  model: " + model.getName());
    // }
    ReactionCartoon rcartoon = new ReactionCartoonFull();
    rcartoon.setModel(model);
    StructureSuite structureSuite = new AllStructureSuite(new Model.Owner() {

        @Override
        public Model getModel() {
            return model;
        }
    });
    rcartoon.setStructureSuite(structureSuite);
    rcartoon.refreshAll();
    // dummy settings to get the real dimensions.
    BufferedImage dummyBufferedImage = new BufferedImage(DEF_IMAGE_WIDTH, DEF_IMAGE_HEIGHT, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D dummyGraphics = (Graphics2D) dummyBufferedImage.getGraphics();
    Dimension prefDim = rcartoon.getPreferedCanvasSize(dummyGraphics);
    dummyGraphics.dispose();
    // double width = prefDim.getWidth();
    // double height = prefDim.getHeight();
    double widthHeightRatio = (double) prefDim.getWidth() / (double) prefDim.getHeight();
    if (width == null) {
        width = ITextWriter.DEF_IMAGE_WIDTH;
    }
    int height = (int) ((double) width / widthHeightRatio);
    // int MAX_IMAGE_HEIGHT = 532;
    // if (width < ITextWriter.DEF_IMAGE_WIDTH) {
    // width = ITextWriter.DEF_IMAGE_WIDTH;
    // }
    // height= height * width/prefDim.getWidth();
    // if (height < ITextWriter.DEF_IMAGE_HEIGHT) {
    // height = ITextWriter.DEF_IMAGE_HEIGHT;
    // } else if (height > MAX_IMAGE_HEIGHT) {
    // height = MAX_IMAGE_HEIGHT;
    // }
    // width= width * height/prefDim.getHeight();
    Dimension newDim = new Dimension((int) width, (int) height);
    rcartoon.getResizeManager().setZoomPercent((int) (100 * width / prefDim.getWidth()));
    BufferedImage bufferedImage = new BufferedImage(newDim.width, newDim.height, BufferedImage.TYPE_3BYTE_BGR);
    Graphics2D g = (Graphics2D) bufferedImage.getGraphics();
    g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    GraphContainerLayoutReactions containerLayout = new GraphContainerLayoutReactions();
    containerLayout.layout(rcartoon, g, prefDim);
    rcartoon.paint(g);
    g.dispose();
    return bufferedImage;
}
Also used : AllStructureSuite(cbit.vcell.graph.structures.AllStructureSuite) StructureSuite(cbit.vcell.graph.structures.StructureSuite) Dimension(java.awt.Dimension) GraphContainerLayoutReactions(cbit.gui.graph.GraphContainerLayoutReactions) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D) ReactionCartoon(cbit.vcell.graph.ReactionCartoon) MathModel(cbit.vcell.mathmodel.MathModel) IndexColorModel(java.awt.image.IndexColorModel) Model(cbit.vcell.model.Model) BioModel(cbit.vcell.biomodel.BioModel) ReactionCartoonFull(cbit.vcell.graph.ReactionCartoonFull) AllStructureSuite(cbit.vcell.graph.structures.AllStructureSuite)

Aggregations

GraphContainerLayoutReactions (cbit.gui.graph.GraphContainerLayoutReactions)1 BioModel (cbit.vcell.biomodel.BioModel)1 ReactionCartoon (cbit.vcell.graph.ReactionCartoon)1 ReactionCartoonFull (cbit.vcell.graph.ReactionCartoonFull)1 AllStructureSuite (cbit.vcell.graph.structures.AllStructureSuite)1 StructureSuite (cbit.vcell.graph.structures.StructureSuite)1 MathModel (cbit.vcell.mathmodel.MathModel)1 Model (cbit.vcell.model.Model)1 Dimension (java.awt.Dimension)1 Graphics2D (java.awt.Graphics2D)1 BufferedImage (java.awt.image.BufferedImage)1 IndexColorModel (java.awt.image.IndexColorModel)1