Search in sources :

Example 1 with VisIrregularPolyhedron

use of org.vcell.vis.vismesh.thrift.VisIrregularPolyhedron 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 VisIrregularPolyhedron

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

the class ChomboMeshMapping method createClippedPolyhedron.

private VisIrregularPolyhedron createClippedPolyhedron(ClippedVoxel clippedVoxel, VisMesh visMesh, VisVoxel oldVoxel) {
    VisIrregularPolyhedron visIrregularPolyhedron = new VisIrregularPolyhedron();
    visIrregularPolyhedron.setChomboVolumeIndex(new ChomboVolumeIndex(oldVoxel.getChomboVolumeIndex()));
    // 
    for (VisSurfaceTriangle triangle : clippedVoxel.surfaceTriangles) {
        List<Integer> triangleIndices = triangle.getPointIndices();
        PolyhedronFace polyhedronFace = new PolyhedronFace(triangleIndices);
        visIrregularPolyhedron.addToPolyhedronFaces(polyhedronFace);
    }
    VoxelFace[] voxelFaces = new VoxelFace[] { clippedVoxel.f0, clippedVoxel.f1, clippedVoxel.f2, clippedVoxel.f3, clippedVoxel.f4, clippedVoxel.f5 };
    for (VoxelFace voxelFace : voxelFaces) {
        VisSurfaceTriangle triangleForThisFace = clippedVoxel.getSurfaceTriangle(voxelFace.face);
        List<Integer> triangleIndices = null;
        VisPoint[] trianglePoints = null;
        if (triangleForThisFace != null) {
            triangleIndices = triangleForThisFace.getPointIndices();
            trianglePoints = new VisPoint[] { visMesh.getPoints().get(triangleIndices.get(0)), visMesh.getPoints().get(triangleIndices.get(1)), visMesh.getPoints().get(triangleIndices.get(2)) };
        }
        ArrayList<Integer> indices = new ArrayList<Integer>();
        if (voxelFace.p0.bIncluded) {
            indices.add(voxelFace.p0.p);
        }
        if (triangleIndices != null) {
            for (int i = 0; i < 3; i++) {
                if (isColinear(voxelFace.p0.vp, trianglePoints[i], voxelFace.p1.vp)) {
                    indices.add(triangleIndices.get(i));
                }
            }
        }
        if (voxelFace.p1.bIncluded) {
            indices.add(voxelFace.p1.p);
        }
        if (triangleIndices != null) {
            for (int i = 0; i < 3; i++) {
                if (isColinear(voxelFace.p1.vp, trianglePoints[i], voxelFace.p2.vp)) {
                    indices.add(triangleIndices.get(i));
                }
            }
        }
        if (voxelFace.p2.bIncluded) {
            indices.add(voxelFace.p2.p);
        }
        if (triangleIndices != null) {
            for (int i = 0; i < 3; i++) {
                if (isColinear(voxelFace.p2.vp, trianglePoints[i], voxelFace.p3.vp)) {
                    indices.add(triangleIndices.get(i));
                }
            }
        }
        if (voxelFace.p3.bIncluded) {
            indices.add(voxelFace.p3.p);
        }
        if (triangleIndices != null) {
            for (int i = 0; i < 3; i++) {
                if (isColinear(voxelFace.p3.vp, trianglePoints[i], voxelFace.p0.vp)) {
                    indices.add(triangleIndices.get(i));
                }
            }
        }
        // indices.add(voxelFace.p3.p);
        if (indices.size() >= 3) {
            ArrayList<Integer> indexArray = new ArrayList<Integer>(indices);
            PolyhedronFace polyFace = new PolyhedronFace(indexArray);
            visIrregularPolyhedron.addToPolyhedronFaces(polyFace);
        }
    }
    return visIrregularPolyhedron;
}
Also used : PolyhedronFace(org.vcell.vis.vismesh.thrift.PolyhedronFace) ArrayList(java.util.ArrayList) ChomboVolumeIndex(org.vcell.vis.vismesh.thrift.ChomboVolumeIndex) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) VisSurfaceTriangle(org.vcell.vis.vismesh.thrift.VisSurfaceTriangle) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) VisIrregularPolyhedron(org.vcell.vis.vismesh.thrift.VisIrregularPolyhedron)

Example 3 with VisIrregularPolyhedron

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

the class DebugWriteProblem method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        VisMesh visMesh = new VisMesh(3, new Vect3D(0, 0, 0), new Vect3D(3, 1, 1));
        VisPoint[] points0 = new VisPoint[] { new VisPoint(0, 0, 0), new VisPoint(1, 0, 0), new VisPoint(0, 1, 0), new VisPoint(0, 0, 1) };
        visMesh.addToPoints(points0[0]);
        visMesh.addToPoints(points0[1]);
        visMesh.addToPoints(points0[2]);
        visMesh.addToPoints(points0[3]);
        List<PolyhedronFace> faces0 = Arrays.asList(new PolyhedronFace(Arrays.asList(0, 1, 3)), new PolyhedronFace(Arrays.asList(0, 3, 2)), new PolyhedronFace(Arrays.asList(0, 2, 1)), new PolyhedronFace(Arrays.asList(1, 3, 2)));
        int level = 0;
        int boxNumber = 0;
        int boxIndex = 0;
        int fraction = 0;
        VisIrregularPolyhedron genPolyhedra0 = new VisIrregularPolyhedron(faces0);
        genPolyhedra0.setChomboVolumeIndex(new ChomboVolumeIndex(level, boxNumber, boxIndex, fraction));
        visMesh.addToIrregularPolyhedra(genPolyhedra0);
    // VisPoint[] points1 = new VisPoint[] {
    // new VisPoint(2+0, 0, 0),
    // new VisPoint(2+1, 0, 0),
    // new VisPoint(2+0, 1, 0),
    // new VisPoint(2+0, 0, 1)
    // };
    // 
    // visMesh.addPoint(points1[0]);
    // visMesh.addPoint(points1[1]);
    // visMesh.addPoint(points1[2]);
    // visMesh.addPoint(points1[3]);
    // 
    // vtkUnstructuredGrid vtkgrid = VtkGridUtils.getVolumeVtkGrid(visMesh);
    // String filenameASCII = "testASCII.vtk";
    // String filenameBinary = "testBinary.vtk";
    // VtkGridUtils.writeXML(vtkgrid, filenameASCII, true);
    // VtkGridUtils.writeXML(vtkgrid, filenameBinary, false);
    // vtkgrid = VtkGridUtils.read(filenameBinary);
    // vtkgrid.BuildLinks();
    // SimpleVTKViewer simpleViewer = new SimpleVTKViewer();
    // String[] varNames = visDomain.getVisMeshData().getVarNames();
    // simpleViewer.showGrid(vtkgrid, varNames[0], varNames[1]);
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : VisMesh(org.vcell.vis.vismesh.thrift.VisMesh) PolyhedronFace(org.vcell.vis.vismesh.thrift.PolyhedronFace) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) VisIrregularPolyhedron(org.vcell.vis.vismesh.thrift.VisIrregularPolyhedron) ChomboVolumeIndex(org.vcell.vis.vismesh.thrift.ChomboVolumeIndex) VisPoint(org.vcell.vis.vismesh.thrift.VisPoint) Vect3D(org.vcell.vis.vismesh.thrift.Vect3D)

Aggregations

VisIrregularPolyhedron (org.vcell.vis.vismesh.thrift.VisIrregularPolyhedron)3 VisPoint (org.vcell.vis.vismesh.thrift.VisPoint)3 ArrayList (java.util.ArrayList)2 ChomboVolumeIndex (org.vcell.vis.vismesh.thrift.ChomboVolumeIndex)2 PolyhedronFace (org.vcell.vis.vismesh.thrift.PolyhedronFace)2 VisSurfaceTriangle (org.vcell.vis.vismesh.thrift.VisSurfaceTriangle)2 BorderCellInfo (org.vcell.vis.chombo.ChomboBoundaries.BorderCellInfo)1 Vect3D (org.vcell.vis.vismesh.thrift.Vect3D)1 VisMesh (org.vcell.vis.vismesh.thrift.VisMesh)1 VisVoxel (org.vcell.vis.vismesh.thrift.VisVoxel)1