Search in sources :

Example 46 with SubVolume

use of cbit.vcell.geometry.SubVolume in project vcell by virtualcell.

the class StructureMappingCartoon method refreshAll.

/**
 * This method was created by a SmartGuide.
 */
@Override
public void refreshAll() {
    clearAllShapes();
    if (getSimulationContext() == null) {
        fireGraphChanged(new GraphEvent(this));
        return;
    }
    GeometryContextGeometryShape geometryShape = new GeometryContextGeometryShape(this, getGeometryContext().getGeometry());
    // GeometryContextStructureShape structureShape = new GeometryContextStructureShape(this,getGeometryContext().getModel());
    // GeometryContextContainerShape containerShape = new GeometryContextContainerShape(this,getGeometryContext(),structureShape,geometryShape);
    // addShape(containerShape);
    addShape(geometryShape);
    // addShape(structureShape);
    getGeometryContext().removePropertyChangeListener(this);
    getGeometryContext().addPropertyChangeListener(this);
    // 
    // create all StructureShapes
    // 
    // Structure structures[] = getGeometryContext().getModel().getStructures();
    // for (int i=0;i<structures.length;i++){
    // if (structures[i] instanceof Feature){
    // //addShape(new FeatureShape((Feature)structures[i],getGeometryContext().getModel(),this));
    // StructureMappingFeatureShape smShape = new StructureMappingFeatureShape((Feature)structures[i],getGeometryContext().getModel(),this);
    // addShape(smShape);
    // containerShape.addChildShape(smShape);
    // structures[i].removePropertyChangeListener(this);
    // structures[i].addPropertyChangeListener(this);
    // }
    // }
    // create all SubvolumeLegendShapes (for legend)
    // 
    GeometrySpec geometrySpec = getGeometryContext().getGeometry().getGeometrySpec();
    SubVolume[] subVolumes = geometrySpec.getSubVolumes();
    for (int i = 0; i < subVolumes.length; i++) {
        cbit.vcell.geometry.SubVolume subvolume = subVolumes[i];
        GeometryClassLegendShape subvolumeLegendShape = new GeometryClassLegendShape(subvolume, getGeometryContext().getGeometry(), this, 10);
        addShape(subvolumeLegendShape);
        geometryShape.addChildShape(subvolumeLegendShape);
    }
    // --------------------------------------------------
    if ((subVolumeContainerShape == null) || (subVolumeContainerShape.getModelObject() != getGeometryContext().getGeometry())) {
        subVolumeContainerShape = new SubVolumeContainerShape(getGeometryContext().getGeometry(), this);
    }
    subVolumeContainerShape.removeAllChildren();
    addShape(subVolumeContainerShape);
    geometryShape.addChildShape(subVolumeContainerShape);
    // --------------------------------------------------
    // // create all SubvolumeShapes (for image)
    // //
    // for (int i=0;i<subVolumes.length;i++){
    // cbit.vcell.geometry.SubVolume subvolume = (cbit.vcell.geometry.SubVolume)subVolumes[i];
    // SubvolumeShape subvolumeShape = new SubvolumeShape(subvolume,getGeometryContext().getGeometry(),this);
    // addShape(subvolumeShape);
    // subVolumeContainerShape.addChildShape(subvolumeShape);
    // }
    // 
    // create all FeatureMappingShapes
    // 
    // StructureMapping structureMappings[] = getGeometryContext().getStructureMappings();
    // for (int i=0;i<structureMappings.length;i++){
    // StructureMapping structureMapping = structureMappings[i];
    // if (structureMapping instanceof FeatureMapping){
    // FeatureMapping featureMapping = (FeatureMapping)structureMapping;
    // if (featureMapping.getSubVolume()!=null){
    // FeatureShape featureShape = (FeatureShape)getShapeFromModelObject(featureMapping.getFeature());
    // SubvolumeLegendShape subvolumeLegendShape = (SubvolumeLegendShape)getShapeFromModelObject(featureMapping.getSubVolume());
    // FeatureMappingShape fmShape = new FeatureMappingShape(featureMapping,featureShape,subvolumeLegendShape,this);
    // //FeatureMappingShape fmShape = new FeatureMappingShape(featureMapping,featureShape,featureMapping.getSubVolume(),imageShape,this);
    // addShape(fmShape);
    // containerShape.addChildShape(fmShape);
    // }
    // }
    // }
    // 
    // assign children to shapes according to heirarchy in Model
    // 
    // int nullParentCount=0;
    // Enumeration enum_shape = getShapes();
    // while (enum_shape.hasMoreElements()){
    // Shape shape = (Shape)enum_shape.nextElement();
    // //
    // // for each featureShape, find corresponding featureShape
    // //
    // if (shape instanceof FeatureShape){
    // FeatureShape fs = (FeatureShape)shape;
    // Membrane membrane = fs.getFeature().getMembrane();
    // if (membrane!=null){
    // //
    // // add this feature as child to parent feature
    // //
    // Feature parentFeature = membrane.getOutsideFeature();
    // FeatureShape parentFeatureShape = (FeatureShape)getShapeFromModelObject(parentFeature);
    // if (!parentFeatureShape.contains(fs)){
    // parentFeatureShape.addChildShape(fs);
    // }
    // }else{
    // if (!structureShape.contains(fs)){
    // structureShape.addChildShape(fs);
    // }
    // nullParentCount++;
    // }
    // }
    // }
    fireGraphChanged(new GraphEvent(this));
}
Also used : GeometrySpec(cbit.vcell.geometry.GeometrySpec) GeometryClassLegendShape(cbit.vcell.graph.GeometryClassLegendShape) SubVolume(cbit.vcell.geometry.SubVolume) GeometryContextGeometryShape(cbit.vcell.graph.GeometryContextGeometryShape) GraphEvent(cbit.gui.graph.GraphEvent) SubVolume(cbit.vcell.geometry.SubVolume) SubVolumeContainerShape(cbit.vcell.graph.SubVolumeContainerShape)

Example 47 with SubVolume

use of cbit.vcell.geometry.SubVolume in project vcell by virtualcell.

the class StructureMappingTableModel method updateSubdomainComboBox.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void updateSubdomainComboBox() {
    GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
    DefaultComboBoxModel aModel = new DefaultComboBoxModel();
    for (GeometryClass gc : geometryClasses) {
        aModel.addElement(gc);
    }
    JComboBox subdomainComboBoxCellEditor = new JComboBox();
    subdomainComboBoxCellEditor.setRenderer(new DefaultListCellRenderer() {

        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            setHorizontalTextPosition(SwingConstants.LEFT);
            if (value instanceof GeometryClass) {
                GeometryClass gc = (GeometryClass) value;
                setText(gc.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);
                }
            }
            return this;
        }
    });
    subdomainComboBoxCellEditor.setModel(aModel);
    ownerTable.getColumnModel().getColumn(SPATIAL_COLUMN_SUBDOMAIN).setCellEditor(new DefaultCellEditor(subdomainComboBoxCellEditor));
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) ColorIcon(org.vcell.util.gui.ColorIcon) JComboBox(javax.swing.JComboBox) SurfaceClass(cbit.vcell.geometry.SurfaceClass) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel) DefaultCellEditor(javax.swing.DefaultCellEditor) DefaultListCellRenderer(javax.swing.DefaultListCellRenderer) SubVolume(cbit.vcell.geometry.SubVolume) ColorIcon(org.vcell.util.gui.ColorIcon) Icon(javax.swing.Icon) Component(java.awt.Component) ColorIconEx(org.vcell.util.gui.ColorIconEx) JList(javax.swing.JList)

Example 48 with SubVolume

use of cbit.vcell.geometry.SubVolume 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 49 with SubVolume

use of cbit.vcell.geometry.SubVolume in project vcell by virtualcell.

the class SimulationContext method isPDERequired.

/**
 * Insert the method's description here.
 * Creation date: (8/8/01 3:46:23 PM)
 * @param speciesContext cbit.vcell.model.SpeciesContext
 * @return boolean
 */
public boolean isPDERequired(SpeciesContext speciesContext) {
    // 
    // compartmental models never need diffusion
    // 
    int dimension = getGeometryContext().getGeometry().getDimension();
    if (dimension == 0) {
        return false;
    }
    StructureMapping structureMapping = getGeometryContext().getStructureMapping(speciesContext.getStructure());
    GeometryClass geometryClass = structureMapping.getGeometryClass();
    if (geometryClass instanceof SubVolume) {
        if (dimension < 1) {
            return false;
        }
    } else if (geometryClass instanceof SurfaceClass) {
        if (dimension < 2) {
            return false;
        }
    } else {
        throw new RuntimeException("structure " + speciesContext.getStructure().getName() + " not mapped, or unsupported GeometryClass " + geometryClass);
    }
    // 
    // check speciesContext needs diffusion/advection
    // 
    SpeciesContextSpec scs = getReactionContext().getSpeciesContextSpec(speciesContext);
    if (scs.isDiffusing() || scs.isAdvecting()) {
        return true;
    }
    return false;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SubVolume(cbit.vcell.geometry.SubVolume)

Example 50 with SubVolume

use of cbit.vcell.geometry.SubVolume in project vcell by virtualcell.

the class MathMapping_4_8 method refreshStructureAnalyzers.

/**
 * This method was created by a SmartGuide.
 */
protected void refreshStructureAnalyzers() {
    structureAnalyzerList.removeAllElements();
    // 
    // update structureAnalyzer list if any subVolumes were added
    // 
    SubVolume[] subVolumes = simContext.getGeometryContext().getGeometry().getGeometrySpec().getSubVolumes();
    for (int j = 0; j < subVolumes.length; j++) {
        SubVolume subVolume = (SubVolume) subVolumes[j];
        if (getVolumeStructureAnalyzer(subVolume) == null) {
            structureAnalyzerList.addElement(new VolumeStructureAnalyzer(this, subVolume));
        }
        // 
        // Add a MembraneStructureAnalyzer if necessary
        // 
        // go through list of MembraneMappings and determine if inner and outer compartment
        // are both mapped to subVolumes, then add
        // 
        Structure[] structures = getStructures(subVolume);
        if (structures != null) {
            for (int i = 0; i < structures.length; i++) {
                if (structures[i] instanceof Membrane) {
                    Membrane membrane = (Membrane) structures[i];
                    MembraneMapping mm = (MembraneMapping) simContext.getGeometryContext().getStructureMapping(membrane);
                    if (mm != null) {
                        if (getResolved(mm) && getMembraneStructureAnalyzer(membrane) == null) {
                            SubVolume outerSubVolume = getSubVolume(((FeatureMapping) simContext.getGeometryContext().getStructureMapping(simContext.getModel().getStructureTopology().getOutsideFeature(membrane))));
                            structureAnalyzerList.addElement(new MembraneStructureAnalyzer(this, membrane, subVolume, outerSubVolume));
                        }
                    }
                }
            }
        }
    }
    // 
    // invoke all structuralAnalyzers
    // 
    Enumeration<StructureAnalyzer> enum1 = getStructureAnalyzers();
    while (enum1.hasMoreElements()) {
        StructureAnalyzer sa = enum1.nextElement();
        sa.refresh();
    }
}
Also used : MembraneMapping(cbit.vcell.mapping.MembraneMapping) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SubVolume(cbit.vcell.geometry.SubVolume) Membrane(cbit.vcell.model.Membrane) Structure(cbit.vcell.model.Structure)

Aggregations

SubVolume (cbit.vcell.geometry.SubVolume)84 SurfaceClass (cbit.vcell.geometry.SurfaceClass)42 Expression (cbit.vcell.parser.Expression)33 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)26 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)22 GeometryClass (cbit.vcell.geometry.GeometryClass)21 ArrayList (java.util.ArrayList)21 Geometry (cbit.vcell.geometry.Geometry)20 MathDescription (cbit.vcell.math.MathDescription)17 SpeciesContext (cbit.vcell.model.SpeciesContext)17 PropertyVetoException (java.beans.PropertyVetoException)17 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)16 CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)15 Model (cbit.vcell.model.Model)15 ImageException (cbit.image.ImageException)14 VCImage (cbit.image.VCImage)14 Feature (cbit.vcell.model.Feature)14 Structure (cbit.vcell.model.Structure)14 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)13 ExpressionException (cbit.vcell.parser.ExpressionException)13