Wildmeshing Toolkit
Loading...
Searching...
No Matches
EmbedSurface.hpp
1#pragma once
2
3#include <set>
4#include <wmtk/Types.hpp>
5#include <wmtk/envelope/Envelope.hpp>
6#include <wmtk/utils/Delaunay.hpp>
7
8namespace wmtk::components::simwild {
9
10using ImageData = std::vector<std::vector<std::vector<size_t>>>;
11
25void delaunay_box_mesh(
26 const wmtk::Envelope& envelope,
27 const MatrixXd& vertices,
28 std::vector<wmtk::delaunay::Point3D>& points,
29 std::vector<wmtk::delaunay::Tetrahedron>& tets,
30 Vector3d& box_min,
31 Vector3d& box_max);
32
50void embed_surface(
51 const MatrixXd& V_surface,
52 const MatrixXi& F_surface,
53 const MatrixXd& V_vol,
54 const MatrixXi& T_vol,
55 MatrixXr& V_emb,
56 MatrixXi& T_emb,
57 MatrixXi& F_on_surface,
58 const bool perform_sanity_checks = false,
59 const std::vector<size_t>& F_input = {},
60 std::vector<std::vector<size_t>>* F_on_surface_inputs = nullptr);
61
66{
67public:
82 const std::vector<std::string>& img_filenames,
83 const std::vector<Matrix4d>& img_transform = {},
84 const double tol_rel = -1,
85 const double tol_abs = -1,
86 const bool split_connected_components = false);
87
93 void simplify_surface(const double eps, const int num_threads = 0);
94
98 void remove_duplicates(const double eps);
99
108 bool embed_surface(const bool flood_fill = false, const bool tag_from_winding_number = true);
109
113 void consolidate();
114
115 const MatrixXd& V_emb() const { return m_V_emb; }
116 const MatrixXr& V_emb_r() const { return m_V_emb_r; }
117 const MatrixXd& V_surface() const { return m_V_surface; }
118 const MatrixXi& T_emb() const { return m_T_emb; }
119 const MatrixSi& T_tags() const { return m_T_tags; }
120 const MatrixXi& F_on_surface() const { return m_F_on_surface; }
121 const MatrixXi& F_surface() const { return m_F_surface; }
122
129 void write_surf_off(const std::string& filename) const;
136 void write_emb_surf_off(const std::string& filename) const;
137
138 void write_emb_msh(const std::string& filename) const;
139 void write_emb_vtu(const std::string& filename) const;
140
141 std::pair<Vector3d, Vector3d> bbox_minmax() const;
142 std::pair<Vector3d, Vector3d> bbox_surf_minmax() const;
143
144 std::vector<Eigen::Vector3d> V_surf_to_vector() const;
145 std::vector<std::array<size_t, 3>> F_surf_to_vector() const;
146
147private:
148 void V_surf_from_vector(const std::vector<Eigen::Vector3d>& verts);
149 void F_surf_from_vector(const std::vector<std::array<size_t, 3>>& tris);
150
151 void tag_from_winding_number();
152
164 void tag_from_provenance();
165
173 void check_tag_surface_invariant(const std::string& how) const;
174
175private:
176 std::vector<std::string> m_img_filenames;
177 std::vector<ImageData> m_img_datas;
178
179 // the surface separating all tags
180 MatrixXd m_V_surface;
181 MatrixXi m_F_surface;
182
183 // per row of m_F_surface: which input it came from, or SIZE_MAX for none
184 std::vector<size_t> m_F_input;
185
186 // per row of m_F_on_surface: which inputs tile it, from the arrangement's provenance.
187 // Only filled when the provenance tagging is asked for.
188 std::vector<std::vector<size_t>> m_F_tags_surface;
189
190 std::vector<size_t> modified_nonmanifold_v;
191
192 // the embedding
193 MatrixXd m_V_emb;
194 MatrixXr m_V_emb_r;
195 MatrixXi m_T_emb;
196 // triangles of the embedding representing the surface
197 MatrixXi m_F_on_surface;
198 // tags on the tets
199 MatrixSi m_T_tags;
200 std::vector<std::set<int64_t>> m_tags;
201
202 // input from triangle meshes
203 std::vector<MatrixXd> Vs;
204 std::vector<MatrixXi> Fs;
205
206public:
207 bool m_smooth_surface = false;
208 bool m_perform_sanity_checks = false;
209 int m_num_threads = 0;
210};
211
212} // namespace wmtk::components::simwild
Definition Envelope.hpp:16
Definition EmbedSurface.hpp:66
void consolidate()
Remove unreferenced vertices.
Definition EmbedSurface.cpp:785
void simplify_surface(const double eps, const int num_threads=0)
Simplify the input surface while staying within the eps envelope.
Definition EmbedSurface.cpp:383
void check_tag_surface_invariant(const std::string &how) const
Count where the tagging and the arrangement's surface disagree.
Definition EmbedSurface.cpp:942
bool embed_surface(const bool flood_fill=false, const bool tag_from_winding_number=true)
Run the arrangement and tag the resulting cells.
Definition EmbedSurface.cpp:459
void tag_from_provenance()
Decide the cell tags from the arrangement's surface provenance.
Definition EmbedSurface.cpp:993
void write_emb_surf_off(const std::string &filename) const
Write embedded surface.
Definition EmbedSurface.cpp:837
void remove_duplicates(const double eps)
Merge vertices that are closer than eps.
Definition EmbedSurface.cpp:443
void write_surf_off(const std::string &filename) const
Write surface as read from image.
Definition EmbedSurface.cpp:832