use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class ClientDocumentManager method getGeometry.
/**
* Insert the method's description here.
* Creation date: (11/14/00 4:02:44 PM)
* @return cbit.vcell.biomodel.BioModel
* @param bioModelInfo cbit.vcell.biomodel.BioModelInfo
*/
public Geometry getGeometry(GeometryInfo geometryInfo) throws DataAccessException {
Geometry geometry = null;
try {
XMLSource geomSource = new XMLSource(getGeometryXML(geometryInfo.getVersion().getVersionKey()));
geometry = XmlHelper.XMLToGeometry(geomSource);
} catch (XmlParseException e) {
e.printStackTrace(System.out);
throw new DataAccessException(e.getMessage());
}
try {
if (geometry.getDimension() > 0 && geometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
geometry.getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
// throw new DataAccessException("Geometric surface generation error:\n"+e.getMessage());
}
return geometry;
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class ClientDocumentManager method getGeometryFromDatabaseXML.
/**
* Insert the method's description here.
* Creation date: (9/22/2004 5:22:40 PM)
* @return cbit.vcell.mathmodel.MathModel
* @param mathModelXML java.lang.String
*/
private Geometry getGeometryFromDatabaseXML(String geometryXML) throws DataAccessException {
try {
Geometry geometry = XmlHelper.XMLToGeometry(new XMLSource(geometryXML));
geometry.refreshDependencies();
try {
if (geometry.getDimension() > 0) {
geometry.getGeometrySurfaceDescription().updateAll();
}
} catch (Exception e) {
e.printStackTrace(System.out);
throw new DataAccessException("Geometric surface generation error:\n" + e.getMessage());
}
return geometry;
} catch (XmlParseException e) {
e.printStackTrace();
throw new DataAccessException(e.getClass().getName() + ": " + e.getMessage());
}
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class SimulationContext method setGeometry.
/**
* This method was created in VisualAge.
*/
public void setGeometry(Geometry geometry) throws MappingException {
Geometry oldGeometry = this.getGeometry();
if (geometry != oldGeometry) {
getGeometryContext().setGeometry(geometry);
try {
refreshCharacteristicSize();
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
refreshSpatialObjects();
oldGeometry.getGeometrySpec().removePropertyChangeListener(this);
getGeometry().getGeometrySpec().addPropertyChangeListener(this);
if (geometry != null && geometry.getDimension() > 0) {
try {
if (fieldBioEvents != null) {
setBioEvents(null);
}
if (fieldRateRules != null) {
setRateRules(null);
}
if (fieldAnalysisTasks != null) {
setAnalysisTasks(null);
}
if (oldGeometry != null && oldGeometry.getDimension() == 0) {
// && geometry != null && geometry.getDimension() > 0
initializeForSpatial();
}
} catch (PropertyVetoException e) {
e.printStackTrace(System.out);
throw new MappingException(e.getMessage());
}
}
// now firing from geoContext
// firePropertyChange("geometry",oldGeometry,geometry);
}
}
use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.
the class SimulationContext method copySimulationContext.
public static SimulationContext copySimulationContext(SimulationContext srcSimContext, String newSimulationContextName, boolean bSpatial, Application simContextType) throws java.beans.PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException {
Geometry newClonedGeometry = new Geometry(srcSimContext.getGeometry());
newClonedGeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
// if stoch copy to ode, we need to check is stoch is using particles. If yes, should convert particles to concentraton.
// the other 3 cases are fine. ode->ode, ode->stoch, stoch-> stoch
SimulationContext destSimContext = new SimulationContext(srcSimContext, newClonedGeometry, simContextType);
if (srcSimContext.getApplicationType() == Application.NETWORK_STOCHASTIC && !srcSimContext.isUsingConcentration() && simContextType == Application.NETWORK_DETERMINISTIC) {
try {
destSimContext.convertSpeciesIniCondition(true);
} catch (MappingException e) {
e.printStackTrace();
throw new java.beans.PropertyVetoException(e.getMessage(), null);
}
}
if (srcSimContext.getGeometry().getDimension() > 0 && !bSpatial) {
// copy the size over
destSimContext.setGeometry(new Geometry("nonspatial", 0));
StructureMapping[] srcStructureMappings = srcSimContext.getGeometryContext().getStructureMappings();
StructureMapping[] destStructureMappings = destSimContext.getGeometryContext().getStructureMappings();
for (StructureMapping destStructureMapping : destStructureMappings) {
for (StructureMapping srcStructureMapping : srcStructureMappings) {
if (destStructureMapping.getStructure() == srcStructureMapping.getStructure()) {
if (srcStructureMapping.getUnitSizeParameter() != null) {
Expression sizeRatio = srcStructureMapping.getUnitSizeParameter().getExpression();
GeometryClass srcGeometryClass = srcStructureMapping.getGeometryClass();
GeometricRegion[] srcGeometricRegions = srcSimContext.getGeometry().getGeometrySurfaceDescription().getGeometricRegions(srcGeometryClass);
if (srcGeometricRegions != null) {
double size = 0;
for (GeometricRegion srcGeometricRegion : srcGeometricRegions) {
size += srcGeometricRegion.getSize();
}
destStructureMapping.getSizeParameter().setExpression(Expression.mult(sizeRatio, new Expression(size)));
}
}
break;
}
}
}
// If changing spatial to non-spatial
// set diffusion to 0, velocity and boundary to null
// srcSimContext.getReactionContext().getspe
Parameter[] allParameters = destSimContext.getAllParameters();
if (allParameters != null && allParameters.length > 0) {
for (int i = 0; i < allParameters.length; i++) {
if (allParameters[i] instanceof SpeciesContextSpecParameter) {
SpeciesContextSpecParameter speciesContextSpecParameter = (SpeciesContextSpecParameter) allParameters[i];
int role = speciesContextSpecParameter.getRole();
if (role == SpeciesContextSpec.ROLE_DiffusionRate) {
speciesContextSpecParameter.setExpression(new Expression(0));
} else if (role == SpeciesContextSpec.ROLE_BoundaryValueXm || role == SpeciesContextSpec.ROLE_BoundaryValueXp || role == SpeciesContextSpec.ROLE_BoundaryValueYm || role == SpeciesContextSpec.ROLE_BoundaryValueYp || role == SpeciesContextSpec.ROLE_BoundaryValueZm || role == SpeciesContextSpec.ROLE_BoundaryValueZp) {
speciesContextSpecParameter.setExpression(null);
} else if (role == SpeciesContextSpec.ROLE_VelocityX || role == SpeciesContextSpec.ROLE_VelocityY || role == SpeciesContextSpec.ROLE_VelocityZ) {
speciesContextSpecParameter.setExpression(null);
}
}
}
}
}
destSimContext.fixFlags();
destSimContext.setName(newSimulationContextName);
return destSimContext;
}
use of cbit.vcell.geometry.Geometry 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();
}
}
}
Aggregations