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

Method MshLoader

src/IO/MshLoader.cpp:13–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11using namespace PyMesh;
12
13MshLoader::MshLoader(const std::string& filename) {
14 std::ifstream fin(filename.c_str(), std::ios::in | std::ios::binary);
15
16 if (!fin.is_open()) {
17 std::stringstream err_msg;
18 err_msg << "failed to open file \"" << filename << "\"";
19 throw IOError(err_msg.str());
20 }
21 // Parse header
22 std::string buf;
23 double version;
24 int type;
25 fin >> buf;
26 if (buf != "$MeshFormat") { throw INVALID_FORMAT; }
27
28 fin >> version >> type >> m_data_size;
29 m_binary = (type == 1);
30
31 // Some sanity check.
32 if (m_data_size != 8) {
33 std::cerr << "Error: data size must be 8 bytes." << std::endl;
34 throw NOT_IMPLEMENTED;
35 }
36 if (sizeof(int) != 4) {
37 std::cerr << "Error: code must be compiled with int size 4 bytes." << std::endl;
38 throw NOT_IMPLEMENTED;
39 }
40
41 // Read in extra info from binary header.
42 if (m_binary) {
43 int one;
44 IOUtils::eat_white_space(fin);
45 fin.read(reinterpret_cast<char*>(&one), sizeof(int));
46 if (one != 1) {
47 std::cerr << "Warning: binary msh file " << filename
48 << " is saved with different endianness than this machine."
49 << std::endl;
50 throw NOT_IMPLEMENTED;
51 }
52 }
53
54 fin >> buf;
55 if (buf != "$EndMeshFormat") { throw NOT_IMPLEMENTED; }
56
57 while (!fin.eof()) {
58 buf.clear();
59 fin >> buf;
60 if (buf == "$Nodes") {
61 parse_nodes(fin);
62 fin >> buf;
63 if (buf != "$EndNodes") { throw INVALID_FORMAT; }
64 } else if (buf == "$Elements") {
65 parse_elements(fin);
66 fin >> buf;
67 if (buf != "$EndElements") { throw INVALID_FORMAT; }
68 } else if (buf == "$NodeData") {
69 parse_node_field(fin);
70 fin >> buf;

Callers

nothing calls this directly

Calls 3

IOErrorClass · 0.85
strMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected