From d303c7c33105c0b82f801be125971b77945d86bd Mon Sep 17 00:00:00 2001 From: zhxx1987 Date: Sun, 29 Sep 2024 16:51:40 +0800 Subject: [PATCH] improve vtk --- .../geometry/file_parser/read_vtk_mesh.hpp | 124 ++++++++++++++---- 1 file changed, 101 insertions(+), 23 deletions(-) diff --git a/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp b/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp index 9e26a356e6..84b0b184db 100644 --- a/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp +++ b/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp @@ -11,6 +11,7 @@ #include #include +#include #include @@ -643,6 +644,82 @@ namespace zeno { } } } + else if(line_str.find("POINT_DATA ")!=std::string::npos) + { + std::getline(file,line_str); + std::string a; + std::string b; + std::string c; + std::stringstream ss; + ss<>a>>b>>c; + std::string name = b; + while(stringReplace(name, "%20","_")); + while(stringReplace(name, ".","_")); + while(stringReplace(name, "-","_")); + std::getline(file,line_str); + + if(a=="VECTORS") { + auto &Velocity = prim->verts.add_attr(name); + if (readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) + file >> Velocity[i][j]; + } + } else if (readtype == "BINARY") { + if (c=="float") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) { + char buf[4]; + for (auto k = 3; k >= 0; k--) { + buf[k] = file.get(); + } + Velocity[i][j] = *(float *)buf; + } + } + } else if (c=="double") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) { + char buf[8]; + for (auto k = 7; k >= 0; k--) { + buf[k] = file.get(); + } + Velocity[i][j] = *(double *)buf; + } + } + } + } + }else if(a=="SCALARS") { + auto &Velocity = prim->verts.add_attr(name); + if (readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + file >> Velocity[i]; + } + } else if (readtype == "BINARY") { + if (c=="float") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 1; j++) { + char buf[4]; + for (auto k = 3; k >= 0; k--) { + buf[k] = file.get(); + } + Velocity[i] = *(float *)buf; + } + } + } else if (c=="double") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 1; j++) { + char buf[8]; + for (auto k = 7; k >= 0; k--) { + buf[k] = file.get(); + } + Velocity[i] = *(double *)buf; + } + } + } + } + } + } else if(line_str.find("Field ")) { std::string a; @@ -695,33 +772,34 @@ namespace zeno { } }else if(strs[1] == "3") { - auto &vars = prim->verts.add_attr(varname); - if(readtype == "ASCII") { - for (int i = 0; i < num_points; i++) { - for (int j = 0; j < 3; j++) - file >> vars[i][j]; - } - }else if(readtype == "BINARY") - { - if (strs[3] == "float") { + if(prim->has_attr(varname) == false) { + auto &vars = prim->verts.add_attr(varname); + + if (readtype == "ASCII") { for (int i = 0; i < num_points; i++) { - for (int j = 0; j < 3; j++) { - char buf[4]; - for (auto k = 3; k >= 0; k--) { - buf[k] = file.get(); + for (int j = 0; j < 3; j++) + file >> vars[i][j]; + } + } else if (readtype == "BINARY") { + if (strs[3] == "float") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) { + char buf[4]; + for (auto k = 3; k >= 0; k--) { + buf[k] = file.get(); + } + vars[i][j] = *(float *)buf; } - vars[i][j] = *(float*)buf; } - } - } - else if (strs[3] == "double") { - for (int i = 0; i < num_points; i++) { - for (int j = 0; j < 3; j++) { - char buf[8]; - for (auto k = 7; k >= 0; k--) { - buf[k] = file.get(); + } else if (strs[3] == "double") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) { + char buf[8]; + for (auto k = 7; k >= 0; k--) { + buf[k] = file.get(); + } + vars[i][j] = *(double *)buf; } - vars[i][j] = *(double*)buf; } } }