use of cbit.vcell.mapping.spatial.PointObject in project vcell by virtualcell.
the class SimulationContext method createPointObject.
public PointObject createPointObject() {
String pointName = "pobj_0";
while (getSpatialObject(pointName) != null) {
pointName = TokenMangler.getNextEnumeratedToken(pointName);
}
PointObject pointObject = new PointObject(pointName, this);
try {
addSpatialObject(pointObject);
// PointLocation pointLocation = createPointLocation(pointObject);
// try {
// pointLocation.getParameter(SpatialProcessParameterType.PointPositionX).setExpression(new Expression(1.0));
// pointLocation.getParameter(SpatialProcessParameterType.PointPositionY).setExpression(new Expression(2.0));
// pointLocation.getParameter(SpatialProcessParameterType.PointPositionZ).setExpression(new Expression(3.0));
// } catch (ExpressionBindingException e) {
// e.printStackTrace();
// }
} catch (PropertyVetoException e) {
throw new RuntimeException(e.getMessage(), e);
}
return pointObject;
}
use of cbit.vcell.mapping.spatial.PointObject in project vcell by virtualcell.
the class SimulationContext method refreshSpatialObjects.
public void refreshSpatialObjects() {
Geometry geometry = getGeometry();
if (geometry != null && geometry.getGeometrySurfaceDescription() != null && geometry.getGeometrySurfaceDescription().getGeometricRegions() != null) {
ArrayList<SpatialObject> unmappedSpatialObjects = new ArrayList<SpatialObject>(Arrays.asList(spatialObjects));
ArrayList<GeometricRegion> mappedRegions = new ArrayList<GeometricRegion>();
//
for (SpatialObject spatialObject : spatialObjects) {
if (spatialObject instanceof VolumeRegionObject) {
VolumeRegionObject volRegionObj = (VolumeRegionObject) spatialObject;
SubVolume existingSubvolume = volRegionObj.getSubVolume();
Integer existingRegionID = volRegionObj.getRegionID();
SubVolume newSubvolume = geometry.getGeometrySpec().getSubVolume(existingSubvolume.getName());
if (newSubvolume != null && geometry.getGeometrySurfaceDescription().getGeometricRegions() != null) {
for (GeometricRegion newRegion : geometry.getGeometrySurfaceDescription().getGeometricRegions(newSubvolume)) {
VolumeGeometricRegion newVolRegion = (VolumeGeometricRegion) newRegion;
if (newVolRegion.getRegionID() == existingRegionID) {
((VolumeRegionObject) spatialObject).setSubVolume(newSubvolume);
mappedRegions.add(newVolRegion);
unmappedSpatialObjects.remove(spatialObject);
}
}
}
}
if (spatialObject instanceof SurfaceRegionObject) {
SurfaceRegionObject surfaceRegionObj = (SurfaceRegionObject) spatialObject;
SubVolume existingInsideSubvolume = surfaceRegionObj.getInsideSubVolume();
SubVolume existingOutsideSubvolume = surfaceRegionObj.getOutsideSubVolume();
Integer existingInsideRegionID = surfaceRegionObj.getInsideRegionID();
Integer existingOutsideRegionID = surfaceRegionObj.getOutsideRegionID();
SubVolume newInsideSubvolume = geometry.getGeometrySpec().getSubVolume(existingInsideSubvolume.getName());
SubVolume newOutsideSubvolume = geometry.getGeometrySpec().getSubVolume(existingOutsideSubvolume.getName());
if (newInsideSubvolume != null && newOutsideSubvolume != null) {
SurfaceClass surfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(newInsideSubvolume, newOutsideSubvolume);
for (GeometricRegion newRegion : geometry.getGeometrySurfaceDescription().getGeometricRegions(surfaceClass)) {
SurfaceGeometricRegion newSurfaceRegion = (SurfaceGeometricRegion) newRegion;
GeometricRegion[] adjacentRegions = newSurfaceRegion.getAdjacentGeometricRegions();
if (adjacentRegions.length == 2 && adjacentRegions[0] instanceof VolumeGeometricRegion && adjacentRegions[1] instanceof VolumeGeometricRegion) {
VolumeGeometricRegion adjVolRegion0 = (VolumeGeometricRegion) adjacentRegions[0];
VolumeGeometricRegion adjVolRegion1 = (VolumeGeometricRegion) adjacentRegions[1];
if (adjVolRegion0.getSubVolume() == newInsideSubvolume && adjVolRegion0.getRegionID() == existingInsideRegionID && adjVolRegion1.getSubVolume() == newOutsideSubvolume && adjVolRegion1.getRegionID() == existingOutsideRegionID) {
surfaceRegionObj.setInsideSubVolume(newInsideSubvolume);
surfaceRegionObj.setOutsideSubVolume(newOutsideSubvolume);
mappedRegions.add(newSurfaceRegion);
unmappedSpatialObjects.remove(spatialObject);
}
if (adjVolRegion0.getSubVolume() == newOutsideSubvolume && adjVolRegion0.getRegionID() == existingOutsideRegionID && adjVolRegion1.getSubVolume() == newInsideSubvolume && adjVolRegion1.getRegionID() == existingInsideRegionID) {
surfaceRegionObj.setInsideSubVolume(newInsideSubvolume);
surfaceRegionObj.setOutsideSubVolume(newOutsideSubvolume);
mappedRegions.add(newSurfaceRegion);
unmappedSpatialObjects.remove(spatialObject);
}
}
}
}
}
}
//
// for geometric regions not represented as spatial objects, add them
//
ArrayList<GeometricRegion> unmappedRegions = new ArrayList<GeometricRegion>(Arrays.asList(geometry.getGeometrySurfaceDescription().getGeometricRegions()));
unmappedRegions.removeAll(mappedRegions);
for (GeometricRegion unmappedRegion : unmappedRegions) {
if (unmappedRegion instanceof VolumeGeometricRegion) {
VolumeGeometricRegion unmappedVolRegion = (VolumeGeometricRegion) unmappedRegion;
try {
VolumeRegionObject vro = new VolumeRegionObject(unmappedVolRegion.getSubVolume(), unmappedVolRegion.getRegionID(), this);
addSpatialObject(vro);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
} else if (unmappedRegion instanceof SurfaceGeometricRegion) {
SurfaceGeometricRegion unmappedSurfRegion = (SurfaceGeometricRegion) unmappedRegion;
GeometricRegion[] adjacentRegions = unmappedSurfRegion.getAdjacentGeometricRegions();
if (adjacentRegions.length == 2 && adjacentRegions[0] instanceof VolumeGeometricRegion && adjacentRegions[1] instanceof VolumeGeometricRegion) {
VolumeGeometricRegion volRegion0 = (VolumeGeometricRegion) adjacentRegions[0];
VolumeGeometricRegion volRegion1 = (VolumeGeometricRegion) adjacentRegions[1];
SubVolume insideSubVolume = volRegion0.getSubVolume();
SubVolume outsideSubVolume = volRegion1.getSubVolume();
int insideRegionID = volRegion0.getRegionID();
int outsideRegionID = volRegion1.getRegionID();
SurfaceClass surfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(insideSubVolume, outsideSubVolume);
try {
addSpatialObject(new SurfaceRegionObject(insideSubVolume, insideRegionID, outsideSubVolume, outsideRegionID, this));
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
}
}
//
try {
for (SpatialObject unmappedSpatialObject : unmappedSpatialObjects) {
if (unmappedSpatialObject instanceof VolumeRegionObject) {
System.err.println("volume region spatial object '" + unmappedSpatialObject.getName() + "' not found in geometry, delete.");
removeSpatialObject(unmappedSpatialObject);
}
if (unmappedSpatialObject instanceof SurfaceRegionObject) {
System.err.println("surface region spatial object '" + unmappedSpatialObject.getName() + "' not found in geometry, delete.");
removeSpatialObject(unmappedSpatialObject);
}
if (unmappedSpatialObject instanceof PointObject) {
System.err.println("point spatial object '" + unmappedSpatialObject.getName() + "' not found in geometry, this is expected.");
// removeSpatialObject(unmappedSpatialObject);
}
}
} catch (PropertyVetoException e) {
e.printStackTrace();
}
}
}
use of cbit.vcell.mapping.spatial.PointObject in project vcell by virtualcell.
the class XmlReader method getSpatialObjects.
public SpatialObject[] getSpatialObjects(SimulationContext simContext, Element spatialObjectsElement) throws XmlParseException {
Iterator<Element> spatialObjectElementIterator = spatialObjectsElement.getChildren(XMLTags.SpatialObjectTag, vcNamespace).iterator();
ArrayList<SpatialObject> spatialObjectList = new ArrayList<SpatialObject>();
while (spatialObjectElementIterator.hasNext()) {
Element spatialObjectElement = (Element) spatialObjectElementIterator.next();
SpatialObject spatialObject = null;
String name = unMangle(spatialObjectElement.getAttributeValue(XMLTags.NameAttrTag));
String type = unMangle(spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectTypeAttrTag));
if (type.equals(XMLTags.SpatialObjectTypeAttrValue_Point)) {
PointObject pointObject = new PointObject(name, simContext);
spatialObject = pointObject;
} else if (type.equals(XMLTags.SpatialObjectTypeAttrValue_Surface)) {
String insideSubvolumeName = unMangle(spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectSubVolumeInsideAttrTag));
String insideRegionIDString = spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectRegionIdInsideAttrTag);
String outsideSubvolumeName = unMangle(spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectSubVolumeOutsideAttrTag));
String outsideRegionIDString = spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectRegionIdOutsideAttrTag);
SubVolume insideSubvolume = null;
if (insideSubvolumeName != null) {
insideSubvolume = simContext.getGeometry().getGeometrySpec().getSubVolume(insideSubvolumeName);
}
Integer insideRegionID = null;
if (insideRegionIDString != null) {
insideRegionID = Integer.parseUnsignedInt(insideRegionIDString);
}
SubVolume outsideSubvolume = null;
if (outsideSubvolumeName != null) {
outsideSubvolume = simContext.getGeometry().getGeometrySpec().getSubVolume(outsideSubvolumeName);
}
Integer outsideRegionID = null;
if (outsideRegionIDString != null) {
outsideRegionID = Integer.parseUnsignedInt(outsideRegionIDString);
}
SurfaceRegionObject surfaceRegionObject = new SurfaceRegionObject(name, insideSubvolume, insideRegionID, outsideSubvolume, outsideRegionID, simContext);
spatialObject = surfaceRegionObject;
} else if (type.equals(XMLTags.SpatialObjectTypeAttrValue_Volume)) {
String subvolumeName = unMangle(spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectSubVolumeAttrTag));
String regionIDString = spatialObjectElement.getAttributeValue(XMLTags.SpatialObjectRegionIdAttrTag);
SubVolume subvolume = null;
if (subvolumeName != null) {
subvolume = simContext.getGeometry().getGeometrySpec().getSubVolume(subvolumeName);
}
Integer regionID = null;
if (regionIDString != null) {
regionID = Integer.parseUnsignedInt(regionIDString);
}
VolumeRegionObject volumeRegionObject = new VolumeRegionObject(name, subvolume, regionID, simContext);
spatialObject = volumeRegionObject;
}
// set Quantity enables
Element quantityCategoryListElement = spatialObjectElement.getChild(XMLTags.QuantityCategoryListTag, vcNamespace);
List<Element> quantityCategoryElements = quantityCategoryListElement.getChildren(XMLTags.QuantityCategoryTag, vcNamespace);
for (Element quantityCategoryElement : quantityCategoryElements) {
String quantityCategoryName = unMangle(quantityCategoryElement.getAttributeValue(XMLTags.QuantityCategoryNameAttrTag));
Boolean enabled = Boolean.parseBoolean(quantityCategoryElement.getAttributeValue(XMLTags.QuantityCategoryEnabledAttrTag));
QuantityCategory category = QuantityCategory.fromXMLName(quantityCategoryName);
spatialObject.setQuantityCategoryEnabled(category, enabled);
}
spatialObjectList.add(spatialObject);
}
return spatialObjectList.toArray(new SpatialObject[0]);
}
use of cbit.vcell.mapping.spatial.PointObject in project vcell by virtualcell.
the class XmlReader method getSpatialProcesses.
public SpatialProcess[] getSpatialProcesses(SimulationContext simContext, Element spatialProcessesElement) throws XmlParseException {
Iterator<Element> spatialProcessElementIterator = spatialProcessesElement.getChildren(XMLTags.SpatialProcessTag, vcNamespace).iterator();
ArrayList<SpatialProcess> spatialProcessList = new ArrayList<SpatialProcess>();
while (spatialProcessElementIterator.hasNext()) {
Element spatialProcessElement = (Element) spatialProcessElementIterator.next();
SpatialProcess spatialProcess = null;
String name = unMangle(spatialProcessElement.getAttributeValue(XMLTags.NameAttrTag));
String type = unMangle(spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessTypeAttrTag));
if (type.equals(XMLTags.SpatialProcessTypeAttrValue_PointKinematics)) {
PointKinematics pointKinematics = new PointKinematics(name, simContext);
String pointObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessPointObjectAttrTag);
PointObject pointObject = (PointObject) simContext.getSpatialObject(pointObjectName);
pointKinematics.setPointObject(pointObject);
spatialProcess = pointKinematics;
} else if (type.equals(XMLTags.SpatialProcessTypeAttrValue_PointLocation)) {
PointLocation pointLocation = new PointLocation(name, simContext);
String pointObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessPointObjectAttrTag);
PointObject pointObject = (PointObject) simContext.getSpatialObject(pointObjectName);
pointLocation.setPointObject(pointObject);
spatialProcess = pointLocation;
} else if (type.equals(XMLTags.SpatialProcessTypeAttrValue_SurfaceKinematics)) {
SurfaceKinematics surfaceKinematics = new SurfaceKinematics(name, simContext);
String surfaceRegionObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessSurfaceObjectAttrTag);
SurfaceRegionObject surfaceRegionObject = (SurfaceRegionObject) simContext.getSpatialObject(surfaceRegionObjectName);
surfaceKinematics.setSurfaceRegionObject(surfaceRegionObject);
spatialProcess = surfaceKinematics;
} else if (type.equals(XMLTags.SpatialProcessTypeAttrValue_VolumeKinematics)) {
VolumeKinematics volumeKinematics = new VolumeKinematics(name, simContext);
String volumeRegionObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessVolumeObjectAttrTag);
VolumeRegionObject volumeRegionObject = (VolumeRegionObject) simContext.getSpatialObject(volumeRegionObjectName);
volumeKinematics.setVolumeRegionObject(volumeRegionObject);
spatialProcess = volumeKinematics;
}
// set parameters
Iterator<Element> paramElementIter = spatialProcessElement.getChildren(XMLTags.ParameterTag, vcNamespace).iterator();
ArrayList<LocalParameter> parameters = new ArrayList<LocalParameter>();
while (paramElementIter.hasNext()) {
Element paramElement = paramElementIter.next();
// Get parameter attributes
String paramName = paramElement.getAttributeValue(XMLTags.NameAttrTag);
Expression exp = unMangleExpression(paramElement.getText());
String roleStr = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
SpatialProcessParameterType parameterType = SpatialProcessParameterType.fromRoleXmlName(roleStr);
VCUnitDefinition unit = simContext.getModel().getUnitSystem().getInstance_TBD();
String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
if (unitSymbol != null) {
unit = simContext.getModel().getUnitSystem().getInstance(unitSymbol);
}
parameters.add(spatialProcess.createNewParameter(paramName, parameterType, exp, unit));
}
try {
spatialProcess.setParameters(parameters.toArray(new LocalParameter[0]));
} catch (PropertyVetoException | ExpressionBindingException e) {
e.printStackTrace();
throw new XmlParseException("failed to read parameters in bioEvent " + name + ": " + e.getMessage(), e);
}
spatialProcessList.add(spatialProcess);
}
return spatialProcessList.toArray(new SpatialProcess[0]);
}
use of cbit.vcell.mapping.spatial.PointObject in project vcell by virtualcell.
the class SpatialProcessDisplayPanel method createNewPointKinematics.
private void createNewPointKinematics() {
if (simulationContext != null) {
PointObject pointObject = getOrCreateNextPointObject();
pointObject.setQuantityCategoryEnabled(QuantityCategory.PointPosition, true);
pointObject.setQuantityCategoryEnabled(QuantityCategory.PointVelocity, true);
simulationContext.createPointKinematics(pointObject);
}
}
Aggregations