Wildmeshing Toolkit
Loading...
Searching...
No Matches
IsotropicRemeshing.h
1#pragma once
2
3#include <wmtk/utils/PartitionMesh.h>
4#include <wmtk/utils/VectorUtils.h>
5#include <wmtk/envelope/Envelope.hpp>
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/concurrent_priority_queue.h>
12#include <tbb/concurrent_vector.h>
13#include <tbb/enumerable_thread_specific.h>
14#include <tbb/parallel_for.h>
15#include <tbb/parallel_sort.h>
16#include <fastenvelope/FastEnvelope.h>
17#include <wmtk/utils/EnableWarnings.hpp>
18// clang-format on
19
20#include <Eigen/Core>
21#include <Eigen/Geometry>
22#include <atomic>
23#include <memory>
24#include <queue>
25
26namespace wmtk::components::isotropic_remeshing {
27
29{
30 Eigen::Vector3d pos;
31 // TODO: in fact, partition id should not be vertex attribute, it is a fixed marker to distinguish tuple/operations.
32 size_t partition_id;
33 bool freeze = false;
34};
35
37{
38public:
39 wmtk::SampleEnvelope m_envelope;
40 bool m_has_envelope = false;
41
43 VertAttCol vertex_attrs;
44
45 int retry_limit = 10;
47 std::vector<Eigen::Vector3d> _m_vertex_positions,
48 int num_threads = 1,
49 bool use_exact = true);
50
52
53 void create_mesh(
54 size_t n_vertices,
55 const std::vector<std::array<size_t, 3>>& tris,
56 const std::vector<size_t>& frozen_verts = std::vector<size_t>(),
57 bool m_freeze = true,
58 double eps = 0);
59
61 {
62 Eigen::Vector3d v1p;
63 Eigen::Vector3d v2p;
64 size_t partition_id;
65 };
66 tbb::enumerable_thread_specific<PositionInfoCache> position_cache;
67
68 void cache_edge_positions(const Tuple& t);
69
70 bool invariants(const std::vector<Tuple>& new_tris) override;
71
72 // TODO: this should not be here
73 void partition_mesh();
74
75 // TODO: morton should not be here, but inside wmtk
76 void partition_mesh_morton();
77
78 size_t get_partition_id(const Tuple& loc) const
79 {
80 return vertex_attrs[loc.vid(*this)].partition_id;
81 }
82
83 bool smooth_all_vertices();
84
85 Eigen::Vector3d smooth(const Tuple& t);
86
87
88 Eigen::Vector3d tangential_smooth(const Tuple& t);
89
90 bool collapse_edge_before(const Tuple& t) override;
91 bool collapse_edge_after(const Tuple& t) override;
92
93 bool swap_edge_before(const Tuple& t) override;
94 bool swap_edge_after(const Tuple& t) override;
95
96 std::vector<TriMesh::Tuple> new_edges_after(const std::vector<TriMesh::Tuple>& tris) const;
97 std::vector<TriMesh::Tuple> new_edges_after_swap(const TriMesh::Tuple& t) const;
98 std::vector<TriMesh::Tuple> replace_edges_after_split(
99 const std::vector<TriMesh::Tuple>& tris,
100 const size_t vid_threshold) const;
101 std::vector<TriMesh::Tuple> new_sub_edges_after_split(
102 const std::vector<TriMesh::Tuple>& tris) const;
103
104
105 bool split_edge_before(const Tuple& t) override;
106 bool split_edge_after(const Tuple& t) override;
107
108 bool smooth_before(const Tuple& t) override;
109 bool smooth_after(const Tuple& t) override;
110
111 double compute_edge_cost_collapse(const TriMesh::Tuple& t, double L) const;
112 double compute_edge_cost_split(const TriMesh::Tuple& t, double L) const;
113 double compute_vertex_valence(const TriMesh::Tuple& t) const;
125 std::vector<double> average_len_valen();
126 bool split_remeshing(double L);
127 bool collapse_remeshing(double L);
128 bool swap_remeshing();
129 bool uniform_remeshing(double L, int interations);
130 bool write_triangle_mesh(std::string path);
131};
132
133} // namespace wmtk::components::isotropic_remeshing
Definition Envelope.hpp:56
Definition TriMesh.h:32
Definition TriMesh.h:28
bool collapse_edge_after(const Tuple &t) override
User specified modifications and desideratas after an edge collapse.
Definition IsotropicRemeshing.cpp:286
bool invariants(const std::vector< Tuple > &new_tris) override
User specified invariants that can't be violated.
Definition IsotropicRemeshing.cpp:88
bool split_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge split.
Definition IsotropicRemeshing.cpp:296
bool collapse_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge collapse including the link check as collapse...
Definition IsotropicRemeshing.cpp:276
bool swap_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge swap including 1.can't swap on boundary edge....
Definition IsotropicRemeshing.cpp:225
std::vector< double > average_len_valen()
Report statistics.
Definition IsotropicRemeshing.cpp:385
bool smooth_after(const Tuple &t) override
User specified modifications and desideras after an edge smooth.
Definition IsotropicRemeshing.cpp:319
bool smooth_before(const Tuple &t) override
User specified preparations and desideratas for an edge smooth.
Definition IsotropicRemeshing.cpp:313
bool swap_edge_after(const Tuple &t) override
User specified modifications and desideras after an edge swap.
Definition IsotropicRemeshing.cpp:234
bool split_edge_after(const Tuple &t) override
User specified modifications and desideratas after an edge split.
Definition IsotropicRemeshing.cpp:304