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/utils/EnableWarnings.hpp>
14// clang-format on
15
16#include <Eigen/Core>
17#include <Eigen/Geometry>
18
19#include <atomic>
20#include <memory>
21#include <queue>
22
23namespace wmtk::components::qslim {
24
26{
27 Eigen::Matrix3d A;
28 Eigen::Vector3d b;
29 double c;
30};
31
33{
34 Eigen::Vector3d pos;
35 size_t partition_id = 0;
36 bool freeze = false;
37 Quadrics Q;
38};
39
41{
42 Quadrics Q;
43 Eigen::Vector3d n = Eigen::Vector3d::Zero(); // for quadrics computation
44};
45
47{
48 Eigen::Vector3d vbar; // for quadrics computation
49};
50
52{
53public:
54 // wmtk::ExactEnvelope m_envelope;
55 wmtk::SampleEnvelope m_envelope;
56 bool m_has_envelope = false;
60
61 int retry_limit = 10;
62 QSlimMesh(std::vector<Eigen::Vector3d> _m_vertex_positions, int num_threads = 1);
63 void set_freeze(TriMesh::Tuple& v);
64
65 ~QSlimMesh() {}
66
67 void create_mesh(
68 size_t n_vertices,
69 const std::vector<std::array<size_t, 3>>& tris,
70 const std::vector<size_t>& frozen_verts = std::vector<size_t>(),
71 double eps = 0);
72
73 void initiate_quadrics_for_face();
74
75 void initiate_quadrics_for_vertices();
76
77 void partition_mesh()
78 {
79 auto m_vertex_partition_id = partition_TriMesh(*this, NUM_THREADS);
80 for (auto i = 0; i < m_vertex_partition_id.size(); i++)
81 vertex_attrs[i].partition_id = m_vertex_partition_id[i];
82 }
83
84 // TODO: This should not be exposed to the application, but hidden in wmtk
85 void partition_mesh_morton();
86
87 size_t get_partition_id(const Tuple& loc) const
88 {
89 return vertex_attrs[loc.vid(*this)].partition_id;
90 }
91
92public:
93 bool collapse_edge_before(const Tuple& t) override;
94 bool collapse_edge_after(const Tuple& t) override;
95 bool collapse_qslim(int target_vertex_count);
96 bool write_triangle_mesh(std::string path);
97 bool invariants(const std::vector<Tuple>& new_tris) override;
98 double compute_cost_for_e(const TriMesh::Tuple& v_tuple);
99 Quadrics compute_quadric_for_face(const TriMesh::Tuple& f_tuple);
100 void update_quadrics(const TriMesh::Tuple& v_tuple);
101
102private:
104 {
105 Eigen::Vector3d v1p;
106 Eigen::Vector3d v2p;
107 Eigen::Vector3d vbar;
108 Quadrics Q1;
109 Quadrics Q2;
110 int partition_id;
111 };
113
114 std::vector<TriMesh::Tuple> new_edges_after(const std::vector<TriMesh::Tuple>& t) const;
115};
116
117} // namespace wmtk::components::qslim
Definition Envelope.hpp:52
Definition TriMesh.h:31
Definition TriMesh.h:27
Definition QSlimMesh.h:52
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:235
bool invariants(const std::vector< Tuple > &new_tris) override
User specified invariants that can't be violated.
Definition QSlimMesh.cpp:198
bool collapse_edge_after(const Tuple &t) override
User specified modifications and desideratas after an edge collapse.
Definition QSlimMesh.cpp:250
Definition enumerable_thread_specific.hpp:26
Definition AttributeCollection.hpp:36
Definition QSlimMesh.h:26