Wildmeshing Toolkit
Loading...
Searching...
No Matches
Parameters.h
1#pragma once
2#include <nlohmann/json.hpp>
3#include <wmtk/Types.hpp>
4
5namespace wmtk::components::image_simulation {
7{
8 // parameters set by user
9 double epsr = 2e-3; // relative error bound (wrt diagonal)
10 double eps = -1.; // absolute error bound
11 double lr = 5e-2; // target edge length (relative)
12 double l = -1.; // target edge length (absolute)
13 double l_min = -1;
14 bool preserve_topology = false;
15 std::string output_path;
16
17 double epsr_simplify = 2e-3; // relative error bound (wrt diagonal) for simplification
18 double eps_simplify = -1.; // absolute error bound for simplification
19
20 // parameters set in `init` function based on mesh bbox
21 double diag_l = -1.;
22 VectorXd box_min;
23 VectorXd box_max;
24 double splitting_l2 = -1.; // the lower bound length (squared) for edge split
25 double collapsing_l2 =
26 std::numeric_limits<double>::max(); // the upper bound length (squared) for edge collapse
27
28 double stop_energy = 10;
29 bool stop_at_float = false;
30
31 bool debug_output = false;
32 bool perform_sanity_checks = false;
33
34 // weighting terms for the optimization
35 double w_amips = 1e-4;
36 double w_envelope = 0;
37
38 std::string operation = "remeshing";
39
40 bool skip_simplify = true;
41 bool use_sample_envelope = false;
42 int NUM_THREADS = 0;
43 int max_its = 80;
44 bool write_vtu = false;
45 bool write_envelope = true;
46
47 Parameters() = default;
48
49 Parameters(const nlohmann::json& json_params)
50 {
51 output_path = json_params["output"];
52 skip_simplify = json_params["skip_simplify"];
53 use_sample_envelope = json_params["use_sample_envelope"];
54 NUM_THREADS = json_params["num_threads"];
55 max_its = json_params["max_iterations"];
56 write_vtu = json_params["write_vtu"];
57 write_envelope = json_params["write_envelope"];
58
59 epsr = json_params["eps_rel"];
60 eps = json_params["eps"];
61 lr = json_params["length_rel"];
62 l = json_params["length"];
63 stop_energy = json_params["stop_energy"];
64 stop_at_float = json_params["stop_at_float"];
65 preserve_topology = json_params["preserve_topology"];
66
67 epsr_simplify = json_params["eps_simplify_rel"];
68 eps_simplify = json_params["eps_simplify"];
69
70 w_amips = json_params["w_amips"];
71
72 debug_output = json_params["DEBUG_output"];
73 perform_sanity_checks = json_params["DEBUG_sanity_checks"];
74
75 operation = json_params["operation"];
76 }
77
78 void init(const VectorXd& min_, const VectorXd& max_)
79 {
80 box_min = min_;
81 box_max = max_;
82 diag_l = (box_max - box_min).norm();
83 if (l > 0)
84 lr = l / diag_l;
85 else
86 l = lr * diag_l;
87 splitting_l2 = l * l * (16 / 9.);
88 collapsing_l2 = l * l * (16 / 25.);
89
90 if (eps > 0) {
91 epsr = eps / diag_l;
92 } else {
93 eps = epsr * diag_l;
94 }
95
96 if (eps_simplify > 0) {
97 epsr_simplify = eps_simplify / diag_l;
98 } else {
99 eps_simplify = epsr_simplify * diag_l;
100 }
101
102 l_min = 0.5 * eps;
103 }
104 void init(
105 const std::vector<Vector3d>& vertices,
106 const std::vector<std::array<size_t, 3>>& faces)
107 {
108 Vector3d min_, max_;
109 for (size_t i = 0; i < vertices.size(); i++) {
110 if (i == 0) {
111 min_ = vertices[i];
112 max_ = vertices[i];
113 continue;
114 }
115 for (int j = 0; j < 3; j++) {
116 if (vertices[i][j] < min_[j]) min_[j] = vertices[i][j];
117 if (vertices[i][j] > max_[j]) max_[j] = vertices[i][j];
118 }
119 }
120
121 init(min_, max_);
122 }
123};
124} // namespace wmtk::components::image_simulation