Wildmeshing Toolkit
Loading...
Searching...
No Matches
c1_multimesh.hpp
1#pragma once
2
3#include <igl/Timer.h>
4#include <wmtk/TetMesh.h>
5#include <wmtk/TriMesh.h>
6
7// clang-format off
8#include <wmtk/utils/EnableWarnings.hpp>
9// clang-format on
10
11#include <memory>
12
13namespace wmtk::components::c1_simplification {
14
15/*
16attributes
17*/
19{
20 int64_t vid_in_tet = -1;
21
22 Vector3d pos;
23
24 // gradient at vertex
25 Vector3d grad;
26
27 bool is_cone = false;
28
30 SurfaceMeshVertexAttribute(const Vector3d& p, const Vector3d& g, const int64_t& tvid)
31 : pos(p)
32 , grad(g)
33 , vid_in_tet(tvid)
34 {}
35};
36
38{
39 Vector3d midgrad;
40
42 SurfaceMeshEdgeAttribute(const Vector3d& g)
43 : midgrad(g)
44 {}
45};
46
48{
49 // midpoint gradients for local edges
50 std::array<Vector3d, 3> midgrad;
51 Eigen::Matrix<double, 12, 3> dofs;
52
54 SurfaceMeshFaceAttribute(const std::array<Vector3d, 3>& g)
55 : midgrad(g)
56 {}
57 SurfaceMeshFaceAttribute(const Vector3d& g0, const Vector3d& g1, const Vector3d& g2)
58 {
59 midgrad = {{g0, g1, g2}};
60 }
61};
62
64{
65 int64_t vid_in_surface = -1;
66
67 Vector3d pos;
68
70 TetMeshVertexAttribute(const Vector3d& p, const int64_t& svid)
71 : pos(p)
72 , vid_in_surface(svid)
73 {}
74};
75
77{
78 Vector2d pos;
79
80 bool is_cone = false;
81
83 UVMeshVertexAttribute(const Vector2d& p)
84 : pos(p)
85 {}
86};
87
88/*
89multimesh meshes
90*/
91
93{
94public:
95 MMTetMesh() { p_vertex_attrs = &v_attrs; }
96 ~MMTetMesh() {}
97
98 void init_from_eigen(const MatrixXd& V, const MatrixXi& T);
99
100 bool is_inverted(const Tuple& t) const;
101
102 bool collapse_edge_before(const Tuple& t) override;
103 bool collapse_edge_after(const Tuple& t) override;
104
106 {
107 size_t v1_id;
108 size_t v2_id;
109 double max_energy;
110 double edge_length;
111 bool is_limit_length;
112
113 // std::vector<std::pair<FaceAttributes, std::array<size_t, 3>>> changed_faces;
114 std::vector<std::array<size_t, 3>> surface_faces;
115 std::vector<size_t> changed_tids;
116
117 std::vector<std::array<size_t, 2>> failed_edges;
118
119 std::map<std::pair<size_t, size_t>, int> edge_link;
120 std::map<size_t, int> vertex_link;
121 size_t global_nonmani_ver_cnt;
122 };
123
124 TetCollpaseInfoCache t_cache;
125
126public:
128 Tvattrs v_attrs;
129};
130
132{
133public:
134 MMUVMesh() { p_vertex_attrs = &v_attrs; }
135 ~MMUVMesh() {}
136
137 void init_from_eigen(const MatrixXd& V, const MatrixXi& F);
138
139 bool is_inverted(const Tuple& t) const;
140
141 bool collapse_edge_before(const Tuple& t) override;
142 bool collapse_edge_after(const Tuple& t) override;
143
144 void output_uv_mesh(const std::string& file, bool consolidate = false);
145
146
148 {
149 Vector2d old_uv_pos;
150 Vector2d v2_pos;
151 };
152
153 UVCollpaseInfoCache uv_cache;
154
155public:
157 UVvattrs v_attrs;
158};
159
161{
162public:
163 MMSurfaceMesh() {}
165 std::shared_ptr<MMTetMesh>& t_ptr,
166 std::shared_ptr<MMUVMesh>& uv_ptr,
167 const double threshold)
168 : tetmesh_ptr(t_ptr)
169 , uvmesh_ptr(uv_ptr)
170 , deviation_threshold(threshold)
171 {
172 p_vertex_attrs = &v_attrs;
173 p_edge_attrs = &e_attrs;
174 // p_face_attrs = f_attrs;
175 }
176
177 void init_from_eigen_with_map_and_dofs(
178 const MatrixXd& V,
179 const MatrixXi& F,
180 const std::map<int64_t, int64_t>& s2t_vid_map,
181 const std::vector<Eigen::Matrix<double, 12, 3>>& dofs,
182 const std::vector<size_t>& cone_vids);
183 // const std::vector<Vector3d>& vgrads,
184 // const std::vector<std::array<Vector3d, 3>>& egrads);
185
186 // mapping functions
187 TetMesh::Tuple map_to_tet_edge_tuple(const Tuple& e);
188 TetMesh::Tuple map_to_tet_vertex_tuple(const Tuple& v);
189 std::vector<Tuple> map_to_uv_edge_tuples(const Tuple& e);
190 std::vector<Tuple> map_to_uv_vertex_tuples(const Tuple& v);
191 Tuple map_to_equivalent_uv_tuple(const Tuple& v); // return uv tuple with exact same fid, leid
192 // and same vertex (vid may be different)
193
194 bool collapse_edge_before(const Tuple& t) override;
195 bool collapse_edge_after(const Tuple& t) override;
196 bool multimesh_collapse_edge(const Tuple& t);
197
198 Eigen::Matrix<double, 12, 3> assemble_dofs(const size_t& fid);
199
200 void output_surface_mesh(const std::string& file);
201
202 void clear_info_cache();
203
204public:
205 double deviation_threshold;
206
210 Svattrs v_attrs;
211 Seattrs e_attrs;
212 Sfattrs f_attrs;
213
215 {
216 size_t vid;
217 size_t ref_uv_vid; // vid for the collapse-from vertex (v1) in the face containing
218 // the tracked vertex
219
220 Vector3d surface_pos;
221 Vector2d uv_pos; // uv position for the tracked vertex
222 Vector2d ref_uv_pos; // uv position for the collapse-from vertex (v1) in the face containing
223 // the tracked vertex
224
225 Vector2d translation; // ref_pos to origin_pos
226 double rotation;
227 };
228
229 struct LayoutPartInfo // info for vert chart parts
230 {
231 size_t ref_uv_vid;
232
233 double rotation;
234 Vector2d translation;
235
236 Vector2d new_pos;
237
238
239 LayoutPartInfo() {}
240
242 const size_t& vid,
243 const Vector2d& new_p,
244 const Vector2d& trans,
245 const double rot)
246 : ref_uv_vid(vid)
247 , new_pos(new_p)
248 , translation(trans)
249 , rotation(rot)
250 {}
251 };
252
254 {
255 Vector3d old_pos;
256 Vector3d v2_pos;
257
258 Vector2d v1_uv_pos;
259 Vector2d v2_uv_pos;
260
261 size_t ref_uv_v1_id;
262 size_t ref_uv_v2_id;
263
264 size_t deleted_fid_1;
265 size_t deleted_fid_2 = -1;
266
267 size_t deleted_vid_1; // uv
268 size_t deleted_vid_2 = -1; // uv
269
270 size_t uv_collapse_to_v1_id; // uv
271 size_t uv_collapse_to_v2_id = -1; // uv
272
273 std::map<size_t, LayoutPartInfo> layout_parts_map;
274 std::vector<TrackedVertexInfo> tracked_vertex_info_cache;
275 std::map<size_t, bool> collapse_area_fid_involved;
276 };
277
279
280 std::shared_ptr<MMTetMesh> tetmesh_ptr;
281 std::shared_ptr<MMUVMesh> uvmesh_ptr;
282
283 // for uv tracking
285 {
286 Vector2d uv_pos;
287 Vector3d surface_pos;
288
289 size_t vid;
290 size_t in_tri_id = -1;
291
292 tracked_vertex() {}
293
294 tracked_vertex(const Vector2d& p, const Vector3d& sp, const size_t& id, const size_t& fid)
295 : uv_pos(p)
296 , surface_pos(sp)
297 , vid(id)
298 , in_tri_id(fid)
299 {}
300 };
301
302 std::vector<tracked_vertex> tracked_vertices;
303
304 std::map<size_t, std::vector<size_t>> tracked_fid_to_vids_map;
305 std::map<size_t, size_t> tracked_vid_to_fid_map;
306
307 void output_tracked_vertices(const std::string& filename);
308};
309
310
311} // namespace wmtk::components::c1_simplification
a Tuple refers to a global vid and a global tet id, and a local edge id and local face id
Definition TetMesh.h:48
Definition TetMesh.h:23
Definition TriMesh.h:32
Definition TriMesh.h:28
bool collapse_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge collapse including the link check as collapse...
Definition c1_multimesh.cpp:561
bool collapse_edge_after(const Tuple &t) override
User specified modifications and desideratas after an edge collapse.
Definition c1_multimesh.cpp:755
bool collapse_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge collapse before changing the connectivity.
Definition c1_multimesh.cpp:72
bool collapse_edge_after(const Tuple &t) override
User specified modifications and desideratas for after an edge collapse.
Definition c1_multimesh.cpp:117
Definition c1_multimesh.hpp:132
bool collapse_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge collapse including the link check as collapse...
Definition c1_multimesh.cpp:180
bool collapse_edge_after(const Tuple &t) override
User specified modifications and desideratas after an edge collapse.
Definition c1_multimesh.cpp:221