Wildmeshing Toolkit
Loading...
Searching...
No Matches
QSlimMesh.h
1#pragma once
2#include <igl/per_face_normals.h>
3#include <wmtk/TriMesh.h>
4#include <wmtk/utils/PartitionMesh.h>
5#include <wmtk/utils/VectorUtils.h>
6#include <wmtk/AttributeCollection.hpp>
7
8// clang-format off
9#include <wmtk/utils/DisableWarnings.hpp>
10#include <igl/write_triangle_mesh.h>
11#include <tbb/enumerable_thread_specific.h>
12#include <tbb/parallel_for.h>
13#include <tbb/parallel_sort.h>
14#include <tbb/task_arena.h>
15#include <wmtk/envelope/Envelope.hpp>
16#include <wmtk/utils/EnableWarnings.hpp>
17// clang-format on
18
19#include <Eigen/Core>
20#include <Eigen/Geometry>
21
22#include <atomic>
23#include <memory>
24#include <queue>
25
26namespace wmtk::components::qslim {
27
29{
30 Eigen::Matrix3d A;
31 Eigen::Vector3d b;
32 double c;
33};
34
36{
37 Eigen::Vector3d pos;
38 size_t partition_id = 0;
39 bool freeze = false;
40 Quadrics Q;
41};
42
44{
45 Quadrics Q;
46 Eigen::Vector3d n = Eigen::Vector3d::Zero(); // for quadrics computation
47};
48
50{
51 Eigen::Vector3d vbar; // for quadrics computation
52};
53
55{
56public:
57 // wmtk::ExactEnvelope m_envelope;
58 wmtk::SampleEnvelope m_envelope;
59 bool m_has_envelope = false;
63
64 int retry_limit = 10;
65 QSlimMesh(std::vector<Eigen::Vector3d> _m_vertex_positions, int num_threads = 1);
66 void set_freeze(TriMesh::Tuple& v);
67
68 ~QSlimMesh() {}
69
70 void create_mesh(
71 size_t n_vertices,
72 const std::vector<std::array<size_t, 3>>& tris,
73 const std::vector<size_t>& frozen_verts = std::vector<size_t>(),
74 double eps = 0);
75
76 void initiate_quadrics_for_face();
77
78 void initiate_quadrics_for_vertices();
79
80 void partition_mesh()
81 {
82 auto m_vertex_partition_id = partition_TriMesh(*this, NUM_THREADS);
83 for (auto i = 0; i < m_vertex_partition_id.size(); i++)
84 vertex_attrs[i].partition_id = m_vertex_partition_id[i];
85 }
86
87 // TODO: This should not be exposed to the application, but hidden in wmtk
88 void partition_mesh_morton();
89
90 size_t get_partition_id(const Tuple& loc) const
91 {
92 return vertex_attrs[loc.vid(*this)].partition_id;
93 }
94
95public:
96 bool collapse_edge_before(const Tuple& t) override;
97 bool collapse_edge_after(const Tuple& t) override;
98 bool collapse_qslim(int target_vertex_count);
99 bool write_triangle_mesh(std::string path);
100 bool invariants(const std::vector<Tuple>& new_tris) override;
101 double compute_cost_for_e(const TriMesh::Tuple& v_tuple);
102 Quadrics compute_quadric_for_face(const TriMesh::Tuple& f_tuple);
103 void update_quadrics(const TriMesh::Tuple& v_tuple);
104
105private:
107 {
108 Eigen::Vector3d v1p;
109 Eigen::Vector3d v2p;
110 Eigen::Vector3d vbar;
111 Quadrics Q1;
112 Quadrics Q2;
113 int partition_id;
114 };
115 tbb::enumerable_thread_specific<InfoCache> cache;
116
117 std::vector<TriMesh::Tuple> new_edges_after(const std::vector<TriMesh::Tuple>& t) const;
118};
119
120} // namespace wmtk::components::qslim
Definition Envelope.hpp:56
Definition TriMesh.h:32
Definition TriMesh.h:28
Definition QSlimMesh.h:55
bool collapse_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge collapse including the link check as collapse...
Definition QSlimMesh.cpp:303
bool invariants(const std::vector< Tuple > &new_tris) override
User specified invariants that can't be violated.
Definition QSlimMesh.cpp:266
bool collapse_edge_after(const Tuple &t) override
User specified modifications and desideratas after an edge collapse.
Definition QSlimMesh.cpp:318
Definition AttributeCollection.hpp:37
Definition QSlimMesh.h:29