use of org.vcell.util.ISize in project vcell by virtualcell.
the class ROIMultiPaintManager method loadFD.
private void loadFD(Hashtable<String, Object> hashTable) throws Exception {
final Exception[] excHolder = new Exception[] { null };
final JDialog jDialog = new JDialog(JOptionPane.getFrameForComponent(this.overlayEditorPanelJAI));
jDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
jDialog.setTitle("Import Type");
jDialog.setModal(true);
final JPanel okCancelJPanel = new JPanel(new FlowLayout());
JButton okJButton = new JButton("from File...");
okJButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
fdDelta = new double[] { 0, 0, 0 };
fdDeltaLast = new double[] { 0, 0, 0 };
currScale = 1.0;
currScaleLast = 1.0;
VCDocument.DocumentCreationInfo documentCreationInfo = new VCDocument.DocumentCreationInfo(VCDocumentType.GEOMETRY_DOC, VCDocument.GEOM_OPTION_FILE);
final AsynchClientTask selectImageFile = ClientRequestManager.getSelectImageFileTask(overlayEditorPanelJAI, null);
final AsynchClientTask parseImageTask = ClientRequestManager.getParseImageTask(overlayEditorPanelJAI, documentCreationInfo, null);
final AsynchClientTask importFileImage = ClientRequestManager.getImportFileImageTask(documentCreationInfo);
// final AsynchClientTask resizeImageTask = ClientRequestManager.getResizeImageTask(documentCreationInfo);
hashTable.put(ClientRequestManager.GUI_PARENT, ROIMultiPaintManager.this.overlayEditorPanelJAI);
selectImageFile.run(hashTable);
parseImageTask.run(hashTable);
hashTable.put(ClientRequestManager.NEW_IMAGE_SIZE_INFO, hashTable.get(ClientRequestManager.ORIG_IMAGE_SIZE_INFO));
importFileImage.run(hashTable);
// resizeImageTask.run(hashTable);
saveFDUnderlay(hashTable);
} catch (Exception e1) {
excHolder[0] = e1;
// e1.printStackTrace();
// DialogUtils.showErrorDialog(ROIMultiPaintManager.this.overlayEditorPanelJAI, e1.getMessage());
} finally {
jDialog.dispose();
}
}
});
JButton fdJButton = new JButton("from FieldData...");
fdJButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
ArrayList<Object[]> allRows = new ArrayList<Object[]>();
ArrayList<ISize> iSizes = new ArrayList<ISize>();
ArrayList<CartesianMesh> meshes = new ArrayList<CartesianMesh>();
// DocumentManager documentManager = documentManager.getSessionManager()..getRequestManager().getDocumentManager();
FieldDataDBOperationSpec fdos = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser());
FieldDataDBOperationResults fieldDataDBOperationResults = documentManager.fieldDataDBOperation(fdos);
ExternalDataIdentifier[] externalDataIdentifierArr = fieldDataDBOperationResults.extDataIDArr;
Arrays.sort(externalDataIdentifierArr, new Comparator<ExternalDataIdentifier>() {
@Override
public int compare(ExternalDataIdentifier o1, ExternalDataIdentifier o2) {
// TODO Auto-generated method stub
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
ArrayList<ExternalDataIdentifier> okEDI = new ArrayList<ExternalDataIdentifier>();
for (int i = 0; externalDataIdentifierArr != null && i < externalDataIdentifierArr.length; i++) {
try {
FieldDataFileOperationSpec fieldDataFileOperationSpec = FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec(externalDataIdentifierArr[i].getSimulationKey(), externalDataIdentifierArr[i].getOwner(), externalDataIdentifierArr[i].getJobIndex());
FieldDataFileOperationResults fieldDataFileOperationResults = documentManager.fieldDataFileOperation(fieldDataFileOperationSpec);
// System.out.println(externalDataIdentifierArr[i].getName()+" "+fieldDataFileOperationResults.iSize);
ISize iSize = fieldDataFileOperationResults.iSize;
iSizes.add(iSize);
// isizes.add(iSize);
okEDI.add(externalDataIdentifierArr[i]);
allRows.add(new Object[] { iSize.getX(), iSize.getY(), iSize.getZ(), "FieldData='" + externalDataIdentifierArr[i].getName() + "'" });
VCImageUncompressed vcImageUnc = new VCImageUncompressed(null, new byte[iSize.getXYZ()], fieldDataFileOperationResults.extent, iSize.getX(), iSize.getY(), iSize.getZ());
int dimension = 1 + (iSize.getY() > 1 ? 1 : 0) + (iSize.getZ() > 1 ? 1 : 0);
CartesianMesh simpleMesh = CartesianMesh.createSimpleCartesianMesh(fieldDataFileOperationResults.origin, fieldDataFileOperationResults.extent, iSize, new RegionImage(vcImageUnc, dimension, fieldDataFileOperationResults.extent, fieldDataFileOperationResults.origin, RegionImage.NO_SMOOTHING));
meshes.add(simpleMesh);
} catch (Exception e2) {
e2.printStackTrace();
}
}
if (allRows.size() > 0) {
Object[][] rowData = allRows.toArray(new Object[0][]);
int[] selections = DialogUtils.showComponentOKCancelTableList(ROIMultiPaintManager.this.overlayEditorPanelJAI, "Select Simulation for Geom Size", new String[] { "X", "Y", "Z", "Name" }, rowData, ListSelectionModel.SINGLE_SELECTION);
if (selections != null && selections.length == 1) {
FieldDataFileOperationResults fdfor = documentManager.fieldDataFileOperation(FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec(okEDI.get(selections[0]).getSimulationKey(), okEDI.get(selections[0]).getOwner(), okEDI.get(selections[0]).getJobIndex()));
SimDataBlock simDataBlock = VCellClientTest.getVCellClient().getClientServerManager().getDataSetController().getSimDataBlock(null, okEDI.get(selections[0]), fdfor.dataIdentifierArr[0].getName(), 0.0);
FieldDataFileOperationSpec fieldDataFileOperationSpec = new FieldDataFileOperationSpec();
fieldDataFileOperationSpec.isize = meshes.get(selections[0]).getISize();
fieldDataFileOperationSpec.shortSpecData = new short[][][] { { new short[fieldDataFileOperationSpec.isize.getXYZ()] } };
for (int i = 0; i < simDataBlock.getData().length; i++) {
fieldDataFileOperationSpec.shortSpecData[0][0][i] = (short) simDataBlock.getData()[i];
// if(simDataBlock.getData()[i] != 0) {
// System.out.println(simDataBlock.getData()[i]);
// }
}
hashTable.put(ClientRequestManager.FDFOS, fieldDataFileOperationSpec);
hashTable.put(ClientRequestManager.IMPORT_SOURCE_NAME, "FieldData=" + okEDI.get(selections[0]).getName());
saveFDUnderlay(hashTable);
// ROIMultiPaintManager.this.fdShort = (FieldDataFileOperationSpec)hashTable.get(ClientRequestManager.FDFOS);
// ROIMultiPaintManager.this.importSourceName = (String)hashTable.get(ClientRequestManager.IMPORT_SOURCE_NAME);
// (outMax-outMin)(inVal - inMin)
// ------------------------------ + outMin
// inMax - inMin
// externalDataIdentifierArr[selections[0]].
// // ImageSizeInfo imagesizeInfo = new ImageSizeInfo("internal",meshes.get(selections[0]).getISize(),1,new double[] {0},0);
// ImageSizeInfo imagesizeInfo = new ImageSizeInfo("internal",iSizes.get(selections[0]),1,new double[] {0},0);
// hashTable.put(ClientRequestManager.NEW_IMAGE_SIZE_INFO, imagesizeInfo);
//
// VCImage image = sourceGeom.getGeometrySpec().getImage();
// ISize samplingSize = new ISize(image.getNumX(),image.getNumY(),image.getNumZ());//
// VCImageUncompressed vcImageUnc = new VCImageUncompressed(null, new byte[samplingSize.getXYZ()], sourceGeom.getExtent(), samplingSize.getX(), samplingSize.getY(), samplingSize.getZ());
// CartesianMesh sourceMesh = CartesianMesh.createSimpleCartesianMesh(
// sourceGeom.getOrigin(),
// sourceGeom.getExtent(),
// samplingSize,
// new RegionImage(vcImageUnc, sourceGeom.getDimension(), sourceGeom.getExtent(), sourceGeom.getOrigin(), RegionImage.NO_SMOOTHING));
//
// hashTable.put("newMesh", meshes.get(selections[0]));
// hashTable.put("sourceMesh", sourceMesh);
}
}
} catch (Exception e1) {
excHolder[0] = e1;
// e1.printStackTrace();
// DialogUtils.showErrorDialog(ROIMultiPaintManager.this.overlayEditorPanelJAI, e1.getMessage());
} finally {
jDialog.dispose();
}
}
});
JButton clipbboardJButton = new JButton("from Clipboard");
clipbboardJButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Transferable contents = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
try {
Object transferData = contents.getTransferData(DataFlavor.stringFlavor);
if (transferData instanceof String) {
StringTokenizer st = new StringTokenizer(((String) transferData).toString(), ",");
String varName = st.nextToken();
String vcDataIdentifer = st.nextToken();
double timePoint = Double.parseDouble(st.nextToken());
ISize isize = new ISize(Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()), Integer.parseInt(st.nextToken()));
Range inRange = new Range(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()));
String simDataFile = st.nextToken();
DataInputStream dis = new DataInputStream(new FileInputStream(simDataFile));
FieldDataFileOperationSpec fieldDataFileOperationSpec = new FieldDataFileOperationSpec();
fieldDataFileOperationSpec.isize = isize;
fieldDataFileOperationSpec.shortSpecData = new short[][][] { { new short[fieldDataFileOperationSpec.isize.getXYZ()] } };
double outMax = 65535;
double outMin = 0;
double scale = (outMax - outMin) / (inRange.getMax() - inRange.getMin());
for (int i = 0; i < isize.getXYZ(); i++) {
double val = dis.readDouble();
fieldDataFileOperationSpec.shortSpecData[0][0][i] = (short) (scale * (val - inRange.getMin()) + outMin);
}
hashTable.put(ClientRequestManager.FDFOS, fieldDataFileOperationSpec);
hashTable.put(ClientRequestManager.IMPORT_SOURCE_NAME, "SimData=" + vcDataIdentifer + " varName=" + varName + " time=" + timePoint);
saveFDUnderlay(hashTable);
ROIMultiPaintManager.this.overlayEditorPanelJAI.setFDScale(new double[] { scale, inRange.getMin(), outMin });
}
} catch (Exception e1) {
excHolder[0] = e1;
// e1.printStackTrace();
// DialogUtils.showErrorDialog(ROIMultiPaintManager.this.overlayEditorPanelJAI, e1.getMessage());
} finally {
jDialog.dispose();
}
}
});
final boolean[] bCanelHolder = new boolean[] { false };
JButton cancelJButton = new JButton("Cancel");
cancelJButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
jDialog.dispose();
bCanelHolder[0] = true;
}
});
okCancelJPanel.add(okJButton);
okCancelJPanel.add(fdJButton);
okCancelJPanel.add(clipbboardJButton);
okCancelJPanel.add(cancelJButton);
jDialog.getContentPane().add(okCancelJPanel, BorderLayout.SOUTH);
jDialog.pack();
// jDialog.setSize(300,250);
DialogUtils.showModalJDialogOnTop(jDialog, overlayEditorPanelJAI);
if (bCanelHolder[0]) {
throw UserCancelException.CANCEL_GENERIC;
}
if (excHolder[0] != null) {
throw excHolder[0];
}
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class ROIMultiPaintManager method resizeImpl.
private void resizeImpl(ResizeInfo resizeInfo, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
resizeImpl0(resizeInfo, (bHasOriginalData ? initImageDataSetChannels : null), roiComposite);
ISize newISize = resizeInfo.getNewSize();
ISize oldISize = resizeInfo.getOriginalSize();
Extent resizeExtent = createResizeExtent(originalExtent, oldISize, newISize);
if (bHasOriginalData) {
for (int c = 0; c < initImageDataSetChannels.length; c++) {
UShortImage[] zImageSet = new UShortImage[newISize.getZ()];
for (int z = 0; z < zImageSet.length; z++) {
zImageSet[z] = new UShortImage(resizeInfo.underlayC[c][z], originalOrigin, resizeExtent, newISize.getX(), newISize.getY(), 1);
}
initImageDataSetChannels[c] = new ImageDataset(zImageSet, new double[] { 0.0 }, newISize.getZ());
}
} else {
initImageDataSet(null, newISize);
}
roiComposite = resizeInfo.roiComposite;
updateAuxiliaryInfo(originalISize, clientTaskStatusSupport);
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class ROIMultiPaintManager method cropROIData.
private void cropROIData(final Crop3D cropRectangle3D) /*,boolean bThread*/
{
final AsynchClientTask cropTask = new AsynchClientTask("Cropping...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
ISize origISize = getImageDataSetChannel().getISize();
CoordinateIndex cropLow = new CoordinateIndex(-cropRectangle3D.low.x, -cropRectangle3D.low.y, -cropRectangle3D.low.z);
CoordinateIndex cropHigh = new CoordinateIndex(cropRectangle3D.low.x + cropRectangle3D.width - origISize.getX(), cropRectangle3D.low.y + cropRectangle3D.height - origISize.getY(), cropRectangle3D.low.z + cropRectangle3D.depth - origISize.getZ());
resizeImpl(ResizeInfo.createPadCropResizeInfo(origISize, cropLow, cropHigh), getClientTaskStatusSupport());
updateAuxiliaryInfo(origISize, getClientTaskStatusSupport());
}
};
final AsynchClientTask updatePanelTask = getUpdateDisplayAfterCropTask();
final Hashtable<String, Object> taskHash = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, taskHash, new AsynchClientTask[] { cropTask, updatePanelTask }, false, false, null, true);
// if(bThread){
// ClientTaskDispatcher.dispatch(overlayEditorPanelJAI,taskHash,
// new AsynchClientTask[] {cropTask,updatePanelTask},false,false,null,true);
// }else{
// new Thread(new Runnable() {
// public void run(){
// try{
// cropTask.run(taskHash);
// SwingUtilities.invokeAndWait(new Runnable() {
// public void run() {
// try {
// updatePanelTask.run(taskHash);
// } catch (Exception e) {
// e.printStackTrace();
// throw new RuntimeException(e);
// }
// }
// });
// }catch(Exception e){
// e.printStackTrace();
// DialogUtils.showErrorDialog(overlayEditorPanelJAI, "Crop failed:\n"+e.getMessage()+
// (e.getCause()!= null?"\n"+e.getCause().getMessage():""), e);
// }
// }
// }).run();
// }
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class ROIMultiPaintManager method duplicateROIData.
private void duplicateROIData(final int newZSize) {
final AsynchClientTask extrudeTask = new AsynchClientTask("Extruding...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
ISize origSize = getImageDataSetChannel().getISize();
if (origSize.getZ() != 1 || newZSize < 1) {
throw new IllegalArgumentException("Extrude assumes starting with 2D and new Z size >= 1.");
}
UShortImage[][] newUnderLayImageArr = new UShortImage[initImageDataSetChannels.length][newZSize];
BufferedImage[] newROICompositeArr = new BufferedImage[newZSize];
for (int i = 0; i < newZSize; i++) {
for (int c = 0; c < initImageDataSetChannels.length; c++) {
// short[] zslice = new short[initImageDataSetChannels[c].getAllImages()[0].getPixels().length];
// System.arraycopy(initImageDataSetChannels[c].getAllImages()[0].getPixels(), 0, zslice, 0, zslice.length);
newUnderLayImageArr[c][i] = new UShortImage(// zslice,
initImageDataSetChannels[c].getAllImages()[0].getPixels().clone(), DEFAULT_ORIGIN, DEFAULT_EXTENT, initImageDataSetChannels[c].getAllImages()[0].getNumX(), initImageDataSetChannels[c].getAllImages()[0].getNumY(), 1);
}
newROICompositeArr[i] = new BufferedImage(roiComposite[0].getWidth(), roiComposite[0].getHeight(), BufferedImage.TYPE_BYTE_INDEXED, getContrastIndexColorModel());
System.arraycopy((byte[]) ((DataBufferByte) roiComposite[0].getRaster().getDataBuffer()).getData(), 0, (byte[]) ((DataBufferByte) newROICompositeArr[i].getRaster().getDataBuffer()).getData(), 0, origSize.getX() * origSize.getY());
}
for (int c = 0; c < initImageDataSetChannels.length; c++) {
initImageDataSetChannels[c] = new ImageDataset(newUnderLayImageArr[c], null, newZSize);
}
roiComposite = newROICompositeArr;
if (!(enhanceImageAmount == ROIMultiPaintManager.ENHANCE_NONE)) {
getClientTaskStatusSupport().setMessage("smoothing...");
}
updateAuxiliaryInfo(origSize, getClientTaskStatusSupport());
}
};
final AsynchClientTask updatePanelTask = getUpdateDisplayAfterCropTask();
ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<String, Object>(), new AsynchClientTask[] { extrudeTask, updatePanelTask }, false, false, null, true);
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class ROIMultiPaintManager method checkBorders.
private VCImage checkBorders(VCImage checkThisVCImage) throws Exception {
boolean bAddBorder = false;
BorderInfo borderInfo = checkBorderInfo(checkThisVCImage);
if (borderInfo.bXYTouch || borderInfo.bZTouch) {
boolean b3DTouch = borderInfo.bXYTouch && borderInfo.bZTouch;
String edgeDescrFrag = "on the " + (b3DTouch ? "XY and Z" : (borderInfo.bXYTouch ? "XY" : "Z")) + " border.";
final String addBorder = "Add empty border";
final String keep = "Keep as is";
final String cancel = "Cancel";
String result = DialogUtils.showWarningDialog(overlayEditorPanelJAI, "One or more Domain Regions touches the outer boundary " + edgeDescrFrag + "\n" + "Choose an option:\n" + "1. Keep as is, do not change.\n" + "2. Add empty 'background' border around outer boundary so no Domain Region touches an outer edge.", new String[] { keep, addBorder, cancel }, keep);
if (result.equals(cancel)) {
throw UserCancelException.CANCEL_GENERIC;
} else if (result.equals(addBorder)) {
bAddBorder = true;
;
}
}
if (!bAddBorder) {
return null;
}
ISize checkThisVCImageISize = new ISize(checkThisVCImage.getNumX(), checkThisVCImage.getNumY(), checkThisVCImage.getNumZ());
boolean bxy = borderInfo.bXYTouch;
boolean bz = borderInfo.bZTouch;
ROIMultiPaintManager.PaddedInfo paddedInfo = copyToPadded(checkThisVCImage.getPixels(), checkThisVCImageISize, null, checkThisVCImage.getExtent(), new ISize((bxy ? 1 : 0), (bxy ? 1 : 0), (bz ? 1 : 0)), new ISize((bxy ? 1 : 0), (bxy ? 1 : 0), (bz ? 1 : 0)));
VCImage newVCImage = new VCImageUncompressed(null, (byte[]) paddedInfo.paddedArray, DEFAULT_EXTENT, /*paddedInfo.paddedExtent*/
paddedInfo.paddedISize.getX(), paddedInfo.paddedISize.getY(), paddedInfo.paddedISize.getZ());
return newVCImage;
}
Aggregations