Wildmeshing Toolkit
ValenceImprovementInvariant.cpp
Go to the documentation of this file.
2 
4 #include <wmtk/simplex/link.hpp>
5 
6 
7 namespace wmtk::invariants {
9  : Invariant(m, true, false, false)
10 {}
12 {
13  const Tuple& t = simplex.tuple();
14 
15  assert(simplex.primitive_type() == PrimitiveType::Edge);
16 
18  const simplex::Simplex f1 =
20  const std::vector<Tuple> vertices_t0 =
22  const std::vector<Tuple> vertices_t1 =
24  const Tuple v0 = vertices_t0[0];
25  const Tuple v1 = vertices_t0[1];
26  const Tuple v2 = vertices_t0[2];
27  const Tuple v3 = vertices_t1[2];
28 
29  auto valence = [this](const Tuple& v) {
30  return static_cast<int64_t>(simplex::link(mesh(), simplex::Simplex::vertex(mesh(), v))
32  .size());
33  };
34 
35  int64_t val0 = valence(v0);
36  int64_t val1 = valence(v1);
37  int64_t val2 = valence(v2);
38  int64_t val3 = valence(v3);
39  if (mesh().is_boundary(PrimitiveType::Vertex, v0)) {
40  val0 += 2;
41  }
42  if (mesh().is_boundary(PrimitiveType::Vertex, v1)) {
43  val1 += 2;
44  }
45  if (mesh().is_boundary(PrimitiveType::Vertex, v2)) {
46  val2 += 2;
47  }
48  if (mesh().is_boundary(PrimitiveType::Vertex, v3)) {
49  val3 += 2;
50  }
51 
52  // formula from: https://github.com/daniel-zint/hpmeshgen/blob/cdfb9163ed92523fcf41a127c8173097e935c0a3/src/HPMeshGen2/TriRemeshing.cpp#L315
53  const int64_t val_before = std::max(std::abs(val0 - 6), std::abs(val1 - 6)) +
54  std::max(std::abs(val2 - 6), std::abs(val3 - 6));
55  const int64_t val_after = std::max(std::abs(val0 - 7), std::abs(val1 - 7)) +
56  std::max(std::abs(val2 - 5), std::abs(val3 - 5));
57 
58  if (val_after >= val_before) {
59  return false;
60  }
61 
62  return true;
63 }
64 
65 } // namespace wmtk::invariants
const Mesh & mesh() const
Definition: Invariant.cpp:35
bool before(const simplex::Simplex &t) const override
const std::vector< Simplex > & simplex_vector() const
Return const reference to the simplex vector.
static Simplex face(const Mesh &m, const Tuple &t)
Definition: Simplex.hpp:63
const Tuple & tuple() const
Definition: Simplex.hpp:53
static Simplex vertex(const Mesh &m, const Tuple &t)
Definition: Simplex.hpp:56
PrimitiveType primitive_type() const
Definition: Simplex.hpp:51
SimplexCollection link(const Mesh &mesh, const simplex::Simplex &simplex, const bool sort_and_clean)
Definition: link.cpp:84
std::vector< Tuple > faces_single_dimension_tuples(const Mesh &mesh, const Simplex &simplex, const PrimitiveType face_type)
Rational abs(const Rational &r0)
Definition: Rational.cpp:328