Wildmeshing Toolkit
EdgeSplit.cpp
Go to the documentation of this file.
1 #include "EdgeSplit.hpp"
2 
3 #include <wmtk/EdgeMesh.hpp>
4 #include <wmtk/Mesh.hpp>
5 #include <wmtk/TetMesh.hpp>
6 #include <wmtk/TriMesh.hpp>
8 #include <wmtk/utils/Logger.hpp>
9 
11 #include <wmtk/utils/Logger.hpp>
12 
15 
16 namespace wmtk::operations {
18 {
19  bool all_configured = true;
20  for (const auto& strat : m_new_attr_strategies) {
21  if (strat->invalid_state()) {
22  all_configured = false;
23  wmtk::logger().warn("Attribute new {} was not configured", strat->name());
24  }
25  }
26  return all_configured;
27 }
28 
30  : Operation(m)
31 {
32  auto collect_attrs = [&](auto&& mesh) {
33  // can have const variant values here so gotta filter htose out
34  if constexpr (!std::is_const_v<std::remove_reference_t<decltype(mesh)>>) {
35  for (const auto& attr : mesh.custom_attributes()) {
36  std::visit(
37  [&](auto&& tah) noexcept {
38  using HandleType = typename std::decay_t<decltype(tah)>;
39  if constexpr (attribute::MeshAttributeHandle::template handle_type_is_basic<
40  HandleType>()) {
41  using T = typename HandleType::Type;
42  m_new_attr_strategies.emplace_back(
45  }
46  },
47  attr);
48  }
49  }
50  };
51 
52  multimesh::MultiMeshVisitor custom_attribute_collector(collect_attrs);
53  custom_attribute_collector.execute_from_root(m);
54 }
55 
56 std::vector<simplex::Simplex> EdgeSplit::execute(const simplex::Simplex& simplex)
57 {
59  mesh(),
60  simplex,
62 }
63 std::vector<simplex::Simplex> EdgeSplit::unmodified_primitives(
64  const simplex::Simplex& simplex) const
65 {
66  return {simplex};
67 }
68 
69 
70 std::shared_ptr<const operations::BaseSplitNewAttributeStrategy>
72 {
73  for (auto& s : m_new_attr_strategies) {
74  if (s->matches_attribute(attribute)) return s;
75  }
76 
77  throw std::runtime_error("unable to find attribute");
78 }
79 
80 
82 {
83  m_new_attr_strategies.clear();
84 }
86  const attribute::MeshAttributeHandle& attribute,
87  const std::shared_ptr<const operations::BaseSplitNewAttributeStrategy>& other)
88 {
89  for (size_t i = 0; i < m_new_attr_strategies.size(); ++i) {
90  if (m_new_attr_strategies[i]->matches_attribute(attribute)) {
91  m_new_attr_strategies[i] = other;
92  return;
93  }
94  }
95 
96  throw std::runtime_error("unable to find attribute");
97 }
98 
100  const attribute::MeshAttributeHandle& attribute,
103 {
104  std::visit(
105  [&](auto&& val) noexcept -> void {
106  using HandleType = typename std::decay_t<decltype(val)>;
107  if constexpr (attribute::MeshAttributeHandle::template handle_type_is_basic<
108  HandleType>()) {
109  using T = typename HandleType::Type;
111 
112  std::shared_ptr<OpType> tmp = std::make_shared<OpType>(attribute);
113  tmp->set_strategy(spine);
114  tmp->set_rib_strategy(rib);
115 
116  set_new_attribute_strategy(attribute, tmp);
117  }
118  },
119  attribute.handle());
120 }
121 
122 std::pair<Tuple, Tuple> EdgeSplit::new_spine_edges(const Mesh& mesh, const Tuple& new_vertex)
123 {
124  // new_vertex is a spine edge on a face pointing to the new vertex, so we
125  // * PE -> new edge
126  // * PF -> other face
127  // * PE -> other spine edge
128  constexpr static PrimitiveType PE = PrimitiveType::Edge;
129  constexpr static PrimitiveType PF = PrimitiveType::Triangle;
130  constexpr static PrimitiveType PT = PrimitiveType::Tetrahedron;
131 
132  std::pair<Tuple, Tuple> ret;
133 
134  switch (mesh.top_simplex_type()) {
135  case PE: {
136  ret = {new_vertex, mesh.switch_tuples(new_vertex, {PE})};
137  break;
138  }
139  case PF: {
140  ret = {new_vertex, mesh.switch_tuples(new_vertex, {PE, PF, PE})};
141  break;
142  }
143  case PT: {
144  ret = {new_vertex, mesh.switch_tuples(new_vertex, {PE, PF, PT, PF, PE})};
145  break;
146  }
148  default: assert(false); // "Invalid top simplex"
149  }
150  return ret;
151 }
152 
153 
154 } // namespace wmtk::operations
std::vector< attribute::MeshAttributeHandle::HandleVariant > custom_attributes() const
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition: Mesh.hpp:967
PrimitiveType top_simplex_type() const
Definition: Mesh.hpp:996
std::vector< simplex::Simplex > unmodified_primitives(const simplex::Simplex &simplex) const override
Returns all simplices that will be potentially affected by the operation.
Definition: EdgeSplit.cpp:63
std::vector< std::shared_ptr< const operations::BaseSplitNewAttributeStrategy > > m_new_attr_strategies
Definition: EdgeSplit.hpp:47
bool attribute_new_all_configured() const
Definition: EdgeSplit.cpp:17
void set_new_attribute_strategy(const attribute::MeshAttributeHandle &attribute, const std::shared_ptr< const operations::BaseSplitNewAttributeStrategy > &other)
Definition: EdgeSplit.cpp:85
static std::pair< Tuple, Tuple > new_spine_edges(const Mesh &mesh, const Tuple &new_vertex)
Definition: EdgeSplit.cpp:122
std::vector< simplex::Simplex > execute(const simplex::Simplex &simplex) override
Definition: EdgeSplit.cpp:56
std::shared_ptr< const operations::BaseSplitNewAttributeStrategy > get_new_attribute_strategy(const attribute::MeshAttributeHandle &attribute) const
Definition: EdgeSplit.cpp:71
const Mesh & mesh() const
Definition: Operation.hpp:45
constexpr wmtk::PrimitiveType PT
constexpr wmtk::PrimitiveType PF
std::vector< simplex::Simplex > multi_mesh_edge_split_with_modified_simplices(Mesh &mesh, const simplex::Simplex &simplex, const std::vector< std::shared_ptr< const operations::BaseSplitNewAttributeStrategy >> &new_attr_strategies)
spdlog::logger & logger()
Retrieves the current logger.
Definition: Logger.cpp:58
constexpr PrimitiveType PE