Search in sources :

Example 1 with CartesianMesh

use of org.vcell.vis.vcell.CartesianMesh in project vcell by virtualcell.

the class VCellDataTest method main.

/**
 * @param args
 */
public static void main(String[] args) {
    try {
        ResourceUtil.setNativeLibraryDirectory();
        KeyValue simKey = new KeyValue("1661241954");
        String pathPrefix = "C:\\Users\\schaff\\.vcell\\simdata\\user\\";
        File meshFile = new File(pathPrefix + "SimID_" + simKey + "_0_.mesh");
        File meshMetricsFile = new File(pathPrefix + "SimID_" + simKey + "_0_.meshmetrics");
        File subdomainFile = new File(pathPrefix + "SimID_" + simKey + "_0_.subdomains");
        File logFile = new File(pathPrefix + "SimID_" + simKey + "_0_.log");
        File zipFile = new File(pathPrefix + "SimID_" + simKey + "_0_00.zip");
        File postprocessingFile = new File(pathPrefix + "SimID_" + simKey + "_0_.hdf5");
        VCellSimFiles vcellFiles = new VCellSimFiles(simKey, 0, meshFile, meshMetricsFile, subdomainFile, logFile, postprocessingFile);
        vcellFiles.addDataFileEntry(zipFile, new File("SimID_" + simKey + "_0_0000.sim"), 0.0);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0001.sim"),0.05);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0002.sim"),0.10);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0003.sim"),0.15);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0004.sim"),0.20);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0005.sim"),0.25);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0006.sim"),0.30);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0007.sim"),0.35);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0008.sim"),0.40);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0009.sim"),0.45);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0010.sim"),0.50);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0011.sim"),0.55);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0012.sim"),0.60);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0013.sim"),0.65);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0014.sim"),0.70);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0015.sim"),0.75);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0016.sim"),0.80);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0017.sim"),0.85);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0018.sim"),0.90);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0019.sim"),0.95);
        // vcellFiles.addDataFileEntry(zipFile,new File("SimID_"+simKey+"_0_0020.sim"),1.0);
        // process each domain separately (only have to process the mesh once for each one)
        CartesianMeshVtkFileWriter cartesianMeshVtkFileWriter = new CartesianMeshVtkFileWriter();
        File destinationDirectory = new File("C:\\Developer\\eclipse\\workspace\\VCell_5.3_visfull\\VtkData\\");
        File[] generatedFiles = cartesianMeshVtkFileWriter.writeVtuExportFiles(vcellFiles, destinationDirectory, null);
        boolean bDisplay = true;
        if (bDisplay) {
            CartesianMeshFileReader reader = new CartesianMeshFileReader();
            CartesianMesh mesh = reader.readFromFiles(vcellFiles);
            ArrayList<String> allDomainNames = new ArrayList<String>();
            allDomainNames.addAll(mesh.getVolumeDomainNames());
            allDomainNames.addAll(mesh.getMembraneDomainNames());
            for (String domain : allDomainNames) {
                for (int timeIndex = 0; timeIndex < vcellFiles.getTimes().size(); timeIndex++) {
                    // String filename = new File(destinationDirectory,vcellFiles.getCannonicalFilePrefix(domain,timeIndex)+".vtu").getAbsolutePath();
                    // vtkUnstructuredGrid vtkgrid = vtkGridUtils.read(filename);
                    // vtkgrid.BuildLinks();
                    // 
                    // String varName0 = vtkgrid.GetCellData().GetArrayName(0);
                    // String varName1 = vtkgrid.GetCellData().GetArrayName(1);
                    // SimpleVTKViewer simpleViewer = new SimpleVTKViewer();
                    // simpleViewer.showGrid(vtkgrid, varName0, varName1);
                    Thread.sleep(1000);
                }
            }
        }
        // CartesianMeshFileReader reader = new CartesianMeshFileReader();
        // CartesianMesh mesh = reader.readFromFiles(vcellFiles);
        // CartesianMeshMapping cartesianMeshMapping = new CartesianMeshMapping();
        // 
        // //String domainName = mesh.meshRegionInfo.getVolumeDomainNames().get(1);
        // String domainName = mesh.meshRegionInfo.getVolumeDomainNames().get(0);
        // 
        // System.out.println("making visMesh for domain "+domainName+" of ["+mesh.meshRegionInfo.getVolumeDomainNames()+"]");
        // VisMesh visMesh = cartesianMeshMapping.fromMeshData(mesh, domainName);
        // final int numElements = visMesh.getPolyhedra().size();
        // final double[] data1 = new double[numElements];
        // final double[] data2 = new double[numElements];
        // 
        // for (int i=0;i<numElements;i++){
        // data1[i] = Math.sin(i/10000.0);
        // data2[i] = Math.cos(i/10000.0);
        // }
        // VisMeshData visData = new VisMeshData() {
        // private String[] names = new String[] { "data1", "data2" };
        // 
        // @Override
        // public String[] getVarNames() {
        // return new String[] { "data1", "data2" };
        // }
        // 
        // @Override
        // public double getTime() {
        // return 0.0;
        // }
        // 
        // @Override
        // public double[] getData(String var) {
        // if (var.equals("data1")){
        // return data1;
        // }else if (var.equals("data2")){
        // return data2;
        // }else{
        // throw new RuntimeException("var "+var+" not found");
        // }
        // }
        // };
        // 
        // VisDomain visDomain = new VisDomain("domain1",visMesh,visData);
        // VtkGridUtils vtkGridUtils = new VtkGridUtils();
        // vtkUnstructuredGrid vtkgrid = vtkGridUtils.getVtkGrid(visDomain);
        // vtkgrid = TestVTK.testWindowedSincPolyDataFilter(vtkgrid);
        // String filenameBinary = "testBinary.vtu";
        // vtkGridUtils.writeXML(vtkgrid, filenameBinary, false);
        // vtkgrid = vtkGridUtils.read(filenameBinary);
        // //vtkgrid.s
        // vtkgrid.BuildLinks();
        // SimpleVTKViewer simpleViewer = new SimpleVTKViewer();
        // String[] varNames = visDomain.getVisMeshData().getVarNames();
        // simpleViewer.showGrid(vtkgrid, varNames[0], varNames[1]);
        System.out.println("ran");
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : CartesianMeshFileReader(org.vcell.vis.io.CartesianMeshFileReader) KeyValue(org.vcell.util.document.KeyValue) CartesianMeshVtkFileWriter(org.vcell.vis.mapping.vcell.CartesianMeshVtkFileWriter) ArrayList(java.util.ArrayList) VCellSimFiles(org.vcell.vis.io.VCellSimFiles) CartesianMesh(org.vcell.vis.vcell.CartesianMesh) File(java.io.File)

Example 2 with CartesianMesh

use of org.vcell.vis.vcell.CartesianMesh 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 3 with CartesianMesh

use of org.vcell.vis.vcell.CartesianMesh in project vcell by virtualcell.

the class CartesianMeshVtkFileWriter method getEmptyVtuMeshFiles.

public VtuFileContainer getEmptyVtuMeshFiles(VCellSimFiles vcellFiles, File destinationDirectory) throws IOException, MathException, DataAccessException {
    // 
    // read the simplified cartesian mesh
    // 
    CartesianMeshFileReader reader = new CartesianMeshFileReader();
    CartesianMesh mesh = reader.readFromFiles(vcellFiles);
    // 
    // for each domain in cartesian mesh, get the mesh file
    // 
    ArrayList<String> domains = new ArrayList<String>();
    domains.addAll(mesh.getVolumeDomainNames());
    domains.addAll(mesh.getMembraneDomainNames());
    boolean bMeshFileMissing = false;
    ArrayList<File> meshFiles = new ArrayList<File>();
    for (String domainName : domains) {
        File file = getVtuMeshFileName(vcellFiles, domainName);
        meshFiles.add(file);
        if (!file.exists()) {
            bMeshFileMissing = true;
        }
    }
    if (bMeshFileMissing) {
        writeEmptyMeshFiles(vcellFiles, destinationDirectory, null);
    }
    VtuFileContainer vtuFileContainer = new VtuFileContainer();
    for (int i = 0; i < domains.size(); i++) {
        byte[] vtuMeshFileContents = FileUtils.readByteArrayFromFile(meshFiles.get(i));
        vtuFileContainer.addVtuMesh(new VtuFileContainer.VtuMesh(domains.get(i), 0.0, vtuMeshFileContents));
    }
    return vtuFileContainer;
}
Also used : CartesianMeshFileReader(org.vcell.vis.io.CartesianMeshFileReader) CartesianMesh(org.vcell.vis.vcell.CartesianMesh) ArrayList(java.util.ArrayList) VtuFileContainer(org.vcell.vis.io.VtuFileContainer) File(java.io.File)

Example 4 with CartesianMesh

use of org.vcell.vis.vcell.CartesianMesh in project vcell by virtualcell.

the class CartesianMeshFileReader method readFromFiles.

public CartesianMesh readFromFiles(VCellSimFiles vcellSimFiles) throws IOException, MathException {
    // 
    // read meshFile and parse into 'mesh' object
    // 
    BufferedReader meshReader = null;
    BufferedReader meshMetricsReader = null;
    try {
        meshReader = new BufferedReader(new FileReader(vcellSimFiles.cartesianMeshFile));
        CommentStringTokenizer meshST = new CommentStringTokenizer(meshReader);
        CommentStringTokenizer membraneMeshMetricsST = null;
        if (vcellSimFiles.meshMetricsFile != null) {
            meshMetricsReader = new BufferedReader(new FileReader(vcellSimFiles.meshMetricsFile));
            membraneMeshMetricsST = new CommentStringTokenizer(meshMetricsReader);
        }
        MembraneMeshMetrics membraneMeshMetrics = null;
        SubdomainInfo subdomainInfo = null;
        if (membraneMeshMetricsST != null) {
            membraneMeshMetrics = readMembraneMeshMetrics(membraneMeshMetricsST);
        }
        if (vcellSimFiles.subdomainFile != null) {
            subdomainInfo = SubdomainInfo.read(vcellSimFiles.subdomainFile);
        }
        CartesianMesh mesh = readCartesianMesh(meshST, membraneMeshMetrics, subdomainInfo);
        return mesh;
    } finally {
        if (meshReader != null) {
            try {
                meshReader.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (meshMetricsReader != null) {
            try {
                meshMetricsReader.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : CartesianMesh(org.vcell.vis.vcell.CartesianMesh) MembraneMeshMetrics(org.vcell.vis.vcell.MembraneMeshMetrics) BufferedReader(java.io.BufferedReader) CommentStringTokenizer(org.vcell.util.CommentStringTokenizer) FileReader(java.io.FileReader) SubdomainInfo(org.vcell.vis.vcell.SubdomainInfo) IOException(java.io.IOException) MathFormatException(cbit.vcell.math.MathFormatException) MathException(cbit.vcell.math.MathException)

Example 5 with CartesianMesh

use of org.vcell.vis.vcell.CartesianMesh in project vcell by virtualcell.

the class CartesianMeshVtkFileWriter method getVtuVarInfos.

public VtuVarInfo[] getVtuVarInfos(VCellSimFiles vcellFiles, OutputContext outputContext, VCData vcData) throws IOException, DataAccessException, MathException {
    CartesianMeshFileReader reader = new CartesianMeshFileReader();
    CartesianMesh mesh = reader.readFromFiles(vcellFiles);
    List<String> volumeDomainNames = mesh.getVolumeDomainNames();
    List<String> membraneDomainNames = mesh.getMembraneDomainNames();
    ArrayList<String> allDomains = new ArrayList<String>();
    allDomains.addAll(volumeDomainNames);
    allDomains.addAll(membraneDomainNames);
    DataIdentifier[] dataIdentifiers = vcData.getVarAndFunctionDataIdentifiers(outputContext);
    AnnotatedFunction[] annotationFunctions = vcData.getFunctions(outputContext);
    ArrayList<VtuVarInfo> varInfos = new ArrayList<VtuVarInfo>();
    for (String domainName : allDomains) {
        VariableDomain varDomain = VariableDomain.VARIABLEDOMAIN_UNKNOWN;
        if (volumeDomainNames.contains(domainName)) {
            varDomain = VariableDomain.VARIABLEDOMAIN_VOLUME;
        } else if (membraneDomainNames.contains(domainName)) {
            varDomain = VariableDomain.VARIABLEDOMAIN_MEMBRANE;
        }
        for (DataIdentifier dataID : dataIdentifiers) {
            if (dataID.getDomain() == null || dataID.getDomain().getName().equals(domainName)) {
                boolean bMeshVar = isMeshVar(dataID);
                String expressionString = null;
                if (dataID.isFunction()) {
                    for (AnnotatedFunction f : annotationFunctions) {
                        if (f.getName().equals(dataID.getName())) {
                            expressionString = f.getExpression().infix();
                        }
                    }
                }
                varInfos.add(new VtuVarInfo(dataID.getName(), "(" + domainName + ")  " + dataID.getDisplayName(), domainName, varDomain, expressionString, DataType.CellData, bMeshVar));
            }
        }
        varInfos.add(new VtuVarInfo(GLOBAL_INDEX_VAR, "(" + domainName + ")  " + GLOBAL_INDEX_VAR, domainName, varDomain, null, DataType.CellData, true));
        varInfos.add(new VtuVarInfo(REGION_ID_VAR, "(" + domainName + ")  " + REGION_ID_VAR, domainName, varDomain, null, DataType.CellData, true));
    }
    return varInfos.toArray(new VtuVarInfo[0]);
}
Also used : CartesianMeshFileReader(org.vcell.vis.io.CartesianMeshFileReader) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) DataIdentifier(cbit.vcell.simdata.DataIdentifier) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) ArrayList(java.util.ArrayList) CartesianMesh(org.vcell.vis.vcell.CartesianMesh) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Aggregations

CartesianMesh (org.vcell.vis.vcell.CartesianMesh)6 ArrayList (java.util.ArrayList)4 CartesianMeshFileReader (org.vcell.vis.io.CartesianMeshFileReader)4 File (java.io.File)3 MathFormatException (cbit.vcell.math.MathFormatException)2 IOException (java.io.IOException)2 MathException (cbit.vcell.math.MathException)1 VariableDomain (cbit.vcell.math.VariableType.VariableDomain)1 DataIdentifier (cbit.vcell.simdata.DataIdentifier)1 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 HashMap (java.util.HashMap)1 CommentStringTokenizer (org.vcell.util.CommentStringTokenizer)1 Coordinate (org.vcell.util.Coordinate)1 ISize (org.vcell.util.ISize)1 KeyValue (org.vcell.util.document.KeyValue)1 Vect3D (org.vcell.vis.core.Vect3D)1 VCellSimFiles (org.vcell.vis.io.VCellSimFiles)1 VtuFileContainer (org.vcell.vis.io.VtuFileContainer)1