Skip to content

Commit 40576b4

Browse files
authored
Merge pull request #818 from wildmeshing/dzint/shortest_edge_collapse_app_2
Dzint/shortest edge collapse app (version 2)
2 parents f8b433b + 4bd98fb commit 40576b4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+1379
-326
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ include(CDT)
9898
add_library(wildmeshing_toolkit)
9999
add_library(wmtk::toolkit ALIAS wildmeshing_toolkit)
100100
target_link_libraries(wildmeshing_toolkit PUBLIC wmtk_coverage_config)
101-
set_property(TARGET wildmeshing_toolkit PROPERTY COMPILE_WARNING_AS_ERROR OFF)
101+
set_property(TARGET wildmeshing_toolkit PROPERTY COMPILE_WARNING_AS_ERROR ON)
102102

103103

104104
add_subdirectory(src)

applications/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ if(WMTK_ENABLE_APPLICATION_cdt_sec)
4545
add_subdirectory(cdt_sec)
4646
endif()
4747

48+
option(WMTK_ENABLE_APPLICATION_shortest_edge_collapse "Runs shortest-edge collapse application" ON)
49+
if(WMTK_ENABLE_APPLICATION_shortest_edge_collapse)
50+
add_subdirectory(shortest_edge_collapse)
51+
endif()
52+
4853
option(WMTK_ENABLE_APPLICATION_insertion "Runs insertion application" ON)
4954
if(WMTK_ENABLE_APPLICATION_insertion)
5055
add_subdirectory(insertion)

applications/cdt_sec/CMakeLists.txt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ wmtk_add_application(cdt_sec_app
55

66

77

8-
9-
# delaunay requires the input component and the delaunay component
108
target_link_libraries(cdt_sec_app PRIVATE
119
wmtk::input
1210
wmtk::multimesh
13-
wmtk::shortestedge_collapse
11+
wmtk::shortest_edge_collapse
1412
wmtk::CDT
1513
wmtk::output)
1614

applications/cdt_sec/cdt_sec_main.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <wmtk/components/input/input.hpp>
1616
#include <wmtk/components/multimesh/multimesh.hpp>
1717
#include <wmtk/components/output/output.hpp>
18-
#include <wmtk/components/shortestedge_collapse/shortestedge_collapse.hpp>
18+
#include <wmtk/components/shortest_edge_collapse/shortest_edge_collapse.hpp>
1919

2020

2121
#include "cdt_sec_spec.hpp"
@@ -102,14 +102,16 @@ int main(int argc, char* argv[])
102102
parent_mesh->get_attribute_handle<double>("vertices", PrimitiveType::Vertex);
103103

104104
{
105-
components::ShortestEdgeCollapseOptions options;
105+
using namespace components::shortest_edge_collapse;
106+
107+
ShortestEdgeCollapseOptions options;
106108
options.position_handle = child_mesh_position_handle;
107109
options.length_rel = j["length_rel"];
108110
options.envelope_size = j["envelope_size"];
109111
options.inversion_position_handle = parent_mesh_position_handle;
110112
options.pass_through_attributes = pass_through;
111113

112-
components::shortestedge_collapse(static_cast<TriMesh&>(*child_mesh), options);
114+
shortest_edge_collapse(static_cast<TriMesh&>(*child_mesh), options);
113115
}
114116

115117
wmtk::components::output::output(*parent_mesh, output_file, "vertices");
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
include(wmtk_add_application)
2+
wmtk_add_application(shortest_edge_collapse_app
3+
shortest_edge_collapse_main.cpp
4+
shortest_edge_collapse_spec.hpp
5+
)
6+
7+
8+
target_link_libraries(shortest_edge_collapse_app PRIVATE
9+
wmtk::input
10+
wmtk::shortest_edge_collapse
11+
wmtk::output
12+
nlohmann_json::nlohmann_json
13+
)
14+
15+
wmtk_register_integration_test(
16+
EXEC_NAME shortest_edge_collapse_app
17+
CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/shortest_edge_collapse_test_config.json
18+
GIT_REPOSITORY "https://github.com/wildmeshing/data.git"
19+
GIT_TAG e25dc08b023b235795599120978f6d4dfa9a0996)
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
#include <jse/jse.h>
2+
#include <CLI/CLI.hpp>
3+
#include <filesystem>
4+
#include <nlohmann/json.hpp>
5+
6+
#include <wmtk/Mesh.hpp>
7+
#include <wmtk/utils/Logger.hpp>
8+
9+
#include <wmtk/components/input/input.hpp>
10+
#include <wmtk/components/output/output.hpp>
11+
#include <wmtk/components/shortest_edge_collapse/shortest_edge_collapse.hpp>
12+
#include <wmtk/components/utils/resolve_path.hpp>
13+
14+
#include "shortest_edge_collapse_spec.hpp"
15+
16+
using namespace wmtk;
17+
namespace fs = std::filesystem;
18+
19+
using wmtk::components::utils::resolve_paths;
20+
21+
int main(int argc, char* argv[])
22+
{
23+
CLI::App app{argv[0]};
24+
25+
app.ignore_case();
26+
27+
fs::path json_input_file;
28+
app.add_option("-j, --json", json_input_file, "json specification file")
29+
->required(true)
30+
->check(CLI::ExistingFile);
31+
CLI11_PARSE(app, argc, argv);
32+
33+
nlohmann::json j;
34+
{
35+
std::ifstream ifs(json_input_file);
36+
j = nlohmann::json::parse(ifs);
37+
38+
jse::JSE spec_engine;
39+
bool r = spec_engine.verify_json(j, shortest_edge_collapse_spec);
40+
if (!r) {
41+
wmtk::logger().error("{}", spec_engine.log2str());
42+
return 1;
43+
} else {
44+
j = spec_engine.inject_defaults(j, shortest_edge_collapse_spec);
45+
}
46+
}
47+
48+
const fs::path input_file = resolve_paths(json_input_file, {j["input_path"], j["input"]});
49+
50+
std::shared_ptr<Mesh> mesh_in = wmtk::components::input::input(input_file);
51+
Mesh& mesh = *mesh_in;
52+
53+
54+
attribute::MeshAttributeHandle pos_handle =
55+
mesh.get_attribute_handle<double>("vertices", PrimitiveType::Vertex);
56+
57+
// shortest-edge collapse
58+
{
59+
using namespace components::shortest_edge_collapse;
60+
ShortestEdgeCollapseOptions options;
61+
options.position_handle = pos_handle;
62+
options.length_rel = j["length_rel"];
63+
const double env_size = j["envelope_size"];
64+
if (env_size >= 0) {
65+
options.envelope_size = j["envelope_size"];
66+
}
67+
options.lock_boundary = j["lock_boundary"];
68+
69+
shortest_edge_collapse(static_cast<TriMesh&>(mesh), options);
70+
}
71+
72+
wmtk::components::output::output(mesh, j["output"], pos_handle);
73+
74+
const std::string report = j["report"];
75+
if (!report.empty()) {
76+
nlohmann::json out_json;
77+
out_json["stats"]["vertices"] = mesh.get_all(PrimitiveType::Vertex).size();
78+
out_json["stats"]["edges"] = mesh.get_all(PrimitiveType::Edge).size();
79+
out_json["stats"]["triangles"] = mesh.get_all(PrimitiveType::Triangle).size();
80+
out_json["stats"]["tets"] = mesh.get_all(PrimitiveType::Tetrahedron).size();
81+
82+
out_json["input"] = j;
83+
84+
std::ofstream ofs(report);
85+
ofs << std::setw(4) << out_json;
86+
}
87+
88+
89+
return 0;
90+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#pragma once
2+
#include <nlohmann/json.hpp>
3+
namespace {
4+
5+
nlohmann::json shortest_edge_collapse_spec = R"(
6+
[
7+
{
8+
"pointer": "/",
9+
"type": "object",
10+
"required": ["input", "output"],
11+
"optional": [
12+
"length_rel",
13+
"envelope_size",
14+
"lock_boundary",
15+
"report",
16+
"input_path"
17+
]
18+
},
19+
{
20+
"pointer": "/input",
21+
"type": "string"
22+
},
23+
{
24+
"pointer": "/output",
25+
"type": "string"
26+
},
27+
{
28+
"pointer": "/length_rel",
29+
"type": "float",
30+
"default": 0.1,
31+
"doc": "The desired edge length relative to the AABB."
32+
},
33+
{
34+
"pointer": "/envelope_size",
35+
"type": "float",
36+
"default": 0.001,
37+
"doc": "The envelope size relative to the AABB. Set this to a negative value to deactivate the envelope."
38+
},
39+
{
40+
"pointer": "/lock_boundary",
41+
"type": "bool",
42+
"default": false,
43+
"doc": "Are boundary vertices allowed to be collapsed?"
44+
},
45+
{
46+
"pointer": "/report",
47+
"type": "string",
48+
"default": ""
49+
},
50+
{
51+
"pointer": "/input_path",
52+
"type": "string",
53+
"default": ""
54+
}
55+
]
56+
)"_json;
57+
58+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
[
2+
{
3+
"pointer": "/",
4+
"type": "object",
5+
"required": ["input", "output"],
6+
"optional": [
7+
"length_rel",
8+
"envelope_size",
9+
"lock_boundary",
10+
"report",
11+
"input_path"
12+
]
13+
},
14+
{
15+
"pointer": "/input",
16+
"type": "string"
17+
},
18+
{
19+
"pointer": "/output",
20+
"type": "string"
21+
},
22+
{
23+
"pointer": "/length_rel",
24+
"type": "float",
25+
"default": 0.1,
26+
"doc": "The desired edge length relative to the AABB."
27+
},
28+
{
29+
"pointer": "/envelope_size",
30+
"type": "float",
31+
"default": 0.001,
32+
"doc": "The envelope size relative to the AABB. Set this to a negative value to deactivate the envelope."
33+
},
34+
{
35+
"pointer": "/lock_boundary",
36+
"type": "bool",
37+
"default": false,
38+
"doc": "Are boundary vertices allowed to be collapsed?"
39+
},
40+
{
41+
"pointer": "/report",
42+
"type": "string",
43+
"default": ""
44+
},
45+
{
46+
"pointer": "/input_path",
47+
"type": "string",
48+
"default": ""
49+
}
50+
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"test_directory": "unit_test",
3+
"tests": ["shortest_edge_collapse_out.json"],
4+
"input_tag": "input",
5+
"oracle_tag": "report",
6+
"input_directory_tag": "input_path"
7+
}

components/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ add_subdirectory("procedural/wmtk/components/procedural")
2828
add_subdirectory("tetwild_simplification/wmtk/components/tetwild_simplification")
2929
add_subdirectory("isotropic_remeshing/wmtk/components/isotropic_remeshing")
3030

31-
add_subdirectory("shortestedge_collapse/wmtk/components/shortestedge_collapse")
31+
add_subdirectory("shortest_edge_collapse/wmtk/components/shortest_edge_collapse")
3232
add_subdirectory("CDT/wmtk/components/CDT")
3333

3434
# add_component("export_cache")
@@ -41,7 +41,6 @@ add_subdirectory("CDT/wmtk/components/CDT")
4141
# add_component("fusion")
4242
# add_component("winding_number")
4343
# add_component("periodic_optimization")
44-
# add_component("shortestedge_collapse")
4544

4645

4746

0 commit comments

Comments
 (0)