Wildmeshing Toolkit
Mesh_multimesh.cpp
Go to the documentation of this file.
1 #include "Mesh.hpp"
2 #include <queue>
3 #include <numeric>
4 
5 #include <wmtk/io/MeshWriter.hpp>
6 #include <wmtk/utils/Logger.hpp>
8 
9 #include "Primitive.hpp"
10 
11 namespace wmtk {
12 std::vector<int64_t> Mesh::absolute_multi_mesh_id() const
13 {
15 }
17  const std::shared_ptr<Mesh>& child_mesh_ptr,
18  const std::vector<std::array<Tuple, 2>>& map_tuples)
19 {
20  m_multi_mesh_manager.register_child_mesh(*this, child_mesh_ptr, map_tuples);
21 }
22 
23 void Mesh::deregister_child_mesh(const std::shared_ptr<Mesh>& child_mesh_ptr)
24 {
25  m_multi_mesh_manager.deregister_child_mesh(*this, child_mesh_ptr);
26 }
27 
29 {
31 }
32 
33 
35 {
36  return &get_multi_mesh_root() == &other.get_multi_mesh_root();
37 }
38 
39 bool Mesh::can_map(const Mesh& other_mesh, const simplex::Simplex& my_simplex) const
40 {
41  if (!is_from_same_multi_mesh_structure(other_mesh)) {
42  throw std::runtime_error(
43  "Attempted to map between two simplices in different multi-mesh structures");
44  }
45  return m_multi_mesh_manager.can_map(*this, other_mesh, my_simplex);
46 }
47 
48 std::vector<simplex::Simplex> Mesh::map(const Mesh& other_mesh, const simplex::Simplex& my_simplex)
49  const
50 {
51  if (!is_from_same_multi_mesh_structure(other_mesh)) {
52  throw std::runtime_error(
53  "Attempted to map between two simplices in different multi-mesh structures");
54  }
55  return m_multi_mesh_manager.map(*this, other_mesh, my_simplex);
56 }
57 
58 std::vector<simplex::Simplex> Mesh::map(
59  const Mesh& other_mesh,
60  const std::vector<simplex::Simplex>& simplices) const
61 {
62  std::vector<simplex::Simplex> ret;
63  ret.reserve(simplices.size());
64  for (const auto& s : simplices) {
65  auto v = map(other_mesh, s);
66  ret.insert(ret.end(), v.begin(), v.end());
67  }
68 
69  return ret;
70 }
71 
72 std::vector<simplex::Simplex> Mesh::lub_map(
73  const Mesh& other_mesh,
74  const simplex::Simplex& my_simplex) const
75 {
76  if (!is_from_same_multi_mesh_structure(other_mesh)) {
77  throw std::runtime_error(
78  "Attempted to map between two simplices in different multi-mesh structures");
79  }
80  return m_multi_mesh_manager.lub_map(*this, other_mesh, my_simplex);
81 }
82 
83 std::vector<simplex::Simplex> Mesh::lub_map(
84  const Mesh& other_mesh,
85  const std::vector<simplex::Simplex>& simplices) const
86 {
87  std::vector<simplex::Simplex> ret;
88  ret.reserve(simplices.size());
89  for (const auto& s : simplices) {
90  auto v = lub_map(other_mesh, s);
91  ret.insert(ret.end(), v.begin(), v.end());
92  }
93 
94  return ret;
95 }
96 
97 
99 {
100  if (is_multi_mesh_root()) {
101  throw std::runtime_error("Attempted to map a simplex to parent despite being a root");
102  }
103  return m_multi_mesh_manager.map_to_parent(*this, my_simplex);
104 }
106 {
107  return m_multi_mesh_manager.map_to_root(*this, my_simplex);
108 }
109 
110 std::vector<simplex::Simplex> Mesh::map_to_child(
111  const Mesh& child_mesh,
112  const simplex::Simplex& my_simplex) const
113 {
114  if (!is_from_same_multi_mesh_structure(child_mesh)) {
115  throw std::runtime_error(
116  "Attempted to map between two simplices in different multi-mesh structures");
117  }
118  return m_multi_mesh_manager.map_to_child(*this, child_mesh, my_simplex);
119 }
120 
121 std::vector<Tuple> Mesh::map_tuples(const Mesh& other_mesh, const simplex::Simplex& my_simplex)
122  const
123 {
124  if (!is_from_same_multi_mesh_structure(other_mesh)) {
125  throw std::runtime_error(
126  "Attempted to map between two simplices in different multi-mesh structures");
127  }
128  return m_multi_mesh_manager.map_tuples(*this, other_mesh, my_simplex);
129 }
130 
131 std::vector<Tuple>
132 Mesh::map_tuples(const Mesh& other_mesh, PrimitiveType pt, const std::vector<Tuple>& tuples) const
133 {
134  std::vector<Tuple> ret;
135  ret.reserve(tuples.size());
136  for (const auto& t : tuples) {
137  auto v = map_tuples(other_mesh, simplex::Simplex(*this, pt, t));
138  ret.insert(ret.end(), v.begin(), v.end());
139  }
140 
141  return ret;
142 }
143 std::vector<Tuple> Mesh::lub_map_tuples(const Mesh& other_mesh, const simplex::Simplex& my_simplex)
144  const
145 {
146  if (!is_from_same_multi_mesh_structure(other_mesh)) {
147  throw std::runtime_error(
148  "Attempted to map between two simplices in different multi-mesh structures");
149  }
150  return m_multi_mesh_manager.lub_map_tuples(*this, other_mesh, my_simplex);
151 }
152 
153 std::vector<Tuple> Mesh::lub_map_tuples(
154  const Mesh& other_mesh,
155  PrimitiveType pt,
156  const std::vector<Tuple>& tuples) const
157 {
158  std::vector<Tuple> ret;
159  ret.reserve(tuples.size());
160  for (const auto& t : tuples) {
161  auto v = lub_map_tuples(other_mesh, simplex::Simplex(*this, pt, t));
162  ret.insert(ret.end(), v.begin(), v.end());
163  }
164 
165  return ret;
166 }
167 
169 {
170  if (is_multi_mesh_root()) {
171  throw std::runtime_error("Attempted to map a simplex to parent despite being a root");
172  }
173  return m_multi_mesh_manager.map_to_parent_tuple(*this, my_simplex);
174 }
176 {
177  return m_multi_mesh_manager.map_to_root_tuple(*this, my_simplex);
178 }
179 std::vector<Tuple> Mesh::map_to_child_tuples(
180  const Mesh& child_mesh,
181  const simplex::Simplex& my_simplex) const
182 {
183  if (!is_from_same_multi_mesh_structure(child_mesh)) {
184  throw std::runtime_error(
185  "Attempted to map between two simplices in different multi-mesh structures");
186  }
187  return m_multi_mesh_manager.map_to_child_tuples(*this, child_mesh, my_simplex);
188 }
189 
191 {
192  return m_multi_mesh_manager.is_root();
193 }
195 {
196  return m_multi_mesh_manager.get_root_mesh(*this);
197 }
199 {
200  return m_multi_mesh_manager.get_root_mesh(*this);
201 }
202 
203 Mesh& Mesh::get_multi_mesh_mesh(const std::vector<int64_t>& absolute_id)
204 {
205  return m_multi_mesh_manager.get_mesh(*this, absolute_id);
206 }
207 const Mesh& Mesh::get_multi_mesh_mesh(const std::vector<int64_t>& absolute_id) const
208 {
209  return m_multi_mesh_manager.get_mesh(*this, absolute_id);
210 }
211 
212 
213 Mesh& Mesh::get_multi_mesh_child_mesh(const std::vector<int64_t>& relative_id)
214 {
215  return m_multi_mesh_manager.get_child_mesh(*this, relative_id);
216 }
217 const Mesh& Mesh::get_multi_mesh_child_mesh(const std::vector<int64_t>& relative_id) const
218 {
219  return m_multi_mesh_manager.get_child_mesh(*this, relative_id);
220 }
221 
222 std::vector<std::shared_ptr<Mesh>> Mesh::get_child_meshes() const
223 {
225 }
226 
227 std::vector<std::shared_ptr<Mesh>> Mesh::get_all_child_meshes() const
228 {
229  std::vector<std::shared_ptr<Mesh>> children;
230  auto direct_children = get_child_meshes();
231  for (const auto& child : direct_children) {
232  children.emplace_back(child);
233  auto child_children = child->get_all_child_meshes();
234  if (child_children.empty()) {
235  continue;
236  }
237  std::copy(child_children.begin(), child_children.end(), std::back_inserter(children));
238  }
239  return children;
240 }
241 
242 std::vector<std::shared_ptr<const Mesh>> Mesh::get_all_meshes() const
243 {
244  auto meshes2 = get_all_child_meshes();
245  std::vector<std::shared_ptr<Mesh const>> meshes;
246  meshes.emplace_back(shared_from_this());
247  for(const auto& m: meshes2) {
248  meshes.emplace_back(m);
249  }
250  return meshes;
251  //std::queue<std::shared_ptr<Mesh const>> queue;
253  //meshes.emplace_back(this);
254  //while(!queue.empty()) {
255  // const auto& cur = queue.front();
256  // //Mesh const* cur = queue.front();
257  // queue.pop();
258  // meshes.emplace_back(cur->shared_from_this());
259  // for(const auto& m: cur->get_child_meshes()) {
260  // queue.emplace(m.get());
261  // }
262  //}
263  //return meshes;
264 }
265 } // namespace wmtk
std::vector< int64_t > absolute_multi_mesh_id() const
returns a unique identifier for this mesh within a single multimesh structure
std::vector< simplex::Simplex > lub_map(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh using LUB mesh as root
void update_child_handles()
Update the child handles after clearing attributes.
Mesh & get_multi_mesh_child_mesh(const std::vector< int64_t > &relative_id)
Tuple map_to_root_tuple(const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to the root mesh
std::vector< std::shared_ptr< Mesh > > get_all_child_meshes() const
returns all multimesh child meshes
multimesh::MultiMeshManager m_multi_mesh_manager
Definition: Mesh.hpp:841
std::vector< Tuple > map_tuples(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh
bool is_multi_mesh_root() const
return true if this mesh is the root of a multimesh tree
Tuple map_to_parent_tuple(const simplex::Simplex &my_simplex) const
optimized map from a simplex from this mesh to its direct parent
simplex::Simplex map_to_root(const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to the root mesh
Mesh & get_multi_mesh_root()
returns a reference to the root of a multimesh tree
std::vector< std::shared_ptr< const Mesh > > get_all_meshes() const
returns all meshes in multimesh
simplex::Simplex map_to_parent(const simplex::Simplex &my_simplex) const
optimized map from a simplex from this mesh to its direct parent
void register_child_mesh(const std::shared_ptr< Mesh > &child_mesh_ptr, const std::vector< std::array< Tuple, 2 >> &map_tuples)
register a mesh as the child of this mesh
std::vector< simplex::Simplex > map(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh
Mesh & get_multi_mesh_mesh(const std::vector< int64_t > &absolute_id)
bool can_map(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
bool is_from_same_multi_mesh_structure(const Mesh &other) const
void deregister_child_mesh(const std::shared_ptr< Mesh > &child_mesh_ptr)
Deregister a child mesh.
std::vector< Tuple > map_to_child_tuples(const Mesh &child_mesh, const simplex::Simplex &my_simplex) const
optimized map fromsimplex from this mesh to one of its direct children
std::vector< simplex::Simplex > map_to_child(const Mesh &child_mesh, const simplex::Simplex &my_simplex) const
optimized map fromsimplex from this mesh to one of its direct children
std::vector< std::shared_ptr< Mesh > > get_child_meshes() const
returns the direct multimesh child meshes for the current mesh
std::vector< Tuple > lub_map_tuples(const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh using LUB mesh as root
Tuple map_to_root_tuple(const Mesh &my_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to the root mesh
const Mesh & get_root_mesh(const Mesh &my_mesh) const
void register_child_mesh(Mesh &my_mesh, const std::shared_ptr< Mesh > &child_mesh, const std::vector< std::array< Tuple, 2 >> &child_tuple_my_tuple_map)
register a another mesh as a child of this mesh.
Mesh & get_mesh(Mesh &m, const std::vector< int64_t > &absolute_id)
void deregister_child_mesh(Mesh &my_mesh, const std::shared_ptr< Mesh > &child_mesh_ptr)
Deregister a child mesh.
bool is_root() const
Specifies whether this structure is the root of a multi-mesh tree.
std::vector< int64_t > absolute_id() const
std::vector< simplex::Simplex > map(const Mesh &my_mesh, const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh
std::vector< std::shared_ptr< Mesh > > get_child_meshes() const
std::vector< Tuple > lub_map_tuples(const Mesh &my_mesh, const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh using the LUB as the root
void update_child_handles(Mesh &my_mesh)
Clean up child data after deleting attributes.
simplex::Simplex map_to_root(const Mesh &my_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to the root mesh
simplex::Simplex map_to_parent(const Mesh &my_mesh, const simplex::Simplex &my_simplex) const
optimized map from a simplex from this mesh to its direct parent
std::vector< Tuple > map_tuples(const Mesh &my_mesh, const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh
Tuple map_to_parent_tuple(const Mesh &my_mesh, const simplex::Simplex &my_simplex) const
optimized map from a simplex from this mesh to its direct parent
bool can_map(const Mesh &my_mesh, const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
std::vector< Tuple > map_to_child_tuples(const Mesh &my_mesh, const Mesh &child_mesh, const simplex::Simplex &my_simplex) const
Mesh & get_child_mesh(Mesh &m, const std::vector< int64_t > &relative_id)
std::vector< simplex::Simplex > map_to_child(const Mesh &my_mesh, const Mesh &child_mesh, const simplex::Simplex &my_simplex) const
optimized map fromsimplex from this mesh to one of its direct children
std::vector< simplex::Simplex > lub_map(const Mesh &my_mesh, const Mesh &other_mesh, const simplex::Simplex &my_simplex) const
maps a simplex from this mesh to any other mesh using the LUB as the root
Definition: Accessor.hpp:6