Search in sources :

Example 11 with ISize

use of org.vcell.util.ISize in project vcell by virtualcell.

the class Xmlproducer method getXML.

/**
 * Insert the method's description here.
 * Creation date: (3/3/2001 12:24:59 AM)
 * @return Element
 * @param param cbit.vcell.mesh.MeshSpecification
 */
private Element getXML(MeshSpecification param) {
    Element meshspec = new Element(XMLTags.MeshSpecTag);
    Element size = new Element(XMLTags.SizeTag);
    // Add extent attributes
    ISize sampling = param.getSamplingSize();
    size.setAttribute(XMLTags.XAttrTag, String.valueOf(sampling.getX()));
    size.setAttribute(XMLTags.YAttrTag, String.valueOf(sampling.getY()));
    size.setAttribute(XMLTags.ZAttrTag, String.valueOf(sampling.getZ()));
    meshspec.addContent(size);
    return meshspec;
}
Also used : ISize(org.vcell.util.ISize) Element(org.jdom.Element)

Example 12 with ISize

use of org.vcell.util.ISize in project vcell by virtualcell.

the class MathModel_SBMLExporter method addGeometry.

private static void addGeometry(Model sbmlModel, MathModel vcMathModel) {
    SpatialModelPlugin mplugin = (SpatialModelPlugin) sbmlModel.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
    // Creates a geometry object via SpatialModelPlugin object.
    org.sbml.jsbml.ext.spatial.Geometry sbmlGeometry = mplugin.getGeometry();
    sbmlGeometry.setCoordinateSystem(GeometryKind.cartesian);
    Geometry vcGeometry = vcMathModel.getGeometry();
    // 
    // list of CoordinateComponents : 1 if geometry is 1-d, 2 if geometry is 2-d, 3 if geometry is 3-d
    // 
    int dimension = vcGeometry.getDimension();
    Extent vcExtent = vcGeometry.getExtent();
    Origin vcOrigin = vcGeometry.getOrigin();
    // add x coordinate component
    CoordinateComponent coordCompX = sbmlGeometry.createCoordinateComponent();
    coordCompX.setSpatialId("CoordCompX");
    coordCompX.setType(CoordinateKind.cartesianX);
    Boundary minX = coordCompX.getBoundaryMaximum();
    minX.setSpatialId("Xmin");
    minX.setValue(vcOrigin.getX());
    Boundary maxX = coordCompX.getBoundaryMaximum();
    maxX.setSpatialId("Xmax");
    maxX.setValue(vcOrigin.getX() + (vcExtent.getX()));
    Parameter parameterX = sbmlModel.createParameter();
    // note for exporting BioModels rather than MathModels, get ReservedSymbol from Model with Role of ReservedSymbolRole.X
    parameterX.setId(ReservedVariable.X.getName());
    SpatialSymbolReference coordXSpatialRef = new SpatialSymbolReference();
    coordXSpatialRef.setSpatialRef(coordCompX.getSpatialId());
    SpatialParameterPlugin parameterXSpatialPlugin = (SpatialParameterPlugin) parameterX.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
    parameterXSpatialPlugin.setParamType(coordXSpatialRef);
    // add y coordinate component
    if (dimension == 2 || dimension == 3) {
        CoordinateComponent coordCompY = sbmlGeometry.createCoordinateComponent();
        coordCompY.setSpatialId("CoordCompY");
        coordCompY.setType(CoordinateKind.cartesianY);
        Boundary minY = coordCompY.getBoundaryMinimum();
        minY.setId("Ymin");
        minY.setValue(vcOrigin.getY());
        Boundary maxY = coordCompY.getBoundaryMaximum();
        maxY.setId("Ymax");
        maxY.setValue(vcOrigin.getY() + (vcExtent.getY()));
        Parameter parameterY = sbmlModel.createParameter();
        // note for exporting BioModels rather than MathModels, get ReservedSymbol from Model with Role of ReservedSymbolRole.Y
        parameterY.setId(ReservedVariable.Y.getName());
        SpatialSymbolReference coordYSpatialRef = new SpatialSymbolReference();
        coordYSpatialRef.setSpatialRef(coordCompY.getSpatialId());
        SpatialParameterPlugin parameterYSpatialPlugin = (SpatialParameterPlugin) parameterY.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
        parameterYSpatialPlugin.setParamType(coordYSpatialRef);
    }
    // add z coordinate component
    if (dimension == 3) {
        CoordinateComponent coordCompZ = sbmlGeometry.createCoordinateComponent();
        coordCompZ.setSpatialId("CoordCompZ");
        coordCompZ.setType(CoordinateKind.cartesianZ);
        Boundary minZ = coordCompZ.getBoundaryMinimum();
        minZ.setId("Zmin");
        minZ.setValue(vcOrigin.getZ());
        Boundary maxZ = coordCompZ.getBoundaryMaximum();
        maxZ.setId("Zmax");
        maxZ.setValue(vcOrigin.getZ() + (vcExtent.getZ()));
        Parameter parameterZ = sbmlModel.createParameter();
        // note for exporting BioModels rather than MathModels, get ReservedSymbol from Model with Role of ReservedSymbolRole.Y
        parameterZ.setId(ReservedVariable.Z.getName());
        SpatialSymbolReference coordZSpatialRef = new SpatialSymbolReference();
        coordZSpatialRef.setSpatialRef(coordCompZ.getSpatialId());
        SpatialParameterPlugin parameterZSpatialPlugin = (SpatialParameterPlugin) parameterZ.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
        parameterZSpatialPlugin.setParamType(coordZSpatialRef);
    }
    // 
    // list of domain types : subvolumes and surface classes from VC
    // Also create compartments - one compartment for each geometryClass. set id and spatialDimension based on type of geometryClass.
    // 
    boolean bAnalyticGeom = false;
    boolean bImageGeom = false;
    GeometryClass[] vcGeomClasses = vcGeometry.getGeometryClasses();
    int numVCGeomClasses = vcGeomClasses.length;
    for (int i = 0; i < numVCGeomClasses; i++) {
        DomainType domainType = sbmlGeometry.createDomainType();
        domainType.setId(vcGeomClasses[i].getName());
        if (vcGeomClasses[i] instanceof SubVolume) {
            if (((SubVolume) vcGeomClasses[i]) instanceof AnalyticSubVolume) {
                bAnalyticGeom = true;
            } else if (((SubVolume) vcGeomClasses[i]) instanceof ImageSubVolume) {
                bImageGeom = true;
            }
            domainType.setSpatialDimensions(3);
        } else if (vcGeomClasses[i] instanceof SurfaceClass) {
            domainType.setSpatialDimensions(2);
        }
    }
    // 
    // list of domains, adjacent domains : from VC geometricRegions
    // 
    GeometrySurfaceDescription vcGSD = vcGeometry.getGeometrySurfaceDescription();
    if (vcGSD.getRegionImage() == null) {
        try {
            vcGSD.updateAll();
        } catch (Exception e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Unable to generate region images for geometry");
        }
    }
    GeometricRegion[] vcGeometricRegions = vcGSD.getGeometricRegions();
    ISize sampleSize = vcGSD.getVolumeSampleSize();
    int numX = sampleSize.getX();
    int numY = sampleSize.getY();
    int numZ = sampleSize.getZ();
    double ox = vcOrigin.getX();
    double oy = vcOrigin.getY();
    double oz = vcOrigin.getZ();
    RegionInfo[] regionInfos = vcGSD.getRegionImage().getRegionInfos();
    Compartment compartment = null;
    for (int i = 0; i < vcGeometricRegions.length; i++) {
        // domains
        Domain domain = sbmlGeometry.createDomain();
        domain.setId(vcGeometricRegions[i].getName());
        compartment = sbmlModel.createCompartment();
        compartment.setId("compartment" + i);
        if (vcGeometricRegions[i] instanceof VolumeGeometricRegion) {
            domain.setDomainType(((VolumeGeometricRegion) vcGeometricRegions[i]).getSubVolume().getName());
            // domain.setImplicit(false);
            compartment.setSpatialDimensions(3);
            InteriorPoint interiorPt = domain.createInteriorPoint();
            int regionID = ((VolumeGeometricRegion) vcGeometricRegions[i]).getRegionID();
            boolean bFound = false;
            int regInfoIndx = 0;
            for (int j = 0; j < regionInfos.length; j++) {
                regInfoIndx = j;
                if (regionInfos[j].getRegionIndex() == regionID) {
                    int volIndx = 0;
                    for (int z = 0; z < numZ && !bFound; z++) {
                        for (int y = 0; y < numY && !bFound; y++) {
                            for (int x = 0; x < numX && !bFound; x++) {
                                if (regionInfos[j].isIndexInRegion(volIndx)) {
                                    bFound = true;
                                    double unit_z = (numZ > 1) ? ((double) z) / (numZ - 1) : 0.5;
                                    double coordZ = oz + vcExtent.getZ() * unit_z;
                                    double unit_y = (numY > 1) ? ((double) y) / (numY - 1) : 0.5;
                                    double coordY = oy + vcExtent.getY() * unit_y;
                                    double unit_x = (numX > 1) ? ((double) x) / (numX - 1) : 0.5;
                                    double coordX = ox + vcExtent.getX() * unit_x;
                                    interiorPt.setCoord1(coordX);
                                    interiorPt.setCoord2(coordY);
                                    interiorPt.setCoord3(coordZ);
                                }
                                volIndx++;
                            }
                        // end - for x
                        }
                    // end - for y
                    }
                // end - for z
                }
            // end if
            }
            // end for regionInfos
            if (!bFound) {
                throw new RuntimeException("Unable to find interior point for region '" + regionInfos[regInfoIndx].toString());
            }
        } else if (vcGeometricRegions[i] instanceof SurfaceGeometricRegion) {
            SurfaceGeometricRegion vcSurfaceGeomReg = (SurfaceGeometricRegion) vcGeometricRegions[i];
            GeometricRegion geomRegion0 = vcSurfaceGeomReg.getAdjacentGeometricRegions()[0];
            GeometricRegion geomRegion1 = vcSurfaceGeomReg.getAdjacentGeometricRegions()[1];
            SurfaceClass surfaceClass = vcGSD.getSurfaceClass(((VolumeGeometricRegion) geomRegion0).getSubVolume(), ((VolumeGeometricRegion) geomRegion1).getSubVolume());
            domain.setDomainType(surfaceClass.getName());
            // domain.setImplicit(true);
            compartment.setSpatialDimensions(2);
            // adjacent domains : 2 adjacent domain objects for each surfaceClass in VC.
            // adjacent domain 1
            AdjacentDomains adjDomain = sbmlGeometry.createAdjacentDomain();
            adjDomain.setId(TokenMangler.mangleToSName(vcSurfaceGeomReg.getName() + "_" + geomRegion0.getName()));
            adjDomain.setDomain1(vcSurfaceGeomReg.getName());
            adjDomain.setDomain2(geomRegion0.getName());
            // adjacent domain 2
            adjDomain = sbmlGeometry.createAdjacentDomain();
            adjDomain.setId(TokenMangler.mangleToSName(vcSurfaceGeomReg.getName() + "_" + geomRegion1.getName()));
            adjDomain.setDomain1(vcSurfaceGeomReg.getName());
            adjDomain.setDomain2(geomRegion1.getName());
        }
        // 
        // Mathmodel does not have structureMapping, hence creating compartmentMapping while creating domains.
        // @TODO : how to assign unitSize for compartmentMapping?
        // 
        SpatialCompartmentPlugin cplugin = (SpatialCompartmentPlugin) compartment.getPlugin(SBMLUtils.SBML_SPATIAL_NS_PREFIX);
        CompartmentMapping compMapping = cplugin.getCompartmentMapping();
        String compMappingId = TokenMangler.mangleToSName(domain.getDomainType() + "_" + compartment.getId());
        compMapping.setId(compMappingId);
        compMapping.setDomainType(TokenMangler.mangleToSName(domain.getDomainType()));
    // try {
    // compMapping.setUnitSize(1.0);
    // } catch (ExpressionException e) {
    // e.printStackTrace(System.out);
    // throw new RuntimeException("Unable to create compartment mapping for structureMapping '" + compMapping.getId() +"' : " + e.getMessage());
    // }
    }
    AnalyticGeometry sbmlAnalyticGeom = null;
    SampledFieldGeometry sbmlSFGeom = null;
    // both image and analytic subvolumes?? == not handled in SBML at this time.
    if (bAnalyticGeom && !bImageGeom) {
        sbmlAnalyticGeom = sbmlGeometry.createAnalyticGeometry();
        sbmlAnalyticGeom.setId(TokenMangler.mangleToSName(vcGeometry.getName()));
    } else if (bImageGeom && !bAnalyticGeom) {
        // assuming image based geometry if not analytic geometry
        sbmlSFGeom = sbmlGeometry.createSampledFieldGeometry();
        sbmlSFGeom.setId(TokenMangler.mangleToSName(vcGeometry.getName()));
    } else if (bAnalyticGeom && bImageGeom) {
        throw new RuntimeException("Export to SBML of a combination of Image-based and Analytic geometries is not supported yet.");
    } else if (!bAnalyticGeom && !bImageGeom) {
        throw new RuntimeException("Unknown geometry type.");
    }
    // 
    for (int i = 0; i < vcGeomClasses.length; i++) {
        if (vcGeomClasses[i] instanceof AnalyticSubVolume) {
            // add analytiVols to sbmlAnalyticGeometry
            if (sbmlAnalyticGeom != null) {
                AnalyticVolume analyticVol = sbmlAnalyticGeom.createAnalyticVolume();
                analyticVol.setId(vcGeomClasses[i].getName());
                analyticVol.setDomainType(vcGeomClasses[i].getName());
                analyticVol.setFunctionType(FunctionKind.layered);
                analyticVol.setOrdinal(i);
                Expression expr = ((AnalyticSubVolume) vcGeomClasses[i]).getExpression();
                try {
                    String mathMLStr = ExpressionMathMLPrinter.getMathML(expr, true);
                    ASTNode mathMLNode = ASTNode.readMathMLFromString(mathMLStr);
                    analyticVol.setMath(mathMLNode);
                } catch (Exception e) {
                    e.printStackTrace(System.out);
                    throw new RuntimeException("Error converting VC subvolume expression to mathML" + e.getMessage());
                }
            } else {
                throw new RuntimeException("SBML AnalyticGeometry is null.");
            }
        } else if (vcGeomClasses[i] instanceof ImageSubVolume) {
            // add sampledVols to sbmlSFGeometry
            if (sbmlSFGeom != null) {
                SampledVolume sampledVol = sbmlSFGeom.createSampledVolume();
                sampledVol.setId(vcGeomClasses[i].getName());
                sampledVol.setDomainType(vcGeomClasses[i].getName());
                sampledVol.setSampledValue(((ImageSubVolume) vcGeomClasses[i]).getPixelValue());
            } else {
                throw new RuntimeException("SBML SampledFieldGeometry is null.");
            }
        }
    }
    if (sbmlSFGeom != null) {
        // add sampledField to sampledFieldGeometry
        SampledField sampledField = sbmlGeometry.createSampledField();
        VCImage vcImage = vcGeometry.getGeometrySpec().getImage();
        sampledField.setId(vcImage.getName());
        sampledField.setNumSamples1(vcImage.getNumX());
        if (vcImage.getNumY() > 1) {
            sampledField.setNumSamples2(vcImage.getNumY());
        }
        if (vcImage.getNumZ() > 1) {
            sampledField.setNumSamples3(vcImage.getNumZ());
        }
        sampledField.setInterpolationType(InterpolationKind.nearestneighbor);
        sampledField.setDataType(DataKind.UINT8);
        // add image from vcGeometrySpec to sampledField.
        try {
            StringBuffer sb = new StringBuffer();
            byte[] imagePixelsBytes = vcImage.getPixelsCompressed();
            for (int i = 0; i < imagePixelsBytes.length; i++) {
                int uint8_sample = ((int) imagePixelsBytes[i]) & 0xff;
                sb.append(uint8_sample + " ");
            }
            sampledField.setSamplesLength(vcImage.getNumXYZ());
            sampledField.setSamples(sb.toString().trim());
        } catch (ImageException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Unable to export image from VCell to SBML : " + e.getMessage());
        }
    }
}
Also used : Origin(org.vcell.util.Origin) CompartmentMapping(org.sbml.jsbml.ext.spatial.CompartmentMapping) Compartment(org.sbml.jsbml.Compartment) SpatialParameterPlugin(org.sbml.jsbml.ext.spatial.SpatialParameterPlugin) AnalyticGeometry(org.sbml.jsbml.ext.spatial.AnalyticGeometry) Boundary(org.sbml.jsbml.ext.spatial.Boundary) DomainType(org.sbml.jsbml.ext.spatial.DomainType) SampledVolume(org.sbml.jsbml.ext.spatial.SampledVolume) SubVolume(cbit.vcell.geometry.SubVolume) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) SpatialCompartmentPlugin(org.sbml.jsbml.ext.spatial.SpatialCompartmentPlugin) CoordinateComponent(org.sbml.jsbml.ext.spatial.CoordinateComponent) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) SpatialSymbolReference(org.sbml.jsbml.ext.spatial.SpatialSymbolReference) AnalyticVolume(org.sbml.jsbml.ext.spatial.AnalyticVolume) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) SampledField(org.sbml.jsbml.ext.spatial.SampledField) Domain(org.sbml.jsbml.ext.spatial.Domain) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) GeometryClass(cbit.vcell.geometry.GeometryClass) ImageException(cbit.image.ImageException) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) Extent(org.vcell.util.Extent) SurfaceClass(cbit.vcell.geometry.SurfaceClass) ISize(org.vcell.util.ISize) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) VCImage(cbit.image.VCImage) ASTNode(org.sbml.jsbml.ASTNode) ImageSubVolume(cbit.vcell.geometry.ImageSubVolume) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) SampledFieldGeometry(org.sbml.jsbml.ext.spatial.SampledFieldGeometry) SpatialModelPlugin(org.sbml.jsbml.ext.spatial.SpatialModelPlugin) InteriorPoint(org.sbml.jsbml.ext.spatial.InteriorPoint) XMLStreamException(javax.xml.stream.XMLStreamException) ImageException(cbit.image.ImageException) SBMLException(org.sbml.jsbml.SBMLException) AdjacentDomains(org.sbml.jsbml.ext.spatial.AdjacentDomains) Geometry(cbit.vcell.geometry.Geometry) AnalyticGeometry(org.sbml.jsbml.ext.spatial.AnalyticGeometry) SampledFieldGeometry(org.sbml.jsbml.ext.spatial.SampledFieldGeometry) Expression(cbit.vcell.parser.Expression) Parameter(org.sbml.jsbml.Parameter)

Example 13 with ISize

use of org.vcell.util.ISize in project vcell by virtualcell.

the class XmlReader method getMeshSpecification.

/**
 * This method returns a MeshSpecification object from a XML Element.
 * Creation date: (5/22/2001 12:05:21 PM)
 * @return cbit.vcell.mesh.MeshSpecification
 * @param param org.jdom.Element
 */
private MeshSpecification getMeshSpecification(Element param, Geometry geometry) throws XmlParseException {
    // *** create new MeshSpecification ***
    MeshSpecification meshSpec = new MeshSpecification(geometry);
    // get ISize
    Element size = param.getChild(XMLTags.SizeTag, vcNamespace);
    int x = Integer.parseInt(size.getAttributeValue(XMLTags.XAttrTag));
    int y = Integer.parseInt(size.getAttributeValue(XMLTags.YAttrTag));
    int z = Integer.parseInt(size.getAttributeValue(XMLTags.ZAttrTag));
    ISize newsize = new ISize(x, y, z);
    // set ISize
    try {
        meshSpec.setSamplingSize(newsize);
    } catch (java.beans.PropertyVetoException e) {
        e.printStackTrace();
        throw new XmlParseException("A PropertyVetoException was fired when setting the ISize object to a new MeshSpecification", e);
    }
    return meshSpec;
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ISize(org.vcell.util.ISize) Element(org.jdom.Element) MeshSpecification(cbit.vcell.solver.MeshSpecification)

Example 14 with ISize

use of org.vcell.util.ISize in project vcell by virtualcell.

the class Xmlproducer method getXML.

private Element getXML(GeometrySurfaceDescription param) throws XmlParseException {
    Element gsd = new Element(XMLTags.SurfaceDescriptionTag);
    // add attributes
    ISize isize = param.getVolumeSampleSize();
    if (isize == null) {
        throw new XmlParseException("Unable to retrieve dimensions for surface descriptions for Geometry: " + param.getGeometry().getName());
    }
    gsd.setAttribute(XMLTags.NumSamplesXAttrTag, String.valueOf(isize.getX()));
    gsd.setAttribute(XMLTags.NumSamplesYAttrTag, String.valueOf(isize.getY()));
    gsd.setAttribute(XMLTags.NumSamplesZAttrTag, String.valueOf(isize.getZ()));
    Double coFrequency = param.getFilterCutoffFrequency();
    if (coFrequency == null) {
        throw new XmlParseException("Unable to retrieve cutoff frequency for surface descriptions for Geometry: " + param.getGeometry().getName());
    }
    double cutoffFrequency = coFrequency.doubleValue();
    gsd.setAttribute(XMLTags.CutoffFrequencyAttrTag, String.valueOf(cutoffFrequency));
    // add subelements
    GeometricRegion[] geomRegions = param.getGeometricRegions();
    if (geomRegions != null) {
        for (int i = 0; i < geomRegions.length; i++) {
            if (geomRegions[i] instanceof SurfaceGeometricRegion) {
                SurfaceGeometricRegion sgr = (SurfaceGeometricRegion) geomRegions[i];
                Element membraneRegion = new Element(XMLTags.MembraneRegionTag);
                membraneRegion.setAttribute(XMLTags.NameAttrTag, sgr.getName());
                GeometricRegion[] adjacents = sgr.getAdjacentGeometricRegions();
                if (adjacents == null || adjacents.length != 2) {
                    throw new XmlParseException("Wrong number of adjacent regions for surface descriptions for location: " + sgr.getName() + " in Geometry: " + param.getGeometry().getName());
                }
                membraneRegion.setAttribute(XMLTags.VolumeRegion_1AttrTag, adjacents[0].getName());
                membraneRegion.setAttribute(XMLTags.VolumeRegion_2AttrTag, adjacents[1].getName());
                double size = sgr.getSize();
                if (size != -1) {
                    membraneRegion.setAttribute(XMLTags.SizeAttrTag, String.valueOf(size));
                    VCUnitDefinition unit = sgr.getSizeUnit();
                    if (unit != null) {
                        membraneRegion.setAttribute(XMLTags.VCUnitDefinitionAttrTag, unit.getSymbol());
                    }
                }
                gsd.addContent(membraneRegion);
            } else if (geomRegions[i] instanceof VolumeGeometricRegion) {
                VolumeGeometricRegion vgr = (VolumeGeometricRegion) geomRegions[i];
                Element volumeRegion = new Element(XMLTags.VolumeRegionTag);
                volumeRegion.setAttribute(XMLTags.NameAttrTag, vgr.getName());
                volumeRegion.setAttribute(XMLTags.RegionIDAttrTag, String.valueOf(vgr.getRegionID()));
                volumeRegion.setAttribute(XMLTags.SubVolumeAttrTag, vgr.getSubVolume().getName());
                double size = vgr.getSize();
                if (size != -1) {
                    volumeRegion.setAttribute(XMLTags.SizeAttrTag, String.valueOf(size));
                    VCUnitDefinition unit = vgr.getSizeUnit();
                    if (unit != null) {
                        volumeRegion.setAttribute(XMLTags.VCUnitDefinitionAttrTag, unit.getSymbol());
                    }
                }
                gsd.addContent(volumeRegion);
            }
        }
    }
    return gsd;
}
Also used : VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ISize(org.vcell.util.ISize) Element(org.jdom.Element) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion)

Example 15 with ISize

use of org.vcell.util.ISize in project vcell by virtualcell.

the class FRAPStudy method getROIDataGenerator.

public ROIDataGenerator getROIDataGenerator(LocalWorkspace localWorkspace) {
    // create ROI image
    short[] roiFieldData = null;
    ROI[] rois = getFrapData().getRois();
    if (rois.length > 0) {
        Extent extent = rois[0].getRoiImages()[0].getExtent();
        ISize isize = rois[0].getISize();
        int numROIX = rois[0].getISize().getX();
        int numROIY = rois[0].getISize().getY();
        roiFieldData = new short[numROIX * numROIY];
        short regionCounter = 1;
        for (int roiIdx = FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.ordinal(); roiIdx < rois.length; roiIdx++) {
            short[] roiImg = rois[roiIdx].getPixelsXYZ();
            for (int pixelIdx = 0; pixelIdx < (numROIX * numROIY); pixelIdx++) {
                if (roiImg[pixelIdx] > 0) {
                    roiFieldData[pixelIdx] = regionCounter;
                }
            }
            regionCounter++;
        }
        // create field data
        int NumTimePoints = 1;
        // 8 rois integrated into 1 image
        int NumChannels = 1;
        short[][][] pixData = new short[NumTimePoints][NumChannels][];
        pixData[0][0] = roiFieldData;
        // get extental data id
        ExternalDataIdentifier newROIExtDataID = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_SUMDATA_NAME).getExternalDataIdentifier();
        CartesianMesh cartesianMesh;
        try {
            cartesianMesh = getCartesianMesh();
            Origin origin = new Origin(0, 0, 0);
            FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
            fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
            fdos.cartesianMesh = cartesianMesh;
            fdos.shortSpecData = pixData;
            fdos.specEDI = newROIExtDataID;
            fdos.varNames = new String[] { "roiSumDataVar" };
            fdos.owner = LocalWorkspace.getDefaultOwner();
            fdos.times = new double[] { 0.0 };
            fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
            fdos.origin = origin;
            fdos.extent = extent;
            fdos.isize = isize;
            localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return new ROIDataGenerator(ROI_EXTDATA_NAME, /*name*/
        new int[] { 0 }, /* volumePoints*/
        new int[0], /* membranePoints*/
        regionCounter, /*numRegions*/
        0, /*zSlice*/
        newROIExtDataID.getKey(), /* fieldDataKey, sample image*/
        new FieldFunctionArguments(FRAPStudy.ROI_SUMDATA_NAME, "roiSumDataVar", new Expression(0), VariableType.VOLUME), /*FieldFunctionArguments, sample image*/
        false);
    }
    return null;
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) ROI(cbit.vcell.VirtualMicroscopy.ROI) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Expression(cbit.vcell.parser.Expression) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier)

Aggregations

ISize (org.vcell.util.ISize)134 Extent (org.vcell.util.Extent)52 Origin (org.vcell.util.Origin)45 CartesianMesh (cbit.vcell.solvers.CartesianMesh)24 IOException (java.io.IOException)22 DataAccessException (org.vcell.util.DataAccessException)20 VCImage (cbit.image.VCImage)19 VCImageUncompressed (cbit.image.VCImageUncompressed)19 Geometry (cbit.vcell.geometry.Geometry)19 ImageException (cbit.image.ImageException)18 RegionImage (cbit.vcell.geometry.RegionImage)18 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)17 ExpressionException (cbit.vcell.parser.ExpressionException)17 File (java.io.File)16 GeometrySurfaceDescription (cbit.vcell.geometry.surface.GeometrySurfaceDescription)14 Expression (cbit.vcell.parser.Expression)14 ArrayList (java.util.ArrayList)14 PropertyVetoException (java.beans.PropertyVetoException)13 MathException (cbit.vcell.math.MathException)12 VariableType (cbit.vcell.math.VariableType)12