forked from nmwsharp/polyscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimple_dot_mesh_parser.cpp
78 lines (70 loc) · 1.92 KB
/
simple_dot_mesh_parser.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "simple_dot_mesh_parser.h"
#include <fstream>
#include <iomanip>
#include <iostream>
#include <istream>
#include <memory>
#include <sstream>
void parseVolumeDotMesh(std::string filename, std::vector<std::array<double, 3>>& vertsOut,
std::vector<std::array<int64_t, 8>>& cellsOut) {
// Open the file
std::ifstream in(filename);
if (!in) throw std::invalid_argument("Could not open mesh file " + filename);
vertsOut.clear();
cellsOut.clear();
while (in) {
std::string token;
in >> token;
if (token == "MeshVersionFormatted") {
in >> token; // eat version number
} else if (token == "Dimension") {
in >> token; // eat dimension number
} else if (token == "End") {
return;
} else if (token == "Vertices") {
size_t nVerts;
in >> nVerts;
vertsOut.resize(nVerts);
for (size_t iVert = 0; iVert < nVerts; iVert++) {
double x, y, z;
int value;
in >> x >> y >> z >> value;
vertsOut[iVert][0] = x;
vertsOut[iVert][1] = y;
vertsOut[iVert][2] = z;
// not sure what value even does
}
} else if (token == "Tetrahedra") {
size_t nTet;
in >> nTet;
for (size_t iTet = 0; iTet < nTet; iTet++) {
std::array<int64_t, 8> cell;
int value;
for (int j = 0; j < 4; j++) {
int64_t ind;
in >> ind;
cell[j] = ind - 1;
}
for (int j = 4; j < 8; j++) {
cell[j] = -1;
}
in >> value;
cellsOut.push_back(cell);
}
} else if (token == "Hexahedra") {
size_t nHex;
in >> nHex;
for (size_t iHex = 0; iHex < nHex; iHex++) {
std::array<int64_t, 8> cell;
int value;
for (int j = 0; j < 8; j++) {
int64_t ind;
in >> ind;
cell[j] = ind - 1;
}
in >> value;
cellsOut.push_back(cell);
}
}
}
}