use of org.vcell.util.ISize in project vcell by virtualcell.
the class ClientRequestManager method getISizeFromUser.
public static ISize getISizeFromUser(Component guiParent, ISize initISize, String textMessage) throws UserCancelException {
Integer imageDimension = (initISize == null ? null : (initISize.getX() != 1 ? 1 : 0) + (initISize.getY() != 1 ? 1 : 0) + (initISize.getZ() != 1 ? 1 : 0));
if (imageDimension != null && (imageDimension < 1 || imageDimension > 3)) {
throw new IllegalArgumentException("Dimension must be 1, 2 or 3.");
}
try {
int xsize = (imageDimension == null ? -1 : initISize.getX());
int ysize = (imageDimension == null ? -1 : initISize.getY());
int zsize = (imageDimension == null ? -1 : initISize.getZ());
do {
String result = (imageDimension == null ? "256,256,8" : xsize + "," + ysize + "," + zsize);
result = DialogUtils.showInputDialog0(guiParent, textMessage, result);
String tempResult = result;
try {
if (result == null || result.length() == 0) {
result = "";
throw new Exception("No size values entered.");
}
xsize = Integer.parseInt(tempResult.substring(0, tempResult.indexOf(",")));
tempResult = tempResult.substring(tempResult.indexOf(",") + 1, tempResult.length());
ysize = Integer.parseInt(tempResult.substring(0, tempResult.indexOf(",")));
tempResult = tempResult.substring(tempResult.indexOf(",") + 1, tempResult.length());
zsize = Integer.parseInt(tempResult);
if (imageDimension != null) {
if (imageDimension == 2 && zsize != 1) {
throw new Exception("Dimension " + imageDimension + " must have z = 1.");
} else if (imageDimension == 1 && zsize != 1 && ysize != 1) {
throw new Exception("Dimension " + imageDimension + " must have z = 1 and y = 1.");
}
}
ISize isize = new ISize(xsize, ysize, zsize);
if (isize.getXYZ() <= 0) {
throw new Exception("Total pixels (" + xsize + "*" + ysize + "*" + zsize + ") cannot be <=0.");
}
return isize;
} catch (Exception e) {
DialogUtils.showErrorDialog(guiParent, "Error entering starting sizes\n" + e.getMessage(), e);
}
} while (true);
} catch (UtilCancelException e2) {
throw UserCancelException.CANCEL_GENERIC;
}
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class TopLevelWindowManager method addWorkspaceGeomSizeSelection.
private void addWorkspaceGeomSizeSelection(final Hashtable<String, Object> hash, Geometry sourceGeom) throws Exception {
if (TopLevelWindowManager.this instanceof DocumentWindowManager) {
Simulation[] simulations = null;
SimulationContext[] simContexts = null;
SimulationContext selectedSC = null;
ArrayList<Object[]> allRows = new ArrayList<Object[]>();
ArrayList<ISize> iSizes = new ArrayList<ISize>();
if (this instanceof BioModelWindowManager) {
BioModelWindowManager bmwm = ((BioModelWindowManager) this);
// System.out.println(bmwm);
if (bmwm.getDocumentEditor() instanceof cbit.vcell.client.desktop.biomodel.BioModelEditor) {
cbit.vcell.client.desktop.biomodel.BioModelEditor bme = (cbit.vcell.client.desktop.biomodel.BioModelEditor) bmwm.getDocumentEditor();
// System.out.println(bme);
selectedSC = bme.getSelectedSimulationContext();
// System.out.println(selectedSC);
}
}
if (((DocumentWindowManager) TopLevelWindowManager.this).getVCDocument() instanceof BioModel) {
simContexts = ((BioModel) ((DocumentWindowManager) TopLevelWindowManager.this).getVCDocument()).getSimulationContexts();
} else if (((DocumentWindowManager) TopLevelWindowManager.this).getVCDocument() instanceof MathModel) {
simulations = ((MathModel) ((DocumentWindowManager) TopLevelWindowManager.this).getVCDocument()).getSimulations();
}
String[] simColumnNames = null;
if (simContexts != null) {
simColumnNames = new String[] { "x", "y", "z", "appName", "simName" };
} else {
simColumnNames = new String[] { "x", "y", "z", "simName" };
}
ArrayList<Object[]> simRows = new ArrayList<Object[]>();
ArrayList<CartesianMesh> meshes = new ArrayList<CartesianMesh>();
for (int j = 0; j < (simContexts == null ? 1 : simContexts.length); j++) {
Geometry geom = null;
if (simContexts != null) {
if (simContexts[j] != selectedSC) {
continue;
}
simulations = simContexts[j].getSimulations();
geom = simContexts[j].getGeometry();
} else {
geom = ((MathModel) ((DocumentWindowManager) TopLevelWindowManager.this).getVCDocument()).getGeometry();
}
// ISize defaultSamplesize = geom.getGeometrySpec().getDefaultSampledImageSize();
if (simulations != null && simulations.length > 0) {
for (int i = 0; i < simulations.length; i++) {
Object[] row = new Object[simColumnNames.length];
// }
if (simulations[i].getMeshSpecification() != null && simulations[i].getMeshSpecification() != null) {
row = new Object[simColumnNames.length];
ISize samplingSize = simulations[i].getMeshSpecification().getSamplingSize();
row[0] = samplingSize.getX();
row[1] = samplingSize.getY();
row[2] = samplingSize.getZ();
row[3] = (simContexts != null ? simContexts[j].getName() : simulations[i].getName());
if (simContexts != null) {
row[4] = simulations[i].getName();
}
simRows.add(row);
VCImageUncompressed vcImageUnc = new VCImageUncompressed(null, new byte[samplingSize.getXYZ()], geom.getExtent(), samplingSize.getX(), samplingSize.getY(), samplingSize.getZ());
CartesianMesh simpleMesh = CartesianMesh.createSimpleCartesianMesh(geom.getOrigin(), geom.getExtent(), samplingSize, new RegionImage(vcImageUnc, geom.getDimension(), geom.getExtent(), geom.getOrigin(), RegionImage.NO_SMOOTHING));
meshes.add(simpleMesh);
}
}
}
}
for (int i = 0; i < simRows.size(); i++) {
ISize iSize = meshes.get(i).getISize();
iSizes.add(iSize);
allRows.add(new Object[] { iSize.getX(), iSize.getY(), iSize.getZ(), "Simulation=" + (simColumnNames.length == 4 ? simRows.get(i)[3] : simRows.get(i)[3] + ":" + simRows.get(i)[4]) });
}
// if(allRows.size() > 0) {
if (simRows.size() > 0) {
Object[][] rowData = simRows.toArray(new Object[0][]);
int[] selections = DialogUtils.showComponentOKCancelTableList(TopLevelWindowManager.this.getComponent(), "Select Simulation for Geom Size", simColumnNames, rowData, ListSelectionModel.SINGLE_SELECTION);
if (selections != null && selections.length == 1) {
// 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);
hash.put(ClientRequestManager.NEW_IMAGE_SIZE_INFO, imagesizeInfo);
VCImage image = null;
if (sourceGeom.getGeometrySpec().getImage() == null) {
image = sourceGeom.getGeometrySpec().createSampledImage(iSizes.get(selections[0]));
} else {
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));
hash.put("newMesh", meshes.get(selections[0]));
hash.put("sourceMesh", sourceMesh);
}
}
}
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class ClientRequestManager method continueAfterMathModelGeomChangeWarning.
public static void continueAfterMathModelGeomChangeWarning(MathModelWindowManager mathModelWindowManager, Geometry newGeometry) throws UserCancelException {
MathModel mathModel = mathModelWindowManager.getMathModel();
if (mathModel != null && mathModel.getMathDescription() != null) {
Geometry oldGeometry = mathModel.getMathDescription().getGeometry();
if (oldGeometry != null && oldGeometry.getDimension() == 0) {
return;
}
boolean bMeshResolutionChange = true;
if (oldGeometry == null) {
bMeshResolutionChange = false;
}
if (newGeometry != null && oldGeometry != null && oldGeometry.getDimension() == newGeometry.getDimension()) {
bMeshResolutionChange = false;
}
boolean bHasSims = (mathModel.getSimulations() != null) && (mathModel.getSimulations().length > 0);
StringBuffer meshResolutionChangeSB = new StringBuffer();
if (bHasSims && bMeshResolutionChange) {
ISize newGeomISize = MeshSpecification.calulateResetSamplingSize(newGeometry);
for (int i = 0; i < mathModel.getSimulations().length; i++) {
if (mathModel.getSimulations()[i].getMeshSpecification() != null) {
String simName = mathModel.getSimulations()[i].getName();
ISize simMeshSize = mathModel.getSimulations()[i].getMeshSpecification().getSamplingSize();
meshResolutionChangeSB.append((i != 0 ? "\n" : "") + "'" + simName + "' Mesh" + simMeshSize + " will be reset to " + newGeomISize + "");
}
}
}
String result = DialogUtils.showWarningDialog(JOptionPane.getFrameForComponent(mathModelWindowManager.getComponent()), "After changing MathModel geometry please note:\n" + " 1. Check Geometry subvolume names match MathModel compartment names." + (bHasSims && bMeshResolutionChange ? "\n" + " 2. All existing simulations mesh sizes will be reset" + " because the new Geometry spatial dimension(" + newGeometry.getDimension() + "D)" + " does not equal the current Geometry spatial dimension(" + oldGeometry.getDimension() + "D)" + "\n" + meshResolutionChangeSB.toString() : ""), new String[] { "Continue", "Cancel" }, "Continue");
if (result != null && result.equals("Continue")) {
return;
}
} else {
return;
}
throw UserCancelException.CANCEL_GENERIC;
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class MeshSpecificationPanel method updateSize.
/**
* Comment
*/
private void updateSize() {
String error = null;
String sx = getXTextField().getText();
String sy = getYTextField().getText();
String sz = getZTextField().getText();
sx = (sx == null || sx.equals("")) ? "1" : sx;
sy = (sy == null || sy.equals("")) ? "1" : sy;
sz = (sz == null || sz.equals("")) ? "1" : sz;
try {
ISize iSize = new ISize(sx, sy, sz);
getMeshSpecification().setSamplingSize(iSize);
} catch (NumberFormatException nexc) {
error = "NumberFormatException " + nexc.getMessage();
} catch (java.beans.PropertyVetoException pexc) {
error = pexc.getMessage();
}
if (error != null) {
DialogUtils.showErrorDialog(this, "Error setting mesh size : " + error);
}
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class MeshSpecificationPanel method updateTotalSizeAndSpatialStep.
private void updateTotalSizeAndSpatialStep() {
if (getMeshSpecification() == null) {
return;
}
if (getMeshSpecification().getGeometry() == null || getMeshSpecification().getGeometry().getExtent() == null) {
return;
}
ISize samplingSize = getMeshSpecification().getSamplingSize();
if (samplingSize == null) {
return;
}
try {
int dim = getMeshSpecification().getGeometry().getDimension();
String xtext = getXTextField().getText();
int numX = Integer.parseInt(xtext);
int numY = 1;
int numZ = 1;
String totalSizeText = "";
long totalSizeValue = numX;
if (dim > 1) {
String ytext = getYTextField().getText();
numY = Integer.parseInt(ytext);
totalSizeText += numX + " x " + numY;
totalSizeValue *= numY;
if (dim > 2) {
String ztext = getZTextField().getText();
numZ = Integer.parseInt(ztext);
totalSizeText += " x " + numZ;
totalSizeValue *= numZ;
}
}
totalSizeTextField.setText(totalSizeText + (totalSizeText.length() == 0 ? "" : " = ") + totalSizeValue);
Coordinate h = computeDxDyDz(numX, numY, numZ);
ivjDxTextField.setText(h.getX() + "");
ivjDyTextField.setText(h.getY() + "");
ivjDzTextField.setText(h.getZ() + "");
} catch (NumberFormatException ex) {
clearTotalSizeAndSpatialStep();
}
}
Aggregations