From 7da03b6c31f57db805c036d01d47986d38cffb74 Mon Sep 17 00:00:00 2001 From: seeeagull Date: Fri, 15 Dec 2023 13:48:17 +0800 Subject: [PATCH 1/3] init tetwild --- projects/Geometry/CMakeLists.txt | 4 +- projects/Geometry/tetmesh.cpp | 232 +++++++++++++++++++++++++++++++ 2 files changed, 235 insertions(+), 1 deletion(-) create mode 100644 projects/Geometry/tetmesh.cpp diff --git a/projects/Geometry/CMakeLists.txt b/projects/Geometry/CMakeLists.txt index b4eb1ce357..f0bdff4a71 100644 --- a/projects/Geometry/CMakeLists.txt +++ b/projects/Geometry/CMakeLists.txt @@ -3,6 +3,8 @@ project(Geometry) cmake_minimum_required(VERSION 3.16) set(CMAKE_CXX_STANDARD 17) -target_sources(zeno PRIVATE quadmesh.cpp) +target_sources(zeno PRIVATE quadmesh.cpp tetmesh.cpp) target_link_libraries(zeno PRIVATE InstantMeshesApi) +target_link_libraries(zeno PRIVATE FTetwildApi) add_subdirectory(instant_meshes) +add_subdirectory(fTetWild) diff --git a/projects/Geometry/tetmesh.cpp b/projects/Geometry/tetmesh.cpp new file mode 100644 index 0000000000..7737f13c36 --- /dev/null +++ b/projects/Geometry/tetmesh.cpp @@ -0,0 +1,232 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "./fTetWild/api.h" + +namespace zeno { + +struct FTetWild : INode { + virtual void apply() override { + auto input_dir = get_input2("input_dir"); + auto output_dir = get_input2("output_dir"); + auto tag = get_input2("tag"); + tag.erase(tag.find_last_not_of(" ")+1); + auto operation = get_input2("operation"); + float edge_length = get_input2("edge_length"); + float epsilon = get_input2("epsilon"); + float stop_energy = get_input2("stop_energy"); + bool skip_simplify = get_input2("skip_simplify"); + bool no_binary = get_input2("no_binary"); + bool no_color = get_input2("no_color"); + bool smooth = get_input2("smooth_open_boundary"); + bool export_raw = get_input2("export_raw"); + bool manifold = get_input2("manifold_surface"); + bool coarsen = get_input2("coarsen"); + auto csg = get_input2("csg"); + csg.erase(csg.find_last_not_of(" ")+1); + bool disable_filter = get_input2("disable_filtering"); + bool floodfill = get_input2("use_floodfill"); + bool general_wn = get_input2("use_general_wn"); + bool input_wn = get_input2("use_input_for_wn"); + auto bg_mesh = get_input2("bg_mesh"); + bg_mesh.erase(bg_mesh.find_last_not_of(" ")+1); + + int argc = 1; + char* argv[40]; + argv[0] = (char*)malloc(sizeof("./FloatTetwild_bin\0")); + strcpy(argv[0], "./FloatTetwild_bin\0"); + if (input_dir.size() > 0) { + argv[argc] = (char*)malloc(sizeof("-i\0")); + strcpy(argv[argc], "-i\0"); + argv[argc+1] = (char*)malloc((input_dir.size()+1)*sizeof(char)); + for (int i = 0; i < input_dir.size(); ++i) + argv[argc+1][i] = input_dir[i]; + argv[argc+1][input_dir.size()] = '\0'; + argc += 2; + } + if (output_dir.size() > 0) { + argv[argc] = (char*)malloc(sizeof("-o\0")); + strcpy(argv[argc], "-o\0"); + argv[argc+1] = (char*)malloc((output_dir.size()+1)*sizeof(char)); + for (int i = 0; i < output_dir.size(); ++i) + argv[argc+1][i] = output_dir[i]; + argv[argc+1][output_dir.size()] = '\0'; + argc += 2; + } + if (tag.size() > 0) { + argv[argc] = (char*)malloc(sizeof("--tag\0")); + strcpy(argv[argc], "--tag\0"); + argv[argc+1] = (char*)malloc((tag.size()+1)*sizeof(char)); + for (int i = 0; i < tag.size(); ++i) + argv[argc+1][i] = tag[i]; + argv[argc+1][tag.size()] = '\0'; + argc += 2; + } + if (operation == "union") { + argv[argc] = (char*)malloc(sizeof("--op\0")); + strcpy(argv[argc], "--op\0"); + argv[argc+1] = (char*)malloc(sizeof("0\0")); + strcpy(argv[argc+1], "0\0"); + argc += 2; + } else if (operation == "intersection") { + argv[argc] = (char*)malloc(sizeof("--op\0")); + strcpy(argv[argc], "--op\0"); + argv[argc+1] = (char*)malloc(sizeof("1\0")); + strcpy(argv[argc+1], "1\0"); + argc += 2; + } else if (operation == "difference") { + argv[argc] = (char*)malloc(sizeof("--op\0")); + strcpy(argv[argc], "--op\0"); + argv[argc+1] = (char*)malloc(sizeof("2\0")); + strcpy(argv[argc+1], "2\0"); + argc += 2; + } + if (edge_length > 0) { + argv[argc] = (char*)malloc(sizeof("-l\0")); + strcpy(argv[argc], "-l\0"); + std::string edge_length_str = to_string(edge_length); + argv[argc+1] = (char*)malloc((edge_length_str.size()+1)*sizeof(char)); + for (int i = 0; i < edge_length_str.size(); ++i) + argv[argc+1][i] = edge_length_str[i]; + argv[argc+1][edge_length_str.size()] = '\0'; + argc += 2; + } + if (epsilon > 0) { + argv[argc] = (char*)malloc(sizeof("-e\0")); + strcpy(argv[argc], "-e\0"); + std::string epsilon_str = to_string(epsilon); + argv[argc+1] = (char*)malloc((epsilon_str.size()+1)*sizeof(char)); + for (int i = 0; i < epsilon_str.size(); ++i) + argv[argc+1][i] = epsilon_str[i]; + argv[argc+1][epsilon_str.size()] = '\0'; + argc += 2; + } + if (stop_energy > 0) { + argv[argc] = (char*)malloc(sizeof("--stop-energy\0")); + strcpy(argv[argc], "--stop-energy\0"); + std::string stop_energy_str = to_string(stop_energy); + argv[argc+1] = (char*)malloc((stop_energy_str.size()+1)*sizeof(char)); + for (int i = 0; i < stop_energy_str.size(); ++i) + argv[argc+1][i] = stop_energy_str[i]; + argv[argc+1][stop_energy_str.size()] = '\0'; + argc += 2; + } + if (skip_simplify) { + argv[argc] = (char*)malloc(sizeof("--skip-simplify\0")); + strcpy(argv[argc], "--skip-simplify\0"); + argc += 1; + } + if (no_binary) { + argv[argc] = (char*)malloc(sizeof("--no-binary\0")); + strcpy(argv[argc], "--no-binary\0"); + argc += 1; + } + if (no_color) { + argv[argc] = (char*)malloc(sizeof("--no-color\0")); + strcpy(argv[argc], "--no-color\0"); + argc += 1; + } + if (smooth) { + argv[argc] = (char*)malloc(sizeof("--smooth-open-boundary\0")); + strcpy(argv[argc], "--smooth-open-boundary\0"); + argc += 1; + } + if (export_raw) { + argv[argc] = (char*)malloc(sizeof("--export-raw\0")); + strcpy(argv[argc], "--export-raw\0"); + argc += 1; + } + if (manifold) { + argv[argc] = (char*)malloc(sizeof("--manifold-surface\0")); + strcpy(argv[argc], "--manifold-surface\0"); + argc += 1; + } + if (coarsen) { + argv[argc] = (char*)malloc(sizeof("--coarsen\0")); + strcpy(argv[argc], "--coarsen\0"); + argc += 1; + } + if (csg.size() > 0) { + argv[argc] = (char*)malloc(sizeof("--csg\0")); + strcpy(argv[argc], "--csg\0"); + argv[argc+1] = (char*)malloc((csg.size()+1)*sizeof(char)); + for (int i = 0; i < csg.size(); ++i) + argv[argc+1][i] = csg[i]; + argv[argc+1][csg.size()] = '\0'; + argc += 2; + } + if (disable_filter) { + argv[argc] = (char*)malloc(sizeof("--disable-filtering\0")); + strcpy(argv[argc], "--disable-filtering\0"); + argc += 1; + } + if (floodfill) { + argv[argc] = (char*)malloc(sizeof("--use-floodfill\0")); + strcpy(argv[argc], "--use-floodfill\0"); + argc += 1; + } + if (general_wn) { + argv[argc] = (char*)malloc(sizeof("--use-general-wn\0")); + strcpy(argv[argc], "--use-general-wn\0"); + argc += 1; + } + if (input_wn) { + argv[argc] = (char*)malloc(sizeof("--use-input-for-wn\0")); + strcpy(argv[argc], "--use-input-for-wn\0"); + argc += 1; + } + if (bg_mesh.size() > 0) { + argv[argc] = (char*)malloc(sizeof("--bg-mesh\0")); + strcpy(argv[argc], "--bg-mesh\0"); + argv[argc+1] = (char*)malloc((bg_mesh.size()+1)*sizeof(char)); + for (int i = 0; i < bg_mesh.size(); ++i) + argv[argc+1][i] = bg_mesh[i]; + argv[argc+1][bg_mesh.size()] = '\0'; + argc += 2; + } + argv[argc] = (char*)malloc(sizeof("--level\0")); + strcpy(argv[argc], "--level\0"); + argv[argc+1] = (char*)malloc(sizeof("3\0")); + strcpy(argv[argc+1], "3\0"); + argc += 2; + + runFTetWild(argc, argv); + } +}; + +ZENO_DEFNODE(FTetWild) +({ + {{"readpath", "input_dir"}, + {"string", "output_dir"}, + {"readpath", "tag", " "}, + {"enum none union intersection difference", "operation", "none"}, + {"float", "edge_length", "0"}, + {"float", "epsilon", "0"}, + {"float", "stop_energy", "0"}, + {"bool", "skip_simplify", "0"}, + {"bool", "no_binary", "0"}, + {"bool", "no_color", "0"}, + {"bool", "smooth_open_boundary", "0"}, + {"bool", "export_raw", "0"}, + {"bool", "manifold_surface", "0"}, + {"bool", "coarsen", "0"}, + {"readpath", "csg", " "}, + {"bool", "disable_filtering", "0"}, + {"bool", "use_floodfill", "0"}, + {"bool", "use_general_wn", "0"}, + {"bool", "use_input_for_wn", "0"}, + {"readpath", "bg_mesh", " "}}, + {}, + {}, + {"primitive"}, +}); + + +} // namespace zeno From 3ea12a20c2e44ba8dd2ad877696bd3e306de7725 Mon Sep 17 00:00:00 2001 From: seeeagull Date: Fri, 15 Dec 2023 13:59:45 +0800 Subject: [PATCH 2/3] upd instant_meshes tbb interface --- projects/Geometry/instant_meshes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/Geometry/instant_meshes b/projects/Geometry/instant_meshes index e43215c14d..d9d8109e4e 160000 --- a/projects/Geometry/instant_meshes +++ b/projects/Geometry/instant_meshes @@ -1 +1 @@ -Subproject commit e43215c14df47f95426c8446d27c355c5ee45f05 +Subproject commit d9d8109e4e5be4a0890e09d5d89fb132055db8ef From 1581e2559934641ab5f930a91869204e121dc1e9 Mon Sep 17 00:00:00 2001 From: seeeagull Date: Fri, 15 Dec 2023 17:48:15 +0800 Subject: [PATCH 3/3] add submodule --- .gitmodules | 3 +++ projects/Geometry/fTetWild | 1 + 2 files changed, 4 insertions(+) create mode 160000 projects/Geometry/fTetWild diff --git a/.gitmodules b/.gitmodules index fa55b9ab10..34e43b2ef6 100644 --- a/.gitmodules +++ b/.gitmodules @@ -28,3 +28,6 @@ [submodule "projects/Geometry/instant_meshes"] path = projects/Geometry/instant_meshes url = https://github.com/seeeagull/instant-meshes.git +[submodule "projects/Geometry/fTetWild"] + path = projects/Geometry/fTetWild + url = https://github.com/seeeagull/fTetWild.git diff --git a/projects/Geometry/fTetWild b/projects/Geometry/fTetWild new file mode 160000 index 0000000000..b20ca8700d --- /dev/null +++ b/projects/Geometry/fTetWild @@ -0,0 +1 @@ +Subproject commit b20ca8700dbe80ea4929b5cbda44367cb258bbf7