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 <wmtk/threading/enumerable_thread_specific.hpp>
12#include <wmtk/envelope/Envelope.hpp>
13#include <wmtk/envelope/BoundaryEnvelope.hpp>
14#include <wmtk/utils/EnableWarnings.hpp>
15// clang-format on
16
17#include <Eigen/Core>
18#include <Eigen/Geometry>
19
20#include <atomic>
21#include <memory>
22#include <queue>
23
24namespace wmtk::components::qslim {
25
27{
28 Eigen::Matrix3d A;
29 Eigen::Vector3d b;
30 double c;
31};
32
34{
35 Eigen::Vector3d pos;
36 size_t partition_id = 0;
37 bool freeze = false;
38 Quadrics Q;
42 bool input_boundary = false;
43};
44
46{
47 Quadrics Q;
48 Eigen::Vector3d n = Eigen::Vector3d::Zero(); // for quadrics computation
49};
50
52{
53 Eigen::Vector3d vbar; // for quadrics computation
54};
55
57{
58public:
63 bool m_has_envelope = false;
70
71 int retry_limit = 10;
73 std::vector<Eigen::Vector3d> _m_vertex_positions,
74 int num_threads = 1,
75 bool use_exact = true);
76 void set_freeze(TriMesh::Tuple& v);
77
78 ~QSlimMesh() {}
79
97 void create_mesh(
98 size_t n_vertices,
99 const std::vector<std::array<size_t, 3>>& tris,
100 const std::vector<size_t>& frozen_verts = std::vector<size_t>(),
101 double eps = 0,
102 double boundary_eps = 0);
103
104 void initiate_quadrics_for_face();
105
106 void initiate_quadrics_for_vertices();
107
108 void partition_mesh()
109 {
110 auto m_vertex_partition_id = partition_TriMesh(*this, NUM_THREADS);
111 for (auto i = 0; i < m_vertex_partition_id.size(); i++)
112 vertex_attrs[i].partition_id = m_vertex_partition_id[i];
113 }
114
115 // TODO: This should not be exposed to the application, but hidden in wmtk
116 void partition_mesh_morton();
117
118 size_t get_partition_id(const Tuple& loc) const
119 {
120 return vertex_attrs[loc.vid(*this)].partition_id;
121 }
122
123public:
124 bool collapse_edge_before(const Tuple& t) override;
125 bool collapse_edge_after(const Tuple& t) override;
126 bool collapse_qslim(int target_vertex_count);
127 bool write_triangle_mesh(std::string path);
128 bool invariants(const std::vector<Tuple>& new_tris) override;
129 double compute_cost_for_e(const TriMesh::Tuple& v_tuple);
130 Quadrics compute_quadric_for_face(const TriMesh::Tuple& f_tuple);
131 void update_quadrics(const TriMesh::Tuple& v_tuple);
132
133private:
135 {
136 Eigen::Vector3d v1p;
137 Eigen::Vector3d v2p;
138 Eigen::Vector3d vbar;
139 Quadrics Q1;
140 Quadrics Q2;
141 int partition_id;
142 bool input_boundary = false; // of either endpoint, for the survivor
143 };
145
146 std::vector<TriMesh::Tuple> new_edges_after(const std::vector<TriMesh::Tuple>& t) const;
147};
148
149} // namespace wmtk::components::qslim
A tube around the open boundary of a triangle mesh, for operations allowed to move it.
Definition BoundaryEnvelope.hpp:43
Definition Envelope.hpp:19
Definition TriMesh.h:36
Definition TriMesh.h:32
Definition QSlimMesh.h:57
void create_mesh(size_t n_vertices, const std::vector< std::array< size_t, 3 > > &tris, const std::vector< size_t > &frozen_verts=std::vector< size_t >(), double eps=0, double boundary_eps=0)
Definition QSlimMesh.cpp:44
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:281
bool invariants(const std::vector< Tuple > &new_tris) override
User specified invariants that can't be violated.
Definition QSlimMesh.cpp:240
wmtk::Envelope m_envelope
Definition QSlimMesh.h:62
wmtk::BoundaryEnvelope m_boundary_envelope
Definition QSlimMesh.h:66
bool collapse_edge_after(const Tuple &t) override
User specified modifications and desideratas after an edge collapse.
Definition QSlimMesh.cpp:298
Definition enumerable_thread_specific.hpp:37
Definition AttributeCollection.hpp:46
Definition QSlimMesh.h:27
bool input_boundary
Definition QSlimMesh.h:42