diff --git a/projects/CuLagrange/geometry/MeshIO.cu b/projects/CuLagrange/geometry/MeshIO.cu index e0fadc23fe..78630ef0f6 100644 --- a/projects/CuLagrange/geometry/MeshIO.cu +++ b/projects/CuLagrange/geometry/MeshIO.cu @@ -12,7 +12,7 @@ #include #include #include - +#include namespace zeno { @@ -21,24 +21,31 @@ struct ReadVTKMesh : INode { void apply() override { auto view_interior = get_param("view_interior"); auto path = get_input("path")->get(); + auto type = get_input("method")->get(); auto prim = std::make_shared(); - bool ret = load_vtk_data(path,prim,0); + bool ret; + + if(type == "mesh") + ret = load_vtk_data(path,prim,0); + else + ret = read_unstructured_grid_to_points(path, prim); - if(view_interior && prim->quads.size() > 0){ + if(type == "mesh") { + if (view_interior && prim->quads.size() > 0) { prim->tris.resize(prim->quads.size() * 4); - + constexpr auto space = zs::execspace_e::openmp; auto ompExec = zs::omp_exec(); - ompExec(zs::range(prim->quads.size()), - [prim] (int ei) mutable { - const auto& tet = prim->quads[ei]; - // for(int i = 0;i < 4;++i) - prim->tris[ei * 4 + 0] = zeno::vec3i{tet[0],tet[1],tet[2]}; - prim->tris[ei * 4 + 1] = zeno::vec3i{tet[1],tet[3],tet[2]}; - prim->tris[ei * 4 + 2] = zeno::vec3i{tet[0],tet[2],tet[3]}; - prim->tris[ei * 4 + 3] = zeno::vec3i{tet[0],tet[3],tet[1]}; - }); + ompExec(zs::range(prim->quads.size()), [prim](int ei) mutable { + const auto &tet = prim->quads[ei]; + // for(int i = 0;i < 4;++i) + prim->tris[ei * 4 + 0] = zeno::vec3i{tet[0], tet[1], tet[2]}; + prim->tris[ei * 4 + 1] = zeno::vec3i{tet[1], tet[3], tet[2]}; + prim->tris[ei * 4 + 2] = zeno::vec3i{tet[0], tet[2], tet[3]}; + prim->tris[ei * 4 + 3] = zeno::vec3i{tet[0], tet[3], tet[1]}; + }); + } } set_output("prim",std::move(prim)); @@ -47,6 +54,7 @@ struct ReadVTKMesh : INode { ZENDEFNODE(ReadVTKMesh, {/* inputs: */ { {"readpath", "path"}, + {"enum verts mesh", "method", "verts"}, }, /* outputs: */ { diff --git a/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp b/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp index bc03a2fc2f..b7198d5dad 100644 --- a/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp +++ b/projects/CuLagrange/geometry/file_parser/read_vtk_mesh.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include @@ -543,7 +544,200 @@ namespace zeno { printf("finish reading polydata\n"); return true; } + bool stringReplace(std::string &in, std::string del, std::string add) + { + size_t start_pos = in.find(del); + if(start_pos == std::string::npos) + return false; + in.replace(start_pos, del.length(), add); + return true; + } + bool read_unstructured_grid_to_points(std::string file_name, std::shared_ptr& prim) + { + std::ifstream file; + file.open(file_name.c_str()); + int num_points; + int num_field_data; + std::string readtype; + while(!file.eof()) + { + std::string line_str; + std::getline(file,line_str); + if(line_str == "BINARY") + { + readtype = "BINARY"; + } + if(line_str == "ASCII") + { + readtype = "ASCII"; + } + if(line_str.find("POINTS ")!=std::string::npos) + { + std::string a; + std::string type; + std::stringstream ss; + ss<>a>>num_points>>type; + prim->verts.resize(num_points); + if(readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) + file >> prim->verts[i][j]; + } + }else if(readtype == "BINARY") + { + //read chunck of buffer + } + } + else if(line_str.find("Velocity ")!=std::string::npos) + { + prim->verts.add_attr("Velocity"); + if(readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) + file >> prim->verts.attr("Velocity")[i][j]; + } + }else if(readtype == "BINARY"){ + } + } + else if(line_str.find("FieldData ")) + { + std::string a; + std::string b; + std::stringstream ss; + ss<>a>>b>>num_field_data; + } + if(num_field_data>0) { + std::vector strs; + std::string a; + std::stringstream ss; + ss<>a) + { + strs.push_back(a); + } + std::string varname; + if(strs.size()==4 && std::stoi(strs[2]) == num_points) + { + varname = strs[0]; + while(stringReplace(varname, ".", "_")); + while(stringReplace(varname, "-", "_")); + if(strs[1] == "1") { + prim->verts.add_attr(varname); + if(readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + file >> prim->verts.attr(varname)[i]; + } + }else if(readtype == "BINARY") + { + + } + }else if(strs[1] == "3") + { + prim->verts.add_attr(varname); + if(readtype == "ASCII") { + for (int i = 0; i < num_points; i++) { + for (int j = 0; j < 3; j++) + file >> prim->verts.attr(varname)[i][j]; + } + }else if(readtype == "BINARY") + { + + } + } + } + + +// if (line_str.find("SpeciesDensity ") != std::string::npos) { +// prim->verts.add_attr("SpeciesDensity"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("SpeciesDensity")[i]; +// } +// } +// else if (line_str.find("ViscosityEddy ") != std::string::npos) { +// prim->verts.add_attr("ViscosityEddy"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("ViscosityEddy")[i]; +// } +// } +// else if (line_str.find("Mach ") != std::string::npos) { +// prim->verts.add_attr("Mach"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("Mach")[i]; +// } +// } +// else if (line_str.find("MachNumberinStnFrame ") != +// std::string::npos) { +// prim->verts.add_attr("MachNumberinStnFrame"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("MachNumberinStnFrame")[i]; +// } +// } +// else if (line_str.find("Pressure ") != std::string::npos) { +// prim->verts.add_attr("Pressure"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("Pressure")[i]; +// } +// } +// else if (line_str.find("Temperature ") != std::string::npos) { +// prim->verts.add_attr("Temperature"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("Temperature")[i]; +// } +// } +// else if (line_str.find("PressureStagnation ") != std::string::npos) { +// prim->verts.add_attr("PressureStagnation"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("PressureStagnation")[i]; +// } +// } +// else if (line_str.find("TotalPressureinStnFrame ") != +// std::string::npos) { +// prim->verts.add_attr("TotalPressureinStnFrame"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TotalPressureinStnFrame")[i]; +// } +// } +// else if (line_str.find("TemperatureStagnation ") != +// std::string::npos) { +// prim->verts.add_attr("TemperatureStagnation"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TemperatureStagnation")[i]; +// } +// } +// else if (line_str.find("TotalTemperatureinStnFrame ") != +// std::string::npos) { +// prim->verts.add_attr("TotalTemperatureinStnFrame"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TotalTemperatureinStnFrame")[i]; +// } +// } +// else if (line_str.find("TurbulenceEddyFrequency ") != +// std::string::npos) { +// prim->verts.add_attr("TurbulenceEddyFrequency"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TurbulenceEddyFrequency")[i]; +// } +// } +// else if (line_str.find("TurbulentEnergyKinetic ") != +// std::string::npos) { +// prim->verts.add_attr("TurbulentEnergyKinetic"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("TurbulentEnergyKinetic")[i]; +// } +// } +// else if (line_str.find("VelocityinStnFrame ") != std::string::npos) { +// prim->verts.add_attr("VelocityinStnFrame"); +// for (int i = 0; i < num_points; i++) { +// file >> prim->verts.attr("VelocityinStnFrame")[i]; +// } +// } + } + } + file.close(); + } // DATASET UNSTRUCTURED_GRID // POINTS n dataType // p0x p0y p0z @@ -564,6 +758,7 @@ namespace zeno { // type2 // ... // typen-1 + constexpr char unstructured_grid[] = "UNSTRUCTURED_GRID"; bool read_unstructured_grid(FILE *fp,std::shared_ptr& prim,int& line_count) { char *bufferp;