2 #include <fmt/ranges.h>
3 #include <spdlog/spdlog.h>
4 #include <nlohmann/json.hpp>
19 std::ranges::transform(
22 [&](
const std::unique_ptr<Node>& n) { return std::make_unique<Node>(*n); });
27 std::ranges::transform(
30 [&](
const std::unique_ptr<Node>& n) { return std::make_unique<Node>(*n); });
45 auto& child =
m_children.emplace_back(std::make_unique<Node>());
47 }
else if (js.is_array()) {
48 for (
const auto& value : js) {
49 auto& child =
m_children.emplace_back(std::make_unique<Node>());
52 }
else if (js.is_object()) {
53 for (
const auto& [key, value] : js.items()) {
54 auto& child =
m_children.emplace_back(std::make_unique<Node>());
56 child->set_names(value);
62 void get_name_tokens(
const std::span<const int64_t>& t, std::vector<std::string_view>& toks)
65 toks.emplace_back(
name);
67 const size_t index = t.front();
71 child.get_name_tokens(t.subspan<1>(), toks);
79 for (
size_t j = 0; j <
m_children.size(); ++j) {
88 for (
const auto& c_ptr : nlohmann_json_t.
m_children) {
89 arr.emplace_back(*c_ptr);
91 nlohmann_json_j[nlohmann_json_t.
name] = arr;
113 m_root = m.shared_from_this();
125 const auto id =
get_id(path);
126 return m_root->get_multi_mesh_child_mesh(
id);
130 #if defined(WMTK_ENABLED_CPP20)
136 assert(*split.begin() == cur_mesh->
name || *split.begin() ==
"");
137 for (
const auto& token : std::ranges::views::drop(split, 1)) {
142 cur_mesh = cur_mesh->
m_children[it->second].get();
150 #if defined(WMTK_ENABLED_CPP20)
156 std::vector<int64_t> indices;
157 Node const* cur_mesh = m_name_root.get();
158 assert(*split.begin() == cur_mesh->
name || *split.begin() ==
"");
159 for (
const auto& token : std::ranges::views::drop(split, 1)) {
161 indices.emplace_back(index);
171 m_root->absolute_multi_mesh_id(),
182 assert(js.is_object() || js.is_string() || js.is_null());
187 }
else if (js.is_string()) {
190 assert(js.is_object());
191 assert(js.size() == 1);
192 for (
const auto& [k, v] : js.items()) {
207 std::vector<std::string_view> names;
210 for (
const auto& index :
id) {
212 names.emplace_back(cur_mesh->
name);
214 return fmt::format(
"{}", fmt::join(names,
"."));
226 m_name_root = std::make_unique<Node>(*o.m_name_root);
237 auto js_ptr = std::make_unique<nlohmann::json>();
248 std::map<std::string, const Mesh&> meshes;
249 for (
const auto& mptr :
m_root->get_all_meshes()) {
250 meshes.emplace(
get_name(*mptr), *mptr);
256 std::vector<std::string_view> toks;
258 const auto id =
get_id(m);
260 return fmt::format(
"{}", fmt::join(toks,
"."));
264 const std::vector<int64_t> parent_id =
get_id(parent);
266 for (
const auto& index : parent_id) {
277 fmt::join(child_relid,
","));
278 assert(child_relid.size() == 1);
280 const int64_t&
id = child_relid[0];
281 if (
const size_t child_size = cur_mesh->
m_children.size(); child_size ==
id) {
283 }
else if (child_size <
id) {
std::vector< int64_t > absolute_multi_mesh_id() const
returns a unique identifier for this mesh within a single multimesh structure
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.
std::string_view root_name() const
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
std::shared_ptr< Mesh > m_root
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
std::unique_ptr< Node > m_name_root
void set_name(const std::string_view &root_name="")
std::unique_ptr< nlohmann::json > get_names_json() const
static std::vector< int64_t > relative_id(const std::vector< int64_t > &parent, const std::vector< int64_t > &child)
auto split_path(const std::string_view &view)
std::vector< Simplex > make_unique(const Mesh &m, const std::vector< Simplex > &s)
void get_name_tokens(const std::span< const int64_t > &t, std::vector< std::string_view > &toks) const
friend void to_json(nlohmann::json &nlohmann_json_j, const NamedMultiMesh::Node &nlohmann_json_t)
void update_child_names()
std::map< std::string, int64_t > m_child_indexer
Node & operator=(const Node &o)
void set_names(const nlohmann::json &js)
std::vector< std::unique_ptr< Node > > m_children