Wildmeshing Toolkit
Swap2dEdgeLengthInvariant.cpp
Go to the documentation of this file.
2 #include <wmtk/Mesh.hpp>
4 #include <wmtk/utils/orient.hpp>
5 
6 namespace wmtk {
8  const Mesh& m,
10  : Invariant(m, true, false, false)
11  , m_coordinate_handle(coordinate)
12 {}
13 
15 {
16  assert(mesh().top_cell_dimension() == 2);
17  constexpr static PrimitiveType PV = PrimitiveType::Vertex;
18  constexpr static PrimitiveType PE = PrimitiveType::Edge;
19  constexpr static PrimitiveType PF = PrimitiveType::Triangle;
20 
22 
23  // get the coords of the vertices
24  // input face end points
25  const Tuple v0 = t.tuple();
26  const Tuple v1 = mesh().switch_tuple(v0, PV);
27  // other 2 vertices
28  const Tuple v2 = mesh().switch_tuples(v0, {PE, PV});
29  const Tuple v3 = mesh().switch_tuples(v0, {PF, PE, PV});
30 
31  // use length
32  // const double length_old =
33  // (accessor.const_vector_attribute(v0) - accessor.const_vector_attribute(v1)).norm();
34  // const double length_new =
35  // (accessor.const_vector_attribute(v2) - accessor.const_vector_attribute(v3)).norm();
36 
37  // return length_new > length_old;
38 
39  // use height
40 
41  Eigen::Vector3d p0 = accessor.const_vector_attribute(v0);
42  Eigen::Vector3d p1 = accessor.const_vector_attribute(v1);
43  Eigen::Vector3d p2 = accessor.const_vector_attribute(v2);
44  Eigen::Vector3d p3 = accessor.const_vector_attribute(v3);
45 
46  const double h0 = ((p0 - p2).cross(p0 - p3)).norm() / (p2 - p3).norm();
47  const double h1 = ((p1 - p2).cross(p1 - p3)).norm() / (p2 - p3).norm();
48  const double h2 = ((p2 - p0).cross(p2 - p1)).norm() / (p0 - p1).norm();
49  const double h3 = ((p3 - p0).cross(p3 - p1)).norm() / (p0 - p1).norm();
50 
51  const double min_old = std::min(h2, h3);
52  const double min_new = std::min(h0, h1);
53 
54  if (((p0 - p1).norm() * h2 / 2) < 1e-10 || ((p0 - p1).norm() * h3 / 2) < 1e-10) {
55  if (((p2 - p3).norm() * h0 / 2) > 1e-10 && ((p2 - p3).norm() * h1 / 2) > 1e-10) {
56  return true;
57  }
58  }
59 
60  return min_old < min_new;
61 }
62 
63 } // namespace wmtk
const attribute::Accessor< T, Mesh, D > create_const_accessor(const attribute::MeshAttributeHandle &handle) const
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition: Mesh.hpp:967
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
bool before(const simplex::Simplex &t) const override
Swap2dEdgeLengthInvariant(const Mesh &m, const attribute::TypedAttributeHandle< double > &coordinate)
const attribute::TypedAttributeHandle< double > m_coordinate_handle
const Mesh & mesh() const
Definition: Invariant.cpp:35
const Tuple & tuple() const
Definition: Simplex.hpp:53
constexpr wmtk::PrimitiveType PF
Definition: Accessor.hpp:6
constexpr PrimitiveType PV
Vector< double, 3 > Vector3d
Definition: Types.hpp:39
constexpr PrimitiveType PE