Wildmeshing Toolkit
Loading...
Searching...
No Matches
Mesh.hpp
1#pragma once
2
3#include <wmtk/TetMesh.h>
4#include <Eigen/Core>
5#include <string>
6
7namespace app::interior_tet_opt {
9{
10 bool freeze = false;
11 Eigen::Vector3d pos;
12 size_t partition_id = 0;
13 double m_sizing_scalar = 1.;
14};
15
17{
18 double quality = -1.;
19};
20
21
23{
26 double target_l = 5e-2;
27 double m_splitting_l2 = -1.;
28 double m_collapsing_l2 = -1.;
29 void initialize(const std::vector<Eigen::Vector3d>&, const std::vector<std::array<size_t, 4>>&);
30
33
34 bool is_inverted(const Tuple&) const;
35 double get_quality(const Tuple&) const;
36 double get_length2(const Tuple&) const;
37 bool invariants(const std::vector<Tuple>& t) override; //
38 void final_output_mesh(std::string);
39
41 {
42 size_t v1_id = -1;
43 size_t v2_id = -1;
44 bool bnd = false;
45 double max_quality = -1.;
46 };
47 tbb::enumerable_thread_specific<SplitInfoCache> split_cache;
48
50 {
51 size_t v1_id;
52 size_t v2_id;
53 double max_energy;
54 double edge_length;
55 bool is_limit_length;
56
57 std::vector<std::array<size_t, 3>> surface_faces;
58 std::vector<size_t> changed_tids;
59
60 std::vector<std::array<size_t, 2>> failed_edges;
61 };
62 tbb::enumerable_thread_specific<CollapseInfoCache> collapse_cache;
63
64 bool split_edge_before(const Tuple& loc0) override;
65
66 bool split_edge_after(const Tuple& loc) override;
67
68 bool collapse_edge_before(const Tuple& loc) override
69 {
70 size_t v1_id = loc.vid(*this);
71
72 if (m_vertex_attribute[v1_id].freeze) return false;
73
74 auto loc1 = switch_vertex(loc);
75 size_t v2_id = loc1.vid(*this);
76
77 auto n1_locs = get_one_ring_tets_for_vertex(loc);
78 auto n12_locs = get_incident_tets_for_edge(loc); // todo: duplicated computation
79
80 std::map<size_t, double> qs;
81 for (auto& l : n1_locs) {
82 qs[l.tid(*this)] = m_tet_attribute[l.tid(*this)].quality; // get_quality(l);
83 }
84 for (auto& l : n12_locs) {
85 qs.erase(l.tid(*this));
86 }
87
88 collapse_cache.local().max_energy = 0;
89 for (auto& q : qs) {
90 if (q.second > collapse_cache.local().max_energy)
91 collapse_cache.local().max_energy = q.second;
92 //
93 collapse_cache.local().changed_tids.push_back(q.first);
94 };
95 return true;
96 }
97
98 bool collapse_edge_after(const Tuple& t) override
99 {
100 std::vector<Tuple> locs = get_one_ring_tets_for_vertex(t);
101
102 for (auto& loc : locs) {
103 if (is_inverted(loc)) {
104 return false;
105 }
106 }
107
108 for (size_t tid : collapse_cache.local().changed_tids) {
109 auto tet = tuple_from_tet(tid);
110 if (!tet.is_valid(*this)) continue;
111 if (is_inverted(tet)) return false;
112 double q = get_quality(tet);
113 if (q > collapse_cache.local().max_energy) {
114 return false;
115 }
116 m_tet_attribute[tid].quality = q;
117 }
118 return true;
119 }
120
122 {
123 double max_energy;
124 };
125 tbb::enumerable_thread_specific<SwapInfoCache> swap_cache;
126 bool swap_edge_before(const Tuple& t) override;
127 bool swap_edge_after(const Tuple& t) override;
128 bool swap_face_before(const Tuple& t) override;
129 bool swap_face_after(const Tuple& t) override;
130 bool swap_edge_44_before(const Tuple& t) override;
131 bool swap_edge_44_after(const Tuple& t) override;
132 bool smooth_before(const Tuple& t) override;
133 bool smooth_after(const Tuple& t) override;
134 //
135 void split_all_edges();
136 void smooth_all_vertices();
137 void collapse_all_edges(bool is_limit_length = true);
138 void swap_all_edges_44();
139 void swap_all_edges();
140 void swap_all_faces();
141 //
142 //
143 size_t get_partition_id(const Tuple& loc) const
144 {
145 return m_vertex_attribute[loc.vid(*this)].partition_id;
146 }
147 std::tuple<double, double> get_max_avg_energy()
148 {
149 double max_energy = -1.;
150 double avg_energy = 0;
151 auto cnt = 0;
152
153 TetMesh::for_each_tetra([&](auto& t) {
154 auto& q = m_tet_attribute[t.tid(*this)].quality;
155 if (q < 0) q = get_quality(t);
156
157 if (q > max_energy) max_energy = q;
158
159 avg_energy += std::cbrt(q);
160 cnt++;
161 });
162
163 avg_energy /= cnt;
164
165 return std::make_tuple(std::cbrt(max_energy), avg_energy);
166 }
167};
168} // namespace app::interior_tet_opt
a Tuple refers to a global vid and a global tet id, and a local edge id and local face id
Definition TetMesh.h:49
Definition TetMesh.h:24
Tuple tuple_from_tet(size_t tid) const
get a Tuple from global tetra index
Definition TetMesh.cpp:580
std::vector< Tuple > get_incident_tets_for_edge(const Tuple &t) const
Get the incident tets for edge.
Definition TetMesh.cpp:781
Tuple switch_vertex(const Tuple &t) const
wrapper function from Tuple::switch_vertex
Definition TetMesh.h:921
std::vector< Tuple > get_one_ring_tets_for_vertex(const Tuple &t) const
Get the one ring tets for a vertex.
Definition TetMesh.cpp:701
bool collapse_edge_before(const Tuple &loc) override
User specified preparations and desideratas for an edge collapse before changing the connectivity.
Definition Mesh.hpp:68
bool swap_edge_44_after(const Tuple &t) override
User specified modifications and desideratas for after a 4-4 edge swap.
Definition Mesh.cpp:205
bool swap_edge_before(const Tuple &t) override
User specified preparations and desideratas for an 3-2 edge swap before changing the conenctivity.
Definition Mesh.cpp:113
bool swap_face_after(const Tuple &t) override
User specified modifications and desideratas for after a 2-3 face swap.
Definition Mesh.cpp:167
bool smooth_after(const Tuple &t) override
User specified modifications and desideratas for after smoothing a vertex.
Definition Mesh.cpp:232
bool split_edge_after(const Tuple &loc) override
This function computes the attributes for the added simplices. User specified modifications and desid...
Definition Mesh.cpp:71
bool swap_edge_after(const Tuple &t) override
User specified modifications and desideratas for after a 3-2 edge swap.
Definition Mesh.cpp:129
bool swap_face_before(const Tuple &t) override
User specified preparations and desideratas for an 2-3 face swap befroe changing the geometry.
Definition Mesh.cpp:153
bool split_edge_before(const Tuple &loc0) override
User specified preparations and desideratas for an edge split before changing the connectivity.
Definition Mesh.cpp:54
bool swap_edge_44_before(const Tuple &t) override
User specified preparations and desideratas for an 4-4 edge swap before changing the connectivity.
Definition Mesh.cpp:192
bool smooth_before(const Tuple &t) override
User specified preparations and desideratas for smoothing a vertex.
Definition Mesh.cpp:226
bool collapse_edge_after(const Tuple &t) override
User specified modifications and desideratas for after an edge collapse.
Definition Mesh.hpp:98
Definition AttributeCollection.hpp:37