From 584ebc82dfb830c3c37002930839be792e1396d7 Mon Sep 17 00:00:00 2001 From: Michael Migliore Date: Tue, 12 Mar 2024 21:07:31 +0100 Subject: [PATCH] first_review --- application/CMakeLists.txt | 2 +- application/F3DColorMapTools.cxx | 53 +++++++++++++++++++++++- application/F3DColorMapTools.h | 2 +- application/F3DConfigFileTools.cxx | 6 +-- application/F3DOptionsParser.cxx | 2 +- application/F3DOptionsParser.h | 2 +- application/F3DStarter.cxx | 6 +-- application/testing/CMakeLists.txt | 5 +++ doc/dev/BUILD.md | 1 + testing/baselines/TestColorMap32bits.png | 4 +- testing/baselines/TestColorMapFile.png | 3 ++ testing/baselines/TestColorMapStem.png | 3 ++ 12 files changed, 75 insertions(+), 14 deletions(-) create mode 100644 testing/baselines/TestColorMapFile.png create mode 100644 testing/baselines/TestColorMapStem.png diff --git a/application/CMakeLists.txt b/application/CMakeLists.txt index c092b50c70..a797fd3008 100644 --- a/application/CMakeLists.txt +++ b/application/CMakeLists.txt @@ -186,7 +186,7 @@ install( # Default color maps install( DIRECTORY "${F3D_SOURCE_DIR}/resources/colormaps/" - DESTINATION "${f3d_config_dir}" + DESTINATION "${f3d_config_dir}/colormaps" COMPONENT colormaps EXCLUDE_FROM_ALL) diff --git a/application/F3DColorMapTools.cxx b/application/F3DColorMapTools.cxx index 4ab3d3b754..8cfb2f8df7 100644 --- a/application/F3DColorMapTools.cxx +++ b/application/F3DColorMapTools.cxx @@ -1,5 +1,7 @@ #include "F3DColorMapTools.h" +#include "F3DConfigFileTools.h" + #include "image.h" #include "log.h" @@ -13,11 +15,58 @@ std::string Find(const std::string& str) { if (fs::exists(str)) { - // already full path; + // already full path return str; } - // todo: stem, find file in standard paths + fs::path cmPath; + try + { + std::vector dirsToCheck; + dirsToCheck.emplace_back(F3DConfigFileTools::GetUserConfigFileDirectory() / "colormaps"); +#ifdef __APPLE__ + dirsToCheck.emplace_back("/usr/local/etc/f3d/colormaps"); +#endif +#ifdef __linux__ + dirsToCheck.emplace_back("/etc/f3d/colormaps"); + dirsToCheck.emplace_back("/usr/share/f3d/colormaps"); +#endif + dirsToCheck.emplace_back(F3DConfigFileTools::GetBinaryConfigFileDirectory() / "colormaps"); + + for (const fs::path& dir : dirsToCheck) + { + if (dir.empty()) + { + continue; + } + + // If the string is a stem, add extension + if (fs::path(str).stem() == str) + { + cmPath = dir / (str + ".png"); + if (fs::exists(cmPath)) + { + return cmPath.string(); + } + } + else + { + // If not, use directly + cmPath = dir / str; + if (fs::exists(cmPath)) + { + return cmPath.string(); + } + } + } + + return {}; + } + catch (const fs::filesystem_error&) + { + f3d::log::error("Error recovering color map file path: ", str); + return {}; + } return {}; } diff --git a/application/F3DColorMapTools.h b/application/F3DColorMapTools.h index 9a0b4bfd23..8641898853 100644 --- a/application/F3DColorMapTools.h +++ b/application/F3DColorMapTools.h @@ -1,6 +1,6 @@ /** * @class F3DColorMapReader - * @brief A class used to convert images to libf3d colormap option + * @brief A namespace used to convert images to libf3d colormap option * */ diff --git a/application/F3DConfigFileTools.cxx b/application/F3DConfigFileTools.cxx index 780e548ef8..00e6740b6f 100644 --- a/application/F3DConfigFileTools.cxx +++ b/application/F3DConfigFileTools.cxx @@ -59,9 +59,9 @@ fs::path F3DConfigFileTools::GetBinaryConfigFileDirectory() // Add binary specific paths #if F3D_MACOS_BUNDLE - dirPath /= "Resources/configs"; + dirPath /= "Resources"; #else - dirPath /= "share/f3d/configs"; + dirPath /= "share/f3d"; #endif } catch (const fs::filesystem_error&) @@ -88,7 +88,7 @@ fs::path F3DConfigFileTools::GetConfigPath(const std::string& configSearch) dirsToCheck.emplace_back("/etc/f3d"); dirsToCheck.emplace_back("/usr/share/f3d/configs"); #endif - dirsToCheck.emplace_back(F3DConfigFileTools::GetBinaryConfigFileDirectory()); + dirsToCheck.emplace_back(F3DConfigFileTools::GetBinaryConfigFileDirectory() / "configs"); for (const fs::path& dir : dirsToCheck) { diff --git a/application/F3DOptionsParser.cxx b/application/F3DOptionsParser.cxx index b6e1002a99..a17cf03304 100644 --- a/application/F3DOptionsParser.cxx +++ b/application/F3DOptionsParser.cxx @@ -379,7 +379,7 @@ void ConfigurationOptions::GetOptions(F3DAppOptions& appOptions, f3d::options& o this->DeclareOption(grp4, "cells", "c", "Use a scalar array from the cells", options.getAsBoolRef("model.scivis.cells"), HasDefault::YES, MayHaveConfig::YES); this->DeclareOption(grp4, "range", "", "Custom range for the coloring by array", options.getAsDoubleVectorRef("model.scivis.range"), HasDefault::YES, MayHaveConfig::YES, ""); this->DeclareOption(grp4, "bar", "b", "Show scalar bar", options.getAsBoolRef("ui.bar"), HasDefault::YES, MayHaveConfig::YES); - this->DeclareOption(grp4, "colormap-file", "", "Specify a colormap image (ignored if \"colormap\" is specified)", appOptions.UserColorMap, LocalHasDefaultNo, MayHaveConfig::YES, ""); + this->DeclareOption(grp4, "colormap-file", "", "Specify a colormap image (ignored if \"colormap\" is specified)", appOptions.ColorMapFile, LocalHasDefaultNo, MayHaveConfig::YES, ""); this->DeclareOption(grp4, "colormap", "", "Specify a custom colormap", options.getAsDoubleVectorRef("model.scivis.colormap"), HasDefault::YES, MayHaveConfig::YES, ""); this->DeclareOption(grp4, "volume", "v", "Show volume if the file is compatible", options.getAsBoolRef("model.volume.enable"), HasDefault::YES, MayHaveConfig::YES); this->DeclareOption(grp4, "inverse", "i", "Inverse opacity function for volume rendering", options.getAsBoolRef("model.volume.inverse"), HasDefault::YES, MayHaveConfig::YES); diff --git a/application/F3DOptionsParser.h b/application/F3DOptionsParser.h index 82070093dd..5739af8386 100644 --- a/application/F3DOptionsParser.h +++ b/application/F3DOptionsParser.h @@ -20,7 +20,7 @@ class options; struct F3DAppOptions { std::string UserConfigFile = ""; - std::string UserColorMap = ""; + std::string ColorMapFile = ""; bool DryRun = false; bool GeometryOnly = false; bool GroupGeometries = false; diff --git a/application/F3DStarter.cxx b/application/F3DStarter.cxx index 16f8236c47..68b79d724e 100644 --- a/application/F3DStarter.cxx +++ b/application/F3DStarter.cxx @@ -316,9 +316,9 @@ int F3DStarter::Start(int argc, char** argv) } // Parse colormap - if (!this->Internals->AppOptions.UserColorMap.empty()) + if (!this->Internals->AppOptions.ColorMapFile.empty()) { - std::string fullPath = F3DColorMapTools::Find(this->Internals->AppOptions.UserColorMap); + std::string fullPath = F3DColorMapTools::Find(this->Internals->AppOptions.ColorMapFile); if (!fullPath.empty()) { @@ -331,7 +331,7 @@ int F3DStarter::Start(int argc, char** argv) } else { - f3d::log::error("Cannot find the colormap ", this->Internals->AppOptions.UserColorMap); + f3d::log::error("Cannot find the colormap ", this->Internals->AppOptions.ColorMapFile); } } diff --git a/application/testing/CMakeLists.txt b/application/testing/CMakeLists.txt index e8eb5ed18f..0e1fd837c8 100644 --- a/application/testing/CMakeLists.txt +++ b/application/testing/CMakeLists.txt @@ -206,6 +206,11 @@ f3d_test(NAME TestColorMapGrayscale DATA dragon.vtu ARGS --colormap-file=${F3D_S f3d_test(NAME TestColorMapMore1pxWarning DATA dragon.vtu ARGS --verbose=warning --colormap-file=${F3D_SOURCE_DIR}/testing/data/16bit.png --scalars REGEXP "The specified color map height is not equal to 1" NO_BASELINE) f3d_test(NAME TestColorMap16bits DATA dragon.vtu ARGS --colormap-file=${F3D_SOURCE_DIR}/testing/data/viridis16.png --scalars --comp=1) f3d_test(NAME TestColorMap32bits DATA dragon.vtu ARGS --colormap-file=${F3D_SOURCE_DIR}/testing/data/viridis32.hdr --scalars --comp=1) +if(NOT F3D_MACOS_BUNDLE) + file(COPY "${F3D_SOURCE_DIR}/resources/colormaps/" DESTINATION "${CMAKE_BINARY_DIR}/share/f3d/colormaps") + f3d_test(NAME TestColorMapStem DATA dragon.vtu ARGS --colormap-file=magma --scalars --comp=1) + f3d_test(NAME TestColorMapFile DATA dragon.vtu ARGS --colormap-file=magma.png --scalars --comp=1) +endif() # Needs SSBO: https://gitlab.kitware.com/vtk/vtk/-/merge_requests/10675 if(VTK_VERSION VERSION_GREATER_EQUAL 9.3.20231108) diff --git a/doc/dev/BUILD.md b/doc/dev/BUILD.md index 2f94abdb68..737c45357e 100644 --- a/doc/dev/BUILD.md +++ b/doc/dev/BUILD.md @@ -88,3 +88,4 @@ Name|Installed by default|Operating system|Description `java`|YES|ALL|Java bindings `mimetypes`|NO|Linux|Plugins mimetype XML files for integration with Freedesktop `assets`|YES|Linux|Assets for integration with Freedesktop +`colormaps`|NO|ALL|Color maps presets, see [documentation](../user/COLOR_MAPS.md) diff --git a/testing/baselines/TestColorMap32bits.png b/testing/baselines/TestColorMap32bits.png index 8dbf805fab..5d5e345d18 100644 --- a/testing/baselines/TestColorMap32bits.png +++ b/testing/baselines/TestColorMap32bits.png @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:7316a20383de911278494623a2b88538d94b6dd56a82f523d79c34df4cb018b4 -size 23204 +oid sha256:75d4de9b2e9a8305a14bef645c0d1e75685b6ee307250ea94161a1a607652b03 +size 25953 diff --git a/testing/baselines/TestColorMapFile.png b/testing/baselines/TestColorMapFile.png new file mode 100644 index 0000000000..34895ab7ec --- /dev/null +++ b/testing/baselines/TestColorMapFile.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eaa6310ac92da85b69576bea3365d3414d9a4f35aaa217627b4b285b4696b73b +size 25928 diff --git a/testing/baselines/TestColorMapStem.png b/testing/baselines/TestColorMapStem.png new file mode 100644 index 0000000000..34895ab7ec --- /dev/null +++ b/testing/baselines/TestColorMapStem.png @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:eaa6310ac92da85b69576bea3365d3414d9a4f35aaa217627b4b285b4696b73b +size 25928