Wildmeshing Toolkit
PrimitiveType.cpp
Go to the documentation of this file.
1 #include "PrimitiveType.hpp"
2 #include <string>
3 
4 
5 namespace wmtk {
6 namespace {
7 // NOTE: The order of these entries must be aligned with the order of enum values in PrimitiveType.
8 // Invalid must be the last string here for primitive_type_name to work
9 const static std::string names[] = {
10  "Vertex",
11  "Edge",
12  "Face",
13  "Tetrahedron"
14  "Invalid"};
15 } // namespace
16 
17 int8_t get_max_primitive_type_id(const std::vector<PrimitiveType>& primitive_types)
18 {
19  int8_t max_id = -1;
20  for (const auto& t : primitive_types) {
21  max_id = std::max(max_id, get_primitive_type_id(t));
22  }
23 
24  return max_id;
25 }
26 
27 // PrimitiveType get_primitive_type_from_id(int8_t id)
28 //{
29 // switch (id) {
30 // case 0: return PrimitiveType::Vertex;
31 // case 1: return PrimitiveType::Edge;
32 // case 2: return PrimitiveType::Face;
33 // case 3: return PrimitiveType::Tetrahedron;
34 // case 4: return PrimitiveType::HalfEdge;
35 // default: break; // just return at the end because compilers can be finicky
36 // }
37 //
38 // return PrimitiveType::Vertex;
39 //}
40 
42 {
43  int64_t id = get_primitive_type_id(t);
44  constexpr size_t valid_ids = sizeof(names) / sizeof(std::string) - 1;
45  if (id >= 0 && id <= valid_ids) {
46  return std::string_view(names[id]);
47  } else {
48  return std::string_view(names[valid_ids]);
49  }
50 }
51 
52 } // namespace wmtk
Definition: Accessor.hpp:6
std::string_view primitive_type_name(PrimitiveType t)
constexpr int8_t get_primitive_type_id(PrimitiveType t)
Get a unique integer id corresponding to each primitive type.
int8_t get_max_primitive_type_id(const std::vector< PrimitiveType > &primitive_types)
Get the maximum id for a list of primitive types.