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

Method parse_elements

src/IO/VEGAParser.cpp:83–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81}
82
83void VEGAParser::parse_elements(std::ifstream& fin) {
84 const std::string elem_type = IOUtils::next_line(fin);
85 if (elem_type == "TETS" || elem_type == "TET") {
86 m_vertex_per_face = 3;
87 m_vertex_per_voxel = 4;
88 } else if (elem_type == "CUBIC") {
89 m_vertex_per_face = 4;
90 m_vertex_per_voxel = 8;
91 } else {
92 std::stringstream err_msg;
93 err_msg << "Unknown VEGA element type: " << elem_type;
94 throw IOError(err_msg.str());
95 }
96
97 const std::string header = IOUtils::next_line(fin);
98 std::stringstream header_stream(header);
99 size_t vertex_per_voxel;
100 header_stream >> m_num_voxels >> vertex_per_voxel;
101 assert(vertex_per_voxel == m_vertex_per_voxel);
102
103 for (size_t i=0; i<m_num_voxels; i++) {
104 if (fin.eof()) {
105 throw IOError("Error parsing VEGA elements, EOF reached!");
106 }
107 const std::string line = IOUtils::next_line(fin);
108 std::stringstream e_line(line);
109 size_t index;
110 if (m_vertex_per_voxel == 4) {
111 VectorI v(4);
112 e_line >> index >> v[0] >> v[1] >> v[2] >> v[3];
113 m_voxels.push_back(v);
114 } else {
115 assert(m_vertex_per_voxel == 8);
116 VectorI v(8);
117 e_line >> index
118 >> v[0] >> v[1] >> v[2] >> v[3]
119 >> v[4] >> v[5] >> v[6] >> v[7];
120 m_voxels.push_back(v);
121 }
122 }
123 if (!m_index_start_from_zero) {
124 for (auto& e : m_voxels) {
125 e.array() -= 1;
126 assert(e.minCoeff() >= 0);
127 assert(e.minCoeff() < m_num_vertices);
128 }
129 }
130}
131
132void VEGAParser::parse_material(std::ifstream& fin) {
133 std::cerr << "Warning: MATERIAL command in VEGA format is not yet supported."

Callers

nothing calls this directly

Calls 3

IOErrorClass · 0.85
next_lineFunction · 0.70
strMethod · 0.45

Tested by

no test coverage detected