From 69c90e3c16267106648c4aa1380f43798a52e094 Mon Sep 17 00:00:00 2001 From: Mathieu Westphal Date: Fri, 27 Dec 2024 09:58:09 +0100 Subject: [PATCH] output/reference: A proper collapse support (non-working) --- application/F3DStarter.cxx | 40 ++++++++++++++++++------------ application/testing/CMakeLists.txt | 6 +++++ 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/application/F3DStarter.cxx b/application/F3DStarter.cxx index 150808b25d..cf0c4631e9 100644 --- a/application/F3DStarter.cxx +++ b/application/F3DStarter.cxx @@ -863,8 +863,9 @@ int F3DStarter::Start(int argc, char** argv) f3d::log::debug("========== Configuring engine =========="); double deltaTime = 1.0 / this->Internals->AppOptions.FrameRate; - const std::string& reference = this->Internals->AppOptions.Reference; - const std::string& output = this->Internals->AppOptions.Output; + + fs::path reference(f3d::utils::collapsePath(this->Internals->AppOptions.Reference)); + fs::path output(f3d::utils::collapsePath(this->Internals->applyFilenameTemplate(this->Internals->AppOptions.Output))); if (this->Internals->AppOptions.NoRender) { @@ -1002,21 +1003,29 @@ int F3DStarter::Start(int argc, char** argv) return EXIT_FAILURE; } - if (!fs::exists(reference)) + try { - if (output.empty()) - { - f3d::log::error("Reference image ", reference, - " does not exist, use the output option to output current rendering into an image " - "file.\n"); - } - else + if (!fs::exists(reference)) { - window.renderToImage(this->Internals->AppOptions.NoBackground).save(output); + if (output.empty()) + { + f3d::log::error("Reference image ", reference, + " does not exist, use the output option to output current rendering into an image " + "file.\n"); + } + else + { + window.renderToImage(this->Internals->AppOptions.NoBackground).save(output); - f3d::log::error("Reference image " + reference + - " does not exist, current rendering has been outputted to " + output + ".\n"); + f3d::log::error("Reference image ", reference, + " does not exist, current rendering has been outputted to ", output, ".\n"); + } + return EXIT_FAILURE; } + } + catch (const std::filesystem::filesystem_error& ex) + { + f3d::log::error("Error reading reference image: ", ex.what()); return EXIT_FAILURE; } @@ -1072,9 +1081,8 @@ int F3DStarter::Start(int argc, char** argv) } else { - fs::path path = this->Internals->applyFilenameTemplate(output); - img.save(path.string()); - f3d::log::debug("Output image saved to ", path); + img.save(output); + f3d::log::debug("Output image saved to ", output); } if (this->Internals->FilesGroups.size() > 1) diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index 10121bff51..9f19c09348 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -1135,6 +1135,12 @@ add_test(NAME f3d::TestNoFileFileNameTemplate COMMAND $ --outpu set_tests_properties(f3d::TestNoFileFileNameTemplate PROPERTIES PASS_REGULAR_EXPRESSION "Output image saved to \".*/Testing/Temporary/no_file.png\"") set_tests_properties(f3d::TestNoFileFileNameTemplate PROPERTIES ENVIRONMENT "CTEST_F3D_NO_DATA_FORCE_RENDER=1") +if(NOT WIN32) + # Test output to HOME + add_test(NAME f3d::TestOutputToHOME COMMAND $ ${F3D_SOURCE_DIR}/testing/data/suzanne.stl --output=~/Testing/Temporary/TestOutputToHOME.png --resolution=300,300) + set_tests_properties(f3d::TestOutputToHOME PROPERTIES ENVIRONMENT "HOME=${CMAKE_BINARY_DIR}") +endif() + # Test failure without a reference, please do not create a TestNoRef.png file f3d_test(NAME TestNoRef DATA cow.vtp WILL_FAIL)