From 81feec8f2d9ca569239fb6622f412ada0d836096 Mon Sep 17 00:00:00 2001 From: janos Date: Sat, 17 Oct 2020 16:25:38 +0200 Subject: [PATCH] DebugTools: add Smooth-Cool-Warm colormap. --- doc/colormap-cool-warm-bent.png | Bin 0 -> 279 bytes doc/colormap-cool-warm-smooth.png | Bin 0 -> 289 bytes doc/generated/colormaps.cpp | 4 +- src/Magnum/DebugTools/ColorMap.cpp | 146 ++++++++++++++++++ src/Magnum/DebugTools/ColorMap.h | 62 ++++++++ .../DebugTools/Implementation/cool-warm.py | 57 +++++++ 6 files changed, 268 insertions(+), 1 deletion(-) create mode 100644 doc/colormap-cool-warm-bent.png create mode 100644 doc/colormap-cool-warm-smooth.png create mode 100755 src/Magnum/DebugTools/Implementation/cool-warm.py diff --git a/doc/colormap-cool-warm-bent.png b/doc/colormap-cool-warm-bent.png new file mode 100644 index 0000000000000000000000000000000000000000..364568d310c5440a2fd34c0488e78a68c099a4b1 GIT binary patch literal 279 zcmeAS@N?(olHy`uVBq!ia0y~yU<5K5csQ7VB-7F_|A5pzPZ!6KjC*eBpS6-BHV;%J^k7rF)%cC0Yd^HamUi z)J^@pIzh|2CIn3E3i$88vX1|u-d$0HXZ?i?J{+y)svoOHZ?{Jg;#7^`n2yQD$xh=M|dl{%lOKIx&`BjO>X-qLv^= zb>j-P^7m+74s|b)`zW>AvhQHKGc7_zZQ1D7B*No}`aH%&!$n viridis() { return Containers::StaticArrayView<256, const Vector3ub>{reinterpret_cast(&Viridis[0][0])}; } +Containers::StaticArrayView<256, const Vector3ub> coolWarmSmooth() { + return Containers::StaticArrayView<256, const Vector3ub>{reinterpret_cast(&CoolWarmSmooth[0][0])}; +} + +Containers::StaticArrayView<256, const Vector3ub> coolWarmBent() { + return Containers::StaticArrayView<256, const Vector3ub>{reinterpret_cast(&CoolWarmBent[0][0])}; +} + }}} diff --git a/src/Magnum/DebugTools/ColorMap.h b/src/Magnum/DebugTools/ColorMap.h index e998a9543..7a4763a11 100644 --- a/src/Magnum/DebugTools/ColorMap.h +++ b/src/Magnum/DebugTools/ColorMap.h @@ -114,6 +114,30 @@ See @ref building, @ref cmake and @ref debug-tools for more information. @endparblock +@m_class{m-row} + +@parblock + +@m_div{m-col-l-8 m-push-l-3 m-col-m-8 m-push-m-4 m-nopadt} +@image html colormap-cool-warm-smooth.png width=100% +@m_enddiv + +@m_div{m-col-l-2 m-pull-l-7 m-col-m-4 m-pull-m-8 m-text-center m-nopadt} @ref coolWarmSmooth() @m_enddiv + +@endparblock + +@m_class{m-row} + +@parblock + +@m_div{m-col-l-8 m-push-l-3 m-col-m-8 m-push-m-4 m-nopadt} +@image html colormap-cool-warm-bent.png width=100% +@m_enddiv + +@m_div{m-col-l-2 m-pull-l-7 m-col-m-4 m-pull-m-8 m-text-center m-nopadt} @ref coolWarmBent() @m_enddiv + +@endparblock + For all color maps the returned data is the sRGB colorspace. Desired usage is by uploading to a texture with linear filtering, depending on the use case with either clamp or repeat wrapping. For a sRGB workflow don't forget to set the @@ -204,6 +228,44 @@ MAGNUM_DEBUGTOOLS_EXPORT Containers::StaticArrayView<256, const Vector3ub> infer */ MAGNUM_DEBUGTOOLS_EXPORT Containers::StaticArrayView<256, const Vector3ub> viridis(); +/** +@brief Smooth Cool-Warm colormap +@m_since_latest + +@image html colormap-cool-warm-smooth.png width=100% + +It is a diverging (double-ended) color map with a smooth transition in the +middle to prevent artifacts at the midpoint. Although not isoluminant, this +color map avoids dark colors to allow shading cues throughout. + +@m_class{m-block m-success} + +@thirdparty Created by [Kenneth Moreland](https://www.kennethmoreland.com/color-advice/), + released under a @m_class{m-label m-success} **BSD 3-clause** license as + part of Paraview ([license text](https://www.paraview.org/paraview-license/), + [choosealicense.com](https://choosealicense.com/licenses/bsd-3-clause/)). +*/ +MAGNUM_DEBUGTOOLS_EXPORT Containers::StaticArrayView<256, const Vector3ub> coolWarmSmooth(); + +/** +@brief Bent Cool-Warm colormap +@m_since_latest + +@image html colormap-cool-warm-bent.png width=100% + +This color map is similar @ref coolWarmSmooth() except that the luminance is +interpolated linearly with a sharp bend in the middle. This makes for less +washed out colors in the middle, but also creates an artifact at the midpoint. + +@m_class{m-block m-success} + +@thirdparty Created by [Kenneth Moreland](https://www.kennethmoreland.com/color-advice/), + released under a @m_class{m-label m-success} **BSD 3-clause** license as + part of Paraview ([license text](https://www.paraview.org/paraview-license/), + [choosealicense.com](https://choosealicense.com/licenses/bsd-3-clause/)). +*/ +MAGNUM_DEBUGTOOLS_EXPORT Containers::StaticArrayView<256, const Vector3ub> coolWarmBent(); + } }} diff --git a/src/Magnum/DebugTools/Implementation/cool-warm.py b/src/Magnum/DebugTools/Implementation/cool-warm.py new file mode 100755 index 000000000..7db999602 --- /dev/null +++ b/src/Magnum/DebugTools/Implementation/cool-warm.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 + +# +# This file is part of Magnum. +# +# Copyright © 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, +# 2020 Vladimír Vondruš +# Copyright © 2020 janos +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included +# in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +# DEALINGS IN THE SOFTWARE. +# + +from numpy import genfromtxt + +def format(filename): + data = genfromtxt(filename, delimiter=',') + formatted = '' + data = data[1:,1:].astype(int) + formatted = '' + + for i in range(256//4): + line = ' ' + for j in range(4): + row = data[4*i+j] + line += '{{{:>3}, {:>3}, {:>3}}}, '.format(row[0], row[1], row[2]) + formatted = formatted + line + '\n' + + # Strip trailing comma and newline + return formatted[:-3] + +# The two CSV files taken from https://www.kennethmoreland.com/color-advice/ + +print("/* Generated with Implementation/cool-warm.py */") +print("constexpr UnsignedByte CoolWarmSmooth[][3] = {\n", end='') +print(format('smooth-cool-warm-table-byte-0256.csv')) +print("};\n") + +print("/* Generated with Implementation/cool-warm.py */") +print("constexpr UnsignedByte CoolWarmBent[][3] = {\n", end='') +print(format('bent-cool-warm-table-byte-0256.csv')) +print("};\n")