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  NamedMultiMesh(Mesh& m, const std::string_view& root_name);
21  explicit NamedMultiMesh(Mesh& m, const nlohmann::json& root_name);
22 
23  // Explicit constructors to remove ambiguities between string_view and json constructors
24  explicit NamedMultiMesh(Mesh& m, const std::string& root_name);
25  template <size_t N>
26  explicit NamedMultiMesh(Mesh& m, const char name[N])
27  : NamedMultiMesh(m, std::string_view(name))
28  {}
29  // NamedMultiMesh(NamedMultiMesh&&);
32  // auto operator=(NamedMultiMesh&&) -> NamedMultiMesh&;
33  auto operator=(const NamedMultiMesh&) -> NamedMultiMesh&;
34 
36  void set_name(const std::string_view& root_name = "");
37  void set_names(const nlohmann::json& js);
38  void set_root(Mesh& m);
39  void append_child_mesh_names(const Mesh& parent, const NamedMultiMesh& o);
40 
41  std::unique_ptr<nlohmann::json> get_names_json() const;
42 
43  std::string_view root_name() const;
44  std::string name(const std::vector<int64_t>& id) const;
45 
47  void set_mesh(Mesh& m);
48  Mesh& get_mesh(const std::string_view& path) const;
49  bool has_mesh(const std::string_view& path) const;
50  std::vector<int64_t> get_id(const std::string_view& path) const;
51  std::vector<int64_t> get_id(const Mesh& m) const;
52 
53  Mesh& root() { return *m_root; }
54  const Mesh& root() const { return *m_root; }
55 
56 
57  std::map<std::string, const Mesh&> all_meshes() const;
58 
59  // returns the name of a mesh if it lies in this multimesh
60  std::string get_name(const Mesh& m) const;
61 
62 private:
63  struct Node;
64  std::shared_ptr<Mesh> m_root;
65  std::unique_ptr<Node> m_name_root;
66 };
67 
68 } // namespace wmtk::components::multimesh
std::vector< int64_t > get_id(const std::string_view &path) const
NamedMultiMesh(Mesh &m, const char name[N])
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="")
sets just the name of the root mesh, keeping child names the same
std::unique_ptr< nlohmann::json > get_names_json() const
Definition: autodiff.h:995
Definition: Accessor.hpp:6
nlohmann::json json
Definition: input.cpp:9