Search in sources :

Example 1 with OrigSurface

use of cbit.vcell.geometry.surface.OrigSurface in project vcell by virtualcell.

the class RegionImage method sortSurfaceCollection.

public static void sortSurfaceCollection(SurfaceCollection surfCollection) {
    // Sort nodes
    Object[] nodeObjArr = new Object[surfCollection.getNodes().length];
    for (int i = 0; i < nodeObjArr.length; i++) {
        Object[] temp = new Object[2];
        temp[0] = new Integer(i);
        temp[1] = surfCollection.getNodes()[i];
        nodeObjArr[i] = temp;
    }
    Arrays.sort(nodeObjArr, new Comparator<Object>() {

        public int compare(Object obj1, Object obj2) {
            cbit.vcell.geometry.surface.Node o1 = (cbit.vcell.geometry.surface.Node) ((Object[]) obj1)[1];
            cbit.vcell.geometry.surface.Node o2 = (cbit.vcell.geometry.surface.Node) ((Object[]) obj2)[1];
            double xdiff = o1.getX() - o2.getX();
            double xmin = Math.min(Math.abs(o1.getX()), Math.abs(o2.getX()));
            double xlimit = (1e-12 * (xmin >= 1.0 ? (Math.pow(10, (int) Math.log10(xmin) + 1)) : 1));
            double ydiff = o1.getY() - o2.getY();
            double ymin = Math.min(Math.abs(o1.getY()), Math.abs(o2.getY()));
            double ylimit = (1e-12 * (ymin >= 1.0 ? (Math.pow(10, (int) Math.log10(ymin) + 1)) : 1));
            double zdiff = o1.getZ() - o2.getZ();
            double zmin = Math.min(Math.abs(o1.getZ()), Math.abs(o2.getZ()));
            double zlimit = (1e-12 * (zmin >= 1.0 ? (Math.pow(10, (int) Math.log10(zmin) + 1)) : 1));
            if (Math.abs(zdiff) < zlimit) {
                if (Math.abs(ydiff) < ylimit) {
                    return (int) Math.signum((Math.abs(xdiff) < xlimit ? 0 : xdiff));
                }
                return (int) Math.signum((Math.abs(ydiff) < ylimit ? 0 : ydiff));
            }
            return (int) Math.signum((Math.abs(zdiff) < zlimit ? 0 : zdiff));
        }
    });
    int[] remap = new int[nodeObjArr.length];
    Arrays.fill(remap, -1);
    cbit.vcell.geometry.surface.Node[] sortedNodes = new cbit.vcell.geometry.surface.Node[nodeObjArr.length];
    for (int i = 0; i < nodeObjArr.length; i++) {
        sortedNodes[i] = (cbit.vcell.geometry.surface.Node) ((Object[]) nodeObjArr[i])[1];
        if (remap[sortedNodes[i].getGlobalIndex()] == -1) {
            remap[sortedNodes[i].getGlobalIndex()] = i;
        } else {
            throw new RuntimeException("SORT error: duplicate nodes");
        }
    }
    // surfCollection.setNodes(sortedNodes);
    System.arraycopy(sortedNodes, 0, surfCollection.getNodes(), 0, sortedNodes.length);
    HashSet<cbit.vcell.geometry.surface.Node> remapHashSet = new HashSet<cbit.vcell.geometry.surface.Node>();
    for (int i = 0; i < surfCollection.getSurfaceCount(); i++) {
        Surface surf = surfCollection.getSurfaces(i);
        Polygon[] sortedPolygonArr = new Polygon[surf.getPolygonCount()];
        for (int j = 0; j < surf.getPolygonCount(); j++) {
            Polygon poly = surf.getPolygons(j);
            for (int k = 0; k < poly.getNodes().length; k++) {
                cbit.vcell.geometry.surface.Node node = poly.getNodes(k);
                if (!remapHashSet.contains(node)) {
                    node.setGlobalIndex(remap[node.getGlobalIndex()]);
                    remapHashSet.add(node);
                }
            }
            sortedPolygonArr[j] = poly;
        }
        Arrays.sort(sortedPolygonArr, new Comparator<Polygon>() {

            public int compare(Polygon obj1, Polygon obj2) {
                Coordinate o1 = ((Quadrilateral) obj1).calculateCentroid();
                Coordinate o2 = ((Quadrilateral) obj2).calculateCentroid();
                double xdiff = o1.getX() - o2.getX();
                double xmin = Math.min(Math.abs(o1.getX()), Math.abs(o2.getX()));
                double xlimit = (1e-12 * (xmin >= 1.0 ? (Math.pow(10, (int) Math.log10(xmin) + 1)) : 1));
                double ydiff = o1.getY() - o2.getY();
                double ymin = Math.min(Math.abs(o1.getY()), Math.abs(o2.getY()));
                double ylimit = (1e-12 * (ymin >= 1.0 ? (Math.pow(10, (int) Math.log10(ymin) + 1)) : 1));
                double zdiff = o1.getZ() - o2.getZ();
                double zmin = Math.min(Math.abs(o1.getZ()), Math.abs(o2.getZ()));
                double zlimit = (1e-12 * (zmin >= 1.0 ? (Math.pow(10, (int) Math.log10(zmin) + 1)) : 1));
                if (Math.abs(zdiff) < zlimit) {
                    if (Math.abs(ydiff) < ylimit) {
                        return (int) Math.signum((Math.abs(xdiff) < xlimit ? 0 : xdiff));
                    }
                    return (int) Math.signum((Math.abs(ydiff) < ylimit ? 0 : ydiff));
                }
                return (int) Math.signum((Math.abs(zdiff) < zlimit ? 0 : zdiff));
            }
        });
        OrigSurface sortedSurface = new OrigSurface(surf.getInteriorRegionIndex(), surf.getExteriorRegionIndex());
        for (int k = 0; k < sortedPolygonArr.length; k++) {
            int minGlobalIndex = sortedPolygonArr[k].getNodes(0).getGlobalIndex();
            // System.out.print("Surf "+i+" poly "+k+" nodeGI - ");
            for (int j = 0; j < sortedPolygonArr[k].getNodeCount(); j++) {
                if (sortedPolygonArr[k].getNodes(j).getGlobalIndex() < minGlobalIndex) {
                    minGlobalIndex = sortedPolygonArr[k].getNodes(j).getGlobalIndex();
                }
            // System.out.print(sortedPolygonArr[k].getNodes(j).getGlobalIndex()+" ");
            }
            while (sortedPolygonArr[k].getNodes(0).getGlobalIndex() != minGlobalIndex) {
                cbit.vcell.geometry.surface.Node lastNode = sortedPolygonArr[k].getNodes(sortedPolygonArr[k].getNodeCount() - 1);
                System.arraycopy(sortedPolygonArr[k].getNodes(), 0, sortedPolygonArr[k].getNodes(), 1, sortedPolygonArr[k].getNodeCount() - 1);
                sortedPolygonArr[k].getNodes()[0] = lastNode;
            }
            // System.out.println();
            sortedSurface.addPolygon(sortedPolygonArr[k]);
        }
        surfCollection.setSurfaces(i, sortedSurface);
    }
}
Also used : Node(cbit.util.graph.Node) OrigSurface(cbit.vcell.geometry.surface.OrigSurface) Surface(cbit.vcell.geometry.surface.Surface) Coordinate(org.vcell.util.Coordinate) OrigSurface(cbit.vcell.geometry.surface.OrigSurface) Polygon(cbit.vcell.geometry.surface.Polygon) HashSet(java.util.HashSet)

Example 2 with OrigSurface

use of cbit.vcell.geometry.surface.OrigSurface in project vcell by virtualcell.

the class RegionImage method generateSurfaceCollection.

private void generateSurfaceCollection(int numRegions, // int[] mapImageIndexToLinkRegion,int[] mapLinkRegionToDistinctRegion,
VCImage vcImage, BitSet xSurfElements, BitSet ySurfElements, BitSet zSurfElements, int dimension, Extent extent, Origin origin) {
    bMembraneNeighborCalculationFailed = false;
    int masterIndex = 0;
    double dX = extent.getX() / (vcImage.getNumX() - 1);
    double dY = extent.getY() / (vcImage.getNumY() - 1);
    double dZ = extent.getZ() / (vcImage.getNumZ() - 1);
    // 
    double loX = origin.getX() - 0.5 * dX;
    double loY = origin.getY() - 0.5 * dY;
    double loZ = origin.getZ() - 0.5 * dZ;
    Vector<Vector<Quadrilateral>> surfQuadsV = new Vector<Vector<Quadrilateral>>();
    int[][] mapInsideOutsideToSurface = new int[numRegions][];
    Vector<cbit.vcell.geometry.surface.Node> nodeListV = new Vector<cbit.vcell.geometry.surface.Node>();
    cbit.vcell.geometry.surface.Node[][][] mapImageIndexToNode = new cbit.vcell.geometry.surface.Node[2][vcImage.getNumY() + 1][vcImage.getNumX() + 1];
    double zComp, zpComp;
    double yComp, ypComp;
    double xComp, xpComp;
    final int yStep = vcImage.getNumX();
    final int zStep = vcImage.getNumX() * vcImage.getNumY();
    boolean bMvXm, bMvYm, bMvZm;
    boolean bMvXp, bMvYp, bMvZp;
    double xmEdge = origin.getX();
    double xpEdge = origin.getX() + extent.getX();
    double ymEdge = origin.getY();
    double ypEdge = origin.getY() + extent.getY();
    double zmEdge = origin.getZ();
    double zpEdge = origin.getZ() + extent.getZ();
    for (int zIndex = 0; zIndex < vcImage.getNumZ(); zIndex++) {
        mapImageIndexToNode[0] = mapImageIndexToNode[1];
        mapImageIndexToNode[1] = new cbit.vcell.geometry.surface.Node[vcImage.getNumY() + 1][vcImage.getNumX() + 1];
        zComp = loZ + zIndex * dZ;
        zpComp = zComp + dZ;
        bMvZm = (zIndex != 0);
        bMvZp = (zIndex != (vcImage.getNumZ() - 1));
        for (int yIndex = 0; yIndex < vcImage.getNumY(); yIndex++) {
            yComp = loY + yIndex * dY;
            ypComp = yComp + dY;
            bMvYm = (yIndex != 0);
            bMvYp = (yIndex != (vcImage.getNumY() - 1));
            for (int xIndex = 0; xIndex < vcImage.getNumX(); xIndex++) {
                if (xSurfElements.get(masterIndex)) {
                    bMvXp = (xIndex != (vcImage.getNumX() - 1));
                    xpComp = loX + (xIndex + 1) * dX;
                    cbit.vcell.geometry.surface.Node[] nodeArr = new cbit.vcell.geometry.surface.Node[4];
                    nodeArr[0] = mapImageIndexToNode[0][yIndex][xIndex + 1];
                    if (nodeArr[0] == null) {
                        // nodeArr[0] = new cbit.vcell.geometry.surface.Node(xpComp,yComp,zComp);
                        nodeArr[0] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYm ? yComp : ymEdge), (bMvZm ? zComp : zmEdge));
                        nodeArr[0].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[0]);
                        nodeArr[0].setMoveX(bMvXp);
                        nodeArr[0].setMoveY(bMvYm);
                        nodeArr[0].setMoveZ(bMvZm);
                        mapImageIndexToNode[0][yIndex][xIndex + 1] = nodeArr[0];
                    }
                    nodeArr[1] = mapImageIndexToNode[0][yIndex + 1][xIndex + 1];
                    if (nodeArr[1] == null) {
                        // nodeArr[1] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zComp);
                        nodeArr[1] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZm ? zComp : zmEdge));
                        nodeArr[1].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[1]);
                        nodeArr[1].setMoveX(bMvXp);
                        nodeArr[1].setMoveY(bMvYp);
                        nodeArr[1].setMoveZ(bMvZm);
                        mapImageIndexToNode[0][yIndex + 1][xIndex + 1] = nodeArr[1];
                    }
                    nodeArr[2] = mapImageIndexToNode[1][yIndex + 1][xIndex + 1];
                    if (nodeArr[2] == null) {
                        // nodeArr[2] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zpComp);
                        nodeArr[2] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
                        nodeArr[2].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[2]);
                        nodeArr[2].setMoveX(bMvXp);
                        nodeArr[2].setMoveY(bMvYp);
                        nodeArr[2].setMoveZ(bMvZp);
                        mapImageIndexToNode[1][yIndex + 1][xIndex + 1] = nodeArr[2];
                    }
                    nodeArr[3] = mapImageIndexToNode[1][yIndex][xIndex + 1];
                    if (nodeArr[3] == null) {
                        // nodeArr[3] = new cbit.vcell.geometry.surface.Node(xpComp,yComp,zpComp);
                        nodeArr[3] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYm ? yComp : ymEdge), (bMvZp ? zpComp : zpEdge));
                        nodeArr[3].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[3]);
                        nodeArr[3].setMoveX(bMvXp);
                        nodeArr[3].setMoveY(bMvYm);
                        nodeArr[3].setMoveZ(bMvZp);
                        mapImageIndexToNode[1][yIndex][xIndex + 1] = nodeArr[3];
                    }
                    addQuadToSurface(surfQuadsV, mapInsideOutsideToSurface, // masterIndex+1,mapImageIndexToRegionIndex.getValue(masterIndex+1),
                    masterIndex, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]], masterIndex + 1, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex + 1]], nodeArr, numRegions, MembraneElementIdentifier.PerpendicularTo.X);
                // surfQuad =
                // new Quadrilateral(nodeArr,
                // mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]],
                // mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex+1]]);
                // if(surfQuad.getVolIndexNeighbor1() > surfQuad.getVolIndexNeighbor2()){
                // surfQuad.reverseDirection();
                // }
                // if(mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()] == null){
                // mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()] = new int[numRegions];
                // Arrays.fill(mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()], -1);
                // }
                // if(mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()][surfQuad.getVolIndexNeighbor2()] == -1){
                // mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()][surfQuad.getVolIndexNeighbor2()] = surfQuadsV.size();
                // surfQuadsV.add(new Vector<Quadrilateral>());
                // }
                // surfQuadsV.elementAt(mapInsideOutsideToSurface[surfQuad.getVolIndexNeighbor1()][surfQuad.getVolIndexNeighbor2()]).add(surfQuad);
                }
                if (ySurfElements.get(masterIndex)) {
                    bMvXm = (xIndex != 0);
                    bMvXp = (xIndex != (vcImage.getNumX() - 1));
                    xComp = loX + xIndex * dX;
                    xpComp = loX + (xIndex + 1) * dX;
                    cbit.vcell.geometry.surface.Node[] nodeArr = new cbit.vcell.geometry.surface.Node[4];
                    nodeArr[0] = mapImageIndexToNode[0][yIndex + 1][xIndex + 1];
                    if (nodeArr[0] == null) {
                        // nodeArr[0] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zComp);
                        nodeArr[0] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZm ? zComp : zmEdge));
                        nodeArr[0].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[0]);
                        nodeArr[0].setMoveX(bMvXp);
                        nodeArr[0].setMoveY(bMvYp);
                        nodeArr[0].setMoveZ(bMvZm);
                        mapImageIndexToNode[0][yIndex + 1][xIndex + 1] = nodeArr[0];
                    }
                    nodeArr[1] = mapImageIndexToNode[0][yIndex + 1][xIndex];
                    if (nodeArr[1] == null) {
                        // nodeArr[1] = new cbit.vcell.geometry.surface.Node(xComp,ypComp,zComp);
                        nodeArr[1] = new cbit.vcell.geometry.surface.Node((bMvXm ? xComp : xmEdge), (bMvYp ? ypComp : ypEdge), (bMvZm ? zComp : zmEdge));
                        nodeArr[1].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[1]);
                        nodeArr[1].setMoveX(bMvXm);
                        nodeArr[1].setMoveY(bMvYp);
                        nodeArr[1].setMoveZ(bMvZm);
                        mapImageIndexToNode[0][yIndex + 1][xIndex] = nodeArr[1];
                    }
                    nodeArr[2] = mapImageIndexToNode[1][yIndex + 1][xIndex];
                    if (nodeArr[2] == null) {
                        // nodeArr[2] = new cbit.vcell.geometry.surface.Node(xComp,ypComp,zpComp);
                        nodeArr[2] = new cbit.vcell.geometry.surface.Node((bMvXm ? xComp : xmEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
                        nodeArr[2].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[2]);
                        nodeArr[2].setMoveX(bMvXm);
                        nodeArr[2].setMoveY(bMvYp);
                        nodeArr[2].setMoveZ(bMvZp);
                        mapImageIndexToNode[1][yIndex + 1][xIndex] = nodeArr[2];
                    }
                    nodeArr[3] = mapImageIndexToNode[1][yIndex + 1][xIndex + 1];
                    if (nodeArr[3] == null) {
                        // nodeArr[3] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zpComp);
                        nodeArr[3] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
                        nodeArr[3].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[3]);
                        nodeArr[3].setMoveX(bMvXp);
                        nodeArr[3].setMoveY(bMvYp);
                        nodeArr[3].setMoveZ(bMvZp);
                        mapImageIndexToNode[1][yIndex + 1][xIndex + 1] = nodeArr[3];
                    }
                    addQuadToSurface(surfQuadsV, mapInsideOutsideToSurface, // masterIndex+yStep,mapImageIndexToRegionIndex.getValue(masterIndex+yStep),
                    masterIndex, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]], masterIndex + yStep, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex + yStep]], nodeArr, numRegions, MembraneElementIdentifier.PerpendicularTo.Y);
                // surfQuad =
                // new Quadrilateral(nodeArr,
                // mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]],
                // mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex+yStep]]);
                // if(surfQuad.getVolIndexNeighbor1() > surfQuad.getVolIndexNeighbor2()){
                // surfQuad.reverseDirection();
                // }
                // surfQuadsV[surfQuad.getVolIndexNeighbor1()].add(surfQuad);
                }
                if (zSurfElements.get(masterIndex)) {
                    bMvXm = (xIndex != 0);
                    bMvXp = (xIndex != (vcImage.getNumX() - 1));
                    xComp = loX + xIndex * dX;
                    xpComp = loX + (xIndex + 1) * dX;
                    cbit.vcell.geometry.surface.Node[] nodeArr = new cbit.vcell.geometry.surface.Node[4];
                    nodeArr[0] = mapImageIndexToNode[1][yIndex][xIndex + 1];
                    if (nodeArr[0] == null) {
                        // nodeArr[0] = new cbit.vcell.geometry.surface.Node(xpComp,yComp,zpComp);
                        nodeArr[0] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYm ? yComp : ymEdge), (bMvZp ? zpComp : zpEdge));
                        nodeArr[0].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[0]);
                        nodeArr[0].setMoveX(bMvXp);
                        nodeArr[0].setMoveY(bMvYm);
                        nodeArr[0].setMoveZ(bMvZp);
                        mapImageIndexToNode[1][yIndex][xIndex + 1] = nodeArr[0];
                    }
                    nodeArr[1] = mapImageIndexToNode[1][yIndex + 1][xIndex + 1];
                    if (nodeArr[1] == null) {
                        // nodeArr[1] = new cbit.vcell.geometry.surface.Node(xpComp,ypComp,zpComp);
                        nodeArr[1] = new cbit.vcell.geometry.surface.Node((bMvXp ? xpComp : xpEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
                        nodeArr[1].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[1]);
                        nodeArr[1].setMoveX(bMvXp);
                        nodeArr[1].setMoveY(bMvYp);
                        nodeArr[1].setMoveZ(bMvZp);
                        mapImageIndexToNode[1][yIndex + 1][xIndex + 1] = nodeArr[1];
                    }
                    nodeArr[2] = mapImageIndexToNode[1][yIndex + 1][xIndex];
                    if (nodeArr[2] == null) {
                        // nodeArr[2] = new cbit.vcell.geometry.surface.Node(xComp,ypComp,zpComp);
                        nodeArr[2] = new cbit.vcell.geometry.surface.Node((bMvXm ? xComp : xmEdge), (bMvYp ? ypComp : ypEdge), (bMvZp ? zpComp : zpEdge));
                        nodeArr[2].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[2]);
                        nodeArr[2].setMoveX(bMvXm);
                        nodeArr[2].setMoveY(bMvYp);
                        nodeArr[2].setMoveZ(bMvZp);
                        mapImageIndexToNode[1][yIndex + 1][xIndex] = nodeArr[2];
                    }
                    nodeArr[3] = mapImageIndexToNode[1][yIndex][xIndex];
                    if (nodeArr[3] == null) {
                        // nodeArr[3] = new cbit.vcell.geometry.surface.Node(xComp,yComp,zpComp);
                        nodeArr[3] = new cbit.vcell.geometry.surface.Node((bMvXm ? xComp : xmEdge), (bMvYm ? yComp : ymEdge), (bMvZp ? zpComp : zpEdge));
                        nodeArr[3].setGlobalIndex(nodeListV.size());
                        nodeListV.add(nodeArr[3]);
                        nodeArr[3].setMoveX(bMvXm);
                        nodeArr[3].setMoveY(bMvYm);
                        nodeArr[3].setMoveZ(bMvZp);
                        mapImageIndexToNode[1][yIndex][xIndex] = nodeArr[3];
                    }
                    addQuadToSurface(surfQuadsV, mapInsideOutsideToSurface, // masterIndex+zStep,mapImageIndexToRegionIndex.getValue(masterIndex+zStep),
                    masterIndex, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]], masterIndex + zStep, mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex + zStep]], nodeArr, numRegions, MembraneElementIdentifier.PerpendicularTo.Z);
                // surfQuad =
                // new Quadrilateral(nodeArr,
                // mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex]],
                // mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[masterIndex+zStep]]);
                // if(surfQuad.getVolIndexNeighbor1() > surfQuad.getVolIndexNeighbor2()){
                // surfQuad.reverseDirection();
                // }
                // surfQuadsV[surfQuad.getVolIndexNeighbor1()].add(surfQuad);
                }
                masterIndex += 1;
            }
        }
    }
    remapQuadIndexes = new int[surfQuadsV.size()][];
    int quadCounter = 0;
    surfaceCollection = new SurfaceCollection();
    cbit.vcell.geometry.surface.Node[] allNodes = new cbit.vcell.geometry.surface.Node[nodeListV.size()];
    nodeListV.copyInto(allNodes);
    surfaceCollection.setNodes(allNodes);
    for (int surfaceIndex = 0; surfaceIndex < surfQuadsV.size(); surfaceIndex++) {
        Vector<Quadrilateral> surfV = surfQuadsV.elementAt(surfaceIndex);
        remapQuadIndexes[surfaceIndex] = new int[surfV.size()];
        OrigSurface surface = new OrigSurface(// surfV.elementAt(0).getVolIndexNeighbor1(),
        mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[surfV.elementAt(0).getVolIndexNeighbor1()]], // surfV.elementAt(0).getVolIndexNeighbor2()
        mapLinkRegionToDistinctRegion[mapImageIndexToLinkRegion[surfV.elementAt(0).getVolIndexNeighbor2()]]);
        for (int faceIndex = 0; faceIndex < surfV.size(); faceIndex++) {
            surface.addPolygon(surfV.elementAt(faceIndex));
            remapQuadIndexes[surfaceIndex][faceIndex] = quadCounter;
            quadIndexToSurfAndFace.add(new SurfAndFace(surfaceIndex, faceIndex));
            quadCounter++;
        }
        surfaceCollection.addSurface(surface);
    }
    try {
        if (!bMembraneNeighborCalculationFailed) {
            calculateNeighbors();
            surfaceCollection.setMembraneEdgeNeighbors(membraneEdgeNeighbors);
        }
    } catch (Exception e) {
        // If MembraneNeighbors fails somewhere let Surfacecollection generate without membraneneighbors (original behavior just in case)
        e.printStackTrace();
        bMembraneNeighborCalculationFailed = true;
    } finally {
        // these aren't needed after fail or surfacecollection.set(...)
        remapQuadIndexes = null;
        edgeMap = null;
    }
// RegionImage.sortSurfaceCollection(surfaceCollection);
// //check
// for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
// Surface surface = surfaceCollection.getSurfaces(i);
// for (int j = 0; j < surface.getPolygonCount(); j++) {
// Polygon polygon = surface.getPolygons(j);
// for (int k = 0; k < polygon.getNodes().length; k++) {
// if(surfaceCollection.getNodes()[polygon.getNodes()[k].getGlobalIndex()] != polygon.getNodes()[k]){
// throw new RuntimeException("Nodes not match");
// }
// }
// }
// }
}
Also used : SurfaceCollection(cbit.vcell.geometry.surface.SurfaceCollection) Node(cbit.util.graph.Node) ImageException(cbit.image.ImageException) Quadrilateral(cbit.vcell.geometry.surface.Quadrilateral) OrigSurface(cbit.vcell.geometry.surface.OrigSurface) Vector(java.util.Vector)

Example 3 with OrigSurface

use of cbit.vcell.geometry.surface.OrigSurface in project vcell by virtualcell.

the class ROIMultiPaintManager method calcMinMax.

private static StatsHelper calcMinMax(File[] selectedFiles) throws Exception {
    ArrayList<SurfaceCollection> allSurfCollections = new ArrayList<>();
    TreeMap<String, TreeMap<Integer, ArrayList<TreeMap<Integer, TreeSet<Integer>>>>> fileMapSurfMapSubsurf = new TreeMap<>();
    for (int j = 0; j < selectedFiles.length; j++) {
        File selectedfiFile = selectedFiles[j];
        SurfaceCollection surfaceCollection = ClientRequestManager.createSurfaceCollectionFromSurfaceFile(selectedfiFile);
        if (surfaceCollection == null) {
            throw new Exception("Expecting .stl or .mesh(salk) from file '" + selectedfiFile + "'");
        }
        TreeMap<Integer, ArrayList<TreeMap<Integer, TreeSet<Integer>>>> fileSurf = new TreeMap<>();
        fileMapSurfMapSubsurf.put(selectedfiFile.getAbsolutePath(), fileSurf);
        // nodeMapFace.add(treeMap);
        TreeSet<Integer> allNodes = new TreeSet<>();
        for (int k = 0; k < surfaceCollection.getNodeCount(); k++) {
            allNodes.add(k);
        }
        TreeMap<Integer, ArrayList<TreeSet<Integer>>> allSubSurf = new TreeMap<>();
        int surfOutCount = 0;
        for (int i = 0; i < surfaceCollection.getSurfaceCount(); i++) {
            ArrayList<TreeMap<Integer, TreeSet<Integer>>> surfMap = new ArrayList<>();
            fileSurf.put(i, surfMap);
            TreeMap<Integer, TreeSet<Integer>> treeMap = new TreeMap<>();
            surfMap.add(treeMap);
            Surface surface = surfaceCollection.getSurfaces(i);
            for (int k = 0; k < surface.getPolygonCount(); k++) {
                Polygon polygon = surface.getPolygons(k);
                for (Node node : polygon.getNodes()) {
                    TreeSet<Integer> PolygonIndexes = treeMap.get(node.getGlobalIndex());
                    if (PolygonIndexes == null) {
                        PolygonIndexes = new TreeSet<Integer>();
                        treeMap.put(node.getGlobalIndex(), PolygonIndexes);
                    }
                    PolygonIndexes.add(k);
                }
            }
            allSubSurf.put(i, new ArrayList<>());
            while (allNodes.size() > 0) {
                surfOutCount += 1;
                TreeSet<Integer> searchNodes = new TreeSet<>(Arrays.asList(new Integer[] { allNodes.iterator().next() }));
                TreeSet<Integer> alreadySearched = new TreeSet<>();
                TreeSet<Integer> subSurf = new TreeSet<>();
                allSubSurf.get(i).add(subSurf);
                while (searchNodes.size() > 0) {
                    Integer currentNode = searchNodes.iterator().next();
                    searchNodes.remove(currentNode);
                    alreadySearched.add(currentNode);
                    allNodes.remove(currentNode);
                    TreeSet<Integer> facesForNode = treeMap.get(surfaceCollection.getNodes(currentNode).getGlobalIndex());
                    Iterator<Integer> facesIter = facesForNode.iterator();
                    while (facesIter.hasNext()) {
                        Integer faceIndex = facesIter.next();
                        subSurf.add(faceIndex);
                        Polygon poly = surfaceCollection.getSurfaces(i).getPolygons(faceIndex);
                        for (int k = 0; k < poly.getNodes().length; k++) {
                            if (poly.getNodes()[k].getGlobalIndex() != currentNode && !alreadySearched.contains(poly.getNodes()[k].getGlobalIndex())) {
                                searchNodes.add(poly.getNodes()[k].getGlobalIndex());
                            }
                        }
                    }
                }
            }
        }
        if (surfOutCount > surfaceCollection.getSurfaceCount()) {
            SurfaceCollection newSurfCollection = new SurfaceCollection();
            newSurfCollection.setNodes(surfaceCollection.getNodes());
            for (Integer origSurfIndex : allSubSurf.keySet()) {
                ArrayList<TreeSet<Integer>> newSubSurfaces = allSubSurf.get(origSurfIndex);
                for (TreeSet<Integer> subSurf : newSubSurfaces) {
                    OrigSurface os = new OrigSurface(0, 1);
                    Iterator<Integer> polyIter = subSurf.iterator();
                    while (polyIter.hasNext()) {
                        Polygon poly = surfaceCollection.getSurfaces(origSurfIndex).getPolygons(polyIter.next());
                        os.addPolygon(poly);
                    }
                    newSurfCollection.addSurface(os);
                }
            }
            allSurfCollections.add(newSurfCollection);
        } else {
            allSurfCollections.add(surfaceCollection);
        }
    // fileMapSurfMapSubsurf.get(selectedfiFile.getAbsolutePath()).get(i).add(treeMap);
    }
    StatsHelper statsHelper = new StatsHelper();
    statsHelper.recalSurfs = allSurfCollections;
    for (int j = 0; j < statsHelper.recalSurfs.size(); j++) {
        // File selectedfiFile = selectedFiles[j];
        // SurfaceCollection surfaceCollection = ClientRequestManager.createSurfaceCollectionFromSurfaceFile(selectedfiFile);
        SurfaceCollection surfaceCollection = statsHelper.recalSurfs.get(j);
        for (int i = 0; i < surfaceCollection.getNodes().length; i++) {
            if (j == 0 && i == 0) {
                statsHelper.xmin = surfaceCollection.getNodes()[i].getX();
                statsHelper.xmax = statsHelper.xmin;
                statsHelper.ymin = surfaceCollection.getNodes()[i].getY();
                statsHelper.ymax = statsHelper.ymin;
                statsHelper.zmin = surfaceCollection.getNodes()[i].getZ();
                statsHelper.zmax = statsHelper.zmin;
            }
            statsHelper.xmin = Math.min(statsHelper.xmin, surfaceCollection.getNodes()[i].getX());
            statsHelper.ymin = Math.min(statsHelper.ymin, surfaceCollection.getNodes()[i].getY());
            statsHelper.zmin = Math.min(statsHelper.zmin, surfaceCollection.getNodes()[i].getZ());
            statsHelper.xmax = Math.max(statsHelper.xmax, surfaceCollection.getNodes()[i].getX());
            statsHelper.ymax = Math.max(statsHelper.ymax, surfaceCollection.getNodes()[i].getY());
            statsHelper.zmax = Math.max(statsHelper.zmax, surfaceCollection.getNodes()[i].getZ());
        }
    }
    return statsHelper;
}
Also used : SurfaceCollection(cbit.vcell.geometry.surface.SurfaceCollection) Node(cbit.vcell.geometry.surface.Node) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) Point(java.awt.Point) ImageException(cbit.image.ImageException) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException) Surface(cbit.vcell.geometry.surface.Surface) OrigSurface(cbit.vcell.geometry.surface.OrigSurface) TreeSet(java.util.TreeSet) OrigSurface(cbit.vcell.geometry.surface.OrigSurface) Polygon(cbit.vcell.geometry.surface.Polygon) File(java.io.File)

Aggregations

OrigSurface (cbit.vcell.geometry.surface.OrigSurface)3 ImageException (cbit.image.ImageException)2 Node (cbit.util.graph.Node)2 Polygon (cbit.vcell.geometry.surface.Polygon)2 Surface (cbit.vcell.geometry.surface.Surface)2 SurfaceCollection (cbit.vcell.geometry.surface.SurfaceCollection)2 Node (cbit.vcell.geometry.surface.Node)1 Quadrilateral (cbit.vcell.geometry.surface.Quadrilateral)1 Point (java.awt.Point)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 Vector (java.util.Vector)1 Coordinate (org.vcell.util.Coordinate)1 UserCancelException (org.vcell.util.UserCancelException)1 UtilCancelException (org.vcell.util.UtilCancelException)1