use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.
the class ClientRequestManager method getParseImageTask.
public static AsynchClientTask getParseImageTask(final Component requesterComp, final VCDocument.DocumentCreationInfo documentCreationInfo, final MDIManager mdiManager) {
AsynchClientTask parseImageTask = new AsynchClientTask("read and parse image file", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(final Hashtable<String, Object> hashTable) throws Exception {
final Component guiParent = (Component) hashTable.get(ClientRequestManager.GUI_PARENT);
try {
FieldDataFileOperationSpec fdfos = null;
// }
if (documentCreationInfo.getOption() == VCDocument.GEOM_OPTION_FILE) // || documentCreationInfo.getOption() == VCDocument.GEOM_OPTION_FIJI_IMAGEJ ||
// documentCreationInfo.getOption() == VCDocument.GEOM_OPTION_BLENDER
{
File imageFile = (File) hashTable.get(IMAGE_FILE);
if (imageFile == null) {
throw new Exception("No file selected");
}
if (ExtensionFilter.isMatchingExtension(imageFile, ".nrrd")) {
DataInputStream dis = null;
try {
dis = new DataInputStream(new BufferedInputStream(new FileInputStream(imageFile)));
int xsize = 1;
int ysize = 1;
int zsize = 1;
double xspace = 1.0;
double yspace = 1.0;
double zspace = 1.0;
NRRDTYPE type = null;
NRRDENCODING encoding = null;
int dimension = -1;
// read header lines
while (true) {
@SuppressWarnings("deprecation") String line = dis.readLine();
if (line == null || line.length() == 0) {
break;
}
StringTokenizer stringTokenizer = new StringTokenizer(line, ": ");
String headerParam = stringTokenizer.nextToken();
// System.out.println(headerParam);
if (headerParam.equals("sizes")) {
if (dimension != -1) {
xsize = Integer.parseInt(stringTokenizer.nextToken());
if (dimension >= 2) {
ysize = Integer.parseInt(stringTokenizer.nextToken());
}
if (dimension >= 3) {
zsize = Integer.parseInt(stringTokenizer.nextToken());
}
for (int i = 4; i < dimension; i++) {
if (Integer.parseInt(stringTokenizer.nextToken()) != 1) {
throw new Exception("Dimensions > 3 not supported");
}
}
} else {
throw new Exception("dimension expected to be set before reading sizes");
}
} else if (headerParam.equals("spacings")) {
if (dimension != -1) {
xspace = Double.parseDouble(stringTokenizer.nextToken());
if (dimension >= 2) {
yspace = Double.parseDouble(stringTokenizer.nextToken());
}
if (dimension >= 3) {
zspace = Double.parseDouble(stringTokenizer.nextToken());
}
// ignore other dimension spacings
} else {
throw new Exception("dimension expected to be set before reading spacings");
}
} else if (headerParam.equals("type")) {
String nextToken = stringTokenizer.nextToken();
if (nextToken.equalsIgnoreCase("double")) {
type = NRRDTYPE.DOUBLE;
} else if (nextToken.equalsIgnoreCase("float")) {
type = NRRDTYPE.FLOAT;
} else if (nextToken.equalsIgnoreCase("unsigned")) {
nextToken = stringTokenizer.nextToken();
if (nextToken.equalsIgnoreCase("char")) {
type = NRRDTYPE.UNSIGNEDCHAR;
} else {
throw new Exception("Unknown nrrd data type=" + nextToken);
}
} else {
throw new Exception("Unknown nrrd data type=" + nextToken);
}
} else if (headerParam.equals("dimension")) {
dimension = Integer.parseInt(stringTokenizer.nextToken());
if (dimension < 1) {
throw new Exception("unexpected dimension=" + dimension);
}
} else if (headerParam.equals("encoding")) {
encoding = NRRDENCODING.valueOf(stringTokenizer.nextToken().toUpperCase());
}
}
BufferedInputStream bis = null;
if (encoding == NRRDENCODING.GZIP) {
dis.close();
bis = new BufferedInputStream(new FileInputStream(imageFile));
boolean bnewLine = false;
while (true) {
int currentChar = bis.read();
if (currentChar == '\n') {
if (bnewLine) {
// 2 newlines end header
break;
}
bnewLine = true;
} else {
bnewLine = false;
}
}
GZIPInputStream gzipInputStream = new GZIPInputStream(bis);
dis = new DataInputStream(gzipInputStream);
}
double[] data = new double[xsize * ysize * zsize];
double minValue = Double.POSITIVE_INFINITY;
double maxValue = Double.NEGATIVE_INFINITY;
for (int i = 0; i < data.length; i++) {
if (i % 262144 == 0) {
if (getClientTaskStatusSupport() != null) {
getClientTaskStatusSupport().setMessage("Reading " + encoding + " " + type + " NRRD data " + (((long) i * (long) 100) / (long) data.length) + " % done.");
}
}
if (type == NRRDTYPE.DOUBLE) {
data[i] = dis.readDouble();
} else if (type == NRRDTYPE.FLOAT) {
data[i] = dis.readFloat();
} else if (type == NRRDTYPE.UNSIGNEDCHAR) {
data[i] = dis.readUnsignedByte();
} else {
throw new Exception("Unexpected data type=" + type.toString());
}
minValue = Math.min(minValue, data[i]);
maxValue = Math.max(maxValue, data[i]);
}
dis.close();
if (getClientTaskStatusSupport() != null) {
getClientTaskStatusSupport().setMessage("Scaling " + encoding + " " + type + " NRRD data.");
}
short[] dataToSegment = new short[data.length];
double scaleShort = Math.pow(2, Short.SIZE) - 1;
for (int i = 0; i < data.length; i++) {
dataToSegment[i] |= (int) ((data[i] - minValue) / (maxValue - minValue) * scaleShort);
}
fdfos = new FieldDataFileOperationSpec();
fdfos.origin = new Origin(0, 0, 0);
fdfos.extent = new Extent((xsize == 1 ? .5 : (xsize) * xspace), (ysize == 1 ? .5 : (ysize) * yspace), (zsize == 1 ? .5 : (zsize) * zspace));
fdfos.isize = new ISize(xsize, ysize, zsize);
fdfos.shortSpecData = new short[][][] { { dataToSegment } };
} finally {
if (dis != null) {
try {
dis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
} else if ((fdfos = createFDOSFromSurfaceFile(imageFile)) != null) {
// try surface file formats
// work already done at this point
} else {
File[] dirFiles = null;
ImageSizeInfo origImageSizeInfo = null;
ImageDatasetReaderService imageDatasetReaderServiceInstance = ImageDatasetReaderService.getInstance();
ImageDatasetReader imageDatasetReader = imageDatasetReaderServiceInstance.getImageDatasetReader();
if (imageFile.isDirectory()) {
dirFiles = imageFile.listFiles(new java.io.FileFilter() {
public boolean accept(File pathname) {
// exclude windows Thumbs.db
return pathname.isFile() && !pathname.isHidden();
}
});
if (dirFiles.length == 0) {
throw new Exception("No valid files in selected directory");
}
String fileExt0 = null;
for (int i = 0; i < dirFiles.length; i++) {
int lastDot = dirFiles[i].getName().lastIndexOf('.');
String fileExt = (lastDot != -1 ? dirFiles[i].getName().substring(lastDot) : null);
if (dirFiles[i].isDirectory()) {
fileExt = "dir";
}
if (i == 0) {
fileExt0 = fileExt;
} else if (!Compare.isEqualOrNull(fileExt, fileExt0)) {
String result = DialogUtils.showWarningDialog(requesterComp, "Files in '" + imageFile.getAbsolutePath() + "' have different name extensions, continue?", new String[] { "OK", "Cancel" }, "Cancel");
if (!"OK".equals(result)) {
throw UserCancelException.CANCEL_FILE_SELECTION;
}
break;
}
}
hashTable.put(IMPORT_SOURCE_NAME, "Directory: " + imageFile.getAbsolutePath());
origImageSizeInfo = imageDatasetReader.getImageSizeInfoForceZ(dirFiles[0].getAbsolutePath(), dirFiles.length);
if (dirFiles.length > 1) {
final String importZ = "Import Z-Sections";
final String cancelOption = "Cancel";
String result = DialogUtils.showWarningDialog(guiParent, "Import all files in directory '" + imageFile.getAbsolutePath() + "' as Z-Sections", new String[] { importZ, cancelOption }, importZ);
if (result.equals(cancelOption)) {
throw UserCancelException.CANCEL_GENERIC;
}
}
hashTable.put(DIR_FILES, dirFiles);
} else {
origImageSizeInfo = imageDatasetReader.getImageSizeInfoForceZ(imageFile.getAbsolutePath(), null);
hashTable.put(IMPORT_SOURCE_NAME, "File: " + imageFile.getAbsolutePath());
}
hashTable.put(ORIG_IMAGE_SIZE_INFO, origImageSizeInfo);
return;
}
} else if (documentCreationInfo.getOption() == VCDocument.GEOM_OPTION_FIELDDATA) {
getClientTaskStatusSupport().setMessage("Reading data from VCell server.");
VCDocument.GeomFromFieldDataCreationInfo docInfo = (VCDocument.GeomFromFieldDataCreationInfo) documentCreationInfo;
PDEDataContext pdeDataContext = mdiManager.getFieldDataWindowManager().getPDEDataContext(docInfo.getExternalDataID(), null);
ImageSizeInfo newImageSizeInfo = (ImageSizeInfo) hashTable.get(NEW_IMAGE_SIZE_INFO);
pdeDataContext.setVariableNameAndTime(docInfo.getVarName(), newImageSizeInfo.getTimePoints()[newImageSizeInfo.getSelectedTimeIndex()]);
double[] data = pdeDataContext.getDataValues();
hashTable.put(INITIAL_ANNOTATION, hashTable.get(IMPORT_SOURCE_NAME));
CartesianMesh mesh = (CartesianMesh) hashTable.get(FD_MESH);
ISize meshISize = (ISize) hashTable.get(FD_MESHISIZE);
double minValue = Double.POSITIVE_INFINITY;
double maxValue = Double.NEGATIVE_INFINITY;
for (int i = 0; i < data.length; i++) {
minValue = Math.min(minValue, data[i]);
maxValue = Math.max(maxValue, data[i]);
}
short[] dataToSegment = new short[data.length];
double scaleShort = Math.pow(2, Short.SIZE) - 1;
for (int i = 0; i < data.length; i++) {
dataToSegment[i] |= (int) ((data[i] - minValue) / (maxValue - minValue) * scaleShort);
}
fdfos = new FieldDataFileOperationSpec();
fdfos.origin = mesh.getOrigin();
fdfos.extent = mesh.getExtent();
fdfos.isize = meshISize;
fdfos.shortSpecData = new short[][][] { { dataToSegment } };
} else if (documentCreationInfo.getOption() == VCDocument.GEOM_OPTION_FROM_SCRATCH) {
ISize isize = getISizeFromUser(guiParent, new ISize(256, 256, 8), "Enter # of pixels for x,y,z (e.g. 3D{256,256,8}, 2D{256,256,1}, 1D{256,1,1})");
fdfos = new FieldDataFileOperationSpec();
fdfos.origin = new Origin(0, 0, 0);
fdfos.extent = new Extent(1, 1, 1);
fdfos.isize = isize;
hashTable.put(IMPORT_SOURCE_NAME, "Scratch: New Geometry");
// final int SCRATCH_SIZE_LIMIT = 512*512*20;
// if(isize.getXYZ() > (SCRATCH_SIZE_LIMIT)){
// throw new Exception("Total pixels (x*y*z) cannot be >"+SCRATCH_SIZE_LIMIT+".");
// }
} else if (documentCreationInfo.getOption() == VCDocument.GEOM_OPTION_FROM_WORKSPACE_ANALYTIC) {
if (hashTable.get(ClientRequestManager.GEOM_FROM_WORKSPACE) != null) {
Geometry workspaceGeom = (Geometry) hashTable.get(ClientRequestManager.GEOM_FROM_WORKSPACE);
ISize defaultISize = workspaceGeom.getGeometrySpec().getDefaultSampledImageSize();
ISize isize = getISizeFromUser(guiParent, defaultISize, "Warning: converting analytic expression geometry into an image based geometry\nwill remove analytic expressions after new image is created.\n\n" + "Enter size (x,y,z) for new geometry image (e.g. " + defaultISize.getX() + "," + defaultISize.getY() + "," + defaultISize.getZ() + ")");
hashTable.put(IMPORT_SOURCE_NAME, "Workspace from Analytic Geometry");
VCImage img = workspaceGeom.getGeometrySpec().createSampledImage(isize);
Enumeration<SubVolume> enumSubvolume = workspaceGeom.getGeometrySpec().getAnalyticOrCSGSubVolumes();
ArrayList<VCPixelClass> vcPixelClassArrList = new ArrayList<VCPixelClass>();
while (enumSubvolume.hasMoreElements()) {
SubVolume subVolume = enumSubvolume.nextElement();
vcPixelClassArrList.add(new VCPixelClass(null, subVolume.getName(), subVolume.getHandle()));
}
if (vcPixelClassArrList.size() > img.getPixelClasses().length) {
String result = DialogUtils.showOKCancelWarningDialog(requesterComp, null, "Warning: sampling size is too small to include all subvolumes.");
if (result == null || !result.equals(SimpleUserMessage.OPTION_OK)) {
throw UserCancelException.CANCEL_GENERIC;
}
}
hashTable.put(VCPIXELCLASSES, vcPixelClassArrList.toArray(new VCPixelClass[0]));
fdfos = createFDOSFromVCImage(img);
} else {
throw new Exception("Expecting image source for GEOM_OPTION_FROM_WORKSPACE_ANALYTIC");
}
} else if (documentCreationInfo.getOption() == VCDocument.GEOM_OPTION_FROM_WORKSPACE_IMAGE) {
if (hashTable.get(ClientRequestManager.GEOM_FROM_WORKSPACE) != null) {
Geometry workspaceGeom = (Geometry) hashTable.get(ClientRequestManager.GEOM_FROM_WORKSPACE);
hashTable.put(IMPORT_SOURCE_NAME, "Workspace Image");
fdfos = createFDOSFromVCImage(workspaceGeom.getGeometrySpec().getImage());
if (workspaceGeom.getGeometrySpec().getImage().getDescription() != null) {
hashTable.put(INITIAL_ANNOTATION, workspaceGeom.getGeometrySpec().getImage().getDescription());
}
GeometryClass[] myGeometryClasses = workspaceGeom.getGeometryClasses();
VCPixelClass[] myPixelClasses = workspaceGeom.getGeometrySpec().getImage().getPixelClasses();
VCPixelClass[] newPixelClasses = new VCPixelClass[myPixelClasses.length];
for (int i = 0; i < myPixelClasses.length; i++) {
for (int j = 0; j < myGeometryClasses.length; j++) {
if (myGeometryClasses[j] instanceof ImageSubVolume && myPixelClasses[i].getPixel() == ((ImageSubVolume) myGeometryClasses[j]).getPixelValue()) {
newPixelClasses[i] = new VCPixelClass(null, myGeometryClasses[j].getName(), myPixelClasses[i].getPixel());
break;
}
}
}
hashTable.put(VCPIXELCLASSES, newPixelClasses);
} else {
throw new Exception("Expecting image source for GEOM_OPTION_FROM_WORKSPACE");
}
}
hashTable.put(FDFOS, fdfos);
} catch (DataFormatException ex) {
throw new Exception("Cannot read image file.\n" + ex.getMessage());
}
}
};
return parseImageTask;
}
use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.
the class OutputFunctionsPanel method getPossibleGeometryClassesAndVariableTypes.
private ArrayList<Object> getPossibleGeometryClassesAndVariableTypes(Expression expr) throws ExpressionException, InconsistentDomainException {
SimulationOwner simulationOwner = getSimulationWorkspace().getSimulationOwner();
MathDescription mathDescription = simulationOwner.getMathDescription();
boolean bSpatial = simulationOwner.getGeometry().getDimension() > 0;
if (!bSpatial) {
return null;
}
// making sure that output function is not direct function of constant.
expr.bindExpression(outputFunctionContext);
// new expression itself to be function of constant.
try {
expr = MathUtilities.substituteFunctions(expr, outputFunctionContext).flatten();
} catch (ExpressionBindingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
expr = MathUtilities.substituteFunctions(expr, outputFunctionContext, true).flatten();
}
String[] symbols = expr.getSymbols();
// using bit operation to determine whether geometry classes for symbols in expression are vol, membrane or both. 01 => vol; 10 => membrane; 11 => both
int gatherFlag = 0;
Set<GeometryClass> geomClassSet = new HashSet<GeometryClass>();
ArrayList<Object> objectsList = new ArrayList<Object>();
boolean bHasVariable = false;
VariableType[] varTypes = null;
if (symbols != null && symbols.length > 0) {
// making sure that new expression is defined in the same domain
varTypes = new VariableType[symbols.length];
for (int i = 0; i < symbols.length; i++) {
if (ReservedMathSymbolEntries.getReservedVariableEntry(symbols[i]) != null) {
varTypes[i] = VariableType.VOLUME;
} else {
Variable var = mathDescription.getVariable(symbols[i]);
if (var == null) {
var = mathDescription.getPostProcessingBlock().getDataGenerator(symbols[i]);
}
varTypes[i] = VariableType.getVariableType(var);
bHasVariable = true;
if (var.getDomain() != null) {
GeometryClass varGeoClass = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
geomClassSet.add(varGeoClass);
if (varGeoClass instanceof SubVolume) {
gatherFlag |= 1;
} else if (varGeoClass instanceof SurfaceClass) {
gatherFlag |= 2;
}
}
if (varTypes[i].equals(VariableType.POSTPROCESSING)) {
gatherFlag |= 4;
}
}
}
}
if (gatherFlag > 4) {
throw new RuntimeException("cannot mix post processing variables with membrane or volume variables");
}
int numGeomClasses = geomClassSet.size();
if (numGeomClasses == 0) {
if (bHasVariable) {
// if there are no variables (like built in function, vcRegionArea), check with flattened expression to find out the variable type of the new expression
Function flattenedFunction = new Function(getFunctionNameTextField().getText(), expr, null);
flattenedFunction.bind(outputFunctionContext);
VariableType newVarType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, simulationOwner.getMathDescription(), symbols, varTypes, bSpatial);
objectsList.add(newVarType);
} else {
objectsList.add(VariableType.VOLUME);
objectsList.add(VariableType.MEMBRANE);
}
} else if (numGeomClasses == 1) {
objectsList.add(geomClassSet.iterator().next());
if (gatherFlag == 1) {
objectsList.add(VariableType.MEMBRANE);
}
} else if (gatherFlag == 1) {
// all volumes
if (numGeomClasses == 2) {
// all subvolumes, if there are only 2, check for adjacency.
GeometryClass[] geomClassesArray = geomClassSet.toArray(new GeometryClass[0]);
SurfaceClass sc = simulationOwner.getGeometry().getGeometrySurfaceDescription().getSurfaceClass((SubVolume) geomClassesArray[0], (SubVolume) geomClassesArray[1]);
if (sc != null) {
objectsList.add(sc);
}
}
objectsList.add(VariableType.VOLUME);
} else if (gatherFlag == 2) {
// all membranes
objectsList.add(VariableType.MEMBRANE);
} else if (gatherFlag == 3) {
// mixed - both vols and membranes
// add only membranes?
objectsList.add(VariableType.MEMBRANE);
}
return objectsList;
}
use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.
the class StructureMappingTableRenderer method getTableCellRendererComponent.
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setIcon(null);
if (table.getModel() instanceof StructureMappingTableModel) {
StructureMappingTableModel structureMappingTableModel = (StructureMappingTableModel) table.getModel();
String toolTip = structureMappingTableModel.getToolTip(row, column);
if (value instanceof Structure) {
Structure structure = (Structure) value;
setText(structure.getName());
} else if (value instanceof Double && structureMappingTableModel.isNewSizeColumn(column)) {
StructureMapping structureMapping = structureMappingTableModel.getStructureMapping(row);
if (structureMappingTableModel.isNonSpatial()) {
VCUnitDefinition unitDefinition = structureMapping.getStructure().getStructureSize().getUnitDefinition();
TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
if (sizeIcon == null) {
sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
}
setIcon(sizeIcon);
} else {
// spatial
if (structureMapping.getUnitSizeParameter() != null) {
VCUnitDefinition unitDefinition = structureMapping.getUnitSizeParameter().getUnitDefinition();
TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
if (sizeIcon == null) {
sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
}
setIcon(sizeIcon);
}
}
}
if (structureMappingTableModel.isSubdomainColumn(column)) {
// can be null
if (value == null) {
setText("Unmapped");
setForeground(Color.red);
setIcon(null);
} else {
if (value instanceof GeometryClass) {
setText(((GeometryClass) value).getName());
if (value instanceof SubVolume) {
SubVolume subVolume = (SubVolume) value;
java.awt.Color handleColor = new java.awt.Color(colormap[subVolume.getHandle()]);
// small square icon with subdomain color
Icon icon = new ColorIcon(10, 10, handleColor, true);
setHorizontalTextPosition(SwingConstants.RIGHT);
setIcon(icon);
} else if (value instanceof SurfaceClass) {
SurfaceClass sc = (SurfaceClass) value;
Set<SubVolume> sv = sc.getAdjacentSubvolumes();
Iterator<SubVolume> iterator = sv.iterator();
SubVolume sv1 = iterator.next();
SubVolume sv2 = iterator.next();
java.awt.Color c1 = new java.awt.Color(colormap[sv2.getHandle()]);
java.awt.Color c2 = new java.awt.Color(colormap[sv1.getHandle()]);
Icon icon = new ColorIconEx(10, 10, c1, c2);
setIcon(icon);
setHorizontalTextPosition(SwingConstants.RIGHT);
}
} else {
setText(value.toString());
setIcon(null);
}
}
}
if (value instanceof BoundaryConditionType) {
// we get here only for spatial
Object candidate = structureMappingTableModel.getValueAt(row, StructureMappingTableModel.SPATIAL_COLUMN_SUBDOMAIN);
if (candidate instanceof SurfaceClass) {
SurfaceClass surfaceClass = (SurfaceClass) candidate;
cbit.vcell.model.Model model = structureMappingTableModel.getGeometryContext().getModel();
SimulationContext simContext = structureMappingTableModel.getGeometryContext().getSimulationContext();
Pair<SubVolume, SubVolume> ret = DiffEquMathMapping.computeBoundaryConditionSource(model, simContext, surfaceClass);
SubVolume innerSubVolume = ret.one;
java.awt.Color handleColor = new java.awt.Color(colormap[innerSubVolume.getHandle()]);
// small square icon with subdomain color
Icon icon = new ColorIcon(8, 8, handleColor, true);
setHorizontalTextPosition(SwingConstants.LEFT);
setIcon(icon);
setText("from");
// override default tooltip
toolTip = "Boundary condition inherited from Subdomain '" + innerSubVolume.getName() + "'";
setToolTipText(toolTip);
} else {
setText(((BoundaryConditionType) value).boundaryTypeStringValue());
}
}
List<Issue> issueList = structureMappingTableModel.getIssues(row, column, Issue.SEVERITY_ERROR);
if (issueList.size() > 0) {
// override default tooltip
setToolTipText(Issue.getHtmlIssueMessage(issueList));
if (column == 0) {
setBorder(new MatteBorder(1, 1, 1, 0, Color.red));
} else if (column == table.getColumnCount() - 1) {
setBorder(new MatteBorder(1, 0, 1, 1, Color.red));
} else {
setBorder(new MatteBorder(1, 0, 1, 0, Color.red));
}
} else {
setToolTipText(toolTip);
setBorder(DEFAULT_GAP);
}
}
return this;
}
use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.
the class StructureMappingTableModel method setValueAt.
public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
if (rowIndex < 0 || rowIndex >= getRowCount()) {
throw new RuntimeException("StructureMappingTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
}
if (columnIndex < 0 || columnIndex >= getColumnCount()) {
throw new RuntimeException("StructureMappingTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
}
StructureMapping structureMapping = getValueAt(rowIndex);
Structure structure = structureMapping.getStructure();
if (bNonSpatial) {
switch(columnIndex) {
case NONSPATIAL_COLUMN_SIZE:
{
try {
Expression exp = null;
if (aValue instanceof String) {
exp = new Expression((String) aValue);
} else if (aValue instanceof Double) {
exp = new Expression(((Double) aValue).doubleValue());
}
// if the input volumn is null, leave it as it was.
if (exp != null) {
// for old ode model, once one size is input, solve the rest. if it is unnamed compartment(the only one), we don't need to solve anything
if (!getGeometryContext().getSimulationContext().isStoch() && getGeometryContext().isAllSizeSpecifiedNull() && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().getStructureMappings().length > 1) {
structureMapping.getSizeParameter().setExpression(exp);
double size;
try {
size = exp.evaluateConstant();
VCUnitDefinition volumeUnit = getGeometryContext().getSimulationContext().getModel().getUnitSystem().getVolumeUnit();
StructureSizeSolver.updateAbsoluteStructureSizes(getGeometryContext().getSimulationContext(), structure, size, volumeUnit);
fireTableRowsUpdated(0, getRowCount());
} catch (ExpressionException ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "Size of Feature " + structure.getName() + " can not be solved as constant!");
} catch (Exception ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
}
} else {
structureMapping.getSizeParameter().setExpression(exp);
// set fraction in stoch math description, because these might be used when copy from stoch app to ode app.
if (getGeometryContext().isAllSizeSpecifiedPositive()) /*&& !getGeometryContext().getSimulationContext().isStoch()*/
{
try {
StructureSizeSolver.updateRelativeStructureSizes(getGeometryContext().getSimulationContext());
} catch (Exception ex) {
ex.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
}
}
}
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
}
}
} else {
switch(columnIndex) {
case SPATIAL_COLUMN_SUBDOMAIN:
{
GeometryClass geometryClass = null;
if (aValue instanceof String) {
String svname = (String) aValue;
geometryClass = getGeometryContext().getGeometry().getGeometryClass(svname);
} else if (aValue instanceof GeometryClass) {
geometryClass = (GeometryClass) aValue;
}
if (geometryClass != null) {
try {
getGeometryContext().assignStructure(structure, geometryClass);
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
} catch (IllegalMappingException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
} catch (MappingException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
}
}
break;
}
case SPATIAL_COLUMN_SIZERATIO:
try {
Expression exp = null;
if (aValue instanceof String) {
exp = new Expression((String) aValue);
} else if (aValue instanceof Double) {
exp = new Expression(((Double) aValue).doubleValue());
}
if (exp != null) {
structureMapping.getUnitSizeParameter().setExpression(exp);
StructureSizeSolver.updateUnitStructureSizes(getGeometryContext().getSimulationContext(), structureMapping.getGeometryClass());
}
} catch (ExpressionException e) {
e.printStackTrace(System.out);
PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
}
break;
case SPATIAL_COLUMN_X_MINUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeXm(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_X_PLUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeXp(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Y_MINUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeYm(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Y_PLUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeYp(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Z_MINUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeZm(new BoundaryConditionType((String) aValue));
}
break;
}
case SPATIAL_COLUMN_Z_PLUS:
{
if (aValue != null) {
structureMapping.setBoundaryConditionTypeZp(new BoundaryConditionType((String) aValue));
}
break;
}
}
}
}
use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.
the class StructureMappingTableModel method isCellEditable.
/**
* Insert the method's description here.
* Creation date: (2/24/01 12:27:46 AM)
* @return boolean
* @param rowIndex int
* @param columnIndex int
*/
public boolean isCellEditable(int rowIndex, int columnIndex) {
if (getGeometryContext() == null) {
return false;
}
StructureMapping sm = getGeometryContext().getStructureMapping(rowIndex);
if (bNonSpatial) {
if (columnIndex == NONSPATIAL_COLUMN_SIZE) {
// feature size are editable
return true;
}
return false;
} else {
//
if (columnIndex == SPATIAL_COLUMN_SUBDOMAIN) {
return ((sm instanceof FeatureMapping) || (sm instanceof MembraneMapping));
}
if (columnIndex == SPATIAL_COLUMN_SIZERATIO) {
GeometryClass gc = sm.getGeometryClass();
StructureMapping[] structureMappings = getGeometryContext().getStructureMappings(gc);
boolean bDimensionless = sm.getUnitSizeParameter() != null && sm.getUnitSizeParameter().getUnitDefinition() != null && sm.getUnitSizeParameter().getUnitDefinition().isEquivalent(getGeometryContext().getModel().getUnitSystem().getInstance_DIMENSIONLESS());
return (structureMappings != null && structureMappings.length > 1) || !bDimensionless;
}
// some boundary conditions are editable
if ((columnIndex >= SPATIAL_COLUMN_X_MINUS) && (columnIndex <= SPATIAL_COLUMN_Z_PLUS)) {
if (sm.getGeometryClass() instanceof SurfaceClass) {
return false;
}
return true;
}
}
return false;
}
Aggregations