Search in sources :

Example 1 with Vect3D

use of org.vcell.vis.core.Vect3D in project vcell by virtualcell.

the class CartesianMeshFileReader method readCartesianMesh.

private CartesianMesh readCartesianMesh(CommentStringTokenizer tokens, final MembraneMeshMetrics membraneMeshMetrics, final SubdomainInfo subdomainInfo) throws MathException {
    // 
    // clear previous contents
    // 
    MembraneElement[] membraneElements = null;
    String version = null;
    MeshRegionInfo meshRegionInfo = null;
    ISize size = null;
    Vect3D extent = null;
    Vect3D origin = null;
    ContourElement[] contourElements = null;
    // 
    // read new stuff
    // 
    String token = null;
    token = tokens.nextToken();
    if (token.equalsIgnoreCase(VCML.Version)) {
        // 
        // read version number
        // 
        token = tokens.nextToken();
        version = token;
        token = tokens.nextToken();
    }
    if (token.equalsIgnoreCase(VCML.CartesianMesh)) {
        token = tokens.nextToken();
    } else {
        throw new MathFormatException("unexpected token " + token + " expecting " + VCML.CartesianMesh);
    }
    // 
    // only Version 1.1 and later supports membrane connectivity  (as of 8/30/2000)
    // 
    boolean bConnectivity = false;
    if (version.equals(VERSION_1_1) || version.equals(VERSION_1_2)) {
        bConnectivity = true;
    }
    // 
    // only Version 1.2 and later supports Regions
    // 
    boolean bRegions = false;
    if (version.equals(VERSION_1_2)) {
        bRegions = true;
        meshRegionInfo = new MeshRegionInfo();
    }
    if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
        throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
    }
    while (tokens.hasMoreTokens()) {
        token = tokens.nextToken();
        if (token.equalsIgnoreCase(VCML.EndBlock)) {
            break;
        }
        if (token.equalsIgnoreCase(VCML.Size)) {
            int sx, sy, sz;
            try {
                token = tokens.nextToken();
                sx = Integer.valueOf(token).intValue();
                token = tokens.nextToken();
                sy = Integer.valueOf(token).intValue();
                token = tokens.nextToken();
                sz = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("expected:  " + VCML.Size + " # # #");
            }
            size = new ISize(sx, sy, sz);
            continue;
        }
        if (token.equalsIgnoreCase(VCML.Extent)) {
            double ex, ey, ez;
            try {
                token = tokens.nextToken();
                ex = Double.valueOf(token).doubleValue();
                token = tokens.nextToken();
                ey = Double.valueOf(token).doubleValue();
                token = tokens.nextToken();
                ez = Double.valueOf(token).doubleValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("expected:  " + VCML.Extent + " # # #");
            }
            extent = new Vect3D(ex, ey, ez);
            continue;
        }
        if (token.equalsIgnoreCase(VCML.Origin)) {
            double ox, oy, oz;
            try {
                token = tokens.nextToken();
                ox = Double.valueOf(token).doubleValue();
                token = tokens.nextToken();
                oy = Double.valueOf(token).doubleValue();
                token = tokens.nextToken();
                oz = Double.valueOf(token).doubleValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("expected:  " + VCML.Origin + " # # #");
            }
            origin = new Vect3D(ox, oy, oz);
            continue;
        }
        // 
        if (token.equalsIgnoreCase(VCML.VolumeRegionsMapSubvolume)) {
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numVolumeRegions = 0;
            try {
                numVolumeRegions = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the VolumeRegionsMapSubvolume list length");
            }
            int checkCount = 0;
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken();
                if (token.equalsIgnoreCase(VCML.EndBlock)) {
                    break;
                }
                try {
                    int volRegionID = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int subvolumeID = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    double volume = Double.valueOf(token).doubleValue();
                    String subdomainName = null;
                    if (subdomainInfo != null) {
                        subdomainName = subdomainInfo.getCompartmentSubdomainName(subvolumeID);
                    }
                    meshRegionInfo.mapVolumeRegionToSubvolume(volRegionID, subvolumeID, volume, subdomainName);
                } catch (NumberFormatException e) {
                    throw new MathFormatException("expected:  # # #");
                }
                checkCount += 1;
            }
            if (checkCount != numVolumeRegions) {
                throw new MathFormatException("CartesianMesh.read->VolumeRegionsMapSubvolume: read " + checkCount + " VolRegions but was expecting " + numVolumeRegions);
            }
            continue;
        }
        if (token.equalsIgnoreCase(VCML.MembraneRegionsMapVolumeRegion)) {
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numMembraneRegions = 0;
            try {
                numMembraneRegions = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the MembraneRegionsMapVolumeRegion list length");
            }
            int checkCount = 0;
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken();
                if (token.equalsIgnoreCase(VCML.EndBlock)) {
                    break;
                }
                try {
                    int memRegionID = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int volRegionIn = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int volRegionOut = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    double surface = Double.valueOf(token).doubleValue();
                    meshRegionInfo.mapMembraneRegionToVolumeRegion(memRegionID, volRegionIn, volRegionOut, surface);
                } catch (NumberFormatException e) {
                    throw new MathFormatException("expected:  # # #");
                }
                checkCount += 1;
            }
            if (checkCount != numMembraneRegions) {
                throw new MathFormatException("CartesianMesh.read->MembraneRegionsMapVolumeRegion: read " + checkCount + " MembraneRegions but was expecting " + numMembraneRegions);
            }
            continue;
        }
        if (token.equalsIgnoreCase(VCML.VolumeElementsMapVolumeRegion)) {
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numVolumeElements = 0;
            try {
                numVolumeElements = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the VolumeElementsMapVolumeRegion list length");
            }
            token = tokens.nextToken();
            boolean bCompressed = token.equalsIgnoreCase("Compressed");
            if (!bCompressed) {
                if (!token.equalsIgnoreCase("UnCompressed")) {
                    throw new MathFormatException("unexpected token " + token + " expecting Compress or UnCompress");
                }
            }
            byte[] volumeElementMap = new byte[numVolumeElements];
            int checkCount = 0;
            if (bCompressed) {
                // Get HEX encoded bytes of the compressed VolumeElements-RegionID Map
                StringBuffer hexOfCompressed = new StringBuffer();
                while (tokens.hasMoreTokens()) {
                    token = tokens.nextToken();
                    if (token.equalsIgnoreCase(VCML.EndBlock)) {
                        break;
                    }
                    hexOfCompressed.append(token);
                }
                // Un-HEX the compressed data
                byte[] compressedData = Hex.toBytes(hexOfCompressed.toString());
                try {
                    meshRegionInfo.setCompressedVolumeElementMapVolumeRegion(compressedData, numVolumeElements);
                } catch (IOException e) {
                    throw new MathFormatException("CartesianMesh.read->VolumeElementsMapVolumeRegion " + e.toString());
                }
                checkCount = meshRegionInfo.getUncompressedVolumeElementMapVolumeRegionLength();
            } else {
                while (tokens.hasMoreTokens()) {
                    token = tokens.nextToken();
                    if (token.equalsIgnoreCase(VCML.EndBlock)) {
                        break;
                    }
                    try {
                        int volumeRegionID = Integer.valueOf(token).intValue();
                        volumeElementMap[checkCount] = (byte) volumeRegionID;
                    } catch (NumberFormatException e) {
                        throw new MathFormatException("expected:  # # #");
                    }
                    checkCount += 1;
                }
            }
            if (checkCount != numVolumeElements && checkCount != 2 * numVolumeElements) {
                throw new MathFormatException("CartesianMesh.read->VolumeElementsMapVolumeRegion: read " + checkCount + " VolumeElements but was expecting " + numVolumeElements);
            }
            continue;
        }
        // 
        // 
        // 
        HashMap<Integer, Integer> volumeRegionMapSubvolume = getVolumeRegionMapSubvolume(meshRegionInfo);
        if (token.equalsIgnoreCase(VCML.MembraneElements)) {
            // 
            // read '{'
            // 
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numMemElements = 0;
            try {
                numMemElements = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the membraneElement list length");
            }
            // 
            // read list of the following format:
            // 
            // memIndex insideVolIndex outsideVolIndex
            // 
            membraneElements = new MembraneElement[numMemElements];
            int index = 0;
            int[] membraneElementMapMembraneRegion = null;
            if (bRegions) {
                membraneElementMapMembraneRegion = new int[numMemElements];
                meshRegionInfo.mapMembraneElementsToMembraneRegions(membraneElementMapMembraneRegion);
            }
            // 
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken();
                if (token.equalsIgnoreCase(VCML.EndBlock)) {
                    break;
                }
                int memIndex = -1;
                int insideIndex = -1;
                int outsideIndex = -1;
                try {
                    // 
                    // read first three tokens of a membrane element
                    // 
                    // membraneIndex   insideIndex    outsideIndex
                    // 
                    memIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    insideIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    outsideIndex = Integer.valueOf(token).intValue();
                    if (subdomainInfo != null) {
                        int insideRegionIndex = meshRegionInfo.getVolumeElementMapVolumeRegion(insideIndex);
                        int outsideRegionIndex = meshRegionInfo.getVolumeElementMapVolumeRegion(outsideIndex);
                        int insideSubVolumeHandle = volumeRegionMapSubvolume.get(insideRegionIndex);
                        int outsideSubVolumeHandle = volumeRegionMapSubvolume.get(outsideRegionIndex);
                        int realInsideSubVolumeHandle = subdomainInfo.getInside(insideSubVolumeHandle, outsideSubVolumeHandle);
                        if (realInsideSubVolumeHandle != insideSubVolumeHandle) {
                            int temp = insideIndex;
                            insideIndex = outsideIndex;
                            outsideIndex = temp;
                        }
                    }
                } catch (NumberFormatException e) {
                    throw new MathFormatException("expected:  # # #");
                }
                MembraneElement me = null;
                // 
                if (bConnectivity) {
                    try {
                        token = tokens.nextToken();
                        int neighbor1 = Integer.valueOf(token).intValue();
                        token = tokens.nextToken();
                        int neighbor2 = Integer.valueOf(token).intValue();
                        token = tokens.nextToken();
                        int neighbor3 = Integer.valueOf(token).intValue();
                        token = tokens.nextToken();
                        int neighbor4 = Integer.valueOf(token).intValue();
                        // 
                        if (bRegions) {
                            token = tokens.nextToken();
                            int regionID = Integer.valueOf(token).intValue();
                            membraneElementMapMembraneRegion[memIndex] = regionID;
                        }
                        if (membraneMeshMetrics == null) {
                            me = new MembraneElement(memIndex, insideIndex, outsideIndex, neighbor1, neighbor2, neighbor3, neighbor4, MembraneElement.AREA_UNDEFINED, 0, 0, 0, 0, 0, 0);
                        } else {
                            me = new MembraneElement(memIndex, insideIndex, outsideIndex, neighbor1, neighbor2, neighbor3, neighbor4, membraneMeshMetrics.areas[memIndex], membraneMeshMetrics.normals[memIndex][0], membraneMeshMetrics.normals[memIndex][1], membraneMeshMetrics.normals[memIndex][2], membraneMeshMetrics.centroids[memIndex][0], membraneMeshMetrics.centroids[memIndex][1], membraneMeshMetrics.centroids[memIndex][2]);
                        }
                    } catch (NumberFormatException e) {
                        throw new MathFormatException("expected:  # # # # # # #");
                    }
                } else {
                    me = new MembraneElement(memIndex, insideIndex, outsideIndex);
                }
                membraneElements[index] = me;
                index++;
            }
            continue;
        }
        if (token.equalsIgnoreCase(VCML.ContourElements)) {
            // 
            // read '{'
            // 
            token = tokens.nextToken();
            if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
                throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
            }
            token = tokens.nextToken();
            int numContourElements = 0;
            try {
                numContourElements = Integer.valueOf(token).intValue();
            } catch (NumberFormatException e) {
                throw new MathFormatException("unexpected token " + token + " expecting the contourElement list length");
            }
            // 
            // read list of the following format:
            // 
            // contourIndex volumeIndex beginCoord endCoord prevIndex nextIndex
            // 
            contourElements = new ContourElement[numContourElements];
            int index = 0;
            // 
            while (tokens.hasMoreTokens()) {
                token = tokens.nextToken();
                if (token.equalsIgnoreCase(VCML.EndBlock)) {
                    break;
                }
                ContourElement ce = null;
                try {
                    // 
                    // read first two tokens of a contour element
                    // 
                    // contourIndex volumeIndex
                    // 
                    int contourIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int volumeIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    // 
                    // read beginCoord endCoord
                    // 
                    double beginX = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double beginY = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double beginZ = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double endX = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double endY = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    double endZ = Double.valueOf(token).doubleValue();
                    token = tokens.nextToken();
                    Coordinate begin = new Coordinate(beginX, beginY, beginZ);
                    Coordinate end = new Coordinate(endX, endY, endZ);
                    // 
                    // read last two tokens of a contour element
                    // 
                    // prevContourIndex nextContourIndex
                    // 
                    int prevContourIndex = Integer.valueOf(token).intValue();
                    token = tokens.nextToken();
                    int nextContourIndex = Integer.valueOf(token).intValue();
                    ce = new ContourElement(contourIndex, volumeIndex, begin, end, prevContourIndex, nextContourIndex);
                } catch (NumberFormatException e) {
                    throw new MathFormatException("expected:  %d %d   %f %f %f    %f %f %f   %d %d");
                }
                contourElements[index] = ce;
                index++;
            }
            continue;
        }
        throw new MathFormatException("unexpected identifier " + token);
    }
    int dimension = getGeometryDimension(size);
    switch(dimension) {
        case 1:
            {
                if (extent.y != 1 || extent.z != 1) {
                    System.out.println("Extent " + extent.toString() + " for a 1-D mesh truncated to 1 for y and z");
                    extent = new Vect3D(extent.x, 1.0, 1.0);
                }
                break;
            }
        case 2:
            {
                if (extent.z != 1) {
                    System.out.println("Extent " + extent.toString() + " for a 2-D mesh truncated to 1 for z");
                    extent = new Vect3D(extent.x, extent.y, 1.0);
                }
                break;
            }
    }
    CartesianMesh mesh = new CartesianMesh(version, subdomainInfo, membraneElements, contourElements, meshRegionInfo, size, extent, origin, dimension);
    return mesh;
}
Also used : ISize(org.vcell.util.ISize) MathFormatException(cbit.vcell.math.MathFormatException) MeshRegionInfo(org.vcell.vis.vcell.MeshRegionInfo) IOException(java.io.IOException) Vect3D(org.vcell.vis.core.Vect3D) ContourElement(org.vcell.vis.vcell.ContourElement) CartesianMesh(org.vcell.vis.vcell.CartesianMesh) Coordinate(org.vcell.util.Coordinate) MembraneElement(org.vcell.vis.vcell.MembraneElement)

Example 2 with Vect3D

use of org.vcell.vis.core.Vect3D in project vcell by virtualcell.

the class Hdf5Reader method parseAttrString.

public static Vect3D parseAttrString(String attrString, double defaultZ) {
    StringTokenizer st = new StringTokenizer(attrString, "{,} ");
    List<Double> valueList = new ArrayList<Double>();
    while (st.hasMoreTokens()) {
        String token = st.nextToken();
        valueList.add(Double.parseDouble(token));
    }
    if (valueList.size() == 2) {
        return new Vect3D(valueList.get(0), valueList.get(1), defaultZ);
    } else if (valueList.size() == 3) {
        return new Vect3D(valueList.get(0), valueList.get(1), valueList.get(2));
    } else {
        throw new RuntimeException("cannot parse, unexpected array size " + valueList.size());
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) Vect3D(org.vcell.vis.core.Vect3D)

Example 3 with Vect3D

use of org.vcell.vis.core.Vect3D in project vcell by virtualcell.

the class ChomboMesh method getExampleMesh.

public static ChomboMesh getExampleMesh() {
    ChomboMesh chomboMesh = new ChomboMesh();
    int dimension = 2;
    chomboMesh.setDimension(dimension);
    chomboMesh.setOrigin(new Vect3D(0, 0, 0));
    chomboMesh.setExtent(new Vect3D(10, 10, 1));
    ChomboLevel level0 = new ChomboLevel(chomboMesh, 0, 1);
    ChomboLevel level1 = new ChomboLevel(chomboMesh, 1, 2);
    ChomboLevel level2 = new ChomboLevel(chomboMesh, 2, 2);
    int scale = 1;
    ChomboBox box0 = new ChomboBox(level0, 0 * scale, (3 + 1) * scale - 1, 0 * scale, (3 + 1) * scale - 1, 0, 0, dimension);
    ChomboBox box1a = new ChomboBox(level1, 2 * scale, (3 + 1) * scale - 1, 2 * scale, (3 + 1) * scale - 1, 0, 0, dimension);
    ChomboBox box1b = new ChomboBox(level1, 4 * scale, (5 + 1) * scale - 1, 4 * scale, (5 + 1) * scale - 1, 0, 0, dimension);
    ChomboBox box2 = new ChomboBox(level2, 6 * scale, (7 + 1) * scale - 1, 6 * scale, (7 + 1) * scale - 1, 0, 0, dimension);
    chomboMesh.addLevel(level0);
    chomboMesh.addLevel(level1);
    chomboMesh.addLevel(level2);
    level0.addBox(box0);
    level1.addBox(box1a);
    level1.addBox(box1b);
    level2.addBox(box2);
    return chomboMesh;
}
Also used : Vect3D(org.vcell.vis.core.Vect3D)

Example 4 with Vect3D

use of org.vcell.vis.core.Vect3D in project vcell by virtualcell.

the class ChomboFileReader method readMesh.

private static ChomboMeshData readMesh(String meshFileName, String vol0FileName) throws Exception {
    ChomboMesh chomboMesh = new ChomboMesh();
    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 meshFile = fileFormat.createInstance(new File(meshFileName).getAbsolutePath(), FileFormat.READ);
    try {
        meshFile.open();
        DefaultMutableTreeNode meshRootNode = (DefaultMutableTreeNode) meshFile.getRootNode();
        Group meshRootGroup = (Group) meshRootNode.getUserObject();
        Group meshGroup = Hdf5Reader.getChildGroup(meshRootGroup, "mesh");
        chomboMesh.setDimension(Hdf5Reader.getIntAttribute(meshGroup, MESH_ATTR_DIMENSION));
        chomboMesh.setExtent(Hdf5Reader.getVect3DAttribute(meshGroup, MESH_ATTR_EXTENT, 1.0));
        chomboMesh.setOrigin(Hdf5Reader.getVect3DAttribute(meshGroup, MESH_ATTR_ORIGIN, 0.0));
        // it's very wasteful here, but what can I do?
        CartesianMeshChombo cartesianMeshChombo = CartesianMeshChombo.readMeshFile(new File(meshFileName));
        for (FeaturePhaseVol fpv : cartesianMeshChombo.getFeaturePhaseVols()) {
            chomboMesh.addFeaturePhase(fpv.feature, fpv.iphase);
        }
        // Hdf5Reader.DataColumn[] metricsColumns = Hdf5Reader.getDataTable(meshGroup,METRICS_DATASET);
        if (chomboMesh.getDimension() == 2) {
            Hdf5Reader.DataColumn[] segmentColumns = Hdf5Reader.getDataTable(meshGroup, "segments");
            Hdf5Reader.DataColumn[] verticesColumns = Hdf5Reader.getDataTable(meshGroup, "vertices");
            ChomboBoundaries boundaries = chomboMesh.getBoundaries();
            int numVertices = verticesColumns[0].getNumRows();
            int numSegments = segmentColumns[0].getNumRows();
            for (int i = 0; i < numVertices; i++) {
                double x = verticesColumns[0].getValue(i);
                double y = verticesColumns[1].getValue(i);
                double z = 0.0;
                boundaries.addPoint(new ChomboBoundaries.Point(x, y, z));
            }
            for (int i = 0; i < numSegments; i++) {
                int v1 = (int) segmentColumns[1].getValue(i);
                int v2 = (int) segmentColumns[2].getValue(i);
                // THIS COULD BE WRONG - is the chomboIndex one-to-one with the line segments? ... if not should be in the HDF5 file.
                int chomboIndex = i;
                boundaries.addSegment(new ChomboBoundaries.Segment(chomboIndex, v1, v2));
            }
        } else if (chomboMesh.getDimension() == 3) {
            Hdf5Reader.DataColumn[] surfaceTriangleColumns = Hdf5Reader.getDataTable(meshGroup, "surface triangles");
            ChomboBoundaries boundaries = chomboMesh.getBoundaries();
            int numTriangles = surfaceTriangleColumns[0].getNumRows();
            for (int row = 0; row < numTriangles; row++) {
                int index = (int) surfaceTriangleColumns[0].getValue(row);
                int faceNumber = (int) surfaceTriangleColumns[1].getValue(row);
                // not used currently
                int neighborIndex = (int) surfaceTriangleColumns[2].getValue(row);
                double x0 = surfaceTriangleColumns[3].getValue(row);
                double y0 = surfaceTriangleColumns[4].getValue(row);
                double z0 = surfaceTriangleColumns[5].getValue(row);
                int p0_index = boundaries.getOrCreatePoint(x0, y0, z0);
                double x1 = surfaceTriangleColumns[6].getValue(row);
                double y1 = surfaceTriangleColumns[7].getValue(row);
                double z1 = surfaceTriangleColumns[8].getValue(row);
                int p1_index = boundaries.getOrCreatePoint(x1, y1, z1);
                double x2 = surfaceTriangleColumns[9].getValue(row);
                double y2 = surfaceTriangleColumns[10].getValue(row);
                double z2 = surfaceTriangleColumns[11].getValue(row);
                int p2_index = boundaries.getOrCreatePoint(x2, y2, z2);
                Face face = Face.fromInteger(faceNumber);
                SurfaceTriangle surfaceTriangle = new SurfaceTriangle(index, face, p0_index, p1_index, p2_index);
                boundaries.addSurfaceTriangle(surfaceTriangle);
            }
            Hdf5Reader.DataColumn[] metricsColumns = Hdf5Reader.getDataTable(meshGroup, "membrane elements");
            MeshMetrics meshMetrics = boundaries.getMeshMetrics();
            int numMeshMetrics = metricsColumns[0].getNumRows();
            for (int row = 0; row < numMeshMetrics; row++) {
                int index = (int) metricsColumns[0].getValue(row);
                int level = (int) metricsColumns[1].getValue(row);
                // not used currently
                int i = (int) metricsColumns[2].getValue(row);
                // not used currently
                int j = (int) metricsColumns[3].getValue(row);
                // not used currently
                int k = (int) metricsColumns[4].getValue(row);
                double x = metricsColumns[5].getValue(row);
                double y = metricsColumns[6].getValue(row);
                double z = metricsColumns[7].getValue(row);
                Vect3D center = new Vect3D(x, y, z);
                double normalX = metricsColumns[8].getValue(row);
                double normalY = metricsColumns[9].getValue(row);
                double normalZ = metricsColumns[10].getValue(row);
                Vect3D normal = new Vect3D(normalX, normalY, normalZ);
                double volumeFraction = metricsColumns[11].getValue(row);
                double areaFraction = metricsColumns[12].getValue(row);
                int membraneId = (int) metricsColumns[13].getValue(row);
                int cornerPhaseMask = (int) metricsColumns[14].getValue(row);
                BorderCellInfo borderCellInfo = new BorderCellInfo(index, level, i, j, k, center, normal, volumeFraction, areaFraction, membraneId, cornerPhaseMask);
                meshMetrics.addBorderCellInfo(borderCellInfo);
            }
        } else {
            throw new Exception("failed to read chombo file, unexpected mesh dimension " + chomboMesh.getDimension());
        }
    } finally {
        meshFile.close();
    }
    FileFormat vol0File = fileFormat.createInstance(new File(vol0FileName).getAbsolutePath(), FileFormat.READ);
    try {
        vol0File.open();
        DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) vol0File.getRootNode();
        Group rootGroup = (Group) rootNode.getUserObject();
        Group level0Group = Hdf5Reader.getChildGroup(rootGroup, "level_0");
        double time = Hdf5Reader.getDoubleAttribute(level0Group, "time");
        ChomboMeshData chomboMeshData = new ChomboMeshData(chomboMesh, time);
        int numComponents = Hdf5Reader.getIntAttribute(rootGroup, "num_components");
        int numLevels = Hdf5Reader.getIntAttribute(rootGroup, "num_levels");
        int fractionComponentIndex = -1;
        for (int i = 0; i < numComponents; i++) {
            String compName = Hdf5Reader.getStringAttribute(rootGroup, "component_" + i);
            chomboMeshData.addComponentName(compName);
            if (compName.equals("fraction-0")) {
                fractionComponentIndex = i;
                chomboMeshData.setFraction0ComponentIndex(fractionComponentIndex);
            }
        }
        for (int i = 0; i < numLevels; i++) {
            Group levelGroup = Hdf5Reader.getChildGroup(rootGroup, "level_" + i);
            int refinement = 2;
            if (i == 0) {
                refinement = 1;
            }
            ChomboLevel chomboLevel = new ChomboLevel(chomboMesh, i, refinement);
            Hdf5Reader.DataColumn[] boxColumns = Hdf5Reader.getDataTable(levelGroup, "boxes");
            int[] lo_i, lo_j, lo_k, hi_i, hi_j, hi_k;
            if (chomboMesh.getDimension() == 2) {
                lo_i = ((Hdf5Reader.IntColumn) boxColumns[0]).data;
                lo_j = ((Hdf5Reader.IntColumn) boxColumns[1]).data;
                hi_i = ((Hdf5Reader.IntColumn) boxColumns[2]).data;
                hi_j = ((Hdf5Reader.IntColumn) boxColumns[3]).data;
                lo_k = new int[boxColumns[0].getNumRows()];
                hi_k = new int[boxColumns[0].getNumRows()];
            } else {
                lo_i = ((Hdf5Reader.IntColumn) boxColumns[0]).data;
                lo_j = ((Hdf5Reader.IntColumn) boxColumns[1]).data;
                lo_k = ((Hdf5Reader.IntColumn) boxColumns[2]).data;
                hi_i = ((Hdf5Reader.IntColumn) boxColumns[3]).data;
                hi_j = ((Hdf5Reader.IntColumn) boxColumns[4]).data;
                hi_k = ((Hdf5Reader.IntColumn) boxColumns[5]).data;
            }
            for (int b = 0; b < boxColumns[0].getNumRows(); b++) {
                ChomboBox chomboBox = new ChomboBox(chomboLevel, lo_i[b], hi_i[b], lo_j[b], hi_j[b], lo_k[b], hi_k[b], chomboMesh.getDimension());
                chomboLevel.addBox(chomboBox);
            }
            chomboMesh.addLevel(chomboLevel);
            // 
            // read the variables
            // 
            Hdf5Reader.DataColumn[] data = Hdf5Reader.getDataTable(levelGroup, "data:datatype=0");
            Hdf5Reader.DataColumn[] offsets = Hdf5Reader.getDataTable(levelGroup, "data:offsets=0");
            ChomboLevelData chomboLevelData = new ChomboLevelData(i, fractionComponentIndex, ((Hdf5Reader.DoubleColumn) data[0]).data, ((Hdf5Reader.LongColumn) offsets[0]).data);
            chomboMeshData.addLevelData(chomboLevelData);
        }
        readMembraneVarData(chomboMeshData, rootGroup);
        return chomboMeshData;
    } finally {
        vol0File.close();
    }
}
Also used : Group(ncsa.hdf.object.Group) FeaturePhaseVol(cbit.vcell.solvers.CartesianMeshChombo.FeaturePhaseVol) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ChomboBoundaries(org.vcell.vis.chombo.ChomboBoundaries) FileFormat(ncsa.hdf.object.FileFormat) CartesianMeshChombo(cbit.vcell.solvers.CartesianMeshChombo) Vect3D(org.vcell.vis.core.Vect3D) ChomboMesh(org.vcell.vis.chombo.ChomboMesh) MeshMetrics(org.vcell.vis.chombo.ChomboBoundaries.MeshMetrics) BorderCellInfo(org.vcell.vis.chombo.ChomboBoundaries.BorderCellInfo) ChomboMeshData(org.vcell.vis.chombo.ChomboMeshData) Face(org.vcell.vis.core.Face) ChomboLevel(org.vcell.vis.chombo.ChomboLevel) SurfaceTriangle(org.vcell.vis.chombo.ChomboBoundaries.SurfaceTriangle) ChomboLevelData(org.vcell.vis.chombo.ChomboLevelData) ChomboBox(org.vcell.vis.chombo.ChomboBox) File(java.io.File)

Example 5 with Vect3D

use of org.vcell.vis.core.Vect3D in project vcell by virtualcell.

the class IndexTest method simple.

@Test
public void simple() {
    PointIndexTreeAndList pitl = new PointIndexTreeAndList();
    Map<Vect3D, Integer> check = new HashMap<Vect3D, Integer>();
    for (Vect3D v : raw) {
        Vect3Didx iv = pitl.index(v.x, v.y, v.z);
        check.put(v, iv.index);
    }
    PointIndex pi = pitl;
    for (Vect3D v : raw) {
        int ci = check.get(v);
        Vect3Didx iv = pitl.index(v.x, v.y, v.z);
        assertTrue(ci == iv.index);
        Vect3Didx rb = pi.lookup(ci);
        assertTrue(iv == rb);
    }
}
Also used : HashMap(java.util.HashMap) Vect3D(org.vcell.vis.core.Vect3D) Test(org.junit.Test)

Aggregations

Vect3D (org.vcell.vis.core.Vect3D)5 MathFormatException (cbit.vcell.math.MathFormatException)1 CartesianMeshChombo (cbit.vcell.solvers.CartesianMeshChombo)1 FeaturePhaseVol (cbit.vcell.solvers.CartesianMeshChombo.FeaturePhaseVol)1 File (java.io.File)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 StringTokenizer (java.util.StringTokenizer)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 FileFormat (ncsa.hdf.object.FileFormat)1 Group (ncsa.hdf.object.Group)1 Test (org.junit.Test)1 Coordinate (org.vcell.util.Coordinate)1 ISize (org.vcell.util.ISize)1 ChomboBoundaries (org.vcell.vis.chombo.ChomboBoundaries)1 BorderCellInfo (org.vcell.vis.chombo.ChomboBoundaries.BorderCellInfo)1 MeshMetrics (org.vcell.vis.chombo.ChomboBoundaries.MeshMetrics)1 SurfaceTriangle (org.vcell.vis.chombo.ChomboBoundaries.SurfaceTriangle)1 ChomboBox (org.vcell.vis.chombo.ChomboBox)1