Search in sources :

Example 1 with GeometryUnitSystem

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

the class GeometrySurfaceUtils method getUpdatedGeometricRegions.

/**
 * Insert the method's description here.
 * Creation date: (6/28/2004 3:09:13 PM)
 * @return cbit.vcell.geometry.surface.GeometricRegion[]
 * @param geoSurfaceDescription cbit.vcell.geometry.surface.GeometrySurfaceDescription
 * @param surfaceCollection cbit.vcell.geometry.surface.SurfaceCollection
 */
public static GeometricRegion[] getUpdatedGeometricRegions(GeometrySurfaceDescription geoSurfaceDescription, cbit.vcell.geometry.RegionImage regionImage, SurfaceCollection surfaceCollection) {
    // 
    // parse regionImage into ResolvedVolumeLocations
    // 
    VCellThreadChecker.checkCpuIntensiveInvocation();
    double sizeOfPixel = 0;
    VCUnitDefinition volumeUnit = null;
    VCUnitDefinition surfaceUnit = null;
    GeometrySpec geometrySpec = geoSurfaceDescription.getGeometry().getGeometrySpec();
    GeometryUnitSystem geometryUnitSystem = geoSurfaceDescription.getGeometry().getUnitSystem();
    switch(geometrySpec.getDimension()) {
        case 1:
            {
                sizeOfPixel = geometrySpec.getExtent().getX() / (regionImage.getNumX() - 1);
                // sizeOfPixel /= 9.0;  // to account for the padding from 1D to 3D
                volumeUnit = geometryUnitSystem.getLengthUnit();
                surfaceUnit = geometryUnitSystem.getInstance_DIMENSIONLESS();
                break;
            }
        case 2:
            {
                sizeOfPixel = geometrySpec.getExtent().getX() / (regionImage.getNumX() - 1) * geometrySpec.getExtent().getY() / (regionImage.getNumY() - 1);
                // sizeOfPixel /= 3.0;  // to account for the padding from 2D to 3D
                volumeUnit = geometryUnitSystem.getAreaUnit();
                surfaceUnit = geometryUnitSystem.getLengthUnit();
                break;
            }
        case 3:
            {
                sizeOfPixel = geometrySpec.getExtent().getX() / (regionImage.getNumX() - 1) * geometrySpec.getExtent().getY() / (regionImage.getNumY() - 1) * geometrySpec.getExtent().getZ() / (regionImage.getNumZ() - 1);
                volumeUnit = geometryUnitSystem.getVolumeUnit();
                surfaceUnit = geometryUnitSystem.getAreaUnit();
                break;
            }
    }
    int numX = regionImage.getNumX();
    int numY = regionImage.getNumY();
    int numZ = regionImage.getNumZ();
    int numXY = numX * numY;
    java.util.Vector<GeometricRegion> regionList = new java.util.Vector<GeometricRegion>();
    cbit.vcell.geometry.RegionImage.RegionInfo[] regionInfos = regionImage.getRegionInfos();
    for (int i = 0; i < regionInfos.length; i++) {
        cbit.vcell.geometry.RegionImage.RegionInfo regionInfo = regionInfos[i];
        lg.info(regionInfo);
        cbit.vcell.geometry.SubVolume subVolume = geometrySpec.getSubVolume(regionInfo.getPixelValue());
        String name = subVolume.getName() + regionInfo.getRegionIndex();
        int numPixels = regionInfo.getNumPixels();
        double size = numPixels * sizeOfPixel;
        // 
        switch(geometrySpec.getDimension()) {
            case 1:
                {
                    int numHalvesToRemove = 0;
                    // -x pixel
                    if (regionInfo.isIndexInRegion(0)) {
                        // (regionImage.getRegionIndex(0,0,0) == regionIndex)
                        numHalvesToRemove++;
                    }
                    // +x pixel
                    if (regionInfo.isIndexInRegion(numX - 1)) {
                        // (regionImage.getRegionIndex(regionImageNumX-1,0,0) == regionIndex){
                        numHalvesToRemove++;
                    }
                    // *9; // 1D is padded by 3 in y and 3 in z (hence factor of 9)
                    size -= sizeOfPixel * 0.5 * numHalvesToRemove;
                    break;
                }
            case 2:
                {
                    int numQuadrantsToRemove = 0;
                    int yOffset = 0;
                    for (int yIndex = 0; yIndex < numY; yIndex++) {
                        if (regionInfo.isIndexInRegion(yOffset)) {
                            // (regionImage.getRegionIndex(0,yIndex,0) == regionIndex){
                            if (yIndex == 0 || yIndex == numY - 1) {
                                // corner, remove 3 quadrants
                                numQuadrantsToRemove += 3;
                            } else {
                                // side, remove 2 quadrants
                                numQuadrantsToRemove += 2;
                            }
                        }
                        // +x side (including attached corners)
                        if (regionInfo.isIndexInRegion(numX - 1 + yOffset)) {
                            // (regionImage.getRegionIndex(numX-1,yIndex,0) == regionIndex){
                            if (yIndex == 0 || yIndex == numY - 1) {
                                // corner, remove 3 quadrants
                                numQuadrantsToRemove += 3;
                            } else {
                                // side, remove 2 quadrants
                                numQuadrantsToRemove += 2;
                            }
                        }
                        yOffset += numX;
                    }
                    int yOffsetLastLine = (numY - 1) * numX;
                    for (int xIndex = 1; xIndex < numX - 1; xIndex++) {
                        // -y side (excluding corners)
                        if (regionInfo.isIndexInRegion(xIndex)) {
                            // (regionImage.getRegionIndex(xIndex,0,0) == regionIndex){
                            // side, remove 2 quadrants
                            numQuadrantsToRemove += 2;
                        }
                        // +x side (excluding corners)
                        if (regionInfo.isIndexInRegion(xIndex + yOffsetLastLine)) {
                            // (regionImage.getRegionIndex(xIndex,numY-1,0) == regionIndex){
                            // side, remove 2 quadrants
                            numQuadrantsToRemove += 2;
                        }
                    }
                    // *3; // 2D is padded by 3 in z (hence the factor of 3).
                    size -= sizeOfPixel * 0.25 * numQuadrantsToRemove;
                    break;
                }
            case 3:
                {
                    int numOctantsToRemove = 0;
                    for (int zIndex = 0; zIndex < numZ; zIndex++) {
                        for (int yIndex = 0; yIndex < numY; yIndex++) {
                            // -x side (including attached edges and corners)
                            // already on face of boundary (removing half)
                            int totalOctants = 4;
                            // lg.info("-x side including edges and corners");
                            if (regionInfo.isIndexInRegion(yIndex * numX + zIndex * numXY)) {
                                // (regionImage.getRegionIndex(0,yIndex,zIndex) == regionIndex){
                                if (yIndex == 0 || yIndex == numY - 1) {
                                    totalOctants /= 2;
                                }
                                if (zIndex == 0 || zIndex == numZ - 1) {
                                    totalOctants /= 2;
                                }
                                numOctantsToRemove += (8 - totalOctants);
                            }
                            // lg.info("+x side including edges and corners");
                            // +x side (including attached edges and corners)
                            // already on face of boundary (removing half)
                            totalOctants = 4;
                            if (regionInfo.isIndexInRegion(numX - 1 + yIndex * numX + zIndex * numXY)) {
                                // (regionImage.getRegionIndex(numX-1,yIndex,zIndex) == regionIndex){
                                if (yIndex == 0 || yIndex == numY - 1) {
                                    totalOctants /= 2;
                                }
                                if (zIndex == 0 || zIndex == numZ - 1) {
                                    totalOctants /= 2;
                                }
                                numOctantsToRemove += (8 - totalOctants);
                            }
                        }
                        for (int xIndex = 1; xIndex < numX - 1; xIndex++) {
                            // -y side (including attached edges along x axis, excluding corners)
                            // lg.info("-y side including edges");
                            // already on face of boundary (removing half)
                            int totalOctants = 4;
                            if (regionInfo.isIndexInRegion(xIndex + zIndex * numXY)) {
                                // (regionImage.getRegionIndex(xIndex,0,zIndex) == regionIndex){
                                if (zIndex == 0 || zIndex == numZ - 1) {
                                    totalOctants /= 2;
                                }
                                numOctantsToRemove += (8 - totalOctants);
                            }
                            // lg.info("+y side including edges");
                            // +y side (including attached edges along x axis, excluding corners)
                            // already on face of boundary (removing half)
                            totalOctants = 4;
                            if (regionInfo.isIndexInRegion(xIndex + (numY - 1) * numX + zIndex * numXY)) {
                                // (regionImage.getRegionIndex(xIndex,numY-1,zIndex) == regionIndex){
                                if (zIndex == 0 || zIndex == numZ - 1) {
                                    totalOctants /= 2;
                                }
                                numOctantsToRemove += (8 - totalOctants);
                            }
                        }
                    }
                    for (int yIndex = 1; yIndex < numY - 1; yIndex++) {
                        for (int xIndex = 1; xIndex < numX - 1; xIndex++) {
                            // already on face of boundary (removing half)
                            int totalOctants = 4;
                            // lg.info("-z side including nothing");
                            if (regionInfo.isIndexInRegion(xIndex + yIndex * numX)) {
                                // (regionImage.getRegionIndex(xIndex,yIndex,0) == regionIndex){
                                numOctantsToRemove += (8 - totalOctants);
                            }
                            // lg.info("+z side including nothing");
                            if (regionInfo.isIndexInRegion(xIndex + yIndex * numX + (numZ - 1) * numXY)) {
                                // (regionImage.getRegionIndex(xIndex,yIndex,numZ-1) == regionIndex){
                                numOctantsToRemove += (8 - totalOctants);
                            }
                        }
                    }
                    size -= sizeOfPixel * 0.125 * numOctantsToRemove;
                    if (lg.isInfoEnabled()) {
                        lg.info("size=" + size);
                    }
                    break;
                }
        }
        VolumeGeometricRegion volumeRegion = new VolumeGeometricRegion(name, size, volumeUnit, subVolume, regionInfo.getRegionIndex());
        regionList.add(volumeRegion);
        if (lg.isInfoEnabled()) {
            lg.info("added volumeRegion(" + volumeRegion.getName() + ")");
        }
    }
    // 
    for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
        cbit.vcell.geometry.surface.Surface surface = surfaceCollection.getSurfaces(i);
        int exteriorRegionIndex = surface.getExteriorRegionIndex();
        int interiorRegionIndex = surface.getInteriorRegionIndex();
        cbit.vcell.geometry.SubVolume surfaceExteriorSubvolume = geometrySpec.getSubVolume(regionInfos[exteriorRegionIndex].getPixelValue());
        cbit.vcell.geometry.SubVolume surfaceInteriorSubvolume = geometrySpec.getSubVolume(regionInfos[interiorRegionIndex].getPixelValue());
        String name = "membrane_" + surfaceInteriorSubvolume.getName() + interiorRegionIndex + "_" + surfaceExteriorSubvolume.getName() + exteriorRegionIndex;
        double correctedArea = surface.getArea();
        if (geometrySpec.getDimension() == 2) {
            correctedArea /= geometrySpec.getExtent().getZ();
        } else if (geometrySpec.getDimension() == 1) {
            correctedArea /= (geometrySpec.getExtent().getY() * geometrySpec.getExtent().getZ());
        }
        SurfaceGeometricRegion surfaceRegion = new SurfaceGeometricRegion(name, correctedArea, surfaceUnit);
        regionList.add(surfaceRegion);
        // 
        // connect this surfaceLocation to its exterior and interior volumeLocations
        // 
        VolumeGeometricRegion exteriorVolumeRegion = null;
        for (int j = 0; j < regionList.size(); j++) {
            GeometricRegion region = regionList.elementAt(j);
            if (region instanceof VolumeGeometricRegion && region.getName().equals(surfaceExteriorSubvolume.getName() + exteriorRegionIndex)) {
                exteriorVolumeRegion = (VolumeGeometricRegion) region;
            }
        }
        surfaceRegion.addAdjacentGeometricRegion(exteriorVolumeRegion);
        exteriorVolumeRegion.addAdjacentGeometricRegion(surfaceRegion);
        VolumeGeometricRegion interiorVolumeRegion = null;
        for (int j = 0; j < regionList.size(); j++) {
            GeometricRegion region = regionList.elementAt(j);
            if (region instanceof VolumeGeometricRegion && region.getName().equals(surfaceInteriorSubvolume.getName() + interiorRegionIndex)) {
                interiorVolumeRegion = (VolumeGeometricRegion) region;
            }
        }
        surfaceRegion.addAdjacentGeometricRegion(interiorVolumeRegion);
        interiorVolumeRegion.addAdjacentGeometricRegion(surfaceRegion);
        if (lg.isInfoEnabled()) {
            lg.info("added surfaceRegion(" + surfaceRegion.getName() + ")");
        }
    }
    return org.vcell.util.BeanUtils.getArray(regionList, GeometricRegion.class);
}
Also used : GeometrySpec(cbit.vcell.geometry.GeometrySpec) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) GeometryUnitSystem(cbit.vcell.geometry.GeometryUnitSystem) RegionImage(cbit.vcell.geometry.RegionImage)

Example 2 with GeometryUnitSystem

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

the class XmlReader method getGeometrySurfaceDescription.

private GeometrySurfaceDescription getGeometrySurfaceDescription(Element param, Geometry geom) throws XmlParseException {
    GeometrySurfaceDescription gsd = geom.getGeometrySurfaceDescription();
    String cutoffStr = param.getAttributeValue(XMLTags.CutoffFrequencyAttrTag);
    String xDim = param.getAttributeValue(XMLTags.NumSamplesXAttrTag);
    String yDim = param.getAttributeValue(XMLTags.NumSamplesYAttrTag);
    String zDim = param.getAttributeValue(XMLTags.NumSamplesZAttrTag);
    if (cutoffStr == null || xDim == null || yDim == null || zDim == null) {
        throw new XmlParseException("Attributes for element Surface Description not properly set, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
    }
    try {
        ISize isize = new ISize(Integer.parseInt(xDim), Integer.parseInt(yDim), Integer.parseInt(zDim));
        gsd.setVolumeSampleSize(isize);
        gsd.setFilterCutoffFrequency(new Double(cutoffStr));
        // these lists are allowed to be empty.
        ArrayList<Element> memRegions = new ArrayList<Element>(param.getChildren(XMLTags.MembraneRegionTag, vcNamespace));
        ArrayList<Element> volRegions = new ArrayList<Element>(param.getChildren(XMLTags.VolumeRegionTag, vcNamespace));
        ArrayList<GeometricRegion> regions = new ArrayList<GeometricRegion>();
        GeometryUnitSystem geometryUnitSystem = geom.getUnitSystem();
        for (Element temp : volRegions) {
            String regionID = temp.getAttributeValue(XMLTags.RegionIDAttrTag);
            String name = temp.getAttributeValue(XMLTags.NameAttrTag);
            String subvolumeRef = temp.getAttributeValue(XMLTags.SubVolumeAttrTag);
            if (regionID == null || name == null || subvolumeRef == null) {
                throw new XmlParseException("Attributes for element Volume Region not properly set, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
            }
            SubVolume subvolume = geom.getGeometrySpec().getSubVolume(subvolumeRef);
            if (subvolume == null) {
                throw new XmlParseException("The subvolume " + subvolumeRef + " could not be resolved.");
            }
            double size = -1;
            VCUnitDefinition unit = null;
            String sizeStr = temp.getAttributeValue(XMLTags.SizeAttrTag);
            if (sizeStr != null) {
                size = Double.parseDouble(sizeStr);
                String unitSymbol = temp.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
                if (unitSymbol != null) {
                    unit = geometryUnitSystem.getInstance(unitSymbol);
                }
            }
            VolumeGeometricRegion vgr = new VolumeGeometricRegion(name, size, unit, subvolume, Integer.parseInt(regionID));
            regions.add(vgr);
        }
        for (Element temp : memRegions) {
            String volRegion_1 = temp.getAttributeValue(XMLTags.VolumeRegion_1AttrTag);
            String volRegion_2 = temp.getAttributeValue(XMLTags.VolumeRegion_2AttrTag);
            String name = temp.getAttributeValue(XMLTags.NameAttrTag);
            if (volRegion_1 == null || volRegion_2 == null || name == null) {
                throw new XmlParseException("Attributes for element Membrane Region not properly set, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
            }
            VolumeGeometricRegion region1 = getAdjacentVolumeRegion(regions, volRegion_1);
            VolumeGeometricRegion region2 = getAdjacentVolumeRegion(regions, volRegion_2);
            if (region1 == null || region2 == null) {
                throw new XmlParseException("Element Membrane Region refernces invalid volume regions, under geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
            }
            double size = -1;
            VCUnitDefinition unit = null;
            String sizeStr = temp.getAttributeValue(XMLTags.SizeAttrTag);
            if (sizeStr != null) {
                size = Double.parseDouble(sizeStr);
                String unitSymbol = temp.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
                if (unitSymbol != null) {
                    unit = geometryUnitSystem.getInstance(unitSymbol);
                }
            }
            SurfaceGeometricRegion rsl = new SurfaceGeometricRegion(name, size, unit);
            rsl.addAdjacentGeometricRegion(region1);
            region1.addAdjacentGeometricRegion(rsl);
            rsl.addAdjacentGeometricRegion(region2);
            region2.addAdjacentGeometricRegion(rsl);
            regions.add(rsl);
        }
        if (regions.size() > 0) {
            gsd.setGeometricRegions((GeometricRegion[]) regions.toArray(new GeometricRegion[regions.size()]));
        }
    } catch (Exception e) {
        System.err.println("Unable to read geometry surface description from XML, for geometry: " + ((Element) param.getParent()).getAttributeValue(XMLTags.NameAttrTag));
        e.printStackTrace();
    }
    return gsd;
}
Also used : GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) Element(org.jdom.Element) ArrayList(java.util.ArrayList) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometryException(cbit.vcell.geometry.GeometryException) MathFormatException(cbit.vcell.math.MathFormatException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ModelException(cbit.vcell.model.ModelException) DataConversionException(org.jdom.DataConversionException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) GeometryUnitSystem(cbit.vcell.geometry.GeometryUnitSystem) SubVolume(cbit.vcell.geometry.SubVolume) CompartmentSubVolume(cbit.vcell.geometry.CompartmentSubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion)

Aggregations

GeometryUnitSystem (cbit.vcell.geometry.GeometryUnitSystem)2 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)2 ImageException (cbit.image.ImageException)1 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)1 CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)1 GeometryException (cbit.vcell.geometry.GeometryException)1 GeometrySpec (cbit.vcell.geometry.GeometrySpec)1 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)1 RegionImage (cbit.vcell.geometry.RegionImage)1 SubVolume (cbit.vcell.geometry.SubVolume)1 GeometricRegion (cbit.vcell.geometry.surface.GeometricRegion)1 GeometrySurfaceDescription (cbit.vcell.geometry.surface.GeometrySurfaceDescription)1 SurfaceGeometricRegion (cbit.vcell.geometry.surface.SurfaceGeometricRegion)1 VolumeGeometricRegion (cbit.vcell.geometry.surface.VolumeGeometricRegion)1 MappingException (cbit.vcell.mapping.MappingException)1 MathException (cbit.vcell.math.MathException)1 MathFormatException (cbit.vcell.math.MathFormatException)1 ModelException (cbit.vcell.model.ModelException)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 ExpressionException (cbit.vcell.parser.ExpressionException)1