use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class ROIAssistPanel method pickKeepRegionInfoFromCurrentROI.
private RegionInfo[] pickKeepRegionInfoFromCurrentROI() throws Exception {
RegionInfo[] thresholdRegionInfos = calculateRegionInfos(dataToThreshold.getCurrentlyDisplayedROI().getPixelsXYZ());
Vector<RegionInfo> roiRegionInfoV = new Vector<RegionInfo>();
for (int i = 0; i < thresholdRegionInfos.length; i++) {
if (thresholdRegionInfos[i].getPixelValue() == 1) {
roiRegionInfoV.add(thresholdRegionInfos[i]);
}
}
if (roiRegionInfoV.size() == 0) {
DialogUtils.showInfoDialog(this, "There are no Regions Of Interest to resolve.");
return null;
}
// Present list to pick from
final RegionInfo[] regionInfoArr = roiRegionInfoV.toArray(new RegionInfo[0]);
Arrays.sort(regionInfoArr, new Comparator<RegionInfo>() {
public int compare(RegionInfo o1, RegionInfo o2) {
return o2.getNumPixels() - o1.getNumPixels();
}
});
final Object[][] rowData = new Object[regionInfoArr.length][1];
for (int i = 0; i < regionInfoArr.length; i++) {
rowData[i][0] = regionInfoArr[i].getNumPixels() + " pixels";
}
final ROI beforeROI = new ROI(dataToThreshold.getCurrentlyDisplayedROI());
int[] resultArr = null;
ListSelectionListener listSelectionListener = new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
try {
DefaultListSelectionModel defaultListSelectionModel = (DefaultListSelectionModel) e.getSource();
Vector<Integer> pickedIndexes = new Vector<Integer>();
if (!defaultListSelectionModel.isSelectionEmpty()) {
for (int i = defaultListSelectionModel.getMinSelectionIndex(); i <= defaultListSelectionModel.getMaxSelectionIndex(); i++) {
if (defaultListSelectionModel.isSelectedIndex(i)) {
pickedIndexes.add(i);
}
}
}
// beforeROI.getPixelsXYZ();
short[] pickedPixels = new short[beforeROI.getISize().getXYZ()];
for (int i = 0; i < pickedPixels.length; i++) {
for (int j = 0; j < pickedIndexes.size(); j++) {
if (regionInfoArr[pickedIndexes.elementAt(j)].isIndexInRegion(i)) {
pickedPixels[i] = 1;
}
}
}
ROI newCellROI = null;
if (pickedIndexes.size() == 0) {
newCellROI = beforeROI;
} else {
UShortImage ushortImage = new UShortImage(pickedPixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
newCellROI = new ROI(ushortImage, originalROI.getROIName());
}
dataToThreshold.addReplaceRoi(newCellROI);
} catch (Exception e2) {
e2.printStackTrace();
throw new RuntimeException("Error selecting resolved ROI", e2);
}
}
}
};
try {
resultArr = DialogUtils.showComponentOptionsTableList(this, "Select 1 or more pixel regions to keep in ROI", new String[] { "ROI Size (pixel count)" }, rowData, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, listSelectionListener, null, null, null).selectedTableRows;
} catch (UserCancelException e) {
resultArr = null;
}
if (resultArr != null && resultArr.length > 0) {
RegionInfo[] pickedRegions = new RegionInfo[resultArr.length];
for (int i = 0; i < resultArr.length; i++) {
pickedRegions[i] = regionInfoArr[resultArr[i]];
}
// (resultArr == null?null:regionInfoArr[resultArr]);
return pickedRegions;
} else {
dataToThreshold.addReplaceRoi(beforeROI);
}
return null;
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class VFrap_OverlayEditorPanelJAI method getImportROIMaskButton.
public JButton getImportROIMaskButton() {
if (importROIMaskButton == null) {
importROIMaskButton = new JButton(new ImageIcon(getClass().getResource("/images/importROI.gif")));
importROIMaskButton.setPreferredSize(new Dimension(32, 32));
importROIMaskButton.setMargin(new Insets(2, 2, 2, 2));
importROIMaskButton.setToolTipText("Import ROI mask from file");
importROIMaskButton.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent e) {
File inputFile = null;
try {
int option = openJFileChooser.showOpenDialog(VFrap_OverlayEditorPanelJAI.this);
if (option == JFileChooser.APPROVE_OPTION) {
inputFile = openJFileChooser.getSelectedFile();
} else {
throw UserCancelException.CANCEL_GENERIC;
}
if (!customROIImport.importROI(inputFile)) {
ImageDataset importImageDataset = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDataset(inputFile.getAbsolutePath(), null);
if (importImageDataset.getISize().getX() * importImageDataset.getISize().getY() != getImagePane().getHighlightImage().getWidth() * getImagePane().getHighlightImage().getHeight()) {
throw new Exception("Imported ROI mask size (" + importImageDataset.getISize().getX() + "," + importImageDataset.getISize().getY() + ")" + " does not match current Frap DataSet size (" + getImagePane().getHighlightImage().getWidth() + "," + getImagePane().getHighlightImage().getHeight() + ")");
}
// BufferedImage roiMaskImage = BufferedImageReader.makeBufferedImageReader(iFormatReader).openImage(0);
UShortImage roiMaskImage = importImageDataset.getImage(0, 0, 0);
int maskColor = highlightColor.getRGB();
for (int y = 0; y < importImageDataset.getISize().getY(); y++) {
for (int x = 0; x < importImageDataset.getISize().getX(); x++) {
if ((roiMaskImage.getPixel(x, y, 0) & 0xFFFF) != 0) {
getImagePane().getHighlightImage().setRGB(x, y, maskColor);
}
}
}
getImagePane().refreshImage();
}
} catch (UserCancelException uce) {
// Do Nothing
} catch (Exception e1) {
e1.printStackTrace();
DialogUtils.showErrorDialog(VFrap_OverlayEditorPanelJAI.this, "Error importing ROI" + e1.getMessage());
}
}
});
}
return importROIMaskButton;
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class VFrap_ROIAssistPanel method pickKeepRegionInfoFromCurrentROI.
private RegionInfo pickKeepRegionInfoFromCurrentROI() throws Exception {
if (lastRegionInfos == null) {
throw new Exception("No regionInfo to resolve");
}
final Vector<RegionInfo> roiRegionInfoV2 = new Vector<RegionInfo>();
for (int i = 0; i < lastRegionInfos.length; i++) {
if (lastRegionInfos[i].getPixelValue() == 1) {
roiRegionInfoV2.add(lastRegionInfos[i]);
}
}
if (roiRegionInfoV2.size() <= 1) {
throw new Exception("No regionInfo to resolve");
}
final RegionInfo[] regionInfoArr = roiRegionInfoV2.toArray(new RegionInfo[0]);
Arrays.sort(regionInfoArr, new Comparator<RegionInfo>() {
public int compare(RegionInfo o1, RegionInfo o2) {
return o2.getNumPixels() - o1.getNumPixels();
}
});
final Object[][] rowData = new Object[regionInfoArr.length][1];
for (int i = 0; i < regionInfoArr.length; i++) {
rowData[i][0] = regionInfoArr[i].getNumPixels() + " pixels";
}
ROI beforeROI = new ROI(frapData.getCurrentlyDisplayedROI());
int[] resultArr = null;
// SwingUtilities.invokeAndWait(new Runnable(){public void run(){//}});
try {
resultArr = /*DialogUtils.*/
showComponentOKCancelTableList(this, "Select ROI to Keep", new String[] { "ROI Size (pixel count)" }, rowData, ListSelectionModel.SINGLE_SELECTION, regionInfoArr, beforeROI.getPixelsXYZ());
} catch (UserCancelException e) {
resultArr = null;
}
// }});
if (resultArr != null && resultArr.length > 0) {
return (resultArr == null ? null : regionInfoArr[resultArr[0]]);
} else {
// SwingUtilities.invokeAndWait(new Runnable(){public void run(){//}});
frapData.addReplaceRoi(beforeROI);
applyROIButton.setEnabled(false);
resolveROIButton.setEnabled(true);
fillVoidsButton.setEnabled(false);
// }});
}
return null;
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class ImageJHelper method vcellSendImage.
public static void vcellSendImage(final Component requester, final PDEDataContext pdeDataContext, SubVolume subvolume, Hashtable<SampledCurve, int[]>[] membraneTables, String description, double[] timePoints, String[] channelDescriptions, int[] colormap) throws Exception {
// xyz, 1 time, 1 var
final ImageJConnection[] imageJConnectionArr = new ImageJConnection[1];
AsynchClientTask sendImageTask = new AsynchClientTask("Send image to ImageJ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
try {
ImageJConnection imageJConnection = new ImageJConnection(ExternalCommunicator.IMAGEJ);
imageJConnectionArr[0] = imageJConnection;
imageJConnection.openConnection(VCellImageJCommands.vcellSendImage, description);
// send size of the standard 5 dimensions in this order (width, height, nChannels, nSlices, nFrames)
ISize xyzSize = pdeDataContext.getCartesianMesh().getISize();
Extent extent = pdeDataContext.getCartesianMesh().getExtent();
BasicStackDimensions basicStackDimensions = new BasicStackDimensions(xyzSize.getX(), xyzSize.getY(), xyzSize.getZ(), 1, 1);
sendData0(imageJConnection, new HyperStackHelper(basicStackDimensions, extent, true, Float.class.getSimpleName(), null, new int[] { subvolume.getHandle() }, timePoints, channelDescriptions, colormap), pdeDataContext.getDataValues(), "'" + pdeDataContext.getVariableName() + "'" + pdeDataContext.getTimePoint());
sendVolumeDomain0(imageJConnection, pdeDataContext.getCartesianMesh(), null, description);
sendMembraneOutline(imageJConnection, membraneTables);
} catch (Exception e) {
if (e instanceof UserCancelException) {
throw e;
}
e.printStackTrace();
hashTable.put("imagejerror", e);
} finally {
try {
if (imageJConnectionArr[0] != null) {
imageJConnectionArr[0].closeConnection();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
};
ClientTaskDispatcher.dispatch(requester, new Hashtable<>(), new AsynchClientTask[] { sendImageTask }, false, true, new ProgressDialogListener() {
@Override
public void cancelButton_actionPerformed(EventObject newEvent) {
if (imageJConnectionArr[0] != null) {
imageJConnectionArr[0].closeConnection();
}
}
});
}
use of org.vcell.util.UserCancelException in project vcell by virtualcell.
the class ExportServiceImpl method makeRemoteFile.
public ExportEvent makeRemoteFile(OutputContext outputContext, User user, DataServerImpl dataServerImpl, ExportSpecs exportSpecs, boolean bSaveAsZip, ClientTaskStatusSupport clientTaskStatusSupport) throws DataAccessException {
// if export completes successfully, we return the generated event for logging
if (user == null) {
throw new DataAccessException("ERROR: user is null");
}
JobRequest newExportJob = JobRequest.createExportJobRequest(user);
jobRequestIDs.put(new Long(newExportJob.getJobID()), user);
if (lg.isTraceEnabled())
lg.trace("ExportServiceImpl.makeRemoteFile(): " + newExportJob + ", " + exportSpecs);
String fileFormat = null;
switch(exportSpecs.getFormat()) {
case CSV:
fileFormat = "CSV";
break;
case QUICKTIME:
fileFormat = "MOV";
break;
case GIF:
case ANIMATED_GIF:
fileFormat = "GIF";
break;
case FORMAT_JPEG:
fileFormat = "JPEG";
break;
case NRRD:
fileFormat = "NRRD";
break;
case IMAGEJ:
fileFormat = "IMAGEJ";
break;
}
fireExportStarted(newExportJob.getJobID(), exportSpecs.getVCDataIdentifier(), fileFormat);
try {
String exportBaseURL = PropertyLoader.getRequiredProperty(PropertyLoader.exportBaseURLProperty);
String exportBaseDir = PropertyLoader.getRequiredProperty(PropertyLoader.exportBaseDirInternalProperty);
// we need to make new output
if (lg.isTraceEnabled())
lg.trace("ExportServiceImpl.makeRemoteFile(): Starting new export job: " + newExportJob);
FileDataContainerManager fileDataContainerManager = new FileDataContainerManager();
try {
ExportOutput[] exportOutputs = null;
switch(exportSpecs.getFormat()) {
case CSV:
Collection<ExportOutput> asciiOut = asciiExporter.makeASCIIData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
exportOutputs = asciiOut.toArray(new ExportOutput[asciiOut.size()]);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
case QUICKTIME:
case GIF:
case FORMAT_JPEG:
case ANIMATED_GIF:
exportOutputs = imgExporter.makeMediaData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, clientTaskStatusSupport, fileDataContainerManager);
boolean bOverrideZip = exportOutputs.length == 1;
if (bSaveAsZip && !bOverrideZip) {
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
} else {
return makeRemoteFile_Unzipped(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
}
case NRRD:
case IMAGEJ:
NrrdInfo[] nrrdInfos = rrExporter.makeRasterData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, nrrdInfos, exportSpecs, newExportJob, fileDataContainerManager);
case UCD:
exportOutputs = rrExporter.makeUCDData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
case PLY:
exportOutputs = rrExporter.makePLYWithTexData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
case VTK_IMAGE:
exportOutputs = rrExporter.makeVTKImageData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
case VTK_UNSTRUCT:
exportOutputs = rrExporter.makeVTKUnstructuredData0(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
default:
throw new DataAccessException("Unknown export format requested");
}
} finally {
fileDataContainerManager.closeAllAndDelete();
}
} catch (UserCancelException ex) {
throw ex;
} catch (Throwable exc) {
lg.error(exc.getMessage(), exc);
fireExportFailed(newExportJob.getJobID(), exportSpecs.getVCDataIdentifier(), fileFormat, exc.getMessage());
throw new DataAccessException(exc.getMessage());
}
}
Aggregations