Wildmeshing Toolkit
CDT.cpp
Go to the documentation of this file.
1 
2 
3 //
4 #include "CDT.hpp"
5 #include <wmtk/Scheduler.hpp>
7 #include <wmtk/utils/Logger.hpp>
9 #include <wmtk/utils/orient.hpp>
10 
12 
13 #include "cdt_lib.hpp"
14 #include "get_vf.hpp"
15 
17 
18 std::shared_ptr<wmtk::TetMesh> CDT_internal(
19  const wmtk::TriMesh& m,
20  std::vector<std::array<bool, 4>>& local_f_on_input,
21  bool inner_only,
22  bool rational_output)
23 {
24  auto [vdat, fdat] = get_vf(m);
25  std::vector<double> V_tmp;
26  uint32_t npts, ntri;
27  std::tie(V_tmp, npts) = vdat;
28  std::vector<uint32_t> F;
29 
30  std::tie(F, ntri) = fdat;
31 
32  std::vector<std::array<int64_t, 4>> T_final;
33  std::vector<std::array<std::string, 3>> V_final_str;
34 
36  V_tmp,
37  npts,
38  F,
39  ntri,
40  local_f_on_input,
41  T_final,
42  V_final_str,
43  inner_only);
44 
45 
47 
48  T.resize(T_final.size(), 4);
49 
50  for (int64_t i = 0; i < T_final.size(); ++i) {
51  T(i, 0) = T_final[i][0];
52  T(i, 1) = T_final[i][1];
53  T(i, 2) = T_final[i][2];
54  T(i, 3) = T_final[i][3];
55  }
56 
57  std::shared_ptr<wmtk::TetMesh> tm = std::make_shared<wmtk::TetMesh>();
58  tm->initialize(T);
59 
60 
62  V.resize(V_final_str.size(), 3);
63 
64  for (int64_t i = 0; i < V_final_str.size(); ++i) {
65  V(i, 0).init_from_binary(V_final_str[i][0]);
66  V(i, 1).init_from_binary(V_final_str[i][1]);
67  V(i, 2).init_from_binary(V_final_str[i][2]);
68  }
69 
70  if (rational_output) {
71  // check inversion
72  for (int64_t i = 0; i < T_final.size(); ++i) {
74  V.row(T(i, 0)),
75  V.row(T(i, 1)),
76  V.row(T(i, 2)),
77  V.row(T(i, 3))) < 0) {
78  auto tmp = T(i, 0);
79  T(i, 0) = T(i, 1);
80  T(i, 1) = tmp;
81 
82  wmtk::logger().info("inverted tet rational, swap 0 1");
83  }
84  }
85 
87 
88  auto rounding_pt_attribute =
89  tm->get_attribute_handle_typed<Rational>("vertices", PrimitiveType::Vertex);
90 
91 
92  auto rounding = std::make_shared<wmtk::operations::Rounding>(*tm, rounding_pt_attribute);
93  rounding->add_invariant(
94  std::make_shared<SimplexInversionInvariant<Rational>>(*tm, rounding_pt_attribute));
95 
96  Scheduler scheduler;
97  auto stats = scheduler.run_operation_on_all(*rounding);
98 
99  logger().info(
100  "Executed rounding, {} ops (S/F) {}/{}. Time: collecting: {}, sorting: {}, "
101  "executing: {}",
102  stats.number_of_performed_operations(),
103  stats.number_of_successful_operations(),
104  stats.number_of_failed_operations(),
105  stats.collecting_time,
106  stats.sorting_time,
107  stats.executing_time);
108  } else {
109  MatrixX<double> V_double;
110  V_double.resize(V_final_str.size(), 3);
111 
112  V_double = V.cast<double>();
113 
114  // check inversion
115  for (int64_t i = 0; i < T_final.size(); ++i) {
117  V_double.row(T(i, 0)),
118  V_double.row(T(i, 1)),
119  V_double.row(T(i, 2)),
120  V_double.row(T(i, 3))) < 0) {
121  auto tmp = T(i, 0);
122  T(i, 0) = T(i, 1);
123  T(i, 1) = tmp;
124 
125  wmtk::logger().info("inverted tet double, swap 0 1");
126  }
127  }
128 
129  mesh_utils::set_matrix_attribute(V_double, "vertices", PrimitiveType::Vertex, *tm);
130  }
131 
132 
133  return tm;
134 }
135 
136 } // namespace wmtk::components::internal
SchedulerStats run_operation_on_all(operations::Operation &op)
Definition: Scheduler.cpp:33
void cdt_to_string(const std::vector< double > &V, const uint32_t npts, const std::vector< uint32_t > &F, const uint32_t ntri, std::vector< std::array< bool, 4 >> &local_f_on_input, std::vector< std::array< int64_t, 4 >> &T_final, std::vector< std::array< std::string, 3 >> &V_final, bool inner_only)
Definition: cdt_lib.cpp:166
std::shared_ptr< wmtk::TetMesh > CDT_internal(const wmtk::TriMesh &m, std::vector< std::array< bool, 4 >> &local_f_on_input, bool inner_only, bool rational_output)
Definition: CDT.cpp:18
std::tuple< std::pair< std::vector< double >, uint32_t >, std::pair< std::vector< uint32_t >, uint32_t > > get_vf(const TriMesh &trimesh)
Definition: get_vf.cpp:9
attribute::MeshAttributeHandle set_matrix_attribute(const Mat &data, const std::string &name, const PrimitiveType &type, Mesh &mesh)
Definition: mesh_utils.hpp:9
int wmtk_orient3d(const Eigen::Ref< const Eigen::Vector3< Rational >> &p0, const Eigen::Ref< const Eigen::Vector3< Rational >> &p1, const Eigen::Ref< const Eigen::Vector3< Rational >> &p2, const Eigen::Ref< const Eigen::Vector3< Rational >> &p3)
Definition: orient.cpp:75
spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:58
Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Definition: Types.hpp:14