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:
72 const std::vector<std::string>& img_filenames,
73 const std::vector<Matrix4d>& img_transform = {},
74 const double tol_rel = -1,
75 const double tol_abs = -1);
76
82 void simplify_surface(const double eps, const int num_threads = 0);
83
87 void remove_duplicates(const double eps);
88
97 bool embed_surface(const bool flood_fill = false, const bool tag_from_winding_number = true);
98
102 void consolidate();
103
104 const MatrixXd& V_emb() const { return m_V_emb; }
105 const MatrixXr& V_emb_r() const { return m_V_emb_r; }
106 const MatrixXd& V_surface() const { return m_V_surface; }
107 const MatrixXi& T_emb() const { return m_T_emb; }
108 const MatrixSi& T_tags() const { return m_T_tags; }
109 const MatrixXi& F_on_surface() const { return m_F_on_surface; }
110 const MatrixXi& F_surface() const { return m_F_surface; }
111
118 void write_surf_off(const std::string& filename) const;
125 void write_emb_surf_off(const std::string& filename) const;
126
127 void write_emb_msh(const std::string& filename) const;
128 void write_emb_vtu(const std::string& filename) const;
129
130 std::pair<Vector3d, Vector3d> bbox_minmax() const;
131 std::pair<Vector3d, Vector3d> bbox_surf_minmax() const;
132
133 std::vector<Eigen::Vector3d> V_surf_to_vector() const;
134 std::vector<std::array<size_t, 3>> F_surf_to_vector() const;
135
136private:
137 void V_surf_from_vector(const std::vector<Eigen::Vector3d>& verts);
138 void F_surf_from_vector(const std::vector<std::array<size_t, 3>>& tris);
139
140 void tag_from_winding_number();
141
153 void tag_from_provenance();
154
162 void check_tag_surface_invariant(const std::string& how) const;
163
164private:
165 std::vector<std::string> m_img_filenames;
166 std::vector<ImageData> m_img_datas;
167
168 // the surface separating all tags
169 MatrixXd m_V_surface;
170 MatrixXi m_F_surface;
171
172 // per row of m_F_surface: which input it came from, or SIZE_MAX for none
173 std::vector<size_t> m_F_input;
174
175 // per row of m_F_on_surface: which inputs tile it, from the arrangement's provenance.
176 // Only filled when the provenance tagging is asked for.
177 std::vector<std::vector<size_t>> m_F_tags_surface;
178
179 std::vector<size_t> modified_nonmanifold_v;
180
181 // the embedding
182 MatrixXd m_V_emb;
183 MatrixXr m_V_emb_r;
184 MatrixXi m_T_emb;
185 // triangles of the embedding representing the surface
186 MatrixXi m_F_on_surface;
187 // tags on the tets
188 MatrixSi m_T_tags;
189 std::vector<std::set<int64_t>> m_tags;
190
191 // input from triangle meshes
192 std::vector<MatrixXd> Vs;
193 std::vector<MatrixXi> Fs;
194
195public:
196 bool m_smooth_surface = false;
197 bool m_perform_sanity_checks = false;
198 int m_num_threads = 0;
199};
200
201} // namespace wmtk::components::simwild
Definition Envelope.hpp:16
Definition EmbedSurface.hpp:66
void consolidate()
Remove unreferenced vertices.
Definition EmbedSurface.cpp:705
void simplify_surface(const double eps, const int num_threads=0)
Simplify the input surface while staying within the eps envelope.
Definition EmbedSurface.cpp:305
void check_tag_surface_invariant(const std::string &how) const
Count where the tagging and the arrangement's surface disagree.
Definition EmbedSurface.cpp:862
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:381
void tag_from_provenance()
Decide the cell tags from the arrangement's surface provenance.
Definition EmbedSurface.cpp:913
void write_emb_surf_off(const std::string &filename) const
Write embedded surface.
Definition EmbedSurface.cpp:757
void remove_duplicates(const double eps)
Merge vertices that are closer than eps.
Definition EmbedSurface.cpp:365
void write_surf_off(const std::string &filename) const
Write surface as read from image.
Definition EmbedSurface.cpp:752