Wildmeshing Toolkit
OpenStarIterable.cpp
Go to the documentation of this file.
1 #include "OpenStarIterable.hpp"
2 
7 #include <wmtk/utils/Logger.hpp>
9 
10 namespace wmtk::simplex {
11 
12 
13 OpenStarIterable::OpenStarIterable(const Mesh& mesh, const Simplex& simplex)
14  : m_mesh(mesh)
15  , m_simplex(simplex)
16  , m_tdc_itrbl(mesh, simplex, true)
17  , m_it_end(m_tdc_itrbl.end())
18 {}
19 
21  : m_container(container)
22  , m_it(container.m_tdc_itrbl, t)
23  , m_t(t)
24  , m_pt(get_primitive_type_id(container.m_simplex.primitive_type()))
25 {
26  if (m_t.is_null()) {
27  return;
28  }
29 
30  init();
31 }
32 
34 {
35  if (depth() == 3) {
36  return step_depth_3();
37  }
38 
39  const Mesh& mesh = m_container.m_mesh;
40  const simplex::Simplex& simplex = m_container.m_simplex;
41  const int8_t m = mesh.top_cell_dimension();
42  const int8_t s = get_primitive_type_id(simplex.primitive_type());
43 
44  if (m_pt < m && !m_it.is_intermediate()) {
45  // go to next primitive type
46  ++m_pt;
47  } else {
48  m_pt = s + 1;
49  // change tuple
50  ++m_it;
51  m_t = *m_it;
52  }
53 
54  if (m_t.is_null()) {
55  m_pt = s;
56  }
57 
58  return *this;
59 }
60 
62 {
63  return (m_t != other.m_t) || (m_pt != other.m_pt);
64 }
65 
67 {
68  return m_container.m_mesh.get_id_simplex(m_t, get_primitive_type_from_id(m_pt));
69 }
70 
72 {
73  return m_container.m_mesh.get_id_simplex(m_t, get_primitive_type_from_id(m_pt));
74 }
75 
77 {
78  const Mesh& mesh = m_container.m_mesh;
79  const simplex::Simplex& simplex = m_container.m_simplex;
80  assert(mesh.top_cell_dimension() >= get_primitive_type_id(simplex.primitive_type()));
81  assert(mesh.top_cell_dimension() - get_primitive_type_id(simplex.primitive_type()) < 4);
82 
83  return mesh.top_cell_dimension() - get_primitive_type_id(simplex.primitive_type());
84 }
85 
87 
89 {
90  const Mesh& mesh = m_container.m_mesh;
91  const simplex::Simplex& simplex = m_container.m_simplex;
92  auto& visited = m_container.m_visited_cofaces;
93 
95  assert(simplex.primitive_type() == PrimitiveType::Vertex);
96 
97  ++m_pt;
98 
99  if (m_pt == 4) {
100  // go to next cell
101  m_pt = 1;
102  m_edge_counter = 0;
103  ++m_it;
104  m_t = *m_it;
105  if (m_t.is_null()) {
106  m_pt = 0;
107  return *this;
108  }
109  }
110 
111  for (; m_edge_counter < 3; ++m_edge_counter) {
112  for (; m_pt < 3; ++m_pt) {
113  if (!visited[m_pt - 1].is_visited(
114  mesh.get_id_simplex(m_t, get_primitive_type_from_id(m_pt)))) {
115  return *this;
116  }
117  }
119  m_pt = 1;
120  }
121 
122  // return tet
123  m_pt = 3;
124  return *this;
125 }
126 
127 } // namespace wmtk::simplex
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition: Mesh.hpp:967
int64_t top_cell_dimension() const
Definition: Mesh.hpp:992
simplex::IdSimplex get_id_simplex(const Tuple &tuple, PrimitiveType pt) const
Retrieve the IdSimplex that is represented by the tuple and primitive type.
Definition: Mesh.cpp:28
PrimitiveType top_simplex_type() const
Definition: Mesh.hpp:996
bool is_null() const
Checks if a tuple is "null". This merely implies the global index is -1.
Definition: Tuple.hxx:40
void init()
Depending on the depth, the iterator must be initialized differently.
bool operator!=(const Iterator &other) const
int64_t depth()
Compute the depth from the mesh and the simplex type.
Iterator(OpenStarIterable &container, const Tuple &t=Tuple())
Iterator & step_depth_3()
Use breadth first search to find all d-simplices, and iterate through all cofaces in a d-simplex.
This iterator internally uses TopDimensionCofacesIterable.
OpenStarIterable(const Mesh &mesh, const Simplex &simplex)
PrimitiveType primitive_type() const
Definition: Simplex.hpp:51
constexpr PrimitiveType get_primitive_type_from_id(int8_t id)
Get the primitive type corresponding to its unique integer id.
constexpr int8_t get_primitive_type_id(PrimitiveType t)
Get a unique integer id corresponding to each primitive type.