Wildmeshing Toolkit
RawSimplexCollection.cpp
Go to the documentation of this file.
2 
3 #include "SimplexCollection.hpp"
4 
5 #include <algorithm>
6 
7 namespace wmtk::simplex {
9 {
10  add(sc);
11 }
12 
13 std::vector<RawSimplex> RawSimplexCollection::simplex_vector(const int64_t dimension) const
14 {
15  std::vector<RawSimplex> simplices;
16  simplices.reserve(m_simplices.size() / 3); // giving the vector some (hopefully) resonable size
17 
18  // add simplices to the vector
19  for (const RawSimplex& s : m_simplices) {
20  if (s.dimension() == dimension) {
21  simplices.emplace_back(s);
22  }
23  }
24 
25  return simplices;
26 }
27 
29 {
30  m_simplices.push_back(simplex);
31 }
32 
33 void RawSimplexCollection::add(const Mesh& mesh, const Simplex& simplex)
34 {
35  add(RawSimplex(mesh, simplex));
36 }
37 
38 void RawSimplexCollection::add(const RawSimplexCollection& simplex_collection)
39 {
40  const auto& s = simplex_collection.m_simplices;
41  m_simplices.insert(m_simplices.end(), s.begin(), s.end());
42 }
43 
44 void RawSimplexCollection::add(const SimplexCollection& simplex_collection)
45 {
46  const std::vector<Simplex>& simplices = simplex_collection.simplex_vector();
47 
48  m_simplices.reserve(m_simplices.size() + simplices.size());
49 
50  for (const Simplex& s : simplices) {
51  add(RawSimplex(simplex_collection.mesh(), s));
52  }
53 }
54 
56  const Mesh& mesh,
57  const PrimitiveType& ptype,
58  const std::vector<Tuple>& tuple_vec)
59 {
60  m_simplices.reserve(m_simplices.size() + tuple_vec.size());
61 
62  for (const Tuple& t : tuple_vec) {
63  m_simplices.emplace_back(RawSimplex(mesh, Simplex(mesh, ptype, t)));
64  }
65 }
66 
68 {
69  std::sort(m_simplices.begin(), m_simplices.end());
70  const auto last = std::unique(m_simplices.begin(), m_simplices.end());
71  m_simplices.erase(last, m_simplices.end());
72 }
73 
74 bool RawSimplexCollection::contains(const RawSimplex& simplex) const
75 {
76  assert(std::is_sorted(begin(), end()));
77  return std::binary_search(begin(), end(), simplex);
78 }
79 
81  const RawSimplexCollection& collection_a,
82  const RawSimplexCollection& collection_b)
83 {
84  assert(std::is_sorted(collection_a.begin(), collection_a.end()));
85  assert(std::is_sorted(collection_b.begin(), collection_b.end()));
87 
88  const auto& a = collection_a.m_simplices;
89  const auto& b = collection_b.m_simplices;
90 
91  std::set_union(a.cbegin(), a.cend(), b.cbegin(), b.cend(), std::back_inserter(sc.m_simplices));
92 
93  return sc;
94 }
95 
97  const RawSimplexCollection& collection_a,
98  const RawSimplexCollection& collection_b)
99 {
101 
102  const auto& a = collection_a;
103  const auto& b = collection_b;
104 
106  a.cbegin(),
107  a.cend(),
108  b.cbegin(),
109  b.cend(),
110  std::back_inserter(sc.m_simplices));
111 
112  return sc;
113 }
114 
116  const RawSimplexCollection& collection_a,
117  const RawSimplexCollection& collection_b)
118 {
119  if (collection_a.m_simplices.size() != collection_b.m_simplices.size()) {
120  return false;
121  }
122  RawSimplexCollection sc_union = RawSimplexCollection::get_union(collection_a, collection_b);
123  return sc_union.m_simplices.size() == collection_a.m_simplices.size();
124 }
125 
126 } // namespace wmtk::simplex
static bool are_simplex_collections_equal(const RawSimplexCollection &collection_a, const RawSimplexCollection &collection_b)
Check if the two simplex collections are equal.
void add(const RawSimplex &simplex)
Add simplex to the collection.
bool contains(const RawSimplex &simplex) const
Check if simplex is contained in collection.
static RawSimplexCollection get_intersection(const RawSimplexCollection &collection_a, const RawSimplexCollection &collection_b)
Get intersection of two simplex collections.
static RawSimplexCollection get_union(const RawSimplexCollection &collection_a, const RawSimplexCollection &collection_b)
Get union of two simplex collections.
RawSimplexCollection(std::vector< RawSimplex > &&simplices={})
void sort_and_clean()
Sort simplex vector and remove duplicates.
const std::vector< RawSimplex > & simplex_vector() const
Return const reference to the RawSimplex vector.
A meshless implementation of the simplex that just stores an array of ids.
Definition: RawSimplex.hpp:20
const std::vector< Simplex > & simplex_vector() const
Return const reference to the simplex vector.
void set_intersection(const std::unordered_set< int > &s1, const std::unordered_set< int > &s2, std::vector< int > &v)