Skip to content

Commit

Permalink
Merge pull request #834 from wildmeshing/jiacheng/tetwild_triwild_cle…
Browse files Browse the repository at this point in the history
…anup

tetwild triwild cleanup
  • Loading branch information
JcDai authored Nov 4, 2024
2 parents 0ed5ebe + be6f3f4 commit 01b4d9e
Show file tree
Hide file tree
Showing 16 changed files with 290 additions and 84 deletions.
1 change: 1 addition & 0 deletions applications/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ add_application(multimesh OFF)
add_application(isotropic_remeshing OFF)
add_application(tetwild_simplification ON)
add_application(triwild ON)
add_application(tetwild ON)
add_application(cdt_sec ON)
add_application(shortest_edge_collapse ON)
add_application(insertion ON)
Expand Down
17 changes: 14 additions & 3 deletions applications/tetwild/tetwild_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using wmtk::components::utils::resolve_paths;

int main(int argc, char* argv[])
{
opt_logger().set_level(spdlog::level::off);
CLI::App app{argv[0]};

app.ignore_case();
Expand Down Expand Up @@ -69,7 +70,7 @@ int main(int argc, char* argv[])
auto [out, stats] = tetwild_simplification(
static_cast<const TriMesh&>(*mesh),
"vertices",
j["target_edge_length"]);
j["envelope_size"]);
mesh_after_simp = out;
}

Expand Down Expand Up @@ -103,6 +104,14 @@ int main(int argc, char* argv[])
true,
false);

std::string output_file = j["output"];

wmtk::components::output::output(*main_mesh, output_file + "_after_insertion", "vertices");
wmtk::components::output::output(
*child_meshes.surface_mesh,
output_file + "_surface_after_insertion",
"vertices");

std::vector<wmtk::components::EnvelopeOptions> enves;

wmtk::components::EnvelopeOptions e_surface;
Expand Down Expand Up @@ -163,12 +172,14 @@ int main(int argc, char* argv[])
wmo.intermediate_output_name = j["output"];
wmo.envelopes = enves;
wmo.pass_through = pass_through;
wmo.skip_split = j["skip_split"];
wmo.skip_collapse = j["skip_collapse"];
wmo.skip_swap = j["skip_swap"];
wmo.skip_smooth = j["skip_smooth"];

auto meshes_after_tetwild = wildmeshing(wmo);
auto main_mesh_after_tetwild = meshes_after_tetwild[0].first;

std::string output_file = j["output"];

std::shared_ptr<Mesh> surface_mesh;
for (int64_t i = 1; i < meshes_after_tetwild.size(); ++i) {
// output child meshes
Expand Down
40 changes: 32 additions & 8 deletions applications/tetwild/tetwild_spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ nlohmann::json tetwild_spec = R"(
"envelope_size",
"target_edge_length",
"skip_simplification",
"max_amips",
"target_max_amips",
"max_passes",
"intermediate_output"
"intermediate_output",
"skip_split",
"skip_collapse",
"skip_swap",
"skip_smooth"
]
},
{
Expand All @@ -28,11 +32,6 @@ nlohmann::json tetwild_spec = R"(
"type": "float",
"default": 0.001
},
{
"pointer": "/length_rel",
"type": "float",
"default": 0.1
},
{
"pointer": "/skip_simplification",
"type": "bool",
Expand All @@ -44,15 +43,40 @@ nlohmann::json tetwild_spec = R"(
"default": false
},
{
"pointer": "/max_amips",
"pointer": "/target_max_amips",
"type": "float",
"default": 10.0
},
{
"pointer": "/target_edge_length",
"type": "float",
"default": 0.05
},
{
"pointer": "/max_passes",
"type": "int",
"default": 10
},
{
"pointer": "/skip_split",
"type": "bool",
"default": false
},
{
"pointer": "/skip_collapse",
"type": "bool",
"default": false
},
{
"pointer": "/skip_swap",
"type": "bool",
"default": false
},
{
"pointer": "/skip_smooth",
"type": "bool",
"default": false
},
{
"pointer": "/output",
"type": "string"
Expand Down
7 changes: 6 additions & 1 deletion applications/triwild/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ wmtk::procedural
wmtk::edge_insertion
wmtk::wildmeshing
wmtk::winding_number
wmtk::output)
wmtk::output)

wmtk_register_integration_test(EXEC_NAME triwild_app
CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/triwild_test_config.json
GIT_REPOSITORY "https://github.com/wildmeshing/data.git"
GIT_TAG 82ea9d55c901bbc86d48de39383e9c85d8f67686)
4 changes: 4 additions & 0 deletions applications/triwild/triwild_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ int main(int argc, char* argv[])
wmo.intermediate_output_name = j["output"];
wmo.envelopes = enves;
wmo.pass_through = pass_through;
wmo.skip_split = j["skip_split"];
wmo.skip_collapse = j["skip_collapse"];
wmo.skip_swap = j["skip_swap"];
wmo.skip_smooth = j["skip_smooth"];

auto meshes_after_tetwild = wildmeshing(wmo);
auto main_mesh = meshes_after_tetwild[0].first;
Expand Down
26 changes: 25 additions & 1 deletion applications/triwild/triwild_spec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ nlohmann::json triwild_spec = R"(
"target_edge_length",
"target_max_amips",
"max_passes",
"intermediate_output"
"intermediate_output",
"skip_split",
"skip_collapse",
"skip_swap",
"skip_smooth"
]
},
{
Expand All @@ -37,6 +41,26 @@ nlohmann::json triwild_spec = R"(
"type": "bool",
"default": false
},
{
"pointer": "/skip_split",
"type": "bool",
"default": false
},
{
"pointer": "/skip_collapse",
"type": "bool",
"default": false
},
{
"pointer": "/skip_swap",
"type": "bool",
"default": false
},
{
"pointer": "/skip_smooth",
"type": "bool",
"default": false
},
{
"pointer": "/target_max_amips",
"type": "float",
Expand Down
Empty file.
9 changes: 9 additions & 0 deletions applications/triwild/triwild_test_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"test_directory": "unit_test",
"tests": ["triwild_siggraph_icon_out.json"],
"input_tag": "input",
"oracle_tag": "report",
"input_directory_tag": "root",
"platform": "Linux",
"checks": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(
auto [tetmesh, tet_face_on_input_surface] =
utils::generate_raw_tetmesh_from_input_surface(V, F, Vbg, Fbg);

ChildMeshes child_meshes;
std::shared_ptr<Mesh> surface_mesh = child_meshes.surface_mesh;
std::shared_ptr<Mesh> open_boundary_mesh = child_meshes.open_boundary_mesh;
std::shared_ptr<Mesh> nonmanifold_edge_mesh = child_meshes.nonmanifold_edge_mesh;
std::shared_ptr<Mesh> bbox_mesh = child_meshes.bbox_mesh;

/* -------------rounding------------ */

if (round) {
Expand All @@ -95,6 +89,8 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(
stats.executing_time);
}

ChildMeshes child_meshes;

if (track_submeshes) {
/* -----------input surface--------- */

Expand Down Expand Up @@ -133,18 +129,19 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(

if (make_child_free) {
logger().info("Making free child surface mesh");
surface_mesh = wmtk::multimesh::utils::extract_and_register_child_mesh_from_tag_handle(
*tetmesh,
surface_handle.as<int64_t>(),
1,
/*free = */ true);
child_meshes.surface_mesh =
wmtk::multimesh::utils::extract_and_register_child_mesh_from_tag_handle(
*tetmesh,
surface_handle.as<int64_t>(),
1,
/*free = */ true);

} else {
logger().info("Making child surface mesh");
internal::MultiMeshFromTag SurfaceMeshFromTag(*tetmesh, surface_handle, 1);
SurfaceMeshFromTag.compute_substructure_mesh();

surface_mesh = tetmesh->get_child_meshes().back();
child_meshes.surface_mesh = tetmesh->get_child_meshes().back();

SurfaceMeshFromTag.remove_soup();
}
Expand All @@ -168,12 +165,13 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(
bool has_nonmanifold_edge = false;

logger().info("Looping edges for open/nonmanifold ones");
for (const auto& e : surface_mesh->get_all(PrimitiveType::Edge)) {
const auto surface_edge = simplex::Simplex::edge(*surface_mesh, e);
if (!surface_mesh->is_boundary(surface_edge)) continue;
for (const auto& e : child_meshes.surface_mesh->get_all(PrimitiveType::Edge)) {
const auto surface_edge = simplex::Simplex::edge(*child_meshes.surface_mesh, e);
if (!child_meshes.surface_mesh->is_boundary(surface_edge)) continue;

const auto& parent_e = surface_mesh->map_to_parent(surface_edge);
const auto& child_e = tetmesh->map_to_child_tuples(*surface_mesh, parent_e);
const auto& parent_e = child_meshes.surface_mesh->map_to_parent(surface_edge);
const auto& child_e =
tetmesh->map_to_child_tuples(*child_meshes.surface_mesh, parent_e);

assert(child_e.size() > 0);

Expand All @@ -196,7 +194,7 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(
if (has_openboundary) {
if (make_child_free) {
logger().error("Creating free open boundary child mesh");
open_boundary_mesh =
child_meshes.open_boundary_mesh =
wmtk::multimesh::utils::extract_and_register_child_mesh_from_tag_handle(
*tetmesh,
open_boundary_handle.as<int64_t>(),
Expand All @@ -208,7 +206,7 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(
internal::MultiMeshFromTag OpenBoundaryFromTag(*tetmesh, open_boundary_handle, 1);
OpenBoundaryFromTag.compute_substructure_mesh();

open_boundary_mesh = tetmesh->get_child_meshes().back();
child_meshes.open_boundary_mesh = tetmesh->get_child_meshes().back();
OpenBoundaryFromTag.remove_soup();
}
}
Expand All @@ -218,7 +216,7 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(
internal::MultiMeshFromTag NonmanifoldEdgeFromTag(*tetmesh, nonmanifold_edge_handle, 1);
NonmanifoldEdgeFromTag.compute_substructure_mesh();

nonmanifold_edge_mesh = tetmesh->get_child_meshes().back();
child_meshes.nonmanifold_edge_mesh = tetmesh->get_child_meshes().back();
NonmanifoldEdgeFromTag.remove_soup();
}

Expand All @@ -237,7 +235,7 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(
internal::MultiMeshFromTag NonmanifoldEdgeFromTag(*tetmesh, bbox_handle, 1);
NonmanifoldEdgeFromTag.compute_substructure_mesh();

bbox_mesh = tetmesh->get_child_meshes().back();
child_meshes.bbox_mesh = tetmesh->get_child_meshes().back();
NonmanifoldEdgeFromTag.remove_soup();


Expand All @@ -249,20 +247,23 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(
auto nonmanifold_vertex_accessor =
tetmesh->create_accessor<int64_t>(nonmanifold_vertex_handle);

pass_through.push_back(nonmanifold_vertex_handle);

for (const auto& v : tetmesh->get_all(PrimitiveType::Vertex)) {
int64_t on_open_boundary_cnt = 0;
int64_t on_nonmanifold_edge_cnt = 0;

if (has_openboundary) {
on_open_boundary_cnt =
tetmesh
->map_to_child(*open_boundary_mesh, simplex::Simplex::vertex(*tetmesh, v))
.size();
on_open_boundary_cnt = tetmesh
->map_to_child(
*child_meshes.open_boundary_mesh,
simplex::Simplex::vertex(*tetmesh, v))
.size();
}
if (process_nonmanifold_edges) {
on_nonmanifold_edge_cnt = tetmesh
->map_to_child(
*nonmanifold_edge_mesh,
*child_meshes.nonmanifold_edge_mesh,
simplex::Simplex::vertex(*tetmesh, v))
.size();
}
Expand All @@ -273,8 +274,10 @@ std::tuple<std::shared_ptr<wmtk::TetMesh>, ChildMeshes> triangle_insertion(
} else if (
// not on the edgemeshes and more than 1 copy on the surface mesh
on_open_boundary_cnt + on_nonmanifold_edge_cnt == 0 &&
tetmesh->map_to_child(*surface_mesh, simplex::Simplex::vertex(*tetmesh, v)).size() >
1) {
tetmesh->map_to_child(
*child_meshes.surface_mesh,
simplex::Simplex::vertex(*tetmesh, v))
.size() > 1) {
nonmanifold_vertex_accessor.scalar_attribute(v) = 1;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ struct WildMeshingOptions
std::string intermediate_output_path;
std::string intermediate_output_name;

bool skip_split;
bool skip_collapse;
bool skip_swap;
bool skip_smooth;

std::vector<EnvelopeOptions> envelopes;
std::vector<attribute::MeshAttributeHandle> pass_through;
};
Expand Down
Loading

0 comments on commit 01b4d9e

Please sign in to comment.