* @param f file to read mesh data from
* @return the mesh object described by the file
*/
public static TriMesh2D readGrdFile(File f) throws Exception{
TriMesh2D mesh = new TriMesh2D();
List<String> lines;
lines = FileUtils.readLines(f);
int index = 0;
while(lines.get(index).startsWith("#"))
index++;
String[] vals = lines.get(index).split(WHITESPACE_DELIMITER);
index++;
int nodes = Integer.parseInt(vals[0]);
int elems = Integer.parseInt(vals[1]);
// read nodes
for(int i=0; i < nodes; i++){
vals = lines.get(index+i).split(WHITESPACE_DELIMITER);
int ni = Integer.parseInt(vals[0]);
float x = Float.parseFloat(vals[1]);
float y = Float.parseFloat(vals[2]);
mesh.addNode(new Node2D(ni, x, y));
}
index += nodes;
// read elements
for(int i=0; i < elems; i++){
vals = lines.get(index+i).split(WHITESPACE_DELIMITER);
if(!vals[2].equals("tri"))
throw new Exception("Element type not supported: " + vals[2]);
int ei = Integer.parseInt(vals[0]);
int[] nodeIndex = new int[3];
for(int j=0; j < 3; j++)
nodeIndex[j] = Integer.parseInt(vals[j+3]);
mesh.addNewElement(ei, nodeIndex);
}
mesh.finalizeConstruction();
return mesh;
}