Skip to content

Commit

Permalink
updating input and output to use path instead of file
Browse files Browse the repository at this point in the history
  • Loading branch information
mtao committed Nov 26, 2024
1 parent 323df07 commit 858bb3a
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 23 deletions.
6 changes: 3 additions & 3 deletions applications/isotropic_remeshing/examples/raw/camel.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
},
"root": "/home/mtao/git/wildmeshing-toolkit/data/aa0abd4658bb064515ee7cc2a7be87aa",
"position_attribute": "vertices",
"iterations": 30,
"length_rel": 1,
"iterations": 5,
"length_rel": 0.01,
"length_abs": -1,
"lock_boundary": true,
"edge_swap_mode": "valence",
Expand All @@ -15,6 +15,6 @@
"fix_uv_seam": false,
"output": {
"path": "output.hdf5",
"type": "hdf5"
"type": ".hdf5"
}
}
13 changes: 9 additions & 4 deletions components/input/src/wmtk/components/input/InputOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ namespace nlohmann {
void adl_serializer<wmtk::components::input::InputOptions>::to_json(json& j, const Type& v)
{
//
j["file"] = v.file;
j["file"] = v.file.string();
j["path"] = v.path;
j["path"] = v.path.string();
if (!v.name_spec.is_null()) {
assert(!v.name_spec_file.has_value());
j["name_spec"] = v.name_spec;
Expand All @@ -44,10 +44,15 @@ void adl_serializer<wmtk::components::input::InputOptions>::to_json(json& j, con
void adl_serializer<wmtk::components::input::InputOptions>::from_json(const json& j, Type& v)
{
if (j.is_string()) {
v.file = j.get<std::filesystem::path>();
v.path= j.get<std::filesystem::path>();
return;
} else if(j.contains("path")) {
v.path = j["path"].get<std::filesystem::path>();
} else if(j.contains("file")) {
wmtk::logger().warn("InputOptions using file is deprecated, use file");
v.path = j["file"].get<std::filesystem::path>();
}
v.file = j["file"].get<std::filesystem::path>();

if (j.contains("name_spec")) {
v.name_spec = j["name_spec"];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InputOptions
public:
InputOptions();
~InputOptions();
std::filesystem::path file;
std::filesystem::path path;
std::optional<std::vector<std::vector<std::string>>> imported_attributes;


Expand Down
6 changes: 3 additions & 3 deletions components/input/src/wmtk/components/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ std::shared_ptr<Mesh> input(
{
InputOptions options;
options.old_mode = true;
options.file = file;
options.path = file;
options.ignore_z_if_zero = ignore_z_if_zero;
if (!tetrahedron_attributes.empty()) {
options.imported_attributes = {{}, {}, {}, tetrahedron_attributes};
Expand All @@ -33,7 +33,7 @@ multimesh::NamedMultiMesh input(
const InputOptions& options,
const components::utils::PathResolver& resolver)
{
const auto [file_path, found] = resolver.resolve(options.file);
const auto [file_path, found] = resolver.resolve(options.path);
if (!found) {
const auto& paths = resolver.get_paths();
std::vector<std::string> path_strs;
Expand All @@ -46,7 +46,7 @@ multimesh::NamedMultiMesh input(
log_and_throw_error(
"file [{}] not found (input path was [{}], paths searched were [{}]",
file_path.string(),
options.file.string(),
options.path.string(),
fmt::join(path_strs, ","));
}

Expand Down
4 changes: 2 additions & 2 deletions components/input/tests/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ TEST_CASE("component_input", "[components][input]")
{"ignore_z", false},
{"tetrahedron_attributes", json::array()}};
auto opts = component_json.get<wmtk::components::input::InputOptions>();
CHECK(opts.file == input_file);
CHECK(opts.path == input_file);
CHECK(opts.ignore_z_if_zero == false);
CHECK(opts.old_mode == true);
CHECK(opts.old_mode == true);
Expand All @@ -50,7 +50,7 @@ TEST_CASE("component_input", "[components][input]")
nlohmann::json js = "path";
REQUIRE(js.is_string());
auto opts = js.get<wmtk::components::input::InputOptions>();
CHECK(opts.file.string() == "path");
CHECK(opts.path.string() == "path");
}

SECTION("should throw")
Expand Down
15 changes: 9 additions & 6 deletions components/output/wmtk/components/output/OutputOptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace wmtk::components::output {

WMTK_NLOHMANN_JSON_FRIEND_TO_JSON_PROTOTYPE(OutputOptions)
{
WMTK_NLOHMANN_ASSIGN_TYPE_TO_JSON(file, type)
WMTK_NLOHMANN_ASSIGN_TYPE_TO_JSON(path, type)
if (nlohmann_json_t.mesh_name_path.has_value()) {
nlohmann_json_j["mesh_name_path"] = nlohmann_json_t.mesh_name_path.value();
}
Expand All @@ -33,17 +33,20 @@ WMTK_NLOHMANN_JSON_FRIEND_TO_JSON_PROTOTYPE(OutputOptions)
WMTK_NLOHMANN_JSON_FRIEND_FROM_JSON_PROTOTYPE(OutputOptions)
{
if (nlohmann_json_j.is_string()) {
nlohmann_json_t.file = nlohmann_json_j.get<std::filesystem::path>();
} else {
nlohmann_json_t.file = nlohmann_json_j["file"].get<std::filesystem::path>();
nlohmann_json_t.path = nlohmann_json_j.get<std::filesystem::path>();
} else if(nlohmann_json_j.contains("path")) {
nlohmann_json_t.path = nlohmann_json_j["path"].get<std::filesystem::path>();
} else if(nlohmann_json_j.contains("file")) {
wmtk::logger().warn("OutputOptions using file is deprecated, use file");
nlohmann_json_t.path = nlohmann_json_j["file"].get<std::filesystem::path>();
}
if (nlohmann_json_j.contains("type")) {
nlohmann_json_t.type = nlohmann_json_j["type"];
} else {
nlohmann_json_t.type = nlohmann_json_t.file.extension().string();
nlohmann_json_t.type = nlohmann_json_t.path.extension().string();
wmtk::logger().debug(
"Guessing extension type of [{}] is [{}]",
nlohmann_json_t.file,
nlohmann_json_t.path,
nlohmann_json_t.type);
}
if (nlohmann_json_j.contains("position_attribute")) {
Expand Down
2 changes: 1 addition & 1 deletion components/output/wmtk/components/output/OutputOptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
namespace wmtk::components::output {
struct OutputOptions
{
std::filesystem::path file;
std::filesystem::path path;

std::string type;

Expand Down
6 changes: 3 additions & 3 deletions components/output/wmtk/components/output/output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,14 @@ void output(
for (int64_t d = 0; d <= mesh.top_cell_dimension(); ++d) {
out[d] = true;
}
ParaviewWriter writer(opts.file,name, mesh, out[0], out[1], out[2], out[3]);
ParaviewWriter writer(opts.path,name, mesh, out[0], out[1], out[2], out[3]);
mesh.serialize(writer);
} else if (opts.type == ".hdf5") {
output_hdf5(mesh, opts.file);
output_hdf5(mesh, opts.path);
} else
throw std::runtime_error(
fmt::format("Unable to write file [{}] of extension [{}]",
opts.file, opts.type));
opts.path, opts.type));
}

void output(
Expand Down

0 comments on commit 858bb3a

Please sign in to comment.