Skip to main content

ColorMap

Namespace: DISPLIB  ·  Library: Display Library

#include <disp/colormap.h>

class DISPLIB::ColorMap

Static lookup helpers mapping scalar values to QRgb / QColor across all DISPLIB palettes.

Each palette exists as a 256-row Eigen::MatrixX3i RGB table; the valueToXxx accessors interpolate between rows so callers can map any value in [0,1][0,1] to a colour without instantiating an object. Bundled palettes include Viridis, Jet, Hot, HotNeg1, HotNeg2, Bone, Cool, RedBlue and the MNE-Python hot variant.

src/examples/ex_disp_plots/main.cpp
const QRgb low = ColorMap::valueToColor(0.0, "Viridis"); // v in [0, 1]
const QRgb mid = ColorMap::valueToColor(0.5, "Viridis");
const QRgb jet = ColorMap::valueToJet(0.25);

Public Methods​

ColorMap()​

Default constructor.


~ColorMap()​

Destructs the ColorMap class.


Static Methods​

valueToColor(v, sMap)​

Returns a Jet RGB to a given double value [0,1] and a colormap specified by sMap.

If no matching colormap was found return Jet.

Parameters:

  • v : double the double which has to be part of the intervall [0,1].

  • sMap : const QString & the colormap to choose.

Returns:

  • QRgb — the corresponding RGB value.

valueToJet(v)​

Returns a Jet RGB to a given double value [0,1].

Parameters:

  • v : double the double which has to be part of the intervall [0,1].

Returns:

  • QRgb — the corresponding Jet RGB.

valueToHot(v)​

Returns a Hot RGB to a given double value [0,1].

Parameters:

  • v : double the double which has to be part of the intervall [0,1].

Returns:

  • QRgb — the corresponding Hot RGB.

valueToHotNegative1(v)​

Returns a negative skewed hot RGB to a given double value [0,1].

Parameters:

  • v : double the double which has to be part of the intervall [0,1].

Returns:

  • QRgb — the corresponding negative skewed Hot RGB.

valueToHotNegative2(v)​

Returns a negative skewed hot RGB to a given double value [0,1].

Parameters:

  • v : double the double which has to be part of the intervall [0,1].

Returns:

  • QRgb — the corresponding negative skewed Hot RGB.

valueToBone(v)​

Returns a Bone RGB to a given double value [0,1].

Parameters:

  • v : double the double which has to be part of the intervall [0,1].

Returns:

  • QRgb — the corresponding Bone RGB.

valueToRedBlue(v)​

Returns a RedBlue RGB to a given double value [-1,1].

Parameters:

  • v : double the double which has to be part of the intervall [-1,1].

Returns:

  • QRgb — the corresponding Bone RGB.

valueToCool(v)​

Returns a Cool RGB to a given double value [-1,1].

Parameters:

  • v : double the double which has to be part of the intervall [-1,1].

Returns:

  • QRgb — the corresponding Cool RGB.

valueToViridis(v)​

Returns a Viridis RGB to a given double value [-1,1].

Parameters:

  • v : double the double which has to be part of the intervall [-1,1].

Returns:

  • QRgb — the corresponding Cool RGB.

valueToViridisNegated(v)​

Returns a negated Viridis RGB to a given double value [-1,1].

Parameters:

  • v : double the double which has to be part of the intervall [-1,1].

Returns:

  • QRgb — the corresponding Cool RGB.

Example​

Used in examples​

ex_disp_plots​

Disp plots: colour maps, bar and spline histograms, line plots, image and time-frequency maps.

src/examples/ex_disp_plots/main.cpp, line 107
const QRgb low = ColorMap::valueToColor(0.0, "Viridis"); // v in [0, 1]
const QRgb mid = ColorMap::valueToColor(0.5, "Viridis");
const QRgb jet = ColorMap::valueToJet(0.25);
// matplotlib.colormaps["viridis"](0, 0.5, 1) and ["jet"](0.25, 0.5), ["cool"](0.5); bone is MNE-C's piecewise ramp, not matplotlib's
ok &= expect(close(low, qRgb(68, 1, 84), 1) && close(mid, qRgb(33, 145, 140), 1) && close(ColorMap::valueToColor(1.0, "Viridis"), qRgb(253, 231, 37), 1) && close(jet, qRgb(0, 128, 255), 1) && close(ColorMap::valueToJet(0.5), qRgb(125, 255, 122), 5) && close(ColorMap::valueToCool(0.5), qRgb(128, 127, 255), 1),
"ColorMap viridis, jet and cool match matplotlib to 1-5 levels");

Authors of this file​