From ac6ea7e1e30e8f7959f031fbc1bead1b4fc5002e Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Wed, 5 Mar 2025 10:33:13 +0100 Subject: [PATCH 1/2] options: Add path_t and use it for hdri --- application/F3DStarter.cxx | 4 +-- cmake/f3dOptions.cmake | 6 +++++ library/options.json | 2 +- library/private/options_tools.h | 21 +++++++++++++++ library/public/types.h | 28 ++++++++++++++++++++ library/src/options.cxx | 1 + library/testing/TestSDKDynamicHDRI.cxx | 4 +-- library/testing/TestSDKInteractorCommand.cxx | 2 +- 8 files changed, 62 insertions(+), 6 deletions(-) diff --git a/application/F3DStarter.cxx b/application/F3DStarter.cxx index 503ceae670..618a7a1231 100644 --- a/application/F3DStarter.cxx +++ b/application/F3DStarter.cxx @@ -1773,7 +1773,7 @@ void F3DStarter::AddCommands() { // Set the first file has an HDRI f3d::options& options = this->Internals->Engine->getOptions(); - options.render.hdri.file = files[0]; + options.render.hdri.file = f3d::path_t(files[0]); options.render.hdri.ambient = true; options.render.background.skybox = true; @@ -1794,7 +1794,7 @@ void F3DStarter::AddCommands() // Load the file as an HDRI instead of adding it. f3d::options& options = this->Internals->Engine->getOptions(); - options.render.hdri.file = file; + options.render.hdri.file = f3d::path_t(file); options.render.hdri.ambient = true; options.render.background.skybox = true; diff --git a/cmake/f3dOptions.cmake b/cmake/f3dOptions.cmake index 235f325d1b..06f1c71e6d 100644 --- a/cmake/f3dOptions.cmake +++ b/cmake/f3dOptions.cmake @@ -129,6 +129,12 @@ function(_parse_json_option _top_json) set(_option_variant_type "std::string") set(_option_default_value_start "\"") set(_option_default_value_end "\"") + elseif(_option_type STREQUAL "path") + set(_option_actual_type "f3d::path_t") + set(_option_explicit_constr "f3d::path_t") + set(_option_variant_type "std::string") + set(_option_default_value_start "\"") + set(_option_default_value_end "\"") elseif(_option_type STREQUAL "ratio") set(_option_actual_type "f3d::ratio_t") set(_option_explicit_constr "f3d::ratio_t") diff --git a/library/options.json b/library/options.json index da404c9a8d..69fb4f3c69 100644 --- a/library/options.json +++ b/library/options.json @@ -98,7 +98,7 @@ }, "hdri": { "file": { - "type": "string" + "type": "path" }, "ambient": { "type": "bool", diff --git a/library/private/options_tools.h b/library/private/options_tools.h index ba60dffa34..cb8860c8e4 100644 --- a/library/private/options_tools.h +++ b/library/private/options_tools.h @@ -183,6 +183,16 @@ ratio_t parse(const std::string& str) } } +//---------------------------------------------------------------------------- +/** + * Parse provided string into a path_t. + */ +template<> +path_t parse(const std::string& str) +{ + return f3d::path_t(str); +} + //---------------------------------------------------------------------------- /** * Parse provided string into a color_t. @@ -323,6 +333,17 @@ std::string format(const std::string& var) return var; } +//---------------------------------------------------------------------------- +/** + * Format provided var into a string from provided path_t + * rely on format(std::string&) + */ +std::string format(path_t var) +{ + // TODO generate a proper path string + return options_tools::format(static_cast(var)); +} + //---------------------------------------------------------------------------- /** * Format provided var into a string from provided double vector diff --git a/library/public/types.h b/library/public/types.h index 04c9a23816..0df491fca3 100644 --- a/library/public/types.h +++ b/library/public/types.h @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -81,6 +82,33 @@ class ratio_t double Value; }; +/** + * Describe a path. + */ +class path_t +{ +public: + inline path_t() = default; + inline explicit path_t(std::string_view val) + : Value(val) + { + } + inline operator std::string() const + { + return this->Value.string(); + } + [[nodiscard]] bool operator==(const path_t& other) const + { + return this->Value == other.Value; + } + [[nodiscard]] bool operator!=(const path_t& other) const + { + return this->Value != other.Value; + } +private: + std::filesystem::path Value; +}; + /** * A base template type for an array of double */ diff --git a/library/src/options.cxx b/library/src/options.cxx index 4df97f5386..c67dbb9e01 100644 --- a/library/src/options.cxx +++ b/library/src/options.cxx @@ -193,6 +193,7 @@ F3D_DECL_TYPE_WITH_VEC(int); F3D_DECL_TYPE_WITH_VEC(double); F3D_DECL_TYPE_WITH_VEC(f3d::ratio_t); F3D_DECL_TYPE_WITH_VEC(std::string); +F3D_DECL_TYPE_WITH_VEC(f3d::path_t); F3D_DECL_TYPE(color_t); F3D_DECL_TYPE(direction_t); diff --git a/library/testing/TestSDKDynamicHDRI.cxx b/library/testing/TestSDKDynamicHDRI.cxx index 0d8f530d74..351624fade 100644 --- a/library/testing/TestSDKDynamicHDRI.cxx +++ b/library/testing/TestSDKDynamicHDRI.cxx @@ -50,7 +50,7 @@ int TestSDKDynamicHDRI(int argc, char* argv[]) } // Change the hdri and make sure it is taken into account - opt.render.hdri.file = std::string(argv[1]) + "data/palermo_park_1k.hdr"; + opt.render.hdri.file = f3d::path_t(std::string(argv[1]) + "data/palermo_park_1k.hdr"); ret = TestSDKHelpers::RenderTest(eng.getWindow(), std::string(argv[1]) + "baselines/", std::string(argv[2]), "TestSDKDynamicHDRI"); if (!ret) @@ -89,7 +89,7 @@ int TestSDKDynamicHDRI(int argc, char* argv[]) #if F3D_MODULE_EXR // Change the hdri and make sure it is taken into account - opt.render.hdri.file = std::string(argv[1]) + "/data/kloofendal_43d_clear_1k.exr"; + opt.render.hdri.file = f3d::path_t(std::string(argv[1]) + "/data/kloofendal_43d_clear_1k.exr"); ret = TestSDKHelpers::RenderTest(eng.getWindow(), std::string(argv[1]) + "baselines/", std::string(argv[2]), "TestSDKDynamicHDRIExr"); diff --git a/library/testing/TestSDKInteractorCommand.cxx b/library/testing/TestSDKInteractorCommand.cxx index 207c697787..3dea9c9bee 100644 --- a/library/testing/TestSDKInteractorCommand.cxx +++ b/library/testing/TestSDKInteractorCommand.cxx @@ -16,7 +16,7 @@ int TestSDKInteractorCommand(int argc, char* argv[]) inter.triggerCommand("set model.scivis.cells true"); test("triggerCommand set", options.model.scivis.cells == true); inter.triggerCommand("set render.hdri.file filepath"); - test("triggerCommand set double quotes", options.render.hdri.file.value() == "filepath"); + test("triggerCommand set double quotes", options.render.hdri.file.value() == f3d::path_t("filepath")); // Test reset inter.triggerCommand("reset model.scivis.cells"); From 14099e5acf48133b308d714fe71d4a988d794554 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Wed, 5 Mar 2025 11:53:27 +0100 Subject: [PATCH 2/2] fixups --- library/public/types.h | 3 ++- library/testing/TestSDKInteractorCommand.cxx | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/library/public/types.h b/library/public/types.h index 0df491fca3..ab20c2f159 100644 --- a/library/public/types.h +++ b/library/public/types.h @@ -89,7 +89,7 @@ class path_t { public: inline path_t() = default; - inline explicit path_t(std::string_view val) + inline explicit path_t(const std::string& val) : Value(val) { } @@ -105,6 +105,7 @@ class path_t { return this->Value != other.Value; } + private: std::filesystem::path Value; }; diff --git a/library/testing/TestSDKInteractorCommand.cxx b/library/testing/TestSDKInteractorCommand.cxx index 3dea9c9bee..df0fcef7a0 100644 --- a/library/testing/TestSDKInteractorCommand.cxx +++ b/library/testing/TestSDKInteractorCommand.cxx @@ -16,7 +16,8 @@ int TestSDKInteractorCommand(int argc, char* argv[]) inter.triggerCommand("set model.scivis.cells true"); test("triggerCommand set", options.model.scivis.cells == true); inter.triggerCommand("set render.hdri.file filepath"); - test("triggerCommand set double quotes", options.render.hdri.file.value() == f3d::path_t("filepath")); + test("triggerCommand set double quotes", + options.render.hdri.file.value() == f3d::path_t("filepath")); // Test reset inter.triggerCommand("reset model.scivis.cells");