Wildmeshing Toolkit
Loading...
Searching...
No Matches
EdgeValenceEnergy.cpp
Go to the documentation of this file.
2#include <wmtk/Primitive.hpp>
3#include <wmtk/TriMesh.hpp>
5
6namespace wmtk::function {
8 const Mesh& mesh,
9 const attribute::MeshAttributeHandle& variable_attribute_handle)
10 : PerSimplexFunction(mesh, PrimitiveType::Vertex, variable_attribute_handle)
11{}
12
13double EdgeValenceEnergy::get_value(const simplex::Simplex& edge_simplex) const
14{
15 // assume tuple is not a boundary edge
16 Tuple tuple = edge_simplex.tuple();
17 const Tuple& current_v = tuple;
18 const Tuple other_v = tri_mesh().switch_vertex(current_v);
19 int64_t val0 = static_cast<int64_t>(
22 .size());
23 int64_t val1 = static_cast<int64_t>(
26 .size());
27 if (tri_mesh().is_boundary_vertex(current_v)) {
28 val0 += 2;
29 }
30 if (tri_mesh().is_boundary_vertex(other_v)) {
31 val1 += 2;
32 }
33 if (val0 < 4 || val1 < 4) {
34 return -1;
35 }
36
37 /* top_v
38 // / \
39 // / \
40 // current_v-----other_v
41 // \ /
42 // \ /
43 // bottom_v
44 */
45 const Tuple top_v = tri_mesh().switch_vertex(tri_mesh().switch_edge(current_v));
46 const Tuple bottom_v =
47 tri_mesh().switch_vertex(tri_mesh().switch_edge(tri_mesh().switch_face(current_v)));
48 int64_t val2 =
49 static_cast<int64_t>(simplex::link(tri_mesh(), simplex::Simplex::vertex(tri_mesh(), top_v))
51 .size());
52 int64_t val3 = static_cast<int64_t>(
55 .size());
56
57 if (tri_mesh().is_boundary_vertex(top_v)) {
58 val2 += 2;
59 }
60 if (tri_mesh().is_boundary_vertex(bottom_v)) {
61 val3 += 2;
62 }
63 // formula from: https://github.com/daniel-zint/hpmeshgen/blob/cdfb9163ed92523fcf41a127c8173097e935c0a3/src/HPMeshGen2/TriRemeshing.cpp#L315
64 const int64_t val_energy = std::max(std::abs(val0 - 6), std::abs(val1 - 6)) +
65 std::max(std::abs(val2 - 6), std::abs(val3 - 6));
66 // const int64_t val_after = std::max(std::abs(val0 - 7), std::abs(val1 - 7)) +
67 // std::max(std::abs(val2 - 5), std::abs(val3 - 5));
68
69 return static_cast<double>(val_energy);
70}
71
73{
74 return static_cast<const TriMesh&>(PerSimplexFunction::mesh());
75}
76
77
78} // namespace wmtk::function
bool is_boundary_vertex(const Tuple &tuple) const
Definition TriMesh.cpp:78
Tuple switch_vertex(const Tuple &tuple) const
Definition TriMesh.hpp:113
The Tuple is the basic navigation tool in our mesh data structure.
Definition Tuple.hpp:19
EdgeValenceEnergy(const Mesh &mesh, const attribute::MeshAttributeHandle &variable_attribute_handle)
double get_value(const simplex::Simplex &simplex) const override
This function is defined over a simplex (normally a triangle or tetrahedron).
const std::vector< Simplex > & simplex_vector() const
Return const reference to the simplex vector.
static Simplex vertex(const Mesh &m, const Tuple &t)
Definition Simplex.hpp:56
const Tuple & tuple() const
Definition Simplex.hpp:53
SimplexCollection link(const Mesh &mesh, const simplex::Simplex &simplex, const bool sort_and_clean)
Definition link.cpp:84