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

Method parse_node_field

src/IO/MshLoader.cpp:274–345  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

272}
273
274void MshLoader::parse_node_field(std::ifstream& fin) {
275 size_t num_string_tags;
276 size_t num_real_tags;
277 size_t num_int_tags;
278
279 fin >> num_string_tags;
280 std::string* str_tags = new std::string[num_string_tags];
281 for (size_t i=0; i<num_string_tags; i++) {
282 IOUtils::eat_white_space(fin);
283 if (fin.peek() == '\"') {
284 // Handle field name between quoates.
285 char buf[128];
286 fin.get(); // remove the quote at the beginning.
287 fin.getline(buf, 128, '\"');
288 str_tags[i] = std::string(buf);
289 } else {
290 fin >> str_tags[i];
291 }
292 }
293
294 fin >> num_real_tags;
295 Float* real_tags = new Float[num_real_tags];
296 for (size_t i=0; i<num_real_tags; i++)
297 fin >> real_tags[i];
298
299 fin >> num_int_tags;
300 int* int_tags = new int[num_int_tags];
301 for (size_t i=0; i<num_int_tags; i++)
302 fin >> int_tags[i];
303
304 if (num_string_tags <= 0 || num_int_tags <= 2) {
305 delete [] str_tags;
306 delete [] real_tags;
307 delete [] int_tags;
308 throw INVALID_FORMAT;
309 }
310 std::string fieldname = str_tags[0];
311 int num_components = int_tags[1];
312 int num_entries = int_tags[2];
313 VectorF field(num_entries * num_components);
314
315 delete [] str_tags;
316 delete [] real_tags;
317 delete [] int_tags;
318
319 if (m_binary) {
320 size_t num_bytes = (num_components * m_data_size + 4) * num_entries;
321 char* data = new char[num_bytes];
322 IOUtils::eat_white_space(fin);
323 fin.read(data, num_bytes);
324 for (size_t i=0; i<num_entries; i++) {
325 int node_idx = *reinterpret_cast<int*>(&data[i*(4+num_components*m_data_size)]);
326 node_idx -= 1;
327 size_t base_idx = i*(4+num_components*m_data_size) + 4;
328 for (size_t j=0; j<num_components; j++) {
329 field[node_idx * num_components + j] = *reinterpret_cast<Float*>(&data[base_idx+j*m_data_size]);
330 }
331 }

Callers

nothing calls this directly

Calls 1

getMethod · 0.45

Tested by

no test coverage detected