Search in sources :

Example 6 with PointObject

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;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) PointObject(cbit.vcell.mapping.spatial.PointObject)

Example 7 with 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();
        }
    }
}
Also used : VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ArrayList(java.util.ArrayList) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) PointObject(cbit.vcell.mapping.spatial.PointObject) SubVolume(cbit.vcell.geometry.SubVolume) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion)

Example 8 with PointObject

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]);
}
Also used : VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) Element(org.jdom.Element) QuantityCategory(cbit.vcell.mapping.spatial.SpatialObject.QuantityCategory) ArrayList(java.util.ArrayList) SpatialObject(cbit.vcell.mapping.spatial.SpatialObject) PointObject(cbit.vcell.mapping.spatial.PointObject) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject)

Example 9 with PointObject

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]);
}
Also used : VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) PointLocation(cbit.vcell.mapping.spatial.processes.PointLocation) SurfaceKinematics(cbit.vcell.mapping.spatial.processes.SurfaceKinematics) VolumeKinematics(cbit.vcell.mapping.spatial.processes.VolumeKinematics) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) PointObject(cbit.vcell.mapping.spatial.PointObject) Expression(cbit.vcell.parser.Expression) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) PointKinematics(cbit.vcell.mapping.spatial.processes.PointKinematics) SpatialProcessParameterType(cbit.vcell.mapping.spatial.processes.SpatialProcess.SpatialProcessParameterType) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject)

Example 10 with PointObject

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);
    }
}
Also used : PointObject(cbit.vcell.mapping.spatial.PointObject)

Aggregations

PointObject (cbit.vcell.mapping.spatial.PointObject)10 SpatialObject (cbit.vcell.mapping.spatial.SpatialObject)6 SurfaceRegionObject (cbit.vcell.mapping.spatial.SurfaceRegionObject)6 VolumeRegionObject (cbit.vcell.mapping.spatial.VolumeRegionObject)6 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)4 ArrayList (java.util.ArrayList)4 SubVolume (cbit.vcell.geometry.SubVolume)3 PointKinematics (cbit.vcell.mapping.spatial.processes.PointKinematics)3 PointLocation (cbit.vcell.mapping.spatial.processes.PointLocation)3 SurfaceKinematics (cbit.vcell.mapping.spatial.processes.SurfaceKinematics)3 PropertyVetoException (java.beans.PropertyVetoException)3 Element (org.jdom.Element)3 SurfaceClass (cbit.vcell.geometry.SurfaceClass)2 LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)2 QuantityCategory (cbit.vcell.mapping.spatial.SpatialObject.QuantityCategory)2 VolumeKinematics (cbit.vcell.mapping.spatial.processes.VolumeKinematics)2 Expression (cbit.vcell.parser.Expression)2 SpatialObjectTableModel (cbit.vcell.client.desktop.biomodel.SpatialObjectTableModel)1 SpatialProcessTableModel (cbit.vcell.client.desktop.biomodel.SpatialProcessTableModel)1 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1