Search in sources :

Example 21 with SurfaceClass

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

the class OutputFunctionContext method getAutoCompleteSymbolFilter.

public AutoCompleteSymbolFilter getAutoCompleteSymbolFilter(final Domain functionDomain) {
    AutoCompleteSymbolFilter stef = new AutoCompleteSymbolFilter() {

        public boolean accept(SymbolTableEntry ste) {
            if (simulationOwner.getGeometry().getDimension() > 0) {
                if (functionDomain == null) {
                    return true;
                }
                if (ste.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX) || ste.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
                    return false;
                }
                if (ste instanceof ReservedVariable) {
                    return true;
                }
                if (ste instanceof AnnotatedFunction) {
                    return functionDomain.compareEqual(((AnnotatedFunction) ste).getDomain());
                }
                if (ste instanceof Variable) {
                    Variable var = (Variable) ste;
                    if (var.getDomain() == null) {
                        return true;
                    }
                    GeometryClass gc = simulationOwner.getGeometry().getGeometryClass(functionDomain.getName());
                    GeometryClass vargc = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
                    if (gc instanceof SurfaceClass && vargc instanceof SubVolume) {
                        if (((SurfaceClass) gc).isAdjacentTo((SubVolume) vargc)) {
                            return true;
                        } else {
                            return false;
                        }
                    } else {
                        return var.getDomain().compareEqual(functionDomain);
                    }
                }
            }
            return true;
        }

        public boolean acceptFunction(String funcName) {
            return true;
        }
    };
    return stef;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) AutoCompleteSymbolFilter(cbit.vcell.parser.AutoCompleteSymbolFilter) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) ReservedVariable(cbit.vcell.math.ReservedVariable) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SubVolume(cbit.vcell.geometry.SubVolume)

Example 22 with SurfaceClass

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

the class OutputFunctionContext method computeFunctionTypeWRTExpression.

// check if the new expression is valid for outputFunction of functionType
public VariableType computeFunctionTypeWRTExpression(AnnotatedFunction outputFunction, Expression exp) throws ExpressionException, InconsistentDomainException {
    MathDescription mathDescription = getSimulationOwner().getMathDescription();
    boolean bSpatial = getSimulationOwner().getGeometry().getDimension() > 0;
    if (!bSpatial) {
        return VariableType.NONSPATIAL;
    }
    Expression newexp = new Expression(exp);
    // making sure that output function is not direct function of constant.
    newexp.bindExpression(this);
    // here use math description as symbol table because we allow
    // new expression itself to be function of constant.
    newexp = MathUtilities.substituteFunctions(newexp, this).flatten();
    String[] symbols = newexp.getSymbols();
    VariableType functionType = outputFunction.getFunctionType();
    String funcName = outputFunction.getName();
    Domain funcDomain = outputFunction.getDomain();
    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] = functionType;
            } else {
                Variable var = mathDescription.getVariable(symbols[i]);
                if (var == null) {
                    var = mathDescription.getPostProcessingBlock().getDataGenerator(symbols[i]);
                }
                varTypes[i] = VariableType.getVariableType(var);
                if (funcDomain != null) {
                    if (var.getDomain() == null) {
                        // OK
                        continue;
                    }
                    GeometryClass funcGeoClass = simulationOwner.getGeometry().getGeometryClass(funcDomain.getName());
                    GeometryClass varGeoClass = simulationOwner.getGeometry().getGeometryClass(var.getDomain().getName());
                    if (varGeoClass instanceof SubVolume && funcGeoClass instanceof SurfaceClass) {
                        // seems ok if membrane refereces volume
                        if (!((SurfaceClass) funcGeoClass).isAdjacentTo((SubVolume) varGeoClass)) {
                            // but has to be adjacent
                            String errMsg = "'" + funcName + "' defined on Membrane '" + funcDomain.getName() + "' directly or indirectly references " + " variable '" + symbols[i] + "' defined on Volume '" + var.getDomain().getName() + " which is not adjacent to Membrane '" + funcDomain.getName() + "'.";
                            throw new ExpressionException(errMsg);
                        }
                    } else if (!var.getDomain().compareEqual(funcDomain)) {
                        String errMsg = "'" + funcName + "' defined on '" + funcDomain.getName() + "' directly or indirectly references " + " variable '" + symbols[i] + "' defined on '" + var.getDomain().getName() + ".";
                        throw new ExpressionException(errMsg);
                    }
                }
            }
        }
    }
    // if there are no variables (like built in function, vcRegionArea), check with flattened expression to find out the variable type of the new expression
    VariableDomain functionVariableDomain = functionType.getVariableDomain();
    Function flattenedFunction = new Function(funcName, newexp, funcDomain);
    flattenedFunction.bind(this);
    VariableType newVarType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, getSimulationOwner().getMathDescription(), symbols, varTypes, bSpatial);
    if (!newVarType.getVariableDomain().equals(functionVariableDomain)) {
        String errMsg = "The expression for '" + funcName + "' includes at least one " + newVarType.getVariableDomain().getName() + " variable. Please make sure that only " + functionVariableDomain.getName() + " variables are " + "referenced in " + functionVariableDomain.getName() + " output functions.";
        throw new ExpressionException(errMsg);
    }
    return newVarType;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) VariableType(cbit.vcell.math.VariableType) MathDescription(cbit.vcell.math.MathDescription) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ExpressionException(cbit.vcell.parser.ExpressionException) Function(cbit.vcell.math.Function) Expression(cbit.vcell.parser.Expression) SubVolume(cbit.vcell.geometry.SubVolume) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) Domain(cbit.vcell.math.Variable.Domain)

Example 23 with SurfaceClass

use of cbit.vcell.geometry.SurfaceClass 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);
    // here use math description as symbol table because we allow
    // new expression itself to be function of constant.
    expr = MathUtilities.substituteFunctions(expr, outputFunctionContext).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;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) Variable(cbit.vcell.math.Variable) VariableType(cbit.vcell.math.VariableType) MathDescription(cbit.vcell.math.MathDescription) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ArrayList(java.util.ArrayList) SimulationOwner(cbit.vcell.solver.SimulationOwner) Function(cbit.vcell.math.Function) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) SubVolume(cbit.vcell.geometry.SubVolume) HashSet(java.util.HashSet)

Example 24 with SurfaceClass

use of cbit.vcell.geometry.SurfaceClass 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;
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) MembraneMapping(cbit.vcell.mapping.MembraneMapping) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SurfaceClass(cbit.vcell.geometry.SurfaceClass) StructureMapping(cbit.vcell.mapping.StructureMapping)

Example 25 with SurfaceClass

use of cbit.vcell.geometry.SurfaceClass 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;
}
Also used : Color(java.awt.Color) GeometryClass(cbit.vcell.geometry.GeometryClass) Set(java.util.Set) Issue(org.vcell.util.Issue) SurfaceClass(cbit.vcell.geometry.SurfaceClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) AttributedString(java.text.AttributedString) StructureMapping(cbit.vcell.mapping.StructureMapping) MatteBorder(javax.swing.border.MatteBorder) SubVolume(cbit.vcell.geometry.SubVolume) Iterator(java.util.Iterator) Structure(cbit.vcell.model.Structure) ColorIconEx(org.vcell.util.gui.ColorIconEx) ColorIcon(org.vcell.util.gui.ColorIcon) Color(java.awt.Color) SimulationContext(cbit.vcell.mapping.SimulationContext) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ColorIcon(org.vcell.util.gui.ColorIcon) Icon(javax.swing.Icon)

Aggregations

SurfaceClass (cbit.vcell.geometry.SurfaceClass)48 SubVolume (cbit.vcell.geometry.SubVolume)42 GeometryClass (cbit.vcell.geometry.GeometryClass)19 Expression (cbit.vcell.parser.Expression)19 Geometry (cbit.vcell.geometry.Geometry)15 Feature (cbit.vcell.model.Feature)13 MathDescription (cbit.vcell.math.MathDescription)12 Model (cbit.vcell.model.Model)12 SpeciesContext (cbit.vcell.model.SpeciesContext)12 VCImage (cbit.image.VCImage)11 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)11 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)11 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)11 Membrane (cbit.vcell.model.Membrane)11 Structure (cbit.vcell.model.Structure)11 FeatureMapping (cbit.vcell.mapping.FeatureMapping)10 ArrayList (java.util.ArrayList)10 ImageException (cbit.image.ImageException)9 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)8 CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)8