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 bool output_enabled = true;
164 MMSurfaceMesh() {}
166 std::shared_ptr<MMTetMesh>& t_ptr,
167 std::shared_ptr<MMUVMesh>& uv_ptr,
168 const double threshold)
169 : tetmesh_ptr(t_ptr)
170 , uvmesh_ptr(uv_ptr)
171 , deviation_threshold(threshold)
172 {
173 p_vertex_attrs = &v_attrs;
174 p_edge_attrs = &e_attrs;
175 // p_face_attrs = f_attrs;
176 }
177
178 void init_from_eigen_with_map_and_dofs(
179 const MatrixXd& V,
180 const MatrixXi& F,
181 const std::map<int64_t, int64_t>& s2t_vid_map,
182 const std::vector<Eigen::Matrix<double, 12, 3>>& dofs,
183 const std::vector<size_t>& cone_vids);
184 // const std::vector<Vector3d>& vgrads,
185 // const std::vector<std::array<Vector3d, 3>>& egrads);
186
187 // mapping functions
188 TetMesh::Tuple map_to_tet_edge_tuple(const Tuple& e);
189 TetMesh::Tuple map_to_tet_vertex_tuple(const Tuple& v);
190 std::vector<Tuple> map_to_uv_edge_tuples(const Tuple& e);
191 std::vector<Tuple> map_to_uv_vertex_tuples(const Tuple& v);
192 Tuple map_to_equivalent_uv_tuple(const Tuple& v); // return uv tuple with exact same fid, leid
193 // and same vertex (vid may be different)
194
195 bool collapse_edge_before(const Tuple& t) override;
196 bool collapse_edge_after(const Tuple& t) override;
197 bool multimesh_collapse_edge(const Tuple& t);
198
199 Eigen::Matrix<double, 12, 3> assemble_dofs(const size_t& fid);
200
201 void output_surface_mesh(const std::string& file);
202
203 void clear_info_cache();
204
205public:
206 double deviation_threshold;
207
211 Svattrs v_attrs;
212 Seattrs e_attrs;
213 Sfattrs f_attrs;
214
216 {
217 size_t vid;
218 size_t ref_uv_vid; // vid for the collapse-from vertex (v1) in the face containing
219 // the tracked vertex
220
221 Vector3d surface_pos;
222 Vector2d uv_pos; // uv position for the tracked vertex
223 Vector2d ref_uv_pos; // uv position for the collapse-from vertex (v1) in the face containing
224 // the tracked vertex
225
226 Vector2d translation; // ref_pos to origin_pos
227 double rotation;
228 };
229
230 struct LayoutPartInfo // info for vert chart parts
231 {
232 size_t ref_uv_vid;
233
234 double rotation;
235 Vector2d translation;
236
237 Vector2d new_pos;
238
239
240 LayoutPartInfo() {}
241
243 const size_t& vid,
244 const Vector2d& new_p,
245 const Vector2d& trans,
246 const double rot)
247 : ref_uv_vid(vid)
248 , new_pos(new_p)
249 , translation(trans)
250 , rotation(rot)
251 {}
252 };
253
255 {
256 Vector3d old_pos;
257 Vector3d v2_pos;
258
259 Vector2d v1_uv_pos;
260 Vector2d v2_uv_pos;
261
262 size_t ref_uv_v1_id;
263 size_t ref_uv_v2_id;
264
265 size_t deleted_fid_1;
266 size_t deleted_fid_2 = -1;
267
268 size_t deleted_vid_1; // uv
269 size_t deleted_vid_2 = -1; // uv
270
271 size_t uv_collapse_to_v1_id; // uv
272 size_t uv_collapse_to_v2_id = -1; // uv
273
274 std::map<size_t, LayoutPartInfo> layout_parts_map;
275 std::vector<TrackedVertexInfo> tracked_vertex_info_cache;
276 std::map<size_t, bool> collapse_area_fid_involved;
277 };
278
280
281 std::shared_ptr<MMTetMesh> tetmesh_ptr;
282 std::shared_ptr<MMUVMesh> uvmesh_ptr;
283
284 // for uv tracking
286 {
287 Vector2d uv_pos;
288 Vector3d surface_pos;
289
290 size_t vid;
291 size_t in_tri_id = -1;
292
293 tracked_vertex() {}
294
295 tracked_vertex(const Vector2d& p, const Vector3d& sp, const size_t& id, const size_t& fid)
296 : uv_pos(p)
297 , surface_pos(sp)
298 , vid(id)
299 , in_tri_id(fid)
300 {}
301 };
302
303 std::vector<tracked_vertex> tracked_vertices;
304
305 std::map<size_t, std::vector<size_t>> tracked_fid_to_vids_map;
306 std::map<size_t, size_t> tracked_vid_to_fid_map;
307
308 void output_tracked_vertices(const std::string& filename);
309};
310
311
312} // 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:60
Definition TetMesh.h:32
Definition TriMesh.h:36
Definition TriMesh.h:32
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