Search in sources :

Example 21 with ISize

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

the class RayCasterBitSet method createGeometryFromSTL.

public static Geometry createGeometryFromSTL(GeometryThumbnailImageFactory geometryThumbnailImageFactory, File stlFile, int numSamples) throws ImageException, PropertyVetoException, GeometryException, ExpressionException, IOException {
    SurfaceCollection surfaceCollection = StlReader.readStl(stlFile);
    Node[] nodes = surfaceCollection.getNodes();
    double minX = Double.MAX_VALUE;
    double maxX = -Double.MAX_VALUE;
    double minY = Double.MAX_VALUE;
    double maxY = -Double.MAX_VALUE;
    double minZ = Double.MAX_VALUE;
    double maxZ = -Double.MAX_VALUE;
    for (Node node : nodes) {
        double nx = node.getX();
        double ny = node.getY();
        double nz = node.getZ();
        minX = Math.min(minX, nx);
        maxX = Math.max(maxX, nx);
        minY = Math.min(minY, ny);
        maxY = Math.max(maxY, ny);
        minZ = Math.min(minZ, nz);
        maxZ = Math.max(maxZ, nz);
    }
    Extent extent = new Extent((maxX - minX) * 1.4, (maxY - minY) * 1.4, (maxZ - minZ) * 1.4);
    Origin origin = new Origin(minX - 0.2 * extent.getX(), minY - 0.2 * extent.getY(), minZ - 0.2 * extent.getZ());
    ISize sampleSize = GeometrySpec.calulateResetSamplingSize(3, extent, numSamples);
    Geometry geometry = createGeometry(geometryThumbnailImageFactory, surfaceCollection, origin, extent, sampleSize);
    return geometry;
}
Also used : Origin(org.vcell.util.Origin) Geometry(cbit.vcell.geometry.Geometry) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize)

Example 22 with ISize

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

the class RasterExporter method createSliceNrrdHelper.

private NRRDHelper createSliceNrrdHelper(CartesianMesh mesh, DataProcessingOutputInfo dataProcessingOutputInfo, VCDataIdentifier vcdID, VariableSpecs variableSpecs, TimeSpecs timeSpecs2, GeometrySpecs geometrySpecs, RasterSpecs rasterSpecs, FileDataContainerManager fileDataContainerManager) throws IOException, DataAccessException {
    ISize planeISize = Coordinate.convertAxisFromStandardXYZToNormal(mesh.getISize(), geometrySpecs.getAxis());
    planeISize = new ISize(planeISize.getX(), planeISize.getY(), 1);
    Extent planeExtent = Coordinate.convertAxisFromStandardXYZToNormal(mesh.getExtent(), geometrySpecs.getAxis());
    planeExtent = new Extent(planeExtent.getX(), planeExtent.getY(), 1);
    return NRRDHelper.getSizeCheckedNrrdHelper(variableSpecs, planeISize, planeExtent, dataProcessingOutputInfo);
}
Also used : Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize)

Example 23 with ISize

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

the class CartesianMesh method createSimpleCartesianMesh.

public static CartesianMesh createSimpleCartesianMesh(Geometry geometry, Map<Polygon, MembraneElement> polygonMembaneElementMap) throws IOException, MathFormatException {
    GeometrySurfaceDescription geometrySurfaceDescription = geometry.getGeometrySurfaceDescription();
    RegionImage regionImage = geometrySurfaceDescription.getRegionImage();
    ISize iSize = new ISize(regionImage.getNumX(), regionImage.getNumY(), regionImage.getNumZ());
    CartesianMesh mesh = createSimpleCartesianMesh(geometry.getOrigin(), geometry.getExtent(), iSize, regionImage);
    GeometricRegion[] geometricRegions = geometrySurfaceDescription.getGeometricRegions();
    if (geometricRegions != null) {
        int memRegionCount = 0;
        for (int i = 0; i < geometricRegions.length; i++) {
            if (geometricRegions[i] instanceof VolumeGeometricRegion) {
                VolumeGeometricRegion vgr = (VolumeGeometricRegion) geometricRegions[i];
                mesh.meshRegionInfo.mapVolumeRegionToSubvolume(vgr.getRegionID(), vgr.getSubVolume().getHandle(), vgr.getSize(), vgr.getName());
            } else if (geometricRegions[i] instanceof SurfaceGeometricRegion) {
                SurfaceGeometricRegion sgr = (SurfaceGeometricRegion) geometricRegions[i];
                GeometricRegion[] neighbors = sgr.getAdjacentGeometricRegions();
                VolumeGeometricRegion insideRegion = (VolumeGeometricRegion) neighbors[0];
                VolumeGeometricRegion outsideRegion = (VolumeGeometricRegion) neighbors[1];
                mesh.meshRegionInfo.mapMembraneRegionToVolumeRegion(memRegionCount, insideRegion.getRegionID(), outsideRegion.getRegionID(), sgr.getSize());
                memRegionCount++;
            }
        }
    }
    SurfaceCollection surfaceCollection = geometrySurfaceDescription.getSurfaceCollection();
    if (surfaceCollection != null) {
        int numMembraneElement = surfaceCollection.getTotalPolygonCount();
        mesh.membraneElements = new MembraneElement[numMembraneElement];
        boolean bMembraneEdgeNeighborsAvailable = surfaceCollection.getMembraneEdgeNeighbors() != null && surfaceCollection.getMembraneEdgeNeighbors().length == surfaceCollection.getSurfaceCount();
        int[] membraneElementMapMembraneRegion = new int[numMembraneElement];
        mesh.meshRegionInfo.mapMembraneElementsToMembraneRegions(membraneElementMapMembraneRegion);
        int memCount = 0;
        // original values when no membraneedgeneighbors
        int[] membraneNeighbors = new int[] { 0, 0, 0, 0 };
        for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
            Surface surface = surfaceCollection.getSurfaces(i);
            bMembraneEdgeNeighborsAvailable = bMembraneEdgeNeighborsAvailable && surfaceCollection.getMembraneEdgeNeighbors()[i].length == surface.getPolygonCount();
            for (int j = 0; j < surface.getPolygonCount(); j++) {
                if (bMembraneEdgeNeighborsAvailable) {
                    membraneNeighbors = new int[MembraneElement.MAX_POSSIBLE_NEIGHBORS];
                    Arrays.fill(membraneNeighbors, MembraneElement.NEIGHBOR_UNDEFINED);
                    for (int k = 0; k < surfaceCollection.getMembraneEdgeNeighbors()[i][j].size(); k++) {
                        membraneNeighbors[k] = surfaceCollection.getMembraneEdgeNeighbors()[i][j].get(k).getMasterPolygonIndex();
                    }
                }
                Quadrilateral polygon = (Quadrilateral) surface.getPolygons(j);
                int volNeighbor1Region = regionImage.getRegionInfoFromOffset(polygon.getVolIndexNeighbor1()).getRegionIndex();
                int volNeighbor2Region = regionImage.getRegionInfoFromOffset(polygon.getVolIndexNeighbor2()).getRegionIndex();
                HashMap<Integer, int[]> map = mesh.getMembraneRegionMapSubvolumesInOut();
                Set<Entry<Integer, int[]>> entries = map.entrySet();
                for (Entry<Integer, int[]> entry : entries) {
                    int[] volNeighbors = entry.getValue();
                    if (volNeighbors[0] == volNeighbor1Region && volNeighbors[1] == volNeighbor2Region || volNeighbors[1] == volNeighbor1Region && volNeighbors[0] == volNeighbor2Region) {
                        membraneElementMapMembraneRegion[memCount] = entry.getKey();
                        break;
                    }
                }
                mesh.membraneElements[memCount] = new MembraneElement(memCount, polygon.getVolIndexNeighbor1(), polygon.getVolIndexNeighbor2(), membraneNeighbors[0], membraneNeighbors[1], membraneNeighbors[2], membraneNeighbors[3], MembraneElement.AREA_UNDEFINED, 0, 0, 0, 0, 0, 0);
                if (polygonMembaneElementMap != null) {
                    polygonMembaneElementMap.put(polygon, mesh.membraneElements[memCount]);
                }
                memCount++;
            }
        }
    }
    return mesh;
}
Also used : SurfaceCollection(cbit.vcell.geometry.surface.SurfaceCollection) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) VolumeGeometricRegion(cbit.vcell.geometry.surface.VolumeGeometricRegion) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion) GeometricRegion(cbit.vcell.geometry.surface.GeometricRegion) Surface(cbit.vcell.geometry.surface.Surface) Quadrilateral(cbit.vcell.geometry.surface.Quadrilateral) Entry(java.util.Map.Entry) RegionImage(cbit.vcell.geometry.RegionImage) SurfaceGeometricRegion(cbit.vcell.geometry.surface.SurfaceGeometricRegion)

Example 24 with ISize

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

the class CartesianMeshMovingBoundary method readMeshFile.

public static CartesianMeshMovingBoundary readMeshFile(File meshFile) throws Exception {
    CartesianMeshMovingBoundary mesh = new CartesianMeshMovingBoundary();
    if (H5.H5open() < 0) {
        throw new Exception("H5.H5open() failed");
    }
    FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
    if (fileFormat == null) {
        throw new Exception("FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5) failed, returned null.");
    }
    FileFormat meshH5File = null;
    try {
        meshH5File = fileFormat.createInstance(meshFile.getAbsolutePath(), FileFormat.READ);
        meshH5File.open();
        DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) meshH5File.getRootNode();
        Group rootGroup = (Group) rootNode.getUserObject();
        Group meshGroup = null;
        for (Object member : rootGroup.getMemberList()) {
            if (member instanceof Group) {
                Group g = (Group) member;
                if (g.getName().equals(Group_Mesh))
                    ;
                {
                    meshGroup = g;
                    break;
                }
            }
        }
        if (meshGroup == null) {
            throw new Exception(Group_Mesh + " group not found in mesh");
        }
        for (Object member : meshGroup.getMemberList()) {
            if (member instanceof Dataset) {
                Dataset ds = (Dataset) member;
                Object data = ds.getData();
                MeshDataset mds = MeshDataset.valueOf(ds.getName());
                switch(mds) {
                    case dimension:
                        mesh.dimension = ((int[]) data)[0];
                        break;
                    case extent:
                        {
                            double[] darr = (double[]) data;
                            mesh.extent = new Extent(darr[0], darr[1], 0.5);
                            break;
                        }
                    case origin:
                        {
                            double[] darr = (double[]) data;
                            mesh.origin = new Origin(darr[0], darr[1], 0.5);
                            break;
                        }
                    case size:
                        {
                            int[] iarr = (int[]) data;
                            mesh.size = new ISize(iarr[0], iarr[1], 1);
                            break;
                        }
                }
            }
        }
    } finally {
        if (meshH5File != null) {
            meshH5File.close();
        }
    }
    return mesh;
}
Also used : Origin(org.vcell.util.Origin) Group(ncsa.hdf.object.Group) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Extent(org.vcell.util.Extent) Dataset(ncsa.hdf.object.Dataset) ISize(org.vcell.util.ISize) FileFormat(ncsa.hdf.object.FileFormat) IOException(java.io.IOException)

Example 25 with ISize

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

the class FVSolverStandalone method getResampledGeometry.

public Geometry getResampledGeometry() throws SolverException {
    if (resampledGeometry == null) {
        // clone and resample geometry
        try {
            resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simTask.getSimulation().getMathDescription().getGeometry());
            GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
            ISize newSize = simTask.getSimulation().getMeshSpecification().getSamplingSize();
            geoSurfaceDesc.setVolumeSampleSize(newSize);
            geoSurfaceDesc.updateAll();
        } catch (Exception e) {
            e.printStackTrace();
            throw new SolverException(e.getMessage());
        }
    }
    return resampledGeometry;
}
Also used : GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) SolverException(cbit.vcell.solver.SolverException) SolverException(cbit.vcell.solver.SolverException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException)

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