diff --git a/include/spark_dsg/colormaps.h b/include/spark_dsg/colormaps.h index d5e4ec7..0ef1805 100644 --- a/include/spark_dsg/colormaps.h +++ b/include/spark_dsg/colormaps.h @@ -53,6 +53,19 @@ Color gray(float value); */ Color quality(float value); +/** + * @brief Generate a color based on a ironbow value. + * @param value The temperature value [0,1], where 0 is dark and 1 is light. + */ +Color ironbow(float value); + +/** + * @brief Generate a color based on a rainbow value. + * @param value The rainbow value [0,1], where 0 is red, 0.5 is green, and 1 is + * blue. + */ +Color rainbow(float value); + /** * @brief Generate a color based on a spectrum of colors. * @param value The spectrum value [0,1], where 0 is the first color and 1 is the @@ -79,19 +92,6 @@ Color hls(float value, const std::array& start, const std::array& end); -/** - * @brief Generate a color based on a ironbow value. - * @param value The temperature value [0,1], where 0 is dark and 1 is light. - */ -Color ironbow(float value); - -/** - * @brief Generate a color based on a rainbow value. - * @param value The rainbow value [0,1], where 0 is red, 0.5 is green, and 1 is - * blue. - */ -Color rainbow(float value); - /** * @brief Generate a color from a general divergent colormap * @param value A value in [0, 1]. 0 results in one color, 1 in the other, and 0.5 in a @@ -119,17 +119,17 @@ Color rainbowId(size_t id, size_t ids_per_revolution = 16); */ Color colorbrewerId(size_t id); -/** - * @brief Get the underlying color palette for the distinct150 colormap - */ -const std::vector& colorbrewerPalette(); - /** * @brief Pick a color from a custom palette from distinctipy with 150 colors * @param id The id to pick from the sequence */ Color distinct150Id(size_t id); +/** + * @brief Get the underlying color palette for the distinct150 colormap + */ +const std::vector& colorbrewerPalette(); + /** * @brief Get the underlying color palette for the distinct150 colormap */ diff --git a/src/colormaps.cpp b/src/colormaps.cpp index 413b4c5..a704fbf 100644 --- a/src/colormaps.cpp +++ b/src/colormaps.cpp @@ -108,6 +108,12 @@ Color quality(float value) { return color; } +Color ironbow(float value) { return spectrum(value, ironbow_palette); } + +Color rainbow(float value) { + return Color::fromHLS(std::clamp(value, 0.0f, 1.0f), 0.5f, 1.0f); +} + Color spectrum(float value, const std::vector& colors) { if (colors.empty()) { return Color::black(); @@ -141,12 +147,6 @@ Color hls(float value, return Color::fromHLS(w * h1 + w_inv * h2, w * l1 + w_inv * l2, w * s1 + w_inv * s2); } -Color ironbow(float value) { return spectrum(value, ironbow_palette); } - -Color rainbow(float value) { - return Color::fromHLS(std::clamp(value, 0.0f, 1.0f), 0.5f, 1.0f); -} - Color divergent(float value, float hue_low, float hue_high, @@ -169,13 +169,13 @@ Color colorbrewerId(size_t id) { return cmap.at(id % cmap.size()); } -const std::vector& colorbrewerPalette() { return colorbrewer_palette; } - Color distinct150Id(size_t id) { const auto& cmap = custom_150_palette; return cmap.at(id % cmap.size()); } +const std::vector& colorbrewerPalette() { return colorbrewer_palette; } + const std::vector& distinct150Palette() { return custom_150_palette; } } // namespace spark_dsg::colormaps