use of cbit.plot.Plot2D in project vcell by virtualcell.
the class ODESolverPlotSpecificationPanel method setPlot2D.
private void setPlot2D(Plot2D plot2D) {
// amended March 29, 2007. To fire event to ODEDataViewer.
Plot2D oldValue = this.fieldPlot2D;
this.fieldPlot2D = plot2D;
firePropertyChange("Plot2D", oldValue, plot2D);
}
use of cbit.plot.Plot2D 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);
}
use of cbit.plot.Plot2D 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);
}
use of cbit.plot.Plot2D in project vcell by virtualcell.
the class BNGDataPlotPanel method selectionModel1_ValueChanged.
/**
* Comment
*/
private void selectionModel1_ValueChanged(javax.swing.event.ListSelectionEvent listSelectionEvent) throws Exception {
int firstIndex = listSelectionEvent.getFirstIndex();
int lastIndex = listSelectionEvent.getLastIndex();
if (firstIndex < 0 || lastIndex < 0) {
return;
}
Object[] selectedValues = getJList1().getSelectedValues();
int numSelected = selectedValues.length;
if (numSelected == 0) {
return;
}
double[][] dataValues = new double[1 + numSelected][];
String[] names = new String[numSelected];
int t_index = fieldOdeSolverResultSet.findColumn("t");
dataValues[0] = fieldOdeSolverResultSet.extractColumn(t_index);
for (int i = 0; i < numSelected; i++) {
names[i] = (String) selectedValues[i];
int index = fieldOdeSolverResultSet.findColumn(names[i]);
dataValues[i + 1] = fieldOdeSolverResultSet.extractColumn(index);
}
boolean[] visibleFlags = new boolean[dataValues.length];
Arrays.fill(visibleFlags, true);
String[] labels = { "", "t", "" };
Plot2D plot2D = new SingleXPlot2D(null, null, "Time", names, dataValues, labels, visibleFlags);
getplotPane().setPlot2D(plot2D);
return;
}
use of cbit.plot.Plot2D in project vcell by virtualcell.
the class DataProcessingResultsPanel method onVariablesChange.
private void onVariablesChange() {
try {
// keep old indices
lastSelectedIdxArray = varJList.getSelectedIndices();
Object[] selectedObjects = varJList.getSelectedValues();
int numSelectedVars = selectedObjects.length;
int totalColumns = 1;
for (int v = 0; v < numSelectedVars; v++) {
totalColumns++;
// String varName = (String)selectedObjects[v];
// ucar.nc2.Variable volVar = ncfile.findVariable(varName);
// int[] shape = volVar.getShape();
// int numColumns = shape[1];
//
// totalColumns += numColumns;
}
if (dataProcessingOutputInfo == null) {
throw new RuntimeException("dataProcessingOutInfo null, thread = " + Thread.currentThread().getName());
}
final double[] vtp = dataProcessingOutputInfo.getVariableTimePoints();
if (vtp == null) {
throw new RuntimeException("getVariableTimePoints( ) null, thread = " + Thread.currentThread().getName());
}
final int numTimes = vtp.length;
double[][] plotDatas = new double[totalColumns][numTimes];
// assumes all times same
plotDatas[0] = dataProcessingOutputInfo.getVariableTimePoints();
String[] plotNames = new String[totalColumns - 1];
int columnCount = 0;
for (int v = 0; v < numSelectedVars; v++) {
String varName = ((String) selectedObjects[v]);
// remove the unit from name if exist
if (// "_(" doesn't suppose to be the first char
varName.indexOf("_(") > 0) {
varName = varName.substring(0, varName.indexOf("_("));
}
// }
for (int i = 0; i < /*numColumns*/
1; i++) {
String plotName = varName;
if (i > 0) {
plotName += ": region " + (i - 1);
}
plotNames[columnCount] = plotName;
if (columnCount >= plotDatas.length) {
throw new RuntimeException("invalid columnCount " + columnCount + " >= " + plotDatas.length);
}
for (int j = 0; j < numTimes; j++) {
// data.get(j, i);
double[] vars = dataProcessingOutputInfo.getVariableStatValues().get(varName);
if (j >= vars.length) {
throw new RuntimeException("invalid index " + j + " on " + varName + ", greater than " + vars.length);
}
plotDatas[columnCount + 1][j] = vars[j];
}
columnCount++;
}
}
Plot2D plot2D = new SingleXPlot2D(null, null, ReservedVariable.TIME.getName(), plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
plotPane.setPlot2D(plot2D);
} catch (Exception e1) {
VCDataIdentifier id = dataProcessingOutputInfo.getVCDataIdentifier();
DialogUtils.ErrorContext ec = new DialogUtils.ErrorContext(VerboseDataIdentifier.parse(id));
DialogUtils.showErrorDialog(this, e1.getMessage(), e1, ec);
e1.printStackTrace();
}
}
Aggregations