Search in sources :

Example 6 with PlotData

use of cbit.plot.PlotData in project vcell by virtualcell.

the class DisplayImageOp method displayImage.

public void displayImage(final Image image, String title, WindowListener listener) {
    final ImagePlaneManagerPanel imagePanel = new ImagePlaneManagerPanel();
    double[] doublePixels = image.getDoublePixels();
    double minPixel = Double.MAX_VALUE;
    double maxPixel = -Double.MAX_VALUE;
    for (int i = 0; i < doublePixels.length; i++) {
        double pixel = doublePixels[i];
        doublePixels[i] = pixel;
        minPixel = Math.min(minPixel, pixel);
        maxPixel = Math.max(maxPixel, pixel);
    }
    Range newRange = new Range(minPixel, maxPixel);
    SourceDataInfo source = new SourceDataInfo(SourceDataInfo.RAW_VALUE_TYPE, doublePixels, image.getExtent(), image.getOrigin(), newRange, 0, image.getNumX(), 1, image.getNumY(), image.getNumX(), image.getNumZ(), image.getNumX() * image.getNumY());
    imagePanel.setDisplayAdapterServicePanelVisible(true);
    imagePanel.setCurveValueProvider(new CurveValueProvider() {

        @Override
        public void curveAdded(Curve curve) {
            System.out.println("called curveAdded(" + curve + "), do nothing for now");
        }

        @Override
        public void curveRemoved(Curve curve) {
            System.out.println("called curveRemoved(" + curve + ")");
        }

        @Override
        public String getCurveValue(CurveSelectionInfo csi) {
            System.out.println("called getCurveValue(CurveSelectionInfo " + csi);
            return null;
        }

        @Override
        public CurveSelectionInfo getInitalCurveSelection(int tool, Coordinate wc) {
            System.out.println("called getInitialCurveSelection(tool=" + tool + ", coord=" + wc + ")");
            return null;
        }

        @Override
        public boolean isAddControlPointOK(int tool, Coordinate wc, Curve addedToThisCurve) {
            System.out.println("called isAddControlPointOK");
            return true;
        }

        @Override
        public boolean providesInitalCurve(int tool, Coordinate wc) {
            System.out.println("called providesInitialCurve(tool=" + tool + " (TOOL_LINE=" + CurveEditorTool.TOOL_LINE + "), coord=" + wc);
            return false;
        }

        @Override
        public void setDescription(Curve curve) {
            System.out.println("called setDescription(" + curve + ")");
            curve.setDescription(CurveValueProvider.DESCRIPTION_VOLUME);
        }

        @Override
        public CurveSelectionInfo findChomboCurveSelectionInfoForPoint(CoordinateIndex ci) {
            System.out.println("called find ChomboCurveSelectionInfoForPoint(coord=" + ci + ")");
            return null;
        }
    });
    DisplayAdapterService das = imagePanel.getDisplayAdapterServicePanel().getDisplayAdapterService();
    das.setValueDomain(null);
    das.addColorModelForValues(DisplayAdapterService.createGrayColorModel(), DisplayAdapterService.createGraySpecialColors(), DisplayAdapterService.GRAY);
    das.addColorModelForValues(DisplayAdapterService.createBlueRedColorModel(), DisplayAdapterService.createBlueRedSpecialColors(), DisplayAdapterService.BLUERED);
    das.setActiveColorModelID(DisplayAdapterService.BLUERED);
    final JFrame jframe = new JFrame();
    jframe.setTitle(title);
    JPanel panel = new JPanel();
    panel.setLayout(new GridBagLayout());
    GridBagConstraints imageConstraints = new GridBagConstraints();
    imageConstraints.gridx = 0;
    imageConstraints.gridy = 0;
    imageConstraints.weightx = 1.0;
    imageConstraints.weighty = 1.0;
    imageConstraints.fill = GridBagConstraints.BOTH;
    panel.add(imagePanel, imageConstraints);
    JButton plotButton = new JButton("plot");
    plotButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Curve curve = imagePanel.getCurveRenderer().getSelection().getCurve();
                VariableType variableType = VariableType.VOLUME;
                Curve samplerCurve = curve.getSampledCurve();
                samplerCurve.setDescription(curve.getDescription());
                VCImage vcImage = new VCImageUncompressed(null, new byte[image.getISize().getXYZ()], image.getExtent(), image.getISize().getX(), image.getISize().getY(), image.getISize().getZ());
                int dimension = 1 + (image.getISize().getY() > 0 ? 1 : 0) + (image.getISize().getZ() > 0 ? 1 : 0);
                RegionImage regionImage = new RegionImage(vcImage, dimension, image.getExtent(), image.getOrigin(), RegionImage.NO_SMOOTHING);
                CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(image.getOrigin(), image.getExtent(), image.getISize(), regionImage);
                SpatialSelectionVolume ssVolume = new SpatialSelectionVolume(new CurveSelectionInfo(samplerCurve), variableType, mesh);
                String varName = "var";
                SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[] { new VolVariable(varName, null) };
                PlotData plotData = getLineScan(ssVolume, image, mesh);
                PlotPane plotPane = new PlotPane();
                DataSymbolMetadataResolver resolver = null;
                Plot2D plot2D = new Plot2D(symbolTableEntries, resolver, new String[] { varName }, new PlotData[] { plotData }, new String[] { "Values along curve", "Distance (\u00b5m)", "[" + varName + "]" });
                plotPane.setPlot2D(plot2D);
                DialogUtils.showComponentCloseDialog(jframe, plotPane, "plot");
            } catch (ImageException | IOException | DataAccessException | MathException e1) {
                e1.printStackTrace();
            }
        }
    });
    GridBagConstraints plotButtonConstraints = new GridBagConstraints();
    plotButtonConstraints.gridx = 0;
    plotButtonConstraints.gridy = 1;
    panel.add(plotButton, plotButtonConstraints);
    jframe.getContentPane().add(panel);
    jframe.setSize(500, 500);
    jframe.addWindowListener(listener);
    jframe.setVisible(true);
    imagePanel.setSourceDataInfo(source);
}
Also used : DisplayAdapterService(cbit.image.DisplayAdapterService) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) ImagePlaneManagerPanel(cbit.image.gui.ImagePlaneManagerPanel) JButton(javax.swing.JButton) VCImage(cbit.image.VCImage) SourceDataInfo(cbit.image.SourceDataInfo) CoordinateIndex(org.vcell.util.CoordinateIndex) JFrame(javax.swing.JFrame) PlotData(cbit.plot.PlotData) DataSymbolMetadataResolver(cbit.vcell.solver.SimulationModelInfo.DataSymbolMetadataResolver) VariableType(cbit.vcell.math.VariableType) VolVariable(cbit.vcell.math.VolVariable) Curve(cbit.vcell.geometry.Curve) VCImageUncompressed(cbit.image.VCImageUncompressed) Range(org.vcell.util.Range) CartesianMesh(cbit.vcell.solvers.CartesianMesh) CurveValueProvider(cbit.vcell.simdata.gui.CurveValueProvider) ActionListener(java.awt.event.ActionListener) Coordinate(org.vcell.util.Coordinate) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) RegionImage(cbit.vcell.geometry.RegionImage) PlotPane(cbit.plot.gui.PlotPane) Plot2D(cbit.plot.Plot2D) CurveSelectionInfo(cbit.vcell.geometry.CurveSelectionInfo)

Example 7 with PlotData

use of cbit.plot.PlotData in project vcell by virtualcell.

the class DisplayPlotOp method displayPlot.

public void displayPlot(RowColumnResultSet rowColumnResultSet, String title, WindowListener listener) throws ExpressionException {
    JFrame frame = new javax.swing.JFrame();
    PlotPane aPlotPane;
    aPlotPane = new PlotPane();
    frame.setContentPane(aPlotPane);
    frame.setSize(aPlotPane.getSize());
    if (listener != null) {
        frame.addWindowListener(listener);
    }
    frame.setTitle(title);
    frame.setVisible(true);
    java.awt.Insets insets = frame.getInsets();
    frame.setSize(frame.getWidth() + insets.left + insets.right, frame.getHeight() + insets.top + insets.bottom);
    frame.setVisible(true);
    int dataColumnCount = rowColumnResultSet.getDataColumnCount();
    PlotData[] plotDatas = new PlotData[dataColumnCount - 1];
    String[] labels = new String[dataColumnCount - 1];
    double[] time = rowColumnResultSet.extractColumn(0);
    for (int i = 0; i < dataColumnCount - 1; i++) {
        double[] yArray = rowColumnResultSet.extractColumn(i + 1);
        plotDatas[i] = new PlotData(time, yArray);
        labels[i] = rowColumnResultSet.getColumnDescriptions(i + 1).getName();
    }
    Plot2D plot2D = new Plot2D(null, null, labels, plotDatas);
    aPlotPane.setPlot2D(plot2D);
}
Also used : PlotData(cbit.plot.PlotData) JFrame(javax.swing.JFrame) PlotPane(cbit.plot.gui.PlotPane) Plot2D(cbit.plot.Plot2D)

Example 8 with PlotData

use of cbit.plot.PlotData in project vcell by virtualcell.

the class Plot2DPanel method pointerMoved.

/**
 * Comment
 */
private void pointerMoved(java.awt.event.MouseEvent mouseEvent) {
    if (!getShowCrosshair() || plotDatas == null || plotDatas.length == 0) {
        return;
    }
    Point point = mouseEvent.getPoint();
    Point nodePoint = null;
    Graphics2D g = (Graphics2D) getGraphics();
    g.setColor(Color.white);
    g.setXORMode(getBackground());
    g.setStroke(lineBS_20);
    int index = getCurrentPlotIndex();
    PlotData plotData = null;
    try {
        if (index >= 0) {
            plotData = plotDatas[index];
        }
    } catch (IndexOutOfBoundsException exc) {
    // ignore - we probably don't have any visible plot, so plotData should stay null;
    }
    if (plotData != null) {
        int i = 0;
        while (i < plotData.getSize() && nodes[index].getPoints()[i].getX() < point.getX()) i++;
        if (i == plotData.getSize()) {
            i--;
        } else {
            if (i > 0) {
                if (nodes[index].getPoints()[i].getX() - point.getX() > point.getX() - nodes[index].getPoints()[i - 1].getX()) {
                    i--;
                }
            }
        }
        nodePoint = new Point((int) nodes[index].getPoints()[i].getX(), (int) nodes[index].getPoints()[i].getY());
        getStatusLabel().setText(snf.format(plotData.getIndependent()[i]) + ", " + snf.format(plotData.getDependent()[i]));
        if (getSnapToNodes()) {
            point = nodePoint;
        }
    } else {
        getStatusLabel().setText(" ");
    }
    if (!point.equals(getLastPoint())) {
        if (drawn) {
            drawCrossHair(g, getLastPoint());
        }
        drawCrossHair(g, point);
        setLastPoint(point);
        drawn = true;
    }
}
Also used : PlotData(cbit.plot.PlotData) Point(java.awt.Point) Point(java.awt.Point) Paint(java.awt.Paint) Graphics2D(java.awt.Graphics2D)

Example 9 with PlotData

use of cbit.plot.PlotData in project vcell by virtualcell.

the class Plot2DPanel method getSamplePlot2D.

public static Plot2D getSamplePlot2D() {
    PlotData plotData1 = getSamplePlotData();
    int size = 30;
    double offset = 20;
    double[] xArray = new double[size];
    double[] yArray = new double[size];
    double w = 4 * Math.PI / size;
    for (int i = 0; i < size; i++) {
        xArray[i] = w * i;
        yArray[i] = 5 * i - offset;
    }
    PlotData plotData2 = new PlotData(xArray, yArray);
    xArray = new double[size];
    yArray = new double[size];
    for (int i = 0; i < size; i++) {
        xArray[i] = w * i;
        yArray[i] = 300 - Math.pow(i - offset, 2);
    }
    PlotData plotData3 = new PlotData(xArray, yArray);
    return new Plot2D(null, null, new String[] { "plot one", "plot two", "plot three" }, new PlotData[] { plotData1, plotData2, plotData3 }, new String[] { "title", "X Data", "Y Data" }, new boolean[] { true, false, true });
}
Also used : PlotData(cbit.plot.PlotData) Plot2D(cbit.plot.Plot2D) Point(java.awt.Point) Paint(java.awt.Paint)

Example 10 with PlotData

use of cbit.plot.PlotData in project vcell by virtualcell.

the class PDEDataViewer method showSpatialPlot.

/**
 * Comment
 */
private void showSpatialPlot() {
    // check selections
    final SpatialSelection[] sl = getPDEDataContextPanel1().fetchSpatialSelections(false, true);
    if (sl == null) {
        PopupGenerator.showErrorDialog(this, "Nothing selected!");
        return;
    }
    for (int i = 0; i < sl.length; i++) {
        if (sl[i].isPoint()) {
            PopupGenerator.showErrorDialog(this, "One or more selections are single points - no spatial plot will be produced for those selections");
            break;
        }
    }
    final String varName = getPdeDataContext().getVariableName();
    final double timePoint = getPdeDataContext().getTimePoint();
    final SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[1];
    if (getSimulation() != null && getSimulation().getMathDescription() != null) {
        symbolTableEntries[0] = getSimulation().getMathDescription().getEntry(varName);
    }
    if (symbolTableEntries[0] == null) {
        // TODO domain
        Domain domain = null;
        symbolTableEntries[0] = new VolVariable(varName, domain);
    }
    AsynchClientTask task1 = new AsynchClientTask("Retrieving spatial series for variable '" + varName, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // get plots, ignoring points
            PlotData[] plotDatas = new PlotData[sl.length];
            for (int i = 0; i < sl.length; i++) {
                PlotData plotData = null;
                if (getPdeDataContext() instanceof PDEDataViewerPostProcess.PostProcessDataPDEDataContext) {
                    SpatialSelectionVolume ssVolume = (SpatialSelectionVolume) sl[i];
                    SpatialSelection.SSHelper ssvHelper = ssVolume.getIndexSamples(0.0, 1.0);
                    ssvHelper.initializeValues_VOLUME(getPdeDataContext().getDataValues());
                    double[] values = ssvHelper.getSampledValues();
                    plotData = new PlotData(ssvHelper.getWorldCoordinateLengths(), values);
                } else {
                    plotData = getPdeDataContext().getLineScan(varName, timePoint, sl[i]);
                }
                plotDatas[i] = plotData;
            }
            hashTable.put("plotDatas", plotDatas);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("Showing spatial plot for variable" + varName, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            PlotData[] plotDatas = (PlotData[]) hashTable.get("plotDatas");
            for (PlotData plotData : plotDatas) {
                if (plotData != null) {
                    PlotPane plotPane = new PlotPane();
                    Plot2D plot2D = new Plot2D(symbolTableEntries, getSimulationModelInfo().getDataSymbolMetadataResolver(), new String[] { varName }, new PlotData[] { plotData }, new String[] { "Values along curve", "Distance (\u00b5m)", "[" + varName + "]" });
                    plotPane.setPlot2D(plot2D);
                    String title = createContextTitle(PDEDataViewer.this.isPostProcess(), "Spatial Plot:'" + varName + "' ", getPdeDataContext(), getSimulationModelInfo(), getSimulation());
                    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
                    ChildWindow childWindow = childWindowManager.addChildWindow(plotPane, plotPane, title);
                    childWindow.setIsCenteredOnParent();
                    childWindow.pack();
                    childWindow.show();
                // System.out.println("Spatial plot requesting focus.  Result is: "+childWindow.requestFocusInWindow());
                }
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
Also used : PlotData(cbit.plot.PlotData) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VolVariable(cbit.vcell.math.VolVariable) Hashtable(java.util.Hashtable) PostProcessDataPDEDataContext(cbit.vcell.client.data.PDEDataViewerPostProcess.PostProcessDataPDEDataContext) ChildWindowManager(cbit.vcell.client.ChildWindowManager) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) PlotPane(cbit.plot.gui.PlotPane) SingleXPlot2D(cbit.plot.SingleXPlot2D) Plot2D(cbit.plot.Plot2D) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) Domain(cbit.vcell.math.Variable.Domain)

Aggregations

PlotData (cbit.plot.PlotData)15 Plot2D (cbit.plot.Plot2D)12 SingleXPlot2D (cbit.plot.SingleXPlot2D)4 PlotPane (cbit.plot.gui.PlotPane)4 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)4 Point (java.awt.Point)4 Paint (java.awt.Paint)3 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 VolVariable (cbit.vcell.math.VolVariable)2 Parameter (cbit.vcell.opt.Parameter)2 SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)2 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)2 CartesianMesh (cbit.vcell.solvers.CartesianMesh)2 Point2D (java.awt.geom.Point2D)2 JFrame (javax.swing.JFrame)2 ConfidenceInterval (org.vcell.optimization.ConfidenceInterval)2 ProfileDataElement (org.vcell.optimization.ProfileDataElement)2 ProfileSummaryData (org.vcell.optimization.ProfileSummaryData)2 DescriptiveStatistics (org.vcell.util.DescriptiveStatistics)2