Wildmeshing Toolkit
faces_single_dimension.cpp
Go to the documentation of this file.
2 #include <cassert>
7 
8 namespace wmtk::simplex {
9 std::vector<Tuple> vertices(const Mesh& m, const Simplex& simplex)
10 {
11  if (simplex.primitive_type() == PrimitiveType::Vertex) {
12  return {};
13  }
14 
15  const Tuple v0 = simplex.tuple();
16  const Tuple v1 = m.switch_tuple(v0, PV);
17 
18  if (simplex.primitive_type() == PrimitiveType::Edge) {
19  return {v0, v1};
20  }
21 
22  const Tuple v2 = m.switch_tuples(v0, {PE, PV});
23 
24  if (simplex.primitive_type() == PrimitiveType::Triangle) {
25  return {v0, v1, v2};
26  }
27 
28  const Tuple v3 = m.switch_tuples(v0, {PF, PE, PV});
29 
30  if (simplex.primitive_type() == PrimitiveType::Tetrahedron) {
31  return {v0, v1, v2, v3};
32  }
33 
34  assert(false); // "unknown primitive type"
35  return {};
36 }
37 
38 void vertices(SimplexCollection& simplex_collection, const Simplex& simplex)
39 {
40  if (simplex.primitive_type() == PrimitiveType::Vertex) {
41  return;
42  }
43 
44  const Mesh& m = simplex_collection.mesh();
45 
46  const Tuple v0 = simplex.tuple();
47  const Tuple v1 = m.switch_tuple(v0, PV);
48 
49  if (simplex.primitive_type() == PrimitiveType::Edge) {
50  simplex_collection.add(PrimitiveType::Vertex, v0);
51  simplex_collection.add(PrimitiveType::Vertex, v1);
52  return;
53  }
54 
55  const Tuple v2 = m.switch_tuples(v0, {PE, PV});
56 
57  if (simplex.primitive_type() == PrimitiveType::Triangle) {
58  simplex_collection.add(PrimitiveType::Vertex, v0);
59  simplex_collection.add(PrimitiveType::Vertex, v1);
60  simplex_collection.add(PrimitiveType::Vertex, v2);
61  return;
62  }
63 
64  const Tuple v3 = m.switch_tuples(v0, {PF, PE, PV});
65 
66  if (simplex.primitive_type() == PrimitiveType::Tetrahedron) {
67  simplex_collection.add(PrimitiveType::Vertex, v0);
68  simplex_collection.add(PrimitiveType::Vertex, v1);
69  simplex_collection.add(PrimitiveType::Vertex, v2);
70  simplex_collection.add(PrimitiveType::Vertex, v3);
71  return;
72  }
73 
74  assert(false); // "unknown primitive type"
75 }
76 
77 std::vector<Tuple> edges(const Mesh& m, const Simplex& simplex)
78 {
79  if (simplex.primitive_type() == PrimitiveType::Vertex ||
80  simplex.primitive_type() == PrimitiveType::Edge) {
81  return {};
82  }
83 
84  const Tuple e0 = simplex.tuple();
85  const Tuple e1 = m.switch_tuples(e0, {PV, PE});
86  const Tuple e2 = m.switch_tuples(e0, {PE, PV});
87 
88  if (simplex.primitive_type() == PrimitiveType::Triangle) {
89  return {e0, e1, e2};
90  }
91 
92  const Tuple e3 = m.switch_tuples(e0, {PF, PE});
93  const Tuple e4 = m.switch_tuples(e1, {PF, PE});
94  const Tuple e5 = m.switch_tuples(e2, {PF, PE});
95 
96  if (simplex.primitive_type() == PrimitiveType::Tetrahedron) {
97  return {e0, e1, e2, e3, e4, e5};
98  }
99 
100  assert(false); // "unknown primitive type"
101  return {};
102 }
103 
104 void edges(SimplexCollection& simplex_collection, const Simplex& simplex)
105 {
106  if (simplex.primitive_type() == PrimitiveType::Vertex ||
107  simplex.primitive_type() == PrimitiveType::Edge) {
108  return;
109  }
110 
111  const Mesh& m = simplex_collection.mesh();
112 
113  const Tuple e0 = simplex.tuple();
114  const Tuple e1 = m.switch_tuples(e0, {PV, PE});
115  const Tuple e2 = m.switch_tuples(e0, {PE, PV});
116 
117  if (simplex.primitive_type() == PrimitiveType::Triangle) {
118  simplex_collection.add(PrimitiveType::Edge, e0);
119  simplex_collection.add(PrimitiveType::Edge, e1);
120  simplex_collection.add(PrimitiveType::Edge, e2);
121  return;
122  }
123 
124  const Tuple e3 = m.switch_tuples(e0, {PF, PE});
125  const Tuple e4 = m.switch_tuples(e1, {PF, PE});
126  const Tuple e5 = m.switch_tuples(e2, {PF, PE});
127 
128  if (simplex.primitive_type() == PrimitiveType::Tetrahedron) {
129  simplex_collection.add(PrimitiveType::Edge, e0);
130  simplex_collection.add(PrimitiveType::Edge, e1);
131  simplex_collection.add(PrimitiveType::Edge, e2);
132  simplex_collection.add(PrimitiveType::Edge, e3);
133  simplex_collection.add(PrimitiveType::Edge, e4);
134  simplex_collection.add(PrimitiveType::Edge, e5);
135  return;
136  }
137 
138  assert(false); // "unknown primitive type"
139 }
140 
141 std::vector<Tuple> faces(const Mesh& m, const Simplex& simplex)
142 {
143  if (simplex.primitive_type() == PrimitiveType::Vertex ||
144  simplex.primitive_type() == PrimitiveType::Edge ||
146  return {};
147  }
148 
149  const Tuple f0 = simplex.tuple();
150  const Tuple f1 = m.switch_tuples(f0, {PF, PE});
151  const Tuple f2 = m.switch_tuples(f0, {PV, PE, PF, PE});
152  const Tuple f3 = m.switch_tuples(f0, {PE, PV, PF, PE});
153 
154  if (simplex.primitive_type() == PrimitiveType::Tetrahedron) {
155  return {f0, f1, f2, f3};
156  }
157 
158  assert(false); // "unknown primitive type"
159  return {};
160 }
161 
162 void faces(SimplexCollection& simplex_collection, const Simplex& simplex)
163 {
164  if (simplex.primitive_type() == PrimitiveType::Vertex ||
165  simplex.primitive_type() == PrimitiveType::Edge ||
167  return;
168  }
169 
170  const Mesh& m = simplex_collection.mesh();
171 
172  const Tuple f0 = simplex.tuple();
173  const Tuple f1 = m.switch_tuples(f0, {PF, PE});
174  const Tuple f2 = m.switch_tuples(f0, {PV, PE, PF, PE});
175  const Tuple f3 = m.switch_tuples(f0, {PE, PV, PF, PE});
176 
177  if (simplex.primitive_type() == PrimitiveType::Tetrahedron) {
178  simplex_collection.add(PrimitiveType::Triangle, f0);
179  simplex_collection.add(PrimitiveType::Triangle, f1);
180  simplex_collection.add(PrimitiveType::Triangle, f2);
181  simplex_collection.add(PrimitiveType::Triangle, f3);
182  return;
183  }
184 
185  assert(false); // "unknown primitive type"
186 }
187 
188 SimplexCollection
189 faces_single_dimension(const Mesh& mesh, const Simplex& simplex, const PrimitiveType face_type)
190 {
191  SimplexCollection collection(mesh);
192 
193  faces_single_dimension(collection, simplex, face_type);
194 
195  return collection;
196 }
197 
199  SimplexCollection& simplex_collection,
200  const Simplex& simplex,
201  const PrimitiveType face_type)
202 {
203  assert(simplex.primitive_type() <= simplex_collection.mesh().top_simplex_type());
204  assert(face_type <= simplex_collection.mesh().top_simplex_type());
205  switch (face_type) {
206  case PrimitiveType::Vertex: vertices(simplex_collection, simplex); break;
207  case PrimitiveType::Edge: edges(simplex_collection, simplex); break;
208  case PrimitiveType::Triangle: faces(simplex_collection, simplex); break;
209  case PrimitiveType::Tetrahedron: break;
210  default: assert(false); // "unknown primitive type"
211  }
212 }
213 
214 std::vector<Tuple> faces_single_dimension_tuples(
215  const Mesh& mesh,
216  const Simplex& simplex,
217  const PrimitiveType face_type)
218 {
219  assert(simplex.primitive_type() <= mesh.top_simplex_type());
220  assert(face_type <= mesh.top_simplex_type());
221  switch (face_type) {
222  case PrimitiveType::Vertex: return vertices(mesh, simplex); break;
223  case PrimitiveType::Edge: return edges(mesh, simplex); break;
224  case PrimitiveType::Triangle: return faces(mesh, simplex); break;
225  case PrimitiveType::Tetrahedron: break;
226  default: assert(false); // "unknown primitive type"
227  }
228 
229  return {};
230 }
231 
232 } // namespace wmtk::simplex
Tuple switch_tuples(const Tuple &tuple, const ContainerType &op_sequence) const
Definition: Mesh.hpp:967
virtual Tuple switch_tuple(const Tuple &tuple, PrimitiveType type) const =0
switch the orientation of the Tuple of the given dimension
PrimitiveType top_simplex_type() const
Definition: Mesh.hpp:996
void add(const Simplex &simplex)
Add simplex to the collection.
const Tuple & tuple() const
Definition: Simplex.hpp:53
PrimitiveType primitive_type() const
Definition: Simplex.hpp:51
constexpr wmtk::PrimitiveType PV
constexpr wmtk::PrimitiveType PT
constexpr wmtk::PrimitiveType PE
constexpr wmtk::PrimitiveType PF
std::vector< Tuple > vertices(const Mesh &m, const Simplex &simplex)
std::vector< Tuple > edges(const Mesh &m, const Simplex &simplex)
SimplexCollection faces_single_dimension(const Mesh &mesh, const Simplex &simplex, const PrimitiveType face_type)
Returns a vector with all faces in the boundary of a simplex of the given dimension.
std::vector< Tuple > faces_single_dimension_tuples(const Mesh &mesh, const Simplex &simplex, const PrimitiveType face_type)
SimplexCollection faces(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
Returns all faces of a simplex.
Definition: faces.cpp:10
constexpr PrimitiveType PV
constexpr PrimitiveType PE