Skip to content

Commit

Permalink
first_review
Browse files Browse the repository at this point in the history
  • Loading branch information
Meakk committed Mar 12, 2024
1 parent 59034f5 commit 584ebc8
Show file tree
Hide file tree
Showing 12 changed files with 75 additions and 14 deletions.
2 changes: 1 addition & 1 deletion application/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
53 changes: 51 additions & 2 deletions application/F3DColorMapTools.cxx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "F3DColorMapTools.h"

#include "F3DConfigFileTools.h"

#include "image.h"
#include "log.h"

Expand All @@ -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<fs::path> 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;

Check warning on line 40 in application/F3DColorMapTools.cxx

View check run for this annotation

Codecov / codecov/patch

application/F3DColorMapTools.cxx#L40

Added line #L40 was not covered by tests
}

// 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&)

Check warning on line 65 in application/F3DColorMapTools.cxx

View check run for this annotation

Codecov / codecov/patch

application/F3DColorMapTools.cxx#L65

Added line #L65 was not covered by tests
{
f3d::log::error("Error recovering color map file path: ", str);
return {};
}

Check warning on line 69 in application/F3DColorMapTools.cxx

View check run for this annotation

Codecov / codecov/patch

application/F3DColorMapTools.cxx#L67-L69

Added lines #L67 - L69 were not covered by tests

return {};
}
Expand Down
2 changes: 1 addition & 1 deletion application/F3DColorMapTools.h
Original file line number Diff line number Diff line change
@@ -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
*
*/

Expand Down
6 changes: 3 additions & 3 deletions application/F3DConfigFileTools.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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&)
Expand All @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion application/F3DOptionsParser.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<min,max>");
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, "<filePath/filename/fileStem>");
this->DeclareOption(grp4, "colormap-file", "", "Specify a colormap image (ignored if \"colormap\" is specified)", appOptions.ColorMapFile, LocalHasDefaultNo, MayHaveConfig::YES, "<filePath/filename/fileStem>");
this->DeclareOption(grp4, "colormap", "", "Specify a custom colormap", options.getAsDoubleVectorRef("model.scivis.colormap"), HasDefault::YES, MayHaveConfig::YES, "<color_list>");
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);
Expand Down
2 changes: 1 addition & 1 deletion application/F3DOptionsParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions application/F3DStarter.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -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())
{
Expand All @@ -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);
}
}

Expand Down
5 changes: 5 additions & 0 deletions application/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions doc/dev/BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 2 additions & 2 deletions testing/baselines/TestColorMap32bits.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestColorMapFile.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions testing/baselines/TestColorMapStem.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 584ebc8

Please sign in to comment.