4#include <wmtk/TetMesh.h>
5#include <wmtk/simplex/Simplex.hpp>
7#include "SimplicialComplexBVH.hpp"
10#include <wmtk/utils/DisableWarnings.hpp>
11#include <wmtk/utils/EnableWarnings.hpp>
14using CellTag = std::set<int64_t>;
17namespace wmtk::components::topological_offset {
20const int64_t TEMP_OFFSET_TET_TAG = -1;
21const CellTag TEMP_OFFSET_TET_TAG_SET{TEMP_OFFSET_TET_TAG};
31 size_t component_id = 0;
63 enum class EdgeSplitMode {
74 int m_vtu_counter = 0;
75 std::array<size_t, 4> m_init_counts = {{0, 0, 0, 0}};
78 EdgeSplitMode m_edge_split_mode = EdgeSplitMode::Midpoint;
81 std::map<std::string, int64_t> m_tag_name_to_id;
82 std::map<int64_t, std::string> m_tag_id_to_name;
84 CellTag m_offset_output_tag_ids;
87 bool m_singlebody =
false;
92 MatrixXd m_V_envelope;
93 MatrixXi m_F_envelope;
107 : m_params(_m_params)
109 NUM_THREADS = _num_threads;
110 p_vertex_attrs = &m_vertex_attribute;
111 p_edge_attrs = &m_edge_attribute;
112 p_face_attrs = &m_face_attribute;
113 p_tet_attrs = &m_tet_attribute;
129 const MatrixSi& T_tags,
130 const MatrixXd& V_env,
131 const MatrixXi F_env,
132 const std::vector<std::string>& tag_names);
169 bool invariants(
const std::vector<Tuple>& tets)
override;
240 void write_input_complex(
const std::string& path);
241 void write_vtu(
const std::string& path);
243 void write_msh_groups(
const std::string& file);
260 std::map<size_t, EdgeAttributes> internal_e;
261 std::map<simplex::Edge, EdgeAttributes> external_e;
262 std::map<simplex::Edge, EdgeAttributes> link_e;
265 std::map<size_t, FaceAttributes> split_f;
266 std::map<simplex::Edge, FaceAttributes> internal_f;
267 std::map<std::pair<simplex::Edge, size_t>,
FaceAttributes> external_f;
270 std::map<simplex::Edge, TetAttributes> tets;
272 tbb::enumerable_thread_specific<EdgeSplitCache> edge_split_cache;
281 std::map<simplex::Edge, EdgeAttributes> existing_e;
284 std::map<simplex::Face, FaceAttributes> existing_f;
288 std::map<size_t, TetAttributes> tets;
290 tbb::enumerable_thread_specific<FaceSplitCache> face_split_cache;
294 std::array<size_t, 4> v_ids;
297 std::map<simplex::Edge, EdgeAttributes> existing_e;
300 std::map<simplex::Face, FaceAttributes> existing_f;
305 tbb::enumerable_thread_specific<TetSplitCache> tet_split_cache;
322 for (
const int64_t& i : tag1) {
323 if (tag2.find(i) != tag2.end()) {
339 double len1 = (m_vertex_attribute[e1.vertices()[0]].m_posf -
340 m_vertex_attribute[e1.vertices()[1]].m_posf)
342 double len2 = (m_vertex_attribute[e2.vertices()[0]].m_posf -
343 m_vertex_attribute[e2.vertices()[1]].m_posf)
355 std::vector<Tuple> adj_tets;
356 auto tet_1 = t.switch_tetrahedron(*
this);
358 adj_tets.push_back(tet_1.value());
360 auto tet_2 = t.switch_face(*this).switch_tetrahedron(*
this);
362 adj_tets.push_back(tet_2.value());
364 auto tet_3 = t.switch_edge(*this).switch_face(*this).switch_tetrahedron(*
this);
366 adj_tets.push_back(tet_3.value());
369 t.switch_vertex(*this).switch_edge(*this).switch_face(*this).switch_tetrahedron(*
this);
371 adj_tets.push_back(tet_4.value());
382 std::vector<size_t> ret_v_ids;
383 for (
const size_t& other_v_id : onering_v_ids) {
385 if (m_edge_attribute[e_id].label != 0) {
386 ret_v_ids.push_back(other_v_id);
398 for (
const Tuple& v : verts) {
399 size_t v_id = v.vid(*
this);
400 m_vertex_attribute[v_id].component_id = 0;
a Tuple refers to a global vid and a global tet id, and a local edge id and local face id
Definition TetMesh.h:48
std::vector< size_t > get_one_ring_vids_for_vertex(size_t vid, std::vector< size_t > &cache)
Get the one ring vids for vertex.
Definition TetMesh.cpp:764
Tuple tuple_from_edge(size_t tid, int local_eid) const
get a Tuple from global tetra index and local edge index (from 0-5).
Definition TetMesh.cpp:353
std::vector< Tuple > get_vertices() const
Definition TetMesh.cpp:323
Definition TopoOffsetTetMesh.h:39
Definition TopoOffsetTetMesh.h:46
Definition SimplicialComplexBVH.hpp:12
Definition TopoOffsetTetMesh.h:53
Definition TopoOffsetTetMesh.h:61
std::vector< Tuple > get_face_adjacent_tets(const Tuple &t) const
get tets (as Tuples) that are face-adjacent to the given tet (as Tuple)
Definition TopoOffsetTetMesh.h:353
bool split_edge_after(const Tuple &t) override
This function computes the attributes for the added simplices. User specified modifications and desid...
Definition ComponentSplitting.cpp:154
void sort_edges_by_length(std::vector< simplex::Edge > &edges)
sort edge simplices in place by decreasing edge length
Definition TopoOffsetTetMesh.h:333
bool tet_is_in_offset_conservative(const size_t t_id, const double threshold_r) const
check if a tet is inside the offset (implicitly defined via BVH distance field to input complex) via ...
Definition Spatial.cpp:13
void reset_connected_components()
reset connected component assignments.
Definition TopoOffsetTetMesh.h:395
void edge_split_binary_search(const size_t v1, const size_t v2, Vector3d &p_new) const
split edge at point by minimizing m_params.target_distance - d() (where d() is distance to input comp...
Definition ComponentSplitting.cpp:12
size_t flood_fill()
label connected simplicial complex components (simplices labelled 1 or 2)
Definition TopoOffsetTetMesh.cpp:638
void init_from_image(const MatrixXd &V, const MatrixXi &T, const MatrixSi &T_tags, const MatrixXd &V_env, const MatrixXi F_env, const std::vector< std::string > &tag_names)
initialize TetMesh from vertex, tet, and tag data
Definition TopoOffsetTetMesh.cpp:32
void marching_tets()
execute simplistic marching tets. All edges with one vertex labelled 0 and the other 1/2 are split....
Definition TopoOffsetTetMesh.cpp:823
bool split_edge_before(const Tuple &t) override
User specified preparations and desideratas for an edge split before changing the connectivity.
Definition ComponentSplitting.cpp:34
void set_offset_tet_tags()
update 'tags' data for tets in the offset region (tets labelled 2) based on the given offset tag valu...
Definition TopoOffsetTetMesh.cpp:961
bool split_tet_after(const Tuple &t) override
Compute the attributes for the added simplices.
Definition ComponentSplitting.cpp:416
void grow_offset_conservative()
grow offset region conservatively using conservative checks while ensuring consistent topology
Definition TopoOffsetTetMesh.cpp:896
bool split_face_before(const Tuple &t) override
User specified preparations and desideratas for a face split before changing the connectivity.
Definition ComponentSplitting.cpp:224
bool offset_is_manifold()
verify that the closed offset region (simplices labelled 1 or 2) form a manifold region....
Definition TopoOffsetTetMesh.cpp:996
bool tag_tet_consistent_topology(size_t t_id, int64_t tag) const
check if removing the tet would change the topology of any label
Definition Spatial.cpp:133
bool is_simplicially_embedded() const
check if the input complex (simplices labelled 1) are simplicially embedded w.r.t....
Definition TopoOffsetTetMesh.cpp:683
bool any_tag_present(const CellTag &tag1, const CellTag &tag2)
determine if any tag from tag1 is also present in tag2.
Definition TopoOffsetTetMesh.h:313
std::vector< size_t > connected_components_helper(const size_t &v_id)
get all one-ring vertices through input simplices (labelled 1)
Definition TopoOffsetTetMesh.h:379
void simplicial_embedding()
make mesh a simplicial embedding of the input complex (simplices labelled 1)
Definition TopoOffsetTetMesh.cpp:728
void init_input_complex_bvh()
initialize BVH for input complex. Must be called after init_from_image(...)
Definition TopoOffsetTetMesh.cpp:484
void label_input_complex()
label input simplicial complex simplices, as defined in m_params.offset_selection
Definition TopoOffsetTetMesh.cpp:112
bool tet_is_simp_emb(const Tuple &t) const
check if a tet satisfies simpicial embedding criteria w.r.t. input complex (simplices labelled 1)
Definition TopoOffsetTetMesh.cpp:700
bool offset_tet_consistent_topology(const size_t t_id) const
check if adding a tet to the offset region does not change the topology of the offset....
Definition Spatial.cpp:54
bool split_tet_before(const Tuple &t) override
User specified preparations and desideratas for a tet split before changing the connectivity.
Definition ComponentSplitting.cpp:379
bool empty_input_complex()
check if the input complex is empty. Only valid after calling init_from_image(...)....
Definition TopoOffsetTetMesh.cpp:471
bool split_face_after(const Tuple &t) override
Compute the attributes for the added simplices.
Definition ComponentSplitting.cpp:298
Definition TopoOffsetTetMesh.h:27
Definition Simplex.hpp:46
Definition Parameters.h:9
Definition TopoOffsetTetMesh.h:253
Definition TopoOffsetTetMesh.h:275
Definition TopoOffsetTetMesh.h:293