Wildmeshing Toolkit
Loading...
Searching...
No Matches
InputOptions.cpp
Go to the documentation of this file.
1#include "InputOptions.hpp"
5
6
8
11bool InputOptions::operator==(const InputOptions& o) const = default;
12
13} // namespace wmtk::components::input
14
15namespace nlohmann {
16void adl_serializer<wmtk::components::input::InputOptions>::to_json(json& j, const Type& v)
17{
18 //
19 j["file"] = v.file;
20 j["file"] = v.file.string();
21 if (!v.name_spec.is_null()) {
22 assert(!v.name_spec_file.has_value());
23 j["name_spec"] = v.name_spec;
24 } else if (v.name_spec_file.has_value()) {
25 j["name_spec_file"] = v.name_spec_file.value();
26 }
27
28
29 if (v.old_mode) {
30 j["old_mode"] = true;
31 j["ignore_z"] = v.ignore_z_if_zero; // keep around for deprecation purposes
32 // j["ignore_z_if_zero"] = v.ignore_z_if_zero;
33 if (v.imported_attributes.has_value()) {
34 const auto& imported_attrs = v.imported_attributes.value();
35 if (imported_attrs.size() > 3) {
36 j["tetrahedron_attributes"] = imported_attrs[3];
37 }
38 }
39 } else {
40 if (v.imported_attributes.has_value()) {
41 j["imported_attributes"] = v.imported_attributes.value();
42 }
43 }
44}
45void adl_serializer<wmtk::components::input::InputOptions>::from_json(const json& j, Type& v)
46{
47 if (j.is_string()) {
48 v.file = j.get<std::filesystem::path>();
49 return;
50 }
51 v.file = j["file"].get<std::filesystem::path>();
52 if (j.contains("name_spec")) {
53 v.name_spec = j["name_spec"];
54 }
55 if (j.contains("name_spec_file")) {
56 v.name_spec_file = j["name_spec_file"].get<std::filesystem::path>();
57 }
58
59
60 v.old_mode = false;
61 if (j.contains("old_mode")) {
62 v.old_mode = bool(j["old_mode"]);
63 } else {
64 v.old_mode = j.contains("ignore_z") || j.contains("tetrahedron_attributes");
65 if (v.old_mode) {
66 wmtk::logger().debug(
67 "Input component is using old mode because ignore_z exists ({}) or "
68 "tetrahedron_attributes exists ({})",
69 j.contains("ignore_z"),
70 j.contains("tetrahedron_attributes"));
71 }
72 }
73
74
75 if (v.old_mode) {
76 v.ignore_z_if_zero = j.contains("ignore_z") ? bool(j["ignore_z"]) : false;
77 // overwrite old ignore_z
78 // v.ignore_z_if_zero = j.contains("ignore_z_if_zero") ? bool(j["ignore_z_if_zero"]) :
79 // false;
80 if (j.contains("tetrahedron_attributes")) {
82 {},
83 {},
84 {},
85 j["tetrahedron_attributes"].get<std::vector<std::string>>()};
86 }
87 } else {
88 if (v.imported_attributes.has_value()) {
90 j["imported_attributes"].get<std::vector<std::vector<std::string>>>();
91 }
92 }
93}
94
95} // namespace nlohmann
std::optional< std::vector< std::vector< std::string > > > imported_attributes
bool operator==(const InputOptions &o) const
std::optional< std::filesystem::path > name_spec_file
spdlog::logger & logger()
Retrieves the current logger.
Definition Logger.cpp:58
nlohmann::json json
Definition input.cpp:9