Skip to content
Snippets Groups Projects
Commit f8777d5f authored by Raphael Grimm's avatar Raphael Grimm
Browse files

Add simox::color::ColorMap::at(float, std::optional<float>, std::optional<float>)

parent 17d50a66
No related branches found
No related tags found
No related merge requests found
......@@ -47,6 +47,11 @@ namespace simox::color
Color ColorMap::at(float value) const
{
return at(value, _vmin, _vmax);
}
Color ColorMap::at(float value, std::optional<float> vmin, std::optional<float> vmax) const
{
if (empty())
{
......@@ -58,12 +63,16 @@ namespace simox::color
return keys.begin()->second;
}
if (_vmin || _vmax)
if (vmin || vmax)
{
// Original: [1 .. 2]
// Virtual: [100 .. 200]
// => Scale 150 to 1.5
value = simox::math::rescale(value, vmin(), vmax(), original_vmin(), original_vmax());
value = simox::math::rescale(value,
vmin.value_or(original_vmin()),
vmax.value_or(original_vmax()),
original_vmin(),
original_vmax());
}
// keys.size() >= 2
......
......@@ -56,6 +56,18 @@ namespace simox::color
*/
Color at(float value) const;
/**
* @brief Get the color for the given scalar value.
*
* Empty color maps always return black.
*
* @param value The scalar value.
* @param vmin Override for vmin().
* @param vmax Override for vmax().
* @return
*/
Color at(float value, std::optional<float> vmin, std::optional<float> vmax) const;
/// @see `ColorMap::at()`
Color operator()(float value) const { return this->at(value); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment