use of org.vcell.util.Range in project vcell by virtualcell.
the class KymographPanel method configureMinMax.
/**
* Insert the method's description here.
* Creation date: (12/28/2004 10:01:37 AM)
* @param min double
* @param max double
*/
private void configureMinMax() {
getScaleImageModeJLabel().setText((scaleImageMode == SCALE_IMAGE_ALL ? "All" : "") + (scaleImageMode == SCALE_IMAGE_LINESCAN ? "LS" : "") + (scaleImageMode == SCALE_IMAGE_TIMESERIES ? "TS" : "") + (scaleImageMode == SCALE_IMAGE_USERDEFINED ? "User" : ""));
Range minmaxRange = null;
switch(scaleImageMode) {
case SCALE_IMAGE_ALL:
minmaxRange = (allDataMMMH != null ? allDataMMMH.getRange() : null);
break;
case SCALE_IMAGE_LINESCAN:
minmaxRange = (localDistDataMMMH != null ? localDistDataMMMH.getRange() : null);
break;
case SCALE_IMAGE_TIMESERIES:
minmaxRange = (localTimeDataMMMH != null ? localTimeDataMMMH.getRange() : null);
break;
case SCALE_IMAGE_USERDEFINED:
minmaxRange = (userDefinedMMMH != null ? userDefinedMMMH.getRange() : null);
break;
}
if (minmaxRange == null || minmaxRange.getMin() == minmaxRange.getMax()) {
getColorMapJLabel().setIcon(null);
getColorMapJLabel().setText("No Range");
} else {
getColorMapJLabel().setIcon(cmapImageIcon);
getColorMapJLabel().setText(null);
}
if (minmaxRange == null) {
getDisplayAdapterService1().setActiveScaleRange(null);
getDisplayAdapterService1().setValueDomain(null);
getMinJLabel().setText("?");
getMinJLabel().setToolTipText("Unknown");
getMaxJLabel().setText("?");
getMaxJLabel().setToolTipText("Unknown");
// updateColorMapDisplay();
getimagePaneView1().getImagePaneModel().updateViewPortImage();
} else if (getDisplayAdapterService1().getActiveScaleRange() == null || getDisplayAdapterService1().getActiveScaleRange().getMin() != minmaxRange.getMin() || getDisplayAdapterService1().getActiveScaleRange().getMax() != minmaxRange.getMax()) {
getDisplayAdapterService1().setValueDomain((allDataMMMH != null ? allDataMMMH.getRange() : null));
getDisplayAdapterService1().setActiveScaleRange(minmaxRange);
java.text.DecimalFormat nf = new java.text.DecimalFormat();
nf.applyPattern("#.###E0");
getMinJLabel().setText((("" + minmaxRange.getMin()).length() < 7 ? minmaxRange.getMin() + "" : nf.format(minmaxRange.getMin())));
getMinJLabel().setToolTipText("" + minmaxRange.getMin());
getMaxJLabel().setText((("" + minmaxRange.getMax()).length() < 7 ? minmaxRange.getMax() + "" : nf.format(minmaxRange.getMax())));
getMaxJLabel().setToolTipText("" + minmaxRange.getMax());
// updateColorMapDisplay();
getimagePaneView1().getImagePaneModel().updateViewPortImage();
}
}
use of org.vcell.util.Range in project vcell by virtualcell.
the class PDEDataViewer method makeSurfaceMovie.
private void makeSurfaceMovie(final SurfaceCanvas surfaceCanvas, final int varTotalNumIndices, final String movieDataVarName, final DisplayAdapterService movieDAS, final VCDataIdentifier movieVCDataIdentifier) {
final SurfaceMovieSettingsPanel smsp = new SurfaceMovieSettingsPanel();
final double[] timePoints = getPdeDataContext().getTimePoints();
final int surfaceWidth = surfaceCanvas.getWidth();
final int surfaceHeight = surfaceCanvas.getHeight();
smsp.init(surfaceWidth, surfaceHeight, timePoints);
while (true) {
if (PopupGenerator.showComponentOKCancelDialog(this, smsp, "Movie Settings for var " + movieDataVarName) != JOptionPane.OK_OPTION) {
return;
}
long movieSize = (smsp.getTotalFrames() * surfaceWidth * surfaceHeight * 3);
// raw data size;
long rawDataSize = (smsp.getTotalFrames() * varTotalNumIndices * 8);
if (movieSize + rawDataSize > 50000000) {
final String YES_RESULT = "Yes";
String result = PopupGenerator.showWarningDialog(this, "Movie processing will require at least " + (movieSize + rawDataSize) / 1000000 + " mega-bytes of memory.\nMovie size will be " + (movieSize >= 1000000 ? movieSize / 1000000 + " mega-bytes." : movieSize / 1000.0 + " kilo-bytes.") + " Continue?", new String[] { YES_RESULT, "No" }, YES_RESULT);
if (result != null && result.equals(YES_RESULT)) {
break;
}
} else {
break;
}
}
final int beginTimeIndex = smsp.getBeginTimeIndex();
final int endTimeIndex = smsp.getEndTimeIndex();
final int step = smsp.getSkipParameter() + 1;
final String[] varNames = new String[] { movieDataVarName };
int[] allIndices = new int[varTotalNumIndices];
for (int i = 0; i < allIndices.length; i++) {
allIndices[i] = i;
}
final TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(varNames, new int[][] { allIndices }, null, timePoints[beginTimeIndex], step, timePoints[endTimeIndex], VCDataJobID.createVCDataJobID(getDataViewerManager().getUser(), true));
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put(StringKey_timeSeriesJobSpec, timeSeriesJobSpec);
AsynchClientTask task1 = new TimeSeriesDataRetrievalTask("Retrieving data for variable '" + movieDataVarName + "'", PDEDataViewer.this, getPdeDataContext());
AsynchClientTask task2 = new AsynchClientTask("select a file", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
VCFileChooser fileChooser = new VCFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_MOV);
// Set the default file filter...
fileChooser.setFileFilter(FileFilters.FILE_FILTER_MOV);
// remove all selector
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
fileChooser.setDialogTitle("Saving surface movie");
File selectedFile = null;
while (true) {
if (fileChooser.showSaveDialog(PDEDataViewer.this) != JFileChooser.APPROVE_OPTION) {
return;
}
selectedFile = fileChooser.getSelectedFile();
if (!selectedFile.getName().endsWith(".mov")) {
selectedFile = new File(selectedFile.getAbsolutePath() + ".mov");
}
if (selectedFile.exists()) {
final String YES_RESULT = "Yes";
String result = PopupGenerator.showWarningDialog(PDEDataViewer.this, "Overwrite exisitng file:\n" + selectedFile.getAbsolutePath() + "?", new String[] { YES_RESULT, "No" }, YES_RESULT);
if (result != null && result.equals(YES_RESULT)) {
break;
}
} else {
break;
}
}
hashTable.put("selectedFile", selectedFile);
}
};
AsynchClientTask task3 = new AsynchClientTask("create movie", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
File selectedFile = (File) hashTable.get("selectedFile");
if (selectedFile == null) {
return;
}
TSJobResultsNoStats tsJobResultsNoStats = (TSJobResultsNoStats) hashTable.get(StringKey_timeSeriesJobResults);
double[][] timeSeries = tsJobResultsNoStats.getTimesAndValuesForVariable(movieDataVarName);
int[] singleFrame = new int[surfaceWidth * surfaceHeight];
BufferedImage bufferedImage = new BufferedImage(surfaceWidth, surfaceHeight, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g2D = bufferedImage.createGraphics();
VideoMediaChunk[] chunks = new VideoMediaChunk[tsJobResultsNoStats.getTimes().length];
VideoMediaSample sample;
int sampleDuration = 0;
int timeScale = smsp.getFramesPerSecond();
int bitsPerPixel = 32;
DisplayAdapterService das = new DisplayAdapterService(movieDAS);
int[][] origSurfacesColors = surfaceCanvas.getSurfacesColors();
DataInfoProvider dataInfoProvider = getPDEDataContextPanel1().getDataInfoProvider();
FileDataContainerManager fileDataContainerManager = new FileDataContainerManager();
try {
try {
for (int t = 0; t < tsJobResultsNoStats.getTimes().length; t++) {
getClientTaskStatusSupport().setMessage("Creating Movie... Progress " + NumberUtils.formatNumber(100.0 * ((double) t / (double) tsJobResultsNoStats.getTimes().length), 3) + "%");
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
for (int index = 1; index < timeSeries.length; index++) {
double v = timeSeries[index][t];
if ((dataInfoProvider == null || dataInfoProvider.isDefined(index - 1)) && !Double.isNaN(v) && !Double.isInfinite(v)) {
min = Math.min(min, v);
max = Math.max(max, v);
}
}
das.setValueDomain(new Range(min, max));
if (das.getAutoScale()) {
das.setActiveScaleRange(new Range(min, max));
}
int[][] surfacesColors = new int[surfaceCanvas.getSurfaceCollection().getSurfaceCount()][];
for (int i = 0; i < surfaceCanvas.getSurfaceCollection().getSurfaceCount(); i += 1) {
Surface surface = surfaceCanvas.getSurfaceCollection().getSurfaces(i);
surfacesColors[i] = new int[surface.getPolygonCount()];
for (int j = 0; j < surface.getPolygonCount(); j += 1) {
int membIndex = meshRegionSurfaces.getMembraneIndexForPolygon(i, j);
surfacesColors[i][j] = das.getColorFromValue(timeSeries[membIndex + 1][t]);
}
}
surfaceCanvas.setSurfacesColors(surfacesColors);
surfaceCanvas.paintImmediately(0, 0, surfaceWidth, surfaceHeight);
surfaceCanvas.paint(g2D);
bufferedImage.getRGB(0, 0, surfaceWidth, surfaceHeight, singleFrame, 0, surfaceWidth);
sampleDuration = 1;
sample = FormatSpecificSpecs.getVideoMediaSample(surfaceWidth, surfaceHeight * varNames.length, sampleDuration, false, FormatSpecificSpecs.CODEC_JPEG, 1.0f, singleFrame);
chunks[t] = new VideoMediaChunk(sample, fileDataContainerManager);
}
} finally {
surfaceCanvas.setSurfacesColors(origSurfacesColors);
surfaceCanvas.paintImmediately(0, 0, surfaceWidth, surfaceHeight);
}
MediaTrack videoTrack = new MediaTrack(chunks);
MediaMovie newMovie = new MediaMovie(videoTrack, videoTrack.getDuration(), timeScale);
newMovie.addUserDataEntry(new UserDataEntry("cpy", "\u00A9" + (new GregorianCalendar()).get(Calendar.YEAR) + ", UCHC"));
newMovie.addUserDataEntry(new UserDataEntry("des", "Dataset name: " + movieVCDataIdentifier.getID()));
newMovie.addUserDataEntry(new UserDataEntry("cmt", "Time range: " + timePoints[beginTimeIndex] + " - " + timePoints[endTimeIndex]));
for (int k = 0; k < varNames.length; k++) {
// pad with 0 if k < 10
String entryType = "v" + (k < 10 ? "0" : "") + k;
UserDataEntry entry = new UserDataEntry(entryType, "Variable name: " + varNames[k] + " min: " + das.getValueDomain().getMin() + " max: " + das.getValueDomain().getMax());
newMovie.addUserDataEntry(entry);
}
getClientTaskStatusSupport().setMessage("Writing Movie to disk...");
FileOutputStream fos = new FileOutputStream(selectedFile);
DataOutputStream movieOutput = new DataOutputStream(new BufferedOutputStream(fos));
MediaMethods.writeMovie(movieOutput, newMovie);
movieOutput.close();
fos.close();
} finally {
fileDataContainerManager.closeAllAndDelete();
}
}
};
ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1, task2, task3 }, true, true, null);
}
use of org.vcell.util.Range in project vcell by virtualcell.
the class ImageContainer method setDataRange.
/**
* Sets the dataRange property (cbit.image.Range) value.
* @param dataRange The new value for the property.
* @see #getDataRange
*/
public final void setDataRange(Range dataRange) {
getDisplayAdapter().setDataRange(dataRange);
Range oldValue = fieldDataRange;
fieldDataRange = dataRange;
firePropertyChange("dataRange", oldValue, dataRange);
}
use of org.vcell.util.Range in project vcell by virtualcell.
the class ImageContainer method setScaleRange.
/**
* Sets the scaleRange property (cbit.image.Range) value.
* @param scaleRange The new value for the property.
* @see #getScaleRange
*/
public final void setScaleRange(Range scaleRange) {
if (getDisplayAdapter() == null) {
return;
}
getDisplayAdapter().setScaleRange(scaleRange);
Range oldValue = fieldScaleRange;
fieldScaleRange = scaleRange;
firePropertyChange("scaleRange", oldValue, scaleRange);
}
use of org.vcell.util.Range in project vcell by virtualcell.
the class ScalePanel method setScaleParameters.
/**
* This method was created in VisualAge.
* @param minmax int
* @param inputValue java.lang.String
*/
public void setScaleParameters(String inputMin, String inputMax) {
try {
double min = Math.max(0, Double.valueOf(inputMin).doubleValue());
double max = Math.max(0, Double.valueOf(inputMax).doubleValue());
if (min > max)
min = 0;
setScaleRange(new Range(min, max));
} catch (NumberFormatException e) {
// put back existing values
resetTextFields(getScaleRange());
}
return;
}
Aggregations