Wildmeshing Toolkit
IdSimplexCollection.cpp
Go to the documentation of this file.
2 
3 #include <algorithm>
4 
5 namespace wmtk::simplex {
6 
7 
8 std::vector<IdSimplex> IdSimplexCollection::simplex_vector(const PrimitiveType& ptype) const
9 {
10  std::vector<IdSimplex> simplices;
11  simplices.reserve(m_simplices.size() / 3); // giving the vector some (hopefully) resonable size
12 
13  // add simplices to the vector
14  for (const IdSimplex& s : m_simplices) {
15  if (s.primitive_type() == ptype) {
16  simplices.emplace_back(s);
17  }
18  }
19 
20  return simplices;
21 }
22 
24 {
25  return m_mesh;
26 }
27 
29 {
30  std::vector<Tuple> tuples;
31  tuples.reserve(m_simplices.size() / 3); // giving the vector some (hopefully) resonable size
32 
33  // add simplices to the vector
34  for (const IdSimplex& s : m_simplices) {
35  if (s.primitive_type() == ptype) {
36  tuples.emplace_back(m_mesh.get_tuple_from_id_simplex(s));
37  }
38  }
39 
40  return tuples;
41 }
42 
43 void IdSimplexCollection::add(const IdSimplex& simplex)
44 {
45  m_simplices.push_back(simplex);
46 }
47 
48 void IdSimplexCollection::add(const IdSimplexCollection& simplex_collection)
49 {
50  const auto& s = simplex_collection.m_simplices;
51  m_simplices.insert(m_simplices.end(), s.begin(), s.end());
52 }
53 
54 void IdSimplexCollection::add(const PrimitiveType ptype, const std::vector<Tuple>& tuple_vec)
55 {
56  m_simplices.reserve(m_simplices.size() + tuple_vec.size());
57 
58  for (const Tuple& t : tuple_vec) {
59  m_simplices.emplace_back(mesh().get_id_simplex(t, ptype));
60  }
61 }
62 
63 void IdSimplexCollection::add(const PrimitiveType ptype, const Tuple& tuple)
64 {
65  m_simplices.emplace_back(mesh().get_id_simplex(tuple, ptype));
66 }
67 
69 {
70  std::sort(m_simplices.begin(), m_simplices.end());
71  const auto last = std::unique(m_simplices.begin(), m_simplices.end());
72  m_simplices.erase(last, m_simplices.end());
73 }
74 
76 {
77  std::sort(m_simplices.begin(), m_simplices.end());
78 }
79 
80 
81 bool IdSimplexCollection::contains(const IdSimplex& simplex) const
82 {
83  assert(std::is_sorted(m_simplices.begin(), m_simplices.end()));
84  return std::binary_search(m_simplices.begin(), m_simplices.end(), simplex);
85 }
86 
88  const IdSimplexCollection& collection_a,
89  const IdSimplexCollection& collection_b)
90 {
91  IdSimplexCollection sc(collection_a.m_mesh);
92 
93  const auto& a = collection_a.m_simplices;
94  const auto& b = collection_b.m_simplices;
95 
96  std::set_union(a.cbegin(), a.cend(), b.cbegin(), b.cend(), std::back_inserter(sc.m_simplices));
97 
98  return sc;
99 }
100 
102  const IdSimplexCollection& collection_a,
103  const IdSimplexCollection& collection_b)
104 {
105  IdSimplexCollection sc(collection_a.m_mesh);
106 
107  const auto& a = collection_a.m_simplices;
108  const auto& b = collection_b.m_simplices;
109 
111  a.cbegin(),
112  a.cend(),
113  b.cbegin(),
114  b.cend(),
115  std::back_inserter(sc.m_simplices));
116 
117  return sc;
118 }
119 
121  const IdSimplexCollection& collection_a,
122  const IdSimplexCollection& collection_b)
123 {
124  if (collection_a.m_simplices.size() != collection_b.m_simplices.size()) {
125  return false;
126  }
127 
128  for (int64_t i = 0; i < collection_a.size(); ++i) {
129  if (collection_a.m_simplices[i] != collection_b.m_simplices[i]) {
130  return false;
131  }
132  }
133  return true;
134 
135  // IdSimplexCollection sc_union = IdSimplexCollection::get_union(collection_a, collection_b);
136  // return sc_union.m_simplices.size() == collection_a.m_simplices.size();
137 }
138 
140 {
141  return are_simplex_collections_equal(*this, other);
142 }
143 
144 void IdSimplexCollection::reserve(const size_t new_cap)
145 {
146  m_simplices.reserve(new_cap);
147 }
148 
149 } // namespace wmtk::simplex
Tuple get_tuple_from_id_simplex(const simplex::IdSimplex &s) const
Definition: Mesh.cpp:44
void sort_and_clean()
Sort simplex vector and remove duplicates.
static IdSimplexCollection get_intersection(const IdSimplexCollection &collection_a, const IdSimplexCollection &collection_b)
Get intersection of two simplex collections.
void add(const IdSimplex &simplex)
Add simplex to the collection.
bool operator==(const IdSimplexCollection &other) const
static IdSimplexCollection get_union(const IdSimplexCollection &collection_a, const IdSimplexCollection &collection_b)
Get union of two simplex collections.
std::vector< Tuple > simplex_vector_tuples(PrimitiveType ptype) const
Return vector of all simplices of the requested type, as tuples.
const std::vector< IdSimplex > & simplex_vector() const
Return const reference to the simplex vector.
bool contains(const IdSimplex &simplex) const
Check if simplex is contained in collection.
static bool are_simplex_collections_equal(const IdSimplexCollection &collection_a, const IdSimplexCollection &collection_b)
Check if the two simplex collections are equal.
void set_intersection(const std::unordered_set< int > &s1, const std::unordered_set< int > &s2, std::vector< int > &v)