Search in sources :

Example 1 with MembraneMeshMetrics

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

the class CartesianMeshFileReader method readMembraneMeshMetrics.

private MembraneMeshMetrics readMembraneMeshMetrics(CommentStringTokenizer tokens) throws MathException {
    MembraneMeshMetrics membraneMeshMetrics = new MembraneMeshMetrics();
    String token = null;
    token = tokens.nextToken();
    if (token.equalsIgnoreCase(VCML.MembraneElements)) {
        token = tokens.nextToken();
    } else {
        throw new MathFormatException("unexpected token " + token + " expecting " + VCML.CartesianMesh);
    }
    if (!token.equalsIgnoreCase(VCML.BeginBlock)) {
        throw new MathFormatException("unexpected token " + token + " expecting " + VCML.BeginBlock);
    }
    token = tokens.nextToken();
    int numMembraneElements = 0;
    try {
        numMembraneElements = Integer.valueOf(token).intValue();
    } catch (NumberFormatException e) {
        throw new MathFormatException("unexpected token " + token + " expecting MembraneElement count");
    }
    short[] regionIndex = new short[numMembraneElements];
    float[] areas = new float[numMembraneElements];
    float[][] normals = new float[numMembraneElements][3];
    float[][] centroids = new float[numMembraneElements][3];
    if (!(token = tokens.nextToken()).equals("Index") || !(token = tokens.nextToken()).equals("RegionIndex") || !(token = tokens.nextToken()).equals("X") || !(token = tokens.nextToken()).equals("Y") || !(token = tokens.nextToken()).equals("Z") || !(token = tokens.nextToken()).equals("Area") || !(token = tokens.nextToken()).equals("Nx") || !(token = tokens.nextToken()).equals("Ny") || !(token = tokens.nextToken()).equals("Nz")) {
        throw new MathFormatException("unexpected MeshMetrics column description = " + token);
    }
    int counter = 0;
    while (tokens.hasMoreTokens()) {
        token = tokens.nextToken();
        if (token.equalsIgnoreCase(VCML.EndBlock)) {
            break;
        }
        if (counter >= numMembraneElements) {
            throw new MathFormatException("Error parsing MembraneMeshMetrics values index=" + counter + ".  Expecting only " + numMembraneElements + " MembraneElements");
        }
        try {
            int index = Integer.valueOf(token).intValue();
            if (index != counter) {
                throw new MathFormatException("unexpected token " + token + " expecting " + counter);
            }
            regionIndex[counter] = Short.parseShort(tokens.nextToken());
            // centroids
            centroids[counter][0] = Float.parseFloat(tokens.nextToken());
            centroids[counter][1] = Float.parseFloat(tokens.nextToken());
            centroids[counter][2] = Float.parseFloat(tokens.nextToken());
            // area
            areas[counter] = Float.parseFloat(tokens.nextToken());
            // normals
            normals[counter][0] = Float.parseFloat(tokens.nextToken());
            normals[counter][1] = Float.parseFloat(tokens.nextToken());
            normals[counter][2] = Float.parseFloat(tokens.nextToken());
        } catch (NumberFormatException e) {
            throw new MathFormatException("Error parsing MembraneMeshMetrics values index=" + counter + "  " + e.getMessage());
        }
        counter += 1;
    }
    membraneMeshMetrics.regionIndexes = regionIndex;
    membraneMeshMetrics.areas = areas;
    membraneMeshMetrics.normals = normals;
    membraneMeshMetrics.centroids = centroids;
    return membraneMeshMetrics;
}
Also used : MembraneMeshMetrics(org.vcell.vis.vcell.MembraneMeshMetrics) MathFormatException(cbit.vcell.math.MathFormatException)

Example 2 with MembraneMeshMetrics

use of org.vcell.vis.vcell.MembraneMeshMetrics 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)

Aggregations

MathFormatException (cbit.vcell.math.MathFormatException)2 MembraneMeshMetrics (org.vcell.vis.vcell.MembraneMeshMetrics)2 MathException (cbit.vcell.math.MathException)1 BufferedReader (java.io.BufferedReader)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 CommentStringTokenizer (org.vcell.util.CommentStringTokenizer)1 CartesianMesh (org.vcell.vis.vcell.CartesianMesh)1 SubdomainInfo (org.vcell.vis.vcell.SubdomainInfo)1