Wildmeshing Toolkit
closed_star.cpp
Go to the documentation of this file.
1 #include "closed_star.hpp"
2 
3 #include <wmtk/TetMesh.hpp>
4 #include <wmtk/TriMesh.hpp>
5 #include <wmtk/utils/Logger.hpp>
6 
7 #include "faces.hpp"
10 
11 namespace wmtk::simplex {
12 
13 SimplexCollection closed_star(const Mesh& mesh, const Simplex& simplex, const bool sort_and_clean)
14 {
15  assert(mesh.is_valid(simplex.tuple()));
16  SimplexCollection collection = top_dimension_cofaces(mesh, simplex, false);
17 
18  const size_t n_top_dimension_cofaces = collection.simplex_vector().size();
19 
20  // reserve memory for all cells, their faces, and the input simplex
21  // this is crucial to avoid reallocation!!
22  switch (mesh.top_simplex_type()) {
23  case PrimitiveType::Vertex: break;
24  case PrimitiveType::Edge: collection.reserve(n_top_dimension_cofaces * 3 + 1); break;
25  case PrimitiveType::Triangle: collection.reserve(n_top_dimension_cofaces * 7 + 1); break;
26  case PrimitiveType::Tetrahedron: collection.reserve(n_top_dimension_cofaces * 15 + 1); break;
27  default: log_and_throw_error("unknown mesh type in top_dimension_cofaces_tuples");
28  }
29 
30  for (size_t i = 0; i < n_top_dimension_cofaces; ++i) {
31  // breaks if simplex vector needs to allocate memory due to reference!
32  faces(collection, collection.simplex_vector()[i], false);
33  }
34 
35  collection.add(simplex);
36 
37  if (sort_and_clean) {
38  collection.sort_and_clean();
39  }
40 
41  return collection;
42 }
43 
44 } // namespace wmtk::simplex
virtual bool is_valid(const Tuple &tuple) const
check validity of tuple including its hash
Definition: Mesh.cpp:113
PrimitiveType top_simplex_type() const
Definition: Mesh.hpp:997
void reserve(const size_t new_cap)
void add(const Simplex &simplex)
Add simplex to the collection.
const std::vector< Simplex > & simplex_vector() const
Return const reference to the simplex vector.
void sort_and_clean()
Sort simplex vector and remove duplicates.
const Tuple & tuple() const
Definition: Simplex.hpp:53
SimplexCollection closed_star(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
The closed star contains the input simplex, all its top dimension cofaces, and their faces.
Definition: closed_star.cpp:13
void top_dimension_cofaces(const Simplex &simplex, SimplexCollection &simplex_collection, const bool sort_and_clean)
Get all top dimension cofaces of the given simplex.
SimplexCollection faces(const Mesh &mesh, const Simplex &simplex, const bool sort_and_clean)
Returns all faces of a simplex.
Definition: faces.cpp:10
void log_and_throw_error(const std::string &msg)
Definition: Logger.cpp:101