Wildmeshing Toolkit
NamedMultiMesh.hpp
Go to the documentation of this file.
1 #pragma once
2 #include <memory>
3 #include <nlohmann/json_fwd.hpp>
4 
5 namespace wmtk {
6 class Mesh;
7 }
8 
9 
11 
12 // allows for accessing a mesh by a string ID
13 // The IDs are loaded through a json format, and hte root node can either have a name or be hte
14 // empty string. Even if hte root it has a name, typing it can be skipped by a preceding '.' before
15 // a path
17 {
18 public:
20  explicit NamedMultiMesh(Mesh& m, const std::string& root_name);
21  NamedMultiMesh(Mesh& m, const std::string_view& root_name);
22  explicit NamedMultiMesh(Mesh& m, const nlohmann::json& root_name);
23  // NamedMultiMesh(NamedMultiMesh&&);
26  // auto operator=(NamedMultiMesh&&) -> NamedMultiMesh&;
27  auto operator=(const NamedMultiMesh&) -> NamedMultiMesh&;
28 
29  void set_name(const std::string_view& root_name = "");
30  void set_names(const nlohmann::json& js);
31  void set_root(Mesh& m);
32  void append_child_mesh_names(const Mesh& parent, const NamedMultiMesh& o);
33 
34  std::unique_ptr<nlohmann::json> get_names_json() const;
35 
36  std::string_view root_name() const;
37  std::string name(const std::vector<int64_t>& id) const;
38 
40  void set_mesh(Mesh& m);
41  Mesh& get_mesh(const std::string_view& path) const;
42  bool has_mesh(const std::string_view& path) const;
43  std::vector<int64_t> get_id(const std::string_view& path) const;
44  std::vector<int64_t> get_id(const Mesh& m) const;
45 
46  Mesh& root() { return *m_root; }
47  const Mesh& root() const { return *m_root; }
48 
49 
50  std::map<std::string, const Mesh&> all_meshes() const;
51 
52  // returns the name of a mesh if it lies in this multimesh
53  std::string get_name(const Mesh& m) const;
54 
55 private:
56  struct Node;
57  std::shared_ptr<Mesh> m_root;
58  std::unique_ptr<Node> m_name_root;
59 };
60 
61 } // namespace wmtk::components::multimesh
std::vector< int64_t > get_id(const std::string_view &path) const
auto operator=(const NamedMultiMesh &) -> NamedMultiMesh &
std::map< std::string, const Mesh & > all_meshes() const
void set_mesh(Mesh &m)
Navigates to the root of the multimesh.
bool has_mesh(const std::string_view &path) const
std::string name(const std::vector< int64_t > &id) const
Mesh & get_mesh(const std::string_view &path) const
void append_child_mesh_names(const Mesh &parent, const NamedMultiMesh &o)
void set_names(const nlohmann::json &js)
std::string get_name(const Mesh &m) const
void set_name(const std::string_view &root_name="")
std::unique_ptr< nlohmann::json > get_names_json() const
Definition: Accessor.hpp:6
nlohmann::json json
Definition: input.cpp:9