Wildmeshing Toolkit
ProceduralOptions.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <nlohmann/json.hpp>
6 #include "DiskOptions.hpp"
7 #include "GridOptions.hpp"
8 #include "TriangleFanOptions.hpp"
9 
11 
12 
14 {
15  std::string name;
16  std::variant<GridOptions, TriangleFanOptions, DiskOptions> settings;
17 
18  friend void to_json(nlohmann::json& nlohmann_json_j, const ProceduralOptions& nlohmann_json_t)
19  {
20  std::visit(
21  [&](const auto& s) { nlohmann_json_j["settings"] = s; },
22  nlohmann_json_t.settings);
23  }
24  friend void from_json(const nlohmann::json& nlohmann_json_j, ProceduralOptions& nlohmann_json_t)
25  {
26  if (nlohmann_json_j.contains("triangle_fan")) {
27  const auto& settings_js = nlohmann_json_j["triangle_fan"];
28  nlohmann_json_t.settings = settings_js.get<TriangleFanOptions>();
29  } else if (nlohmann_json_j.contains("grid")) {
30  const auto& settings_js = nlohmann_json_j["grid"];
31  nlohmann_json_t.settings = settings_js.get<GridOptions>();
32  } else if (nlohmann_json_j.contains("disk")) {
33  const auto& settings_js = nlohmann_json_j["disk"];
34  nlohmann_json_t.settings = settings_js.get<DiskOptions>();
35 
36  } else {
37  throw std::runtime_error(fmt::format("Unknown procedural mesh mesh_type"));
38  }
39  }
40 };
41 
42 
43 } // namespace wmtk::components::procedural
friend void to_json(nlohmann::json &nlohmann_json_j, const ProceduralOptions &nlohmann_json_t)
std::variant< GridOptions, TriangleFanOptions, DiskOptions > settings
friend void from_json(const nlohmann::json &nlohmann_json_j, ProceduralOptions &nlohmann_json_t)
nlohmann::json json
Definition: input.cpp:9