use of cbit.plot.Plot2D in project vcell by virtualcell.
the class TimeFunctionPanel method refreshPlot.
private void refreshPlot() throws Exception {
// try {
Expression exp = new Expression(funcTextField.getText());
exp.flatten();
SimpleSymbolTable symbolTable = new SimpleSymbolTable(new String[] { "t", "pi" /*, "x", "y", "z"*/
});
exp.bindExpression(symbolTable);
double[] valueArray = new double[2];
valueArray[1] = Math.PI;
// valueArray[ReservedVariable.Z.getIndex()] = 0 ;
// valueArray[ReservedVariable.Y.getIndex()] = 0 ;
// valueArray[ReservedVariable.X.getIndex()] = 0 ;
int totalTimePoints = 0;
double beginTime = 0;
double timeStep = 0;
double parseEndTime = 0;
try {
beginTime = Double.parseDouble(timeBegTextField.getText());
} catch (Exception e) {
throw new Exception("Couldn't evaluate 'Time Begin' as number\n" + e.getMessage());
}
try {
timeStep = Double.parseDouble(timeStepTextField.getText());
if (timeStep <= 0) {
throw new Exception("timestep value = " + timeStep);
}
} catch (Exception e) {
throw new Exception("'Time Step' must be > 0\n" + e.getMessage());
}
try {
parseEndTime = Double.parseDouble(endTimeTextField.getText());
} catch (Exception e) {
throw new Exception("Couldn't evaluate 'Time End' as number\n" + e.getMessage());
}
try {
if (beginTime > parseEndTime || beginTime == parseEndTime) {
throw new Exception("endTime must be greater than beginTime");
}
totalTimePoints = (int) Math.ceil((parseEndTime - beginTime) / timeStep);
// if(totalTimePoints <= 0){
// throw new Exception("calculated number of time points ="+totalTimePoints);
// }
} catch (Exception e) {
throw new Exception("check beginTime, endTime and timeStep: ((endTime-beginTime)/timeStep) must be greater than 0" + "\n" + e.getMessage());
}
double[] timePoints = new double[totalTimePoints];
double[] funcVals = new double[totalTimePoints];
for (int i = 0; i < totalTimePoints; i++) {
valueArray[ReservedVariable.TIME.getIndex()] = beginTime + i * timeStep;
timePoints[i] = valueArray[ReservedVariable.TIME.getIndex()];
funcVals[i] = exp.evaluateVector(valueArray);
}
PlotData plotData = new PlotData(timePoints, funcVals);
Plot2D plot2D = new Plot2D(null, null, new String[] { "Time Function" }, new PlotData[] { plotData }, new String[] { "Time Function Value", "Time", "[" + "Time Function" + "]" });
plotPane.setPlot2D(plot2D);
// } catch (Exception e) {
// e.printStackTrace();
// DialogUtils.showErrorDialog(this, "Error refreshing Plot:\n"+e.getMessage(), e);
// plotPane.setPlot2D( null);
// }
}
use of cbit.plot.Plot2D in project vcell by virtualcell.
the class FRAPDataPanel method showCurve.
private void showCurve(String[] varNames, double[] independent, double[][] dependents) {
PlotPane plotter = new PlotPane();
PlotData[] plotDatas = new PlotData[dependents.length];
for (int i = 0; i < plotDatas.length; i++) {
plotDatas[i] = new PlotData(independent, dependents[i]);
}
Plot2D plot2D = new Plot2D(null, null, varNames, plotDatas);
plotter.setPlot2D(plot2D);
ChildWindow plotChildWindow = ChildWindowManager.findChildWindowManager(this).addChildWindow(plotter, plotter, "ROI time course", true);
plotChildWindow.setTitle("ROI time course");
plotChildWindow.setIsCenteredOnParent();
plotChildWindow.setSize(new Dimension(400, 400));
plotChildWindow.showModal();
}
use of cbit.plot.Plot2D in project vcell by virtualcell.
the class MultisourcePlotPane method selectionModel1_ValueChanged.
/**
* Comment
*/
private void selectionModel1_ValueChanged(javax.swing.event.ListSelectionEvent listSelectionEvent) throws Exception {
if (listSelectionEvent.getValueIsAdjusting() == true) {
return;
}
int firstIndex = listSelectionEvent.getFirstIndex();
int lastIndex = listSelectionEvent.getLastIndex();
if (firstIndex < 0 || lastIndex < 0) {
getplotPane().setPlot2D(new Plot2D(null, null, new String[0], new PlotData[0]));
}
//
// make plotDatas for the reference data
//
Vector<PlotData> plotDataList = new Vector<PlotData>();
Vector<String> nameList = new Vector<String>();
Vector<Integer> renderHintList = new Vector<Integer>();
Vector<Color> colorV = new Vector<Color>();
int[] selectedIndices = getJList1().getSelectedIndices();
for (int ii = 0; ii < selectedIndices.length; ii++) {
int selectedIndex = selectedIndices[ii];
DataReference dataReference = (DataReference) getmultisourcePlotListModel().getElementAt(selectedIndex);
DataSource dataSource = dataReference.getDataSource();
// instanceof DataSource.DataSourceReferenceData ? refDataLabelPrefix : modelDataLabelPrefix;
String prefix = dataSource.getName() + ": ";
String[] columnNames = dataSource.getColumnNames();
int timeIndex = dataSource.getTimeColumnIndex();
if (timeIndex == -1) {
throw new RuntimeException("no time variable specified");
}
for (int i = 0; i < columnNames.length; i++) {
if (i == timeIndex) {
continue;
}
if (columnNames[i].equals(dataReference.getIdentifier())) {
double[] independentValues = dataSource.getColumnData(timeIndex);
double[] dependentValues = dataSource.getColumnData(i);
PlotData plotData = new PlotData(independentValues, dependentValues);
plotDataList.add(plotData);
int unsortedSelecteIndex = (getmultisourcePlotListModel().getSortedDataReferences() == null ? selectedIndex : getmultisourcePlotListModel().getSortedDataReferences().get(selectedIndex).unsortedIndex);
colorV.add(autoContrastColors[unsortedSelecteIndex]);
nameList.add(prefix + columnNames[i]);
renderHintList.add(dataSource.getRenderHints());
break;
}
}
}
String[] labels = { "", "t", "" };
String[] names = (String[]) BeanUtils.getArray(nameList, String.class);
PlotData[] plotDatas = (PlotData[]) BeanUtils.getArray(plotDataList, PlotData.class);
boolean[] visibleFlags = new boolean[plotDatas.length];
for (int i = 0; i < visibleFlags.length; i++) {
visibleFlags[i] = true;
}
int[] renderHints = new int[plotDatas.length];
for (int i = 0; i < renderHints.length; i++) {
renderHints[i] = ((Integer) renderHintList.elementAt(i)).intValue();
}
Plot2D plot2D = new Plot2D(null, null, names, plotDatas, labels, visibleFlags, renderHints);
Color[] colorArr = colorV.toArray(new Color[0]);
// if(colorV.size() == plot2D.getNumberOfPlots()){
// colorArr = colorV.toArray(new Color[0]);
// }
getplotPane().setPlot2D(plot2D, colorArr);
return;
}
use of cbit.plot.Plot2D in project vcell by virtualcell.
the class KymographPanel method configurePlotData.
/**
* Insert the method's description here.
* Creation date: (12/16/2004 10:46:05 AM)
* @param imgX int
* @param imgY int
*/
private void configurePlotData(int imgX, int imgY) {
//
// TimeScan Data
//
double[][] timeData = new double[2][currentTimes.length];
timeData[0] = currentTimes;
timeData[1] = new double[currentTimes.length];
for (int i = 0; i < currentTimes.length; i += 1) {
// timeData[1][i] = timeSeriesDataOrig[1+imgX][i];
timeData[1][i] = rawValues[imgX + (i * RESAMP_SIZE)];
}
;
localTimeDataMMMH = calcMMM(timeData[1]);
final int MAX_TITLE_VAL_LENGTH = 9;
DecimalFormat nf = new DecimalFormat();
String valS = null;
valS = currentDistances[imgX] + "";
if (valS.length() > MAX_TITLE_VAL_LENGTH) {
nf.applyPattern("#.###E0");
valS = nf.format(currentDistances[imgX]);
}
currentTimeSeriesPlot2D = new SingleXPlot2D(new SymbolTableEntry[] { currentSymbolTablEntry }, multiTimePlotHelper.getDataSymbolMetadataResolver(), "Time", new String[] { currentDataIdentifier.getName() }, timeData, new String[] { "Time Series (d=" + valS + ") Vert", "Time", /*"Time (s)"*/
"Value" });
getPlotPaneTimeSeries().setPlot2D(currentTimeSeriesPlot2D);
//
// LineScan Data
//
double[] lineData = new double[timeSeriesDataOrig.length - 1];
for (int i = 1; i < timeSeriesDataOrig.length; i += 1) {
lineData[i - 1] = timeSeriesDataOrig[i][imgY];
}
double[] lineScanDistances = accumDistancesDataOrig;
localDistDataMMMH = calcMMM(lineData);
PlotData plotData = new PlotData(lineScanDistances, lineData);
valS = currentTimes[imgY] + "";
if (valS.length() > MAX_TITLE_VAL_LENGTH) {
valS = nf.format(currentTimes[imgY]);
}
currentLineScanPlot2D = new Plot2D(new SymbolTableEntry[] { currentSymbolTablEntry }, multiTimePlotHelper.getDataSymbolMetadataResolver(), new String[] { currentDataIdentifier.getName() }, new PlotData[] { plotData }, new String[] { "Line Scan (t=" + valS + ") Horz", "Distance", /*"Distance (\u00b5m)"*/
"Value" });
getPlotPaneLineScan().setPlot2D(currentLineScanPlot2D);
Range xRangeTime = new Range(currentTimes[0], currentTimes[currentTimes.length - 1]);
Range xRangeDist = new Range(lineScanDistances[0], lineScanDistances[lineScanDistances.length - 1]);
Range yRangeTime = (allDataMMMH != null ? allDataMMMH.getRange() : null);
Range yRangeDist = yRangeTime;
if (bLocalScaling) {
yRangeTime = (localTimeDataMMMH != null ? localTimeDataMMMH.getRange() : null);
yRangeDist = (localDistDataMMMH != null ? localDistDataMMMH.getRange() : null);
}
getPlotPaneTimeSeries().forceXYRange(xRangeTime, yRangeTime);
getPlotPaneLineScan().forceXYRange(xRangeDist, yRangeDist);
configureMinMax();
getimagePaneView1().repaint();
}
use of cbit.plot.Plot2D 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);
}
Aggregations