Search in sources :

Example 1 with VisVoxel

use of org.vcell.vis.vismesh.thrift.VisVoxel in project vcell by virtualcell.

the class ChomboMeshMapping method cropVoxels.

private void cropVoxels(VisMesh visMesh, ChomboBoundaries chomboBoundaries, ChomboCombinedVolumeMembraneDomain chomboCombinedVolumeMembraneDomain) {
    if (visMesh.getDimension() != 3) {
        throw new RuntimeException("expecting 3D mesh");
    }
    List<VisVoxel> origVoxelList = visMesh.getVisVoxels();
    ArrayList<VisVoxel> newVoxelList = new ArrayList<VisVoxel>();
    List<VisPoint> points = visMesh.getPoints();
    List<VisSurfaceTriangle> triangles = visMesh.getSurfaceTriangles();
    for (VisVoxel visVoxel : origVoxelList) {
        List<Integer> polyhedronPointIndices = visVoxel.getPointIndices();
        if (visVoxel.getChomboVolumeIndex().getFraction() < 1.0) {
            int p0 = polyhedronPointIndices.get(0);
            int p1 = polyhedronPointIndices.get(1);
            int p2 = polyhedronPointIndices.get(2);
            int p3 = polyhedronPointIndices.get(3);
            int p4 = polyhedronPointIndices.get(4);
            int p5 = polyhedronPointIndices.get(5);
            int p6 = polyhedronPointIndices.get(6);
            int p7 = polyhedronPointIndices.get(7);
            VisPoint vp0 = points.get(p0);
            VisPoint vp1 = points.get(p1);
            VisPoint vp2 = points.get(p2);
            VisPoint vp3 = points.get(p3);
            VisPoint vp4 = points.get(p4);
            VisPoint vp5 = points.get(p5);
            VisPoint vp6 = points.get(p6);
            VisPoint vp7 = points.get(p7);
            ArrayList<VisSurfaceTriangle> intersectingTriangles = new ArrayList<VisSurfaceTriangle>();
            for (VisSurfaceTriangle triangle : triangles) {
                boolean bInRange = true;
                for (int pi = 0; pi < 3; pi++) {
                    VisPoint tp = points.get(triangle.getPointIndices().get(pi));
                    if (!inLoHi(tp, vp0, vp7)) {
                        bInRange = false;
                    }
                }
                if (bInRange) {
                    intersectingTriangles.add(triangle);
                }
            }
            if (intersectingTriangles.size() == 0) {
                LG.info("fraction<1.0 but found no triangles");
                newVoxelList.add(visVoxel);
                continue;
            }
            // p6-------------------p7
            // /|                   /|
            // / |                  / |
            // p4-------------------p5  |
            // |  |                 |  |      face number         coordinates
            // |  |                 |  |
            // |  |                 |  |         5   3            z   y
            // |  p2................|..p3        |  /             |  /
            // | /                  | /          | /              | /
            // |/                   |/           |/               |/
            // p0-------------------p1       0 ---'---- 1          '----- x
            // /|
            // / |
            // 2  4
            BorderCellInfo borderCellInfo = chomboBoundaries.getMeshMetrics().getBorderCellInfo(intersectingTriangles.get(0).getChomboSurfaceIndex().getIndex());
            // 
            // have o flip the inside/outside if domain ordinal is > 0 ... note that "^" is the exclusive or ... to flip a bit
            // 
            VoxelPoint[] v = new VoxelPoint[8];
            for (int i = 0; i < 8; ++i) {
                int p = polyhedronPointIndices.get(i);
                VisPoint vp = points.get(p);
                v[i] = new VoxelPoint(p, vp, chomboCombinedVolumeMembraneDomain.shouldIncludeVertex(borderCellInfo.isVertexInPhase1(i)));
            }
            // choosing an arbitrary face (A,B,C,D) see below
            // 
            // pA   pB
            // 
            // pD   pC
            // 
            // face 0 (X-)
            VoxelFace face0 = new VoxelFace(Face.Xm, v[0], v[4], v[6], v[2]);
            // face 1 (X+)
            VoxelFace face1 = new VoxelFace(Face.Xp, v[1], v[3], v[7], v[5]);
            // face 2 (Y-)
            VoxelFace face2 = new VoxelFace(Face.Ym, v[0], v[1], v[5], v[4]);
            // face 3 (Y+)
            VoxelFace face3 = new VoxelFace(Face.Yp, v[2], v[3], v[7], v[6]);
            // face 4 (Z-)
            VoxelFace face4 = new VoxelFace(Face.Zm, v[0], v[2], v[3], v[1]);
            // face 5 (Z+)
            VoxelFace face5 = new VoxelFace(Face.Zp, v[4], v[5], v[7], v[6]);
            ClippedVoxel clippedVoxel = new ClippedVoxel(face0, face1, face2, face3, face4, face5);
            clippedVoxel.surfaceTriangles.addAll(intersectingTriangles);
            VisIrregularPolyhedron clippedPolyhedron = createClippedPolyhedron(clippedVoxel, visMesh, visVoxel);
            // VisIrregularPolyhedron clippedPolyhedron = new VisIrregularPolyhedron(visVoxel.getLevel(),visVoxel.getBoxNumber(),visVoxel.getBoxIndex(),visVoxel.getFraction());
            // clippedPolyhedron.addFace(new PolyhedronFace(new int[] { p0, p1, p4} ));
            // clippedPolyhedron.addFace(new PolyhedronFace(new int[] { p0, p2, p1} ));
            // clippedPolyhedron.addFace(new PolyhedronFace(new int[] { p0, p4, p2} ));
            // clippedPolyhedron.addFace(new PolyhedronFace(new int[] { p2, p4, p1} ));
            visMesh.addToIrregularPolyhedra(clippedPolyhedron);
        // VisTetrahedron[] delaunayTets = VtkGridUtils.createTetrahedra(clippedPolyhedron, visMesh);
        // for (VisTetrahedron tet : delaunayTets){
        // newPolyhedraList.add(tet);
        // }
        } else {
            // fraction >= 1.0
            newVoxelList.add(visVoxel);
        }
    }
    // for loop (orig polyhedra)
    visMesh.getVisVoxels().clear();
    visMesh.getVisVoxels().addAll(newVoxelList);
}
Also used : VisVoxel(org.vcell.vis.vismesh.thrift.VisVoxel) ArrayList(java.util.ArrayList) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) VisSurfaceTriangle(org.vcell.vis.vismesh.thrift.VisSurfaceTriangle) BorderCellInfo(org.vcell.vis.chombo.ChomboBoundaries.BorderCellInfo) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) VisIrregularPolyhedron(org.vcell.vis.vismesh.thrift.VisIrregularPolyhedron)

Example 2 with VisVoxel

use of org.vcell.vis.vismesh.thrift.VisVoxel in project vcell by virtualcell.

the class CartesianMeshMapping method fromMesh3DVolume.

private VisMesh fromMesh3DVolume(CartesianMesh cartesianMesh, String domainName) {
    ISize size = cartesianMesh.getSize();
    int numX = size.getX();
    int numY = size.getY();
    int numZ = size.getZ();
    int dimension = 3;
    Vect3D origin = new Vect3D(cartesianMesh.getOrigin().x, cartesianMesh.getOrigin().y, cartesianMesh.getOrigin().z);
    Vect3D extent = new Vect3D(cartesianMesh.getExtent().x, cartesianMesh.getExtent().y, cartesianMesh.getExtent().z);
    // invoke VisMesh() constructor
    VisMesh visMesh = new VisMesh(dimension, origin, extent);
    int currPointIndex = 0;
    HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
    List<Integer> volumeRegionIDs = cartesianMesh.getVolumeRegionIDs(domainName);
    int volumeIndex = 0;
    for (int k = 0; k < numZ; k++) {
        for (int j = 0; j < numY; j++) {
            for (int i = 0; i < numX; i++) {
                int regionIndex = cartesianMesh.getVolumeRegionIndex(volumeIndex);
                if (volumeRegionIDs.contains(regionIndex)) {
                    Box3D element = cartesianMesh.getVolumeElementBox(i, j, k);
                    double minX = element.x_lo;
                    double maxX = element.x_hi;
                    double minY = element.y_lo;
                    double maxY = element.y_hi;
                    double minZ = element.z_lo;
                    double maxZ = element.z_hi;
                    // 
                    // points for a VisPolyhedra ... initially a hex ... then may be clipped
                    // 
                    // p6-------------------p7
                    // /|                   /|
                    // / |                  / |
                    // p4-------------------p5  |
                    // |  |                 |  |
                    // |  |                 |  |
                    // |  |                 |  |         z   y
                    // |  p2................|..p3        |  /
                    // | /                  | /          | /
                    // |/                   |/           |/
                    // p0-------------------p1            O----- x
                    // 
                    // p0 = (X-,Y-,Z-)
                    // p1 = (X+,Y-,Z-)
                    // p2 = (X-,Y+,Z-)
                    // p3 = (X+,Y+,Z-)
                    // p4 = (X-,Y-,Z+)
                    // p5 = (X+,Y-,Z+)
                    // p6 = (X-,Y+,Z+)
                    // p7 = (X+,Y+,Z+)
                    // 
                    VisPoint[] visPoints = { // p0
                    new VisPoint(minX, minY, minZ), // p1
                    new VisPoint(maxX, minY, minZ), // p2
                    new VisPoint(minX, maxY, minZ), // p3
                    new VisPoint(maxX, maxY, minZ), // p4
                    new VisPoint(minX, minY, maxZ), // p5
                    new VisPoint(maxX, minY, maxZ), // p6
                    new VisPoint(minX, maxY, maxZ), // p7
                    new VisPoint(maxX, maxY, maxZ) };
                    Integer[] indices = new Integer[8];
                    for (int v = 0; v < 8; v++) {
                        VisPoint visPoint = visPoints[v];
                        String key = toStringKey(visPoint);
                        Integer p = pointDict.get(key);
                        if (p == null) {
                            pointDict.put(key, currPointIndex);
                            p = currPointIndex;
                            visMesh.addToPoints(visPoint);
                            currPointIndex++;
                        }
                        indices[v] = p;
                    }
                    VisVoxel voxel = new VisVoxel(Arrays.asList(indices));
                    voxel.setFiniteVolumeIndex(new FiniteVolumeIndex(volumeIndex, cartesianMesh.getVolumeRegionIndex(volumeIndex)));
                    // print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
                    visMesh.addToVisVoxels(voxel);
                }
                // end if
                volumeIndex++;
            }
        // end for i
        }
    // end for j
    }
    // end for k
    return visMesh;
}
Also used : FiniteVolumeIndex(org.vcell.vis.vismesh.thrift.FiniteVolumeIndex) HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) VisVoxel(org.vcell.vis.vismesh.thrift.VisVoxel) Box3D(org.vcell.vis.core.Box3D) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) Vect3D(org.vcell.vis.vismesh.thrift.Vect3D) VisMesh(org.vcell.vis.vismesh.thrift.VisMesh) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint)

Example 3 with VisVoxel

use of org.vcell.vis.vismesh.thrift.VisVoxel in project vcell by virtualcell.

the class ChomboMeshMapping method fromMeshData3D.

private VisMesh fromMeshData3D(ChomboMeshData chomboMeshData, ChomboCombinedVolumeMembraneDomain chomboCombinedVolumeMembraneDomain) {
    int dimension = chomboMeshData.getMesh().getDimension();
    if (dimension != 3) {
        throw new RuntimeException("expecting a 3D mesh");
    }
    ChomboMesh chomboMesh = chomboMeshData.getMesh();
    ChomboLevel finestLevel = chomboMesh.getLevel(chomboMesh.getNumLevels() - 1);
    int finestAbsRefinement = finestLevel.getAbsoluteRefinement();
    ISize size = finestLevel.getSize();
    int numX = size.getX();
    int numY = size.getY();
    int numZ = size.getZ();
    Vect3D origin = new Vect3D(chomboMesh.getOrigin().x, chomboMesh.getOrigin().y, chomboMesh.getOrigin().z);
    Vect3D extent = new Vect3D(chomboMesh.getExtent().x, chomboMesh.getExtent().y, chomboMesh.getExtent().z);
    // invoke VisMesh() constructor
    VisMesh visMesh = new VisMesh(chomboMesh.getDimension(), origin, extent);
    int currPointIndex = 0;
    HashMap<String, Integer> pointDict = new HashMap<String, Integer>();
    double originX = chomboMesh.getOrigin().x;
    double originY = chomboMesh.getOrigin().y;
    double originZ = chomboMesh.getOrigin().z;
    double extentX = chomboMesh.getExtent().x;
    double extentY = chomboMesh.getExtent().y;
    double extentZ = chomboMesh.getExtent().z;
    ChomboBoundaries chomboBoundaries = chomboMesh.getBoundaries();
    for (ChomboBoundaries.Point chomboPoint : chomboBoundaries.getPoints()) {
        double px = chomboPoint.x;
        double py = chomboPoint.y;
        double pz = chomboPoint.z;
        px = (px - originX) * (numX) / extentX * 2 - 1;
        py = (py - originY) * (numY) / extentY * 2 - 1;
        pz = (pz - originZ) * (numZ) / extentZ * 2 - 1;
        VisPoint newVisPoint = new VisPoint(px, py, pz);
        String coordKey = toStringKey(newVisPoint);
        pointDict.put(coordKey, currPointIndex);
        visMesh.addToPoints(newVisPoint);
        visMesh.addToSurfacePoints(newVisPoint);
        currPointIndex += 1;
    }
    for (ChomboBoundaries.SurfaceTriangle surfaceTriangle : chomboBoundaries.getSurfaceTriangles()) {
        List<Integer> vertices = Arrays.asList(new Integer[] { surfaceTriangle.getP1(), surfaceTriangle.getP2(), surfaceTriangle.getP3() });
        org.vcell.vis.vismesh.thrift.Face face = org.vcell.vis.vismesh.thrift.Face.valueOf(surfaceTriangle.getFace().name());
        VisSurfaceTriangle newVisSurfaceTriangle = new VisSurfaceTriangle(vertices, face);
        newVisSurfaceTriangle.setChomboSurfaceIndex(new ChomboSurfaceIndex(surfaceTriangle.getChomboIndex()));
        visMesh.addToSurfaceTriangles(newVisSurfaceTriangle);
    }
    for (int levelIndex = 0; levelIndex < chomboMesh.getNumLevels(); levelIndex++) {
        ChomboLevelData chomboLevelData = chomboMeshData.getLevelData(levelIndex);
        ChomboLevel currLevel = chomboMesh.getLevel(levelIndex);
        int currAbsRefinement = currLevel.getAbsoluteRefinement();
        Covering covering = currLevel.getCovering();
        int[] levelMap = covering.getLevelMap();
        int[] boxNumberMap = covering.getBoxNumberMap();
        int[] boxIndexMap = covering.getBoxIndexMap();
        int levelNumX = currLevel.getSize().getX();
        int levelNumY = currLevel.getSize().getY();
        int levelNumZ = currLevel.getSize().getZ();
        for (int x = 0; x < levelNumX; x++) {
            for (int y = 0; y < levelNumY; y++) {
                for (int z = 0; z < levelNumZ; z++) {
                    int mapIndex = x + y * levelNumX + z * levelNumX * levelNumY;
                    if (levelMap[mapIndex] == levelIndex) {
                        // 
                        // if fraction (volume fraction of element in box) is 0 ... then skip this element
                        // 
                        int boxNumber = boxNumberMap[mapIndex];
                        int boxIndex = boxIndexMap[mapIndex];
                        double fraction = chomboLevelData.getCellFraction(currLevel, boxNumber, boxIndex);
                        if (fraction > 0) {
                            // 
                            // add cell
                            // 
                            ChomboBox chomboBox = new ChomboBox(currLevel, x, x, y, y, z, z, dimension).getProjectedBox(currAbsRefinement, finestAbsRefinement);
                            double minX = 2 * chomboBox.getMinX() - 1;
                            double maxX = 2 * chomboBox.getMaxX() + 1;
                            double minY = 2 * chomboBox.getMinY() - 1;
                            double maxY = 2 * chomboBox.getMaxY() + 1;
                            double minZ = 2 * chomboBox.getMinZ() - 1;
                            double maxZ = 2 * chomboBox.getMaxZ() + 1;
                            // 
                            // points for a VisPolyhedra ... initially a hex ... then may be clipped
                            // 
                            // p6-------------------p7
                            // /|                   /|
                            // / |                  / |
                            // p4-------------------p5  |
                            // |  |                 |  |
                            // |  |                 |  |
                            // |  |                 |  |         z   y
                            // |  p2................|..p3        |  /
                            // | /                  | /          | /
                            // |/                   |/           |/
                            // p0-------------------p1            O----- x
                            // 
                            // p0 = (X-,Y-,Z-)
                            // p1 = (X+,Y-,Z-)
                            // p2 = (X-,Y+,Z-)
                            // p3 = (X+,Y+,Z-)
                            // p4 = (X-,Y-,Z+)
                            // p5 = (X+,Y-,Z+)
                            // p6 = (X-,Y+,Z+)
                            // p7 = (X+,Y+,Z+)
                            // 
                            VisPoint[] visPoints = { // p0
                            new VisPoint(minX, minY, minZ), // p1
                            new VisPoint(maxX, minY, minZ), // p2
                            new VisPoint(minX, maxY, minZ), // p3
                            new VisPoint(maxX, maxY, minZ), // p4
                            new VisPoint(minX, minY, maxZ), // p5
                            new VisPoint(maxX, minY, maxZ), // p6
                            new VisPoint(minX, maxY, maxZ), // p7
                            new VisPoint(maxX, maxY, maxZ) };
                            Integer[] indices = new Integer[8];
                            for (int v = 0; v < 8; v++) {
                                VisPoint visPoint = visPoints[v];
                                String key = toStringKey(visPoint);
                                Integer i = pointDict.get(key);
                                if (i == null) {
                                    pointDict.put(key, currPointIndex);
                                    i = currPointIndex;
                                    visMesh.addToPoints(visPoint);
                                    currPointIndex++;
                                }
                                indices[v] = i;
                            }
                            VisVoxel voxel = new VisVoxel(Arrays.asList(indices));
                            voxel.setChomboVolumeIndex(new ChomboVolumeIndex(levelIndex, boxNumber, boxIndex, fraction));
                            // print('adding a cell at level '+str(currLevel.getLevel())+" from "+str(p1Coord)+" to "+str(p3Coord))
                            visMesh.addToVisVoxels(voxel);
                        }
                    }
                }
            }
        }
    }
    cropVoxels(visMesh, chomboBoundaries, chomboCombinedVolumeMembraneDomain);
    return visMesh;
}
Also used : HashMap(java.util.HashMap) ISize(org.vcell.util.ISize) Covering(org.vcell.vis.chombo.ChomboLevel.Covering) ChomboBoundaries(org.vcell.vis.chombo.ChomboBoundaries) ChomboVolumeIndex(org.vcell.vis.vismesh.thrift.ChomboVolumeIndex) Vect3D(org.vcell.vis.vismesh.thrift.Vect3D) ChomboMesh(org.vcell.vis.chombo.ChomboMesh) ChomboLevel(org.vcell.vis.chombo.ChomboLevel) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) ChomboSurfaceIndex(org.vcell.vis.vismesh.thrift.ChomboSurfaceIndex) VisVoxel(org.vcell.vis.vismesh.thrift.VisVoxel) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) ChomboLevelData(org.vcell.vis.chombo.ChomboLevelData) VisMesh(org.vcell.vis.vismesh.thrift.VisMesh) VisSurfaceTriangle(org.vcell.vis.vismesh.thrift.VisSurfaceTriangle) ChomboBox(org.vcell.vis.chombo.ChomboBox) Face(org.vcell.vis.vismesh.thrift.Face)

Aggregations

VisPoint (org.vcell.vis.vismesh.thrift.VisPoint)3 VisVoxel (org.vcell.vis.vismesh.thrift.VisVoxel)3 HashMap (java.util.HashMap)2 ISize (org.vcell.util.ISize)2 Vect3D (org.vcell.vis.vismesh.thrift.Vect3D)2 VisMesh (org.vcell.vis.vismesh.thrift.VisMesh)2 VisSurfaceTriangle (org.vcell.vis.vismesh.thrift.VisSurfaceTriangle)2 ArrayList (java.util.ArrayList)1 ChomboBoundaries (org.vcell.vis.chombo.ChomboBoundaries)1 BorderCellInfo (org.vcell.vis.chombo.ChomboBoundaries.BorderCellInfo)1 ChomboBox (org.vcell.vis.chombo.ChomboBox)1 ChomboLevel (org.vcell.vis.chombo.ChomboLevel)1 Covering (org.vcell.vis.chombo.ChomboLevel.Covering)1 ChomboLevelData (org.vcell.vis.chombo.ChomboLevelData)1 ChomboMesh (org.vcell.vis.chombo.ChomboMesh)1 Box3D (org.vcell.vis.core.Box3D)1 ChomboSurfaceIndex (org.vcell.vis.vismesh.thrift.ChomboSurfaceIndex)1 ChomboVolumeIndex (org.vcell.vis.vismesh.thrift.ChomboVolumeIndex)1 Face (org.vcell.vis.vismesh.thrift.Face)1 FiniteVolumeIndex (org.vcell.vis.vismesh.thrift.FiniteVolumeIndex)1