Wildmeshing Toolkit
TriEdgeSwap.cpp
Go to the documentation of this file.
1 #include "TriEdgeSwap.hpp"
2 
3 #include <wmtk/Mesh.hpp>
4 
6 
8  : Operation(m)
9  , m_split(m)
10  , m_collapse(m)
11 {}
12 
13 
14 std::vector<simplex::Simplex> TriEdgeSwap::execute(const simplex::Simplex& simplex)
15 {
16  // input
17  // / \.
18  // / \ .
19  // / f \ .
20  // X--->---
21  // \ /
22  // \ /
23  // \ /
24  const auto split_simplicies = m_split(simplex);
25  if (split_simplicies.empty()) return {};
26  assert(split_simplicies.size() == 1);
27 
28  // after split
29  // /|\ .
30  // / | \ .
31  // / | f\ .
32  // ---X-->
33  // \ | /
34  // \ | /
35  // \|/
36 
37  // switch also face to keep edge orientation
38  const Tuple collapse_input_tuple = mesh().switch_tuples(
39  split_simplicies.front().tuple(),
40  {PrimitiveType::Edge, PrimitiveType::Triangle});
41  // switch edge - switch face
42  // /|\ .
43  // / ^ \ .
44  // /f | \ .
45  // ---X---
46  // \ | /
47  // \ | /
48  // \|/
49  const auto collapse_simplicies =
50  m_collapse(simplex::Simplex(mesh(), m_collapse.primitive_type(), collapse_input_tuple));
51  if (collapse_simplicies.empty()) return {};
52  assert(collapse_simplicies.size() == 1);
53 
54  // collapse output
55  // X
56  // /|\ .
57  // < | \ .
58  // / | \ .
59  // | f | |
60  // \ | /
61  // \ | /
62  // \|/
63  // adjust return tuple to be the swapped edge in the same orientation as the input
64  const Tuple output_tuple = mesh().switch_tuples(
65  collapse_simplicies.front().tuple(),
66  {PrimitiveType::Edge, PrimitiveType::Vertex});
67 
68  return {simplex::Simplex::edge(mesh(), output_tuple)};
69 }
70 
71 
72 std::vector<simplex::Simplex> TriEdgeSwap::unmodified_primitives(
73  const simplex::Simplex& simplex) const
74 {
75  return {simplex};
76 }
77 
78 } // namespace wmtk::operations::composite
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition: Mesh.hpp:968
PrimitiveType primitive_type() const override
const Mesh & mesh() const
Definition: Operation.hpp:45
std::vector< simplex::Simplex > unmodified_primitives(const simplex::Simplex &simplex) const override
Returns all simplices that will be potentially affected by the operation.
Definition: TriEdgeSwap.cpp:72
std::vector< simplex::Simplex > execute(const simplex::Simplex &simplex) override
returns an empty vector in case of failure
Definition: TriEdgeSwap.cpp:14
static Simplex edge(const Mesh &m, const Tuple &t)
Definition: Simplex.hpp:61