Wildmeshing Toolkit
TagIntersection.cpp
Go to the documentation of this file.
1 #include "TagIntersection.hpp"
2 
3 namespace wmtk {
4 namespace components {
5 
7  Mesh& m,
8  const simplex::Simplex& s,
9  const std::deque<TagAttribute>& input_tag_attributes)
10 {
12 
13  std::vector<bool> tag_is_present(input_tag_attributes.size(), false);
14 
15  for (const simplex::Simplex& s : os.simplex_vector()) {
16  for (size_t i = 0; i < input_tag_attributes.size(); ++i) {
17  if (input_tag_attributes[i].is_tagged(m, s)) {
18  tag_is_present[i] = true;
19  }
20  }
21  }
22 
23  // check if all tags are present
24  bool is_intersection = true;
25  for (const bool b : tag_is_present) {
26  is_intersection = is_intersection && b;
27  }
28  return is_intersection;
29 }
30 
31 
33  Mesh& m,
34  const std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>>& input_tags,
35  const std::vector<std::tuple<attribute::MeshAttributeHandle, int64_t>>& output_tags)
36 {
37  std::deque<TagAttribute> input_tag_attributes;
38  for (const auto& [handle, val] : input_tags) {
39  input_tag_attributes.emplace_back(m, handle, handle.primitive_type(), val);
40  }
41  std::deque<TagAttribute> output_tag_attributes;
42  for (const auto& [handle, val] : output_tags) {
43  output_tag_attributes.emplace_back(m, handle, handle.primitive_type(), val);
44  }
45 
46  // iterate through all simplices and check if the simplex itself or any of its cofaces is
47  // tagged
48  for (const Tuple& t : m.get_all(PrimitiveType::Vertex)) {
50  if (simplex_is_in_intersection(m, v, input_tag_attributes)) {
51  for (TagAttribute& ta : output_tag_attributes) {
52  ta.set_tag(m, v);
53  }
54  }
55  }
56 
57  if (m.top_cell_dimension() < 1) {
58  return;
59  }
60 
61  for (const Tuple& t : m.get_all(PrimitiveType::Edge)) {
63  if (simplex_is_in_intersection(m, e, input_tag_attributes)) {
64  for (TagAttribute& ta : output_tag_attributes) {
65  ta.set_tag(m, e);
66  }
67  }
68  }
69 
70  if (m.top_cell_dimension() < 2) {
71  return;
72  }
73 
74  for (const Tuple& t : m.get_all(PrimitiveType::Triangle)) {
76  if (simplex_is_in_intersection(m, f, input_tag_attributes)) {
77  for (TagAttribute& ta : output_tag_attributes) {
78  ta.set_tag(m, f);
79  }
80  }
81  }
82 
83  if (m.top_cell_dimension() < 3) {
84  return;
85  }
86 
87  for (const Tuple& t : m.get_all(PrimitiveType::Tetrahedron)) {
89  if (simplex_is_in_intersection(m, f, input_tag_attributes)) {
90  for (TagAttribute& ta : output_tag_attributes) {
91  ta.set_tag(m, f);
92  }
93  }
94  }
95 }
96 
97 } // namespace components
98 } // namespace wmtk
std::vector< Tuple > get_all(PrimitiveType type) const
Generate a vector of Tuples from global vertex/edge/triangle/tetrahedron index.
Definition: Mesh.cpp:18
int64_t top_cell_dimension() const
Definition: Mesh.hpp:992
bool simplex_is_in_intersection(Mesh &m, const simplex::Simplex &s, const std::deque< TagAttribute > &input_tag_attributes)
Check if a given simplex is in the intersection of a given set of tag attributes.
void compute_intersection(Mesh &m, const std::vector< std::tuple< attribute::MeshAttributeHandle, int64_t >> &input_tags, const std::vector< std::tuple< attribute::MeshAttributeHandle, int64_t >> &output_tags)
const std::vector< Simplex > & simplex_vector() const
Return const reference to the simplex vector.
static Simplex face(const Mesh &m, const Tuple &t)
Definition: Simplex.hpp:63
static Simplex edge(const Mesh &m, const Tuple &t)
Definition: Simplex.hpp:61
static Simplex tetrahedron(const Mesh &m, const Tuple &t)
Definition: Simplex.hpp:68
static Simplex vertex(const Mesh &m, const Tuple &t)
Definition: Simplex.hpp:56
SimplexCollection open_star(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
Definition: open_star.cpp:12
Definition: Accessor.hpp:6