Wildmeshing Toolkit
Loading...
Searching...
No Matches
LinkIterable.cpp
Go to the documentation of this file.
1#include "LinkIterable.hpp"
2
8
9namespace wmtk::simplex {
10
11
12LinkIterable::LinkIterable(const Mesh& mesh, const Simplex& simplex)
13 : m_mesh(mesh)
14 , m_simplex(simplex)
15 , m_tdc_itrbl(mesh, simplex, true)
16 , m_it_end(m_tdc_itrbl.end())
17{}
18
20 : m_container(container)
21 , m_it(container.m_tdc_itrbl, t)
22 , m_t(t)
23{
24 if (m_t.is_null()) {
25 return;
26 }
27
28 // check if link exists
29 {
30 const int8_t m = m_container.m_mesh.top_cell_dimension();
32 if (m <= s) {
33 logger().warn("Trying to retrieve link that cannot exist!");
34 m_t = Tuple();
35 return;
36 }
37 }
38
39 init();
40}
41
43{
44 if (depth() == 3) {
45 return step_depth_3();
46 }
47
48 const Mesh& mesh = m_container.m_mesh;
49 const simplex::Simplex& simplex = m_container.m_simplex;
50 const int8_t m = mesh.top_cell_dimension();
51 const int8_t s = get_primitive_type_id(simplex.primitive_type());
52
53 if (m_pt < m - s - 1 && !m_it.is_intermediate()) {
54 // go to next primitive type
55 ++m_pt;
56 } else {
57 m_pt = 0;
58 // change tuple
59 ++m_it;
60 m_t = navigate_to_link(*m_it);
61 }
62
63 return *this;
64}
65
67{
68 return (m_t != other.m_t) || (m_pt != other.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 return m_container.m_mesh.get_id_simplex(m_t, get_primitive_type_from_id(m_pt));
79}
80
82{
83 const Mesh& mesh = m_container.m_mesh;
84 const simplex::Simplex& simplex = m_container.m_simplex;
85 assert(mesh.top_cell_dimension() >= get_primitive_type_id(simplex.primitive_type()));
86 assert(mesh.top_cell_dimension() - get_primitive_type_id(simplex.primitive_type()) < 4);
87
89}
90
92{
93 m_t = navigate_to_link(*m_it);
94
95 if (depth() == 3) {
96 const Mesh& mesh = m_container.m_mesh;
97
98 m_container.m_visited_link[m_pt].is_visited(
100 }
101}
102
104{
105 const Mesh& mesh = m_container.m_mesh;
106 const simplex::Simplex& simplex = m_container.m_simplex;
107 auto& visited = m_container.m_visited_link;
108
109 ++m_pt;
110
111 if (m_pt == 3) {
112 // go to next cell
113 m_pt = 0;
114 m_edge_counter = 0;
115 ++m_it;
116 m_t = navigate_to_link(*m_it);
117 if (m_t.is_null()) {
118 return *this;
119 }
120 }
121
122 for (; m_edge_counter < 3; ++m_edge_counter) {
123 for (; m_pt < 2; ++m_pt) {
124 if (!visited[m_pt].is_visited(
125 mesh.get_id_simplex(m_t, get_primitive_type_from_id(m_pt)))) {
126 return *this;
127 }
128 }
130 m_pt = 0;
131 }
132
133 // return face
134 m_pt = 2;
135 return *this;
136}
137
139{
140 if (t.is_null()) {
141 return t;
142 }
143 // invert the simplex using SimplexDart
144 const Mesh& mesh = m_container.m_mesh;
145 // const PrimitiveType& mesh_pt = mesh.top_simplex_type();
146 // autogen::SimplexDart sd(mesh_pt);
147
148 // switch (mesh.top_simplex_type()) {
149 // case PrimitiveType::Triangle: {
150 // const int8_t index_switch = sd.product(
151 // sd.primitive_as_index(PrimitiveType::Edge),
152 // sd.primitive_as_index(PrimitiveType::Vertex));
153 // m_t = autogen::local_switch_tuple(mesh_pt, m_t, index_switch);
154 // break;
155 // }
156 // default: log_and_throw_error("missing mesh navigation in link"); break;
157 // }
158
159 {
160 /*
161 * Assume a tuple that contains the vertices (a,b,c,d) and the simplex is an edge, i.e.,
162 * (a,b). The link contains all the vertices that are not in the simplex. To get a tuple
163 * that represents all simplices of the link, we need to move (a,b) to the end of that
164 * tuple.
165 * (a,b,c,d) becomes (c,d,a,b) with the following permutations
166 * (a,b,c,d)
167 * switch edge: (a,c,b,d)
168 * switch face: (a,c,d,b)
169 * switch vert: (c,a,d,b)
170 * switch edge: (c,d,a,b)
171 *
172 * The following code implements these permutations.
173 */
174 const simplex::Simplex& simplex = m_container.m_simplex;
175 const int8_t m = mesh.top_cell_dimension();
176 const int8_t s = get_primitive_type_id(simplex.primitive_type());
177
178 for (int8_t j = s; j > -1; --j) {
179 for (int8_t i = 0; i < m - s; ++i) {
180 t = mesh.switch_tuple(t, get_primitive_type_from_id(j + i));
181 }
182 }
183 }
184
185 return t;
186}
187
188} // namespace wmtk::simplex
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition Mesh.hpp:953
int64_t top_cell_dimension() const
Definition Mesh.hpp:978
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
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
The Tuple is the basic navigation tool in our mesh data structure.
Definition Tuple.hpp:19
bool is_null() const
Checks if a tuple is "null". This merely implies the global index is -1.
Definition Tuple.hxx:41
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.
spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:58