Wildmeshing Toolkit
Loading...
Searching...
No Matches
EmbedSurface.hpp
1#pragma once
2
3#include <wmtk/io/ComponentIO.hpp>
4
5#include <set>
6#include <wmtk/Types.hpp>
7#include <wmtk/envelope/Envelope.hpp>
8#include <wmtk/history/History.hpp>
9#include <wmtk/utils/Delaunay.hpp>
10
11namespace wmtk::components::simwild {
12
13using ImageData = std::vector<std::vector<std::vector<size_t>>>;
14
16using PositionKey = std::array<std::array<double, 3>, 3>;
18using FacetSources = std::vector<std::pair<PositionKey, std::vector<uint32_t>>>;
19
33void delaunay_box_mesh(
34 const wmtk::Envelope& envelope,
35 const MatrixXd& vertices,
36 std::vector<wmtk::delaunay::Point3D>& points,
37 std::vector<wmtk::delaunay::Tetrahedron>& tets,
38 Vector3d& box_min,
39 Vector3d& box_max);
40
61void embed_surface(
62 const MatrixXd& V_surface,
63 const MatrixXi& F_surface,
64 const MatrixXd& V_vol,
65 const MatrixXi& T_vol,
66 MatrixXr& V_emb,
67 MatrixXi& T_emb,
68 MatrixXi& F_on_surface,
69 const bool perform_sanity_checks = false,
70 const std::vector<size_t>& F_input = {},
71 std::vector<std::vector<size_t>>* F_on_surface_inputs = nullptr,
72 std::vector<std::vector<int>>* F_on_surface_orientations = nullptr,
73 FacetSources* facet_sources = nullptr);
74
79{
80public:
95 const std::vector<std::string>& img_filenames,
96 const std::vector<Matrix4d>& img_transform = {},
97 const double tol_rel = -1,
98 const double tol_abs = -1,
99 const bool split_connected_components = false,
100 const io::ComponentIO* component_io = nullptr,
101 const bool record_history = false);
102
108 const history::SurfaceHistory& input_history() const { return m_input_history; }
110 FacetSources& facet_sources() { return m_facet_sources; }
111
122 void simplify_surface(
123 const double eps,
124 const bool use_exact,
125 const int num_threads = 0,
126 const double boundary_eps = 0);
127
131 void remove_duplicates(const double eps);
132
143 bool embed_surface(
144 const bool flood_fill = false,
145 const bool tag_from_winding_number = true,
146 const bool provenance = false);
147
151 void consolidate();
152
153 const MatrixXd& V_emb() const { return m_V_emb; }
154 const MatrixXr& V_emb_r() const { return m_V_emb_r; }
155 const MatrixXd& V_surface() const { return m_V_surface; }
156 const MatrixXi& T_emb() const { return m_T_emb; }
157 const MatrixSi& T_tags() const { return m_T_tags; }
158 const MatrixXi& F_on_surface() const { return m_F_on_surface; }
160 const std::vector<std::vector<size_t>>& F_tags_surface() const { return m_F_tags_surface; }
163 const std::vector<std::vector<int>>& F_tags_surface_orientation() const
164 {
165 return m_F_tags_surface_orientation;
166 }
167 const MatrixXi& F_surface() const { return m_F_surface; }
169 const std::vector<size_t>& F_input() const { return m_F_input; }
170
171private:
172 bool m_record_history = false;
173 history::SurfaceHistory m_input_history;
174 FacetSources m_facet_sources;
175
176public:
183 void write_surf_off(const std::string& filename) const;
190 void write_emb_surf_off(const std::string& filename) const;
191
192 void write_emb_msh(const std::string& filename) const;
193 void write_emb_vtu(const std::string& filename) const;
194
195 std::pair<Vector3d, Vector3d> bbox_minmax() const;
196 std::pair<Vector3d, Vector3d> bbox_surf_minmax() const;
197
198 std::vector<Eigen::Vector3d> V_surf_to_vector() const;
199 std::vector<std::array<size_t, 3>> F_surf_to_vector() const;
200
201private:
202 void V_surf_from_vector(const std::vector<Eigen::Vector3d>& verts);
203 void F_surf_from_vector(const std::vector<std::array<size_t, 3>>& tris);
204
211
223 void tag_from_provenance();
224
232 void check_tag_surface_invariant(const std::string& how) const;
233
234private:
235 std::vector<std::string> m_img_filenames;
236 std::vector<ImageData> m_img_datas;
237
238 // the surface separating all tags
239 MatrixXd m_V_surface;
240 MatrixXi m_F_surface;
241
242 // per row of m_F_surface: which input it came from, or SIZE_MAX for none
243 std::vector<size_t> m_F_input;
244
245 // per row of m_F_on_surface: which inputs tile it, from the arrangement's provenance.
246 // Only filled when the provenance tagging is asked for.
247 std::vector<std::vector<size_t>> m_F_tags_surface;
248 // parallel to m_F_tags_surface: each input's direction on the row (+1, -1, or 0).
249 std::vector<std::vector<int>> m_F_tags_surface_orientation;
250
251 std::vector<size_t> modified_nonmanifold_v;
252
253 // the embedding
254 MatrixXd m_V_emb;
255 MatrixXr m_V_emb_r;
256 MatrixXi m_T_emb;
257 // triangles of the embedding representing the surface
258 MatrixXi m_F_on_surface;
259 // tags on the tets
260 MatrixSi m_T_tags;
261 std::vector<std::set<int64_t>> m_tags;
262
263 // input from triangle meshes
264 std::vector<MatrixXd> Vs;
265 std::vector<MatrixXi> Fs;
266
267public:
268 bool m_smooth_surface = false;
269 bool m_perform_sanity_checks = false;
270 int m_num_threads = 0;
271};
272
273} // namespace wmtk::components::simwild
Definition Envelope.hpp:19
Definition EmbedSurface.hpp:79
void consolidate()
Remove unreferenced vertices.
Definition EmbedSurface.cpp:946
void check_tag_surface_invariant(const std::string &how) const
Count where the tagging and the arrangement's surface disagree.
Definition EmbedSurface.cpp:1103
void tag_from_provenance()
Decide the cell tags from the arrangement's surface provenance.
Definition EmbedSurface.cpp:1154
FacetSources & facet_sources()
With record_history, once embedded: the input triangles each surface facet lies on.
Definition EmbedSurface.hpp:110
const std::vector< size_t > & F_input() const
Per row of F_surface(): the input it came from, SIZE_MAX for none.
Definition EmbedSurface.hpp:169
void write_emb_surf_off(const std::string &filename) const
Write embedded surface.
Definition EmbedSurface.cpp:998
const std::vector< std::vector< int > > & F_tags_surface_orientation() const
Definition EmbedSurface.hpp:163
void remove_duplicates(const double eps)
Merge vertices that are closer than eps.
Definition EmbedSurface.cpp:599
void write_surf_off(const std::string &filename) const
Write surface as read from image.
Definition EmbedSurface.cpp:993
void simplify_surface(const double eps, const bool use_exact, const int num_threads=0, const double boundary_eps=0)
Simplify the input surface while staying within the eps envelope.
Definition EmbedSurface.cpp:524
const history::SurfaceHistory & input_history() const
With record_history: the files as read, concatenated, then what became of them on the way to the arra...
Definition EmbedSurface.hpp:108
void tag_from_winding_number()
One binary tag column per input, set where that input's winding number at a tet barycenter is at leas...
Definition EmbedSurface.cpp:1282
const std::vector< std::vector< size_t > > & F_tags_surface() const
Per row of F_on_surface(): the inputs tiling it. Empty unless embed_surface recorded it.
Definition EmbedSurface.hpp:160
bool embed_surface(const bool flood_fill=false, const bool tag_from_winding_number=true, const bool provenance=false)
Run the arrangement and tag the resulting cells.
Definition EmbedSurface.cpp:615
Definition ComponentIO.hpp:15
A complex and the edits it went through, in commit order.
Definition History.hpp:101