MCPcopy Create free account
hub / github.com/PyMesh/PyMesh / parse

Method parse

src/IO/MEDITParser.cpp:13–93  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11using namespace PyMesh;
12
13bool MEDITParser::parse(const std::string& filename) {
14 std::ifstream fin(filename.c_str());
15 if (!fin.is_open()) {
16 std::stringstream err_msg;
17 err_msg << "failed to open file \"" << filename << "\"";
18 throw IOError(err_msg.str());
19 }
20
21 bool success = true;
22 success &= parse_header(fin);
23 if (!success) {
24 throw IOError("Error parsing file header.");
25 }
26
27 const size_t LINE_SIZE = 256;
28 char line[LINE_SIZE];
29 while (!fin.eof()) {
30 std::string elem_type;
31 fin >> elem_type;
32 if (elem_type.size() == 0) continue;
33 if (elem_type[0] == '#') {
34 fin.getline(line, LINE_SIZE);
35 continue;
36 }
37 if (elem_type == "Vertices") {
38 success &= parse_vertices(fin);
39 } else if (elem_type == "Triangles") {
40 m_vertex_per_face = 3;
41 success &= parse_faces(fin);
42 } else if (elem_type == "Quadrilaterals") {
43 m_vertex_per_face = 4;
44 success &= parse_faces(fin);
45 } else if (elem_type == "Tetrahedra") {
46 if (m_faces.size() == 0) {
47 m_vertex_per_face = 3;
48 } else if (m_vertex_per_face != 3){
49 success = false;
50 }
51 m_vertex_per_voxel = 4;
52 success &= parse_voxels(fin);
53 } else if (elem_type == "Hexahedra") {
54 if (m_faces.size() == 0) {
55 m_vertex_per_face = 4;
56 } else if (m_vertex_per_face != 4){
57 success = false;
58 }
59 m_vertex_per_voxel = 8;
60 success &= parse_voxels(fin);
61 } else if (elem_type == "End") {
62 break;
63 } else {
64 if (elem_type != "Edges" &&
65 elem_type != "Corners" &&
66 elem_type != "RequiredVertices" &&
67 elem_type != "Ridges" &&
68 elem_type != "RequiredEdges" &&
69 elem_type != "Normals" &&
70 elem_type != "Tangents" &&

Callers

nothing calls this directly

Calls 3

IOErrorClass · 0.85
strMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected