use of cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper in project vcell by virtualcell.
the class PDEDataViewer method createMultiTimePlotHelper.
// private static class MultiTimePointPropChangeListener implements PropertyChangeListener {
// @Override
// public void propertyChange(PropertyChangeEvent evt) {
// }
// }
private MultiTimePlotHelper createMultiTimePlotHelper(final ClientPDEDataContext copyThisPDEDatacontext, final User user, DataSymbolMetadataResolver argDataSymbolMetadataResolver) throws Exception {
final ClientPDEDataContext[] copyHolder = new ClientPDEDataContext[1];
if (PDEDataViewer.this.isPostProcess()) {
copyHolder[0] = PDEDataViewerPostProcess.createPostProcessPDEDataContext(copyThisPDEDatacontext);
} else {
copyHolder[0] = (ClientPDEDataContext) ((PDEDataManager) copyThisPDEDatacontext.getDataManager()).createNewPDEDataManager(copyThisPDEDatacontext.getVCDataIdentifier(), null).getPDEDataContext();
}
copyHolder[0].setVariableAndTime(copyThisPDEDatacontext.getDataIdentifier(), copyThisPDEDatacontext.getTimePoint());
return new PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper() {
private DataSymbolMetadataResolver dataSymbolMetadataResolver = argDataSymbolMetadataResolver;
private ArrayList<PropertyChangeListener> myPropertyChangeHolder = new ArrayList<>();
private ClientPDEDataContext myPdeDataContext = copyHolder[0];
private VariableType myVariableType = copyThisPDEDatacontext.getDataIdentifier().getVariableType();
// catch events from 'this' PDEDataViewer and pass with new source
private PropertyChangeListener myPropertyChangeListener;
private User myUser = user;
// List<AnnotatedFunction> myAnnots;
// access to anonymous outer class
private PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelperThis = this;
private PDEPlotControlPanel.IdentifierListCellRenderer myListCellRenderer;
private AnnotatedFunction[] lastAnnotatedFunctions;
private PDEPlotControlPanel.FunctionListProvider functionListProvider = new PDEPlotControlPanel.FunctionListProvider() {
@Override
public List<AnnotatedFunction> getAnnotatedFunctions() {
if (myPdeDataContext.getDataManager().getOutputContext() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions().length > 0) {
return new ArrayList<>(Arrays.asList(myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions()));
}
return new ArrayList<>();
}
};
private Comparator<AnnotatedFunction> nameComparator = new Comparator<AnnotatedFunction>() {
@Override
public int compare(AnnotatedFunction o1, AnnotatedFunction o2) {
return o2.getName().compareToIgnoreCase(o1.getName());
}
};
@Override
public void removeDataJobListener(DataJobListener dataJobListener) {
PDEDataViewer.this.removeDataJobListener(dataJobListener);
}
@Override
public void addDataJobListener(DataJobListener dataJobListener) {
PDEDataViewer.this.addDataJobListener(dataJobListener);
}
@Override
public User getUser() {
return myUser;
}
@Override
public PDEDataContext getPdeDatacontext() {
return myPdeDataContext;
}
@Override
public DataIdentifier[] getCopyOfDisplayedDataIdentifiers() {
DataIdentifier[] newData = PDEDataViewer.this.getPDEPlotControlPanel1().getDataIdentifierFilter().accept(DefaultDataIdentifierFilter.ALL, functionListProvider.getAnnotatedFunctions(), myPdeDataContext.getDataIdentifiers()).toArray(new DataIdentifier[0]);
return DataIdentifier.collectSortedSimilarDataTypes(this.getVariableType(), newData);
}
@Override
public PDEPlotControlPanel.IdentifierListCellRenderer getListCellRenderer() {
if (myListCellRenderer == null) {
myListCellRenderer = new PDEPlotControlPanel.IdentifierListCellRenderer(functionListProvider);
}
return myListCellRenderer;
}
@Override
public Simulation getsimulation() {
return PDEDataViewer.this.getSimulation();
}
private List<AnnotatedFunction> efficiencyFilter(List<AnnotatedFunction> funcs) {
ArrayList<AnnotatedFunction> outputfunctions = new ArrayList<>();
Iterator<AnnotatedFunction> iter = funcs.iterator();
while (iter.hasNext()) {
AnnotatedFunction theFunc = iter.next();
if ((isPostProcess() && theFunc.getFunctionType().equals(VariableType.POSTPROCESSING)) || (!isPostProcess() && !theFunc.getFunctionType().equals(VariableType.POSTPROCESSING))) {
outputfunctions.add(theFunc);
}
}
return outputfunctions;
}
@Override
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
myPropertyChangeHolder.add(propertyChangeListener);
if (myPropertyChangeListener == null) {
myPropertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() == PDEDataViewer.this && evt.getPropertyName().equals(PDEDataContext.PROP_PDE_DATA_CONTEXT)) {
// List<AnnotatedFunction> currentOutputFunctions = functionListProvider.getAnnotatedFunctions();
// currentOutputFunctions = efficiencyFilter(currentOutputFunctions);
// currentOutputFunctions.sort(nameComparator);
List<AnnotatedFunction> newOutputFunctions0 = Arrays.asList(((ClientPDEDataContext) PDEDataViewer.this.getPdeDataContext()).getDataManager().getOutputContext().getOutputFunctions());
List<AnnotatedFunction> newOutputFunctions = efficiencyFilter(newOutputFunctions0);
newOutputFunctions.sort(nameComparator);
if (lastAnnotatedFunctions != null && Compare.isEqualOrNullStrict(lastAnnotatedFunctions, newOutputFunctions.toArray(new AnnotatedFunction[0]))) {
return;
}
lastAnnotatedFunctions = new AnnotatedFunction[newOutputFunctions.size()];
for (int i = 0; i < newOutputFunctions.size(); i++) {
lastAnnotatedFunctions[i] = new AnnotatedFunction(newOutputFunctions.get(i));
}
// lastAnnotatedFunctions = newOutputFunctions0.toArray(new AnnotatedFunction[0]);
myPdeDataContext.getDataManager().setOutputContext(new OutputContext(newOutputFunctions0.toArray(new AnnotatedFunction[0])));
myPdeDataContext.refreshIdentifiers();
for (int i = 0; i < myPropertyChangeHolder.size(); i++) {
myPropertyChangeHolder.get(i).propertyChange(new PropertyChangeEvent(multiTimePlotHelperThis, SimDataConstants.PROPERTY_NAME_DATAIDENTIFIERS, null, null));
}
}
}
};
PDEDataViewer.this.addPropertyChangeListener(myPropertyChangeListener);
}
}
@Override
public void removeallPropertyChangeListeners() {
myPropertyChangeHolder.clear();
if (myPropertyChangeListener != null) {
PDEDataViewer.this.removePropertyChangeListener(myPropertyChangeListener);
}
}
@Override
public VariableType getVariableType() {
return myVariableType;
}
// @Override
// public void addExtraTasks(AsynchClientTask[] moreTasks) {
// PDEDataViewer.this.addExtraTasks(moreTasks);
// }
@Override
public DataSymbolMetadataResolver getDataSymbolMetadataResolver() {
return dataSymbolMetadataResolver;
}
};
}
use of cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper in project vcell by virtualcell.
the class PDEDataViewer method showTimePlot.
// private static final String PROPERTY_PDEDC = "pdedc";
/**
* Comment
*/
private void showTimePlot() {
VariableType varType = getPdeDataContext().getDataIdentifier().getVariableType();
// Collect all sample curves created by user
SpatialSelection[] spatialSelectionArr = getPDEDataContextPanel1().fetchSpatialSelections(true, true);
SpatialSelection[] spatialSelectionArr2 = null;
if (varType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME) || varType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_POSTPROCESSING)) {
spatialSelectionArr2 = getPDEDataContextPanel1().fetchSpatialSelections(varType, true, true);
} else {
spatialSelectionArr2 = getPDEDataContextPanel1().fetchSpatialSelections(varType.equals(VariableType.MEMBRANE) ? VariableType.MEMBRANE_REGION : VariableType.MEMBRANE, true, true);
}
final Vector<SpatialSelection> singlePointSSOnly = new Vector<SpatialSelection>();
final Vector<SpatialSelection> singlePointSSOnly2 = new Vector<SpatialSelection>();
if (spatialSelectionArr != null && spatialSelectionArr.length > 0) {
for (int i = 0; i < spatialSelectionArr.length; i++) {
if (spatialSelectionArr[i].isPoint() || (spatialSelectionArr[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr[i]).getSelectionSource() instanceof SinglePoint)) {
singlePointSSOnly.add(spatialSelectionArr[i]);
}
if (spatialSelectionArr2[i].isPoint() || (spatialSelectionArr2[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr2[i]).getSelectionSource() instanceof SinglePoint)) {
singlePointSSOnly2.add(spatialSelectionArr2[i]);
}
}
}
final String varName = getPdeDataContext().getVariableName();
if (singlePointSSOnly.size() == 0) {
PopupGenerator.showErrorDialog(this, "No Time sampling points match DataType=" + varType);
return;
}
try {
int[] indices = null;
//
indices = new int[singlePointSSOnly.size()];
for (int i = 0; i < singlePointSSOnly.size(); i++) {
if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
SpatialSelectionVolume ssv = (SpatialSelectionVolume) singlePointSSOnly.get(i);
indices[i] = ssv.getIndex(0);
} else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) singlePointSSOnly.get(i);
indices[i] = ssm.getIndex(0);
}
}
double[] timePoints = getPdeDataContext().getTimePoints();
final TimeSeriesJobSpec tsjs = new TimeSeriesJobSpec(new String[] { varName }, new int[][] { indices }, null, timePoints[0], 1, timePoints[timePoints.length - 1], VCDataJobID.createVCDataJobID(getDataViewerManager().getUser(), true));
if (!tsjs.getVcDataJobID().isBackgroundTask()) {
throw new RuntimeException("Use getTimeSeries(...) if not a background job");
}
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put(StringKey_timeSeriesJobSpec, tsjs);
AsynchClientTask task1 = new TimeSeriesDataRetrievalTask("Retrieving Data for '" + varName + "'...", PDEDataViewer.this, getPdeDataContext());
AsynchClientTask multiTimePlotHelperTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelper = createMultiTimePlotHelper((ClientPDEDataContext) PDEDataViewer.this.getPdeDataContext(), PDEDataViewer.this.getDataViewerManager().getUser(), getSimulationModelInfo().getDataSymbolMetadataResolver());
hashTable.put(MULTITPHELPER_TASK_KEY, multiTimePlotHelper);
}
};
AsynchClientTask task2 = new AsynchClientTask("showing time plot for '" + varName + "'", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
TSJobResultsNoStats tsJobResultsNoStats = (TSJobResultsNoStats) hashTable.get(StringKey_timeSeriesJobResults);
// Make independent Plotviewer that is unaffected by changes (time,var,paramscan) in 'this' PDEDataviewer except to pass-thru OutputContext changes
PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelper = (PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) hashTable.get(MULTITPHELPER_TASK_KEY);
try {
PdeTimePlotMultipleVariablesPanel pdeTimePlotPanel = new PdeTimePlotMultipleVariablesPanel(multiTimePlotHelper, singlePointSSOnly, singlePointSSOnly2, tsJobResultsNoStats);
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
String prefix = "Time Plot (" + getPDEPlotControlPanel1().getPlotVariableJList().getSelectedValue().getVariableType().getTypeName() + ") ";
ChildWindow childWindow = childWindowManager.addChildWindow(pdeTimePlotPanel, pdeTimePlotPanel, createContextTitle(PDEDataViewer.this.isPostProcess(), prefix, getPdeDataContext(), getSimulationModelInfo(), getSimulation()));
childWindow.getParent().addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent e) {
super.windowClosing(e);
multiTimePlotHelper.removeallPropertyChangeListeners();
}
@Override
public void windowClosed(WindowEvent e) {
super.windowClosed(e);
multiTimePlotHelper.removeallPropertyChangeListeners();
}
});
// childWindow.addChildWindowListener(new ChildWindowListener() {
// @Override
// public void closing(ChildWindow childWindow) {
// multiTimePlotHelper.removeallPropertyChangeListeners();
// }
// @Override
// public void closed(ChildWindow childWindow) {
// multiTimePlotHelper.removeallPropertyChangeListeners();
// }
// });
childWindow.setSize(900, 550);
childWindow.setIsCenteredOnParent();
childWindow.show();
} catch (Exception e) {
e.printStackTrace();
multiTimePlotHelper.removeallPropertyChangeListeners();
}
}
};
// ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1,multiTimePlotHelperTask, task2 }, true, true, null);
ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1, multiTimePlotHelperTask, task2 }, null, false, false, true, null, false);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper in project vcell by virtualcell.
the class PDEDataViewer method showKymograph.
private void showKymograph() {
String title = createContextTitle(PDEDataViewer.this.isPostProcess(), "Kymograph: ", getPdeDataContext(), getSimulationModelInfo(), getSimulation());
final String INDICES_KEY = "INDICES_KEY";
final String CROSSING_KEY = "CROSSING_KEY";
final String ACCUM_KEY = "ACCUM_KEY";
AsynchClientTask multiTimePlotHelperTask = new AsynchClientTask("multiTimePlotHelperTask...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
// Collect all sample curves created by user
SpatialSelection[] spatialSelectionArr = getPDEDataContextPanel1().fetchSpatialSelections(false, true);
final Vector<SpatialSelection> lineSSOnly = new Vector<SpatialSelection>();
if (spatialSelectionArr != null && spatialSelectionArr.length > 0) {
//
for (int i = 0; i < spatialSelectionArr.length; i++) {
if (spatialSelectionArr[i].isPoint() || (spatialSelectionArr[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr[i]).getSelectionSource() instanceof cbit.vcell.geometry.SinglePoint)) {
} else {
lineSSOnly.add(spatialSelectionArr[i]);
}
}
}
//
if (lineSSOnly.size() == 0) {
throw new Exception("No line samples match DataType=" + getPdeDataContext().getDataIdentifier().getVariableType());
}
VariableType varType = getPdeDataContext().getDataIdentifier().getVariableType();
int[] indices = null;
int[] crossingMembraneIndices = null;
double[] accumDistances = null;
for (int i = 0; i < lineSSOnly.size(); i++) {
if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
SpatialSelectionVolume ssv = (SpatialSelectionVolume) lineSSOnly.get(i);
SpatialSelection.SSHelper ssh = ssv.getIndexSamples(0.0, 1.0);
indices = ssh.getSampledIndexes();
crossingMembraneIndices = ssh.getMembraneIndexesInOut();
accumDistances = ssh.getWorldCoordinateLengths();
} else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) lineSSOnly.get(i);
SpatialSelection.SSHelper ssh = ssm.getIndexSamples();
indices = ssh.getSampledIndexes();
accumDistances = ssh.getWorldCoordinateLengths();
}
}
if (indices != null) {
hashTable.put(INDICES_KEY, indices);
}
if (crossingMembraneIndices != null) {
hashTable.put(CROSSING_KEY, crossingMembraneIndices);
}
if (accumDistances != null) {
hashTable.put(ACCUM_KEY, accumDistances);
}
MultiTimePlotHelper multiTimePlotHelper = createMultiTimePlotHelper((ClientPDEDataContext) getPdeDataContext(), getDataViewerManager().getUser(), getSimulationModelInfo().getDataSymbolMetadataResolver());
hashTable.put(MULTITPHELPER_TASK_KEY, multiTimePlotHelper);
}
};
AsynchClientTask kymographTask = new AsynchClientTask("Kymograph showing...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
KymographPanel kymographPanel = new KymographPanel(PDEDataViewer.this, title, (MultiTimePlotHelper) hashTable.get(MULTITPHELPER_TASK_KEY));
SymbolTable symbolTable;
if (getSimulation() != null && getSimulation().getMathDescription() != null) {
symbolTable = getSimulation().getMathDescription();
} else {
symbolTable = new SimpleSymbolTable(new String[] { getPdeDataContext().getDataIdentifier().getName() });
}
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
ChildWindow childWindow = childWindowManager.addChildWindow(kymographPanel, kymographPanel, title);
childWindow.setSize(new Dimension(700, 500));
childWindow.show();
kymographPanel.initDataManager(getPdeDataContext().getDataIdentifier(), getPdeDataContext().getTimePoints()[0], 1, getPdeDataContext().getTimePoints()[getPdeDataContext().getTimePoints().length - 1], (int[]) hashTable.get(INDICES_KEY), (int[]) hashTable.get(CROSSING_KEY), (double[]) hashTable.get(ACCUM_KEY), true, getPdeDataContext().getTimePoint(), symbolTable);
}
};
ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { multiTimePlotHelperTask, kymographTask }, null, false, false, true, null, false);
}
Aggregations