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;
}
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();
}
}
}
}
Aggregations