ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
QCPColorGradient Class Reference

Defines a color gradient for use with e.g. QCPColorMap. More...

#include <qcustomplot.h>

Public Types

enum  ColorInterpolation { ciRGB , ciHSV , ciRGB , ciHSV }
 
enum  GradientPreset {
  gpGrayscale , gpHot , gpCold , gpNight ,
  gpCandy , gpGeography , gpIon , gpThermal ,
  gpPolar , gpSpectrum , gpJet , gpHues ,
  gpGrayscale , gpHot , gpCold , gpNight ,
  gpCandy , gpGeography , gpIon , gpThermal ,
  gpPolar , gpSpectrum , gpJet , gpHues
}
 
enum  ColorInterpolation { ciRGB , ciHSV , ciRGB , ciHSV }
 
enum  GradientPreset {
  gpGrayscale , gpHot , gpCold , gpNight ,
  gpCandy , gpGeography , gpIon , gpThermal ,
  gpPolar , gpSpectrum , gpJet , gpHues ,
  gpGrayscale , gpHot , gpCold , gpNight ,
  gpCandy , gpGeography , gpIon , gpThermal ,
  gpPolar , gpSpectrum , gpJet , gpHues
}
 

Public Member Functions

 QCPColorGradient ()
 
 QCPColorGradient (GradientPreset preset)
 
bool operator== (const QCPColorGradient &other) const
 
bool operator!= (const QCPColorGradient &other) const
 
int levelCount () const
 
QMap< double, QColor > colorStops () const
 
ColorInterpolation colorInterpolation () const
 
bool periodic () const
 
void setLevelCount (int n)
 
void setColorStops (const QMap< double, QColor > &colorStops)
 
void setColorStopAt (double position, const QColor &color)
 
void setColorInterpolation (ColorInterpolation interpolation)
 
void setPeriodic (bool enabled)
 
void colorize (const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false)
 
void colorize (const double *data, const unsigned char *alpha, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false)
 
QRgb color (double position, const QCPRange &range, bool logarithmic=false)
 
void loadPreset (GradientPreset preset)
 
void clearColorStops ()
 
QCPColorGradient inverted () const
 
 QCPColorGradient (GradientPreset preset=gpCold)
 
bool operator== (const QCPColorGradient &other) const
 
bool operator!= (const QCPColorGradient &other) const
 
int levelCount () const
 
QMap< double, QColor > colorStops () const
 
ColorInterpolation colorInterpolation () const
 
bool periodic () const
 
void setLevelCount (int n)
 
void setColorStops (const QMap< double, QColor > &colorStops)
 
void setColorStopAt (double position, const QColor &color)
 
void setColorInterpolation (ColorInterpolation interpolation)
 
void setPeriodic (bool enabled)
 
void colorize (const double *data, const QCPRange &range, QRgb *scanLine, int n, int dataIndexFactor=1, bool logarithmic=false)
 
QRgb color (double position, const QCPRange &range, bool logarithmic=false)
 
void loadPreset (GradientPreset preset)
 
void clearColorStops ()
 
QCPColorGradient inverted () const
 

Protected Member Functions

bool stopsUseAlpha () const
 
void updateColorBuffer ()
 
void updateColorBuffer ()
 

Protected Attributes

int mLevelCount
 
QMap< double, QColor > mColorStops
 
ColorInterpolation mColorInterpolation
 
bool mPeriodic
 
QVector< QRgb > mColorBuffer
 
bool mColorBufferInvalidated
 

Detailed Description

Defines a color gradient for use with e.g. QCPColorMap.

This class describes a color gradient which can be used to encode data with color. For example, QCPColorMap and QCPColorScale have setGradient methods which take an instance of this class. Colors are set with setColorStopAt(double position, const QColor &color) with a position from 0 to 1. In between these defined color positions, the color will be interpolated linearly either in RGB or HSV space, see setColorInterpolation.

Alternatively, load one of the preset color gradients shown in the image below, with loadPreset, or by directly specifying the preset in the constructor.

Apart from red, green and blue components, the gradient also interpolates the alpha values of the configured color stops. This allows to display some portions of the data range as transparent in the plot.

The QCPColorGradient(GradientPreset preset) constructor allows directly converting a GradientPreset to a QCPColorGradient. This means that you can directly pass GradientPreset to all the setGradient methods, e.g.:

qcpcolorgradient-setgradient

The total number of levels used in the gradient can be set with setLevelCount. Whether the color gradient shall be applied periodically (wrapping around) to data values that lie outside the data range specified on the plottable instance can be controlled with setPeriodic.

This class describes a color gradient which can be used to encode data with color. For example, QCPColorMap and QCPColorScale have setGradient methods which take an instance of this class. Colors are set with setColorStopAt(double position, const QColor &color) with a position from 0 to 1. In between these defined color positions, the color will be interpolated linearly either in RGB or HSV space, see setColorInterpolation.

Alternatively, load one of the preset color gradients shown in the image below, with loadPreset, or by directly specifying the preset in the constructor.

The fact that the QCPColorGradient(GradientPreset preset) constructor allows directly converting a GradientPreset to a QCPColorGradient, you can also directly pass GradientPreset to all the setGradient methods, e.g.:

qcpcolorgradient-setgradient

The total number of levels used in the gradient can be set with setLevelCount. Whether the color gradient shall be applied periodically (wrapping around) to data values that lie outside the data range specified on the plottable instance can be controlled with setPeriodic.

Definition at line 5165 of file qcustomplot.h.

Member Enumeration Documentation

◆ ColorInterpolation [1/2]

Defines the color spaces in which color interpolation between gradient stops can be performed.

See also
setColorInterpolation
Enumerator
ciRGB 

Color channels red, green and blue are linearly interpolated.

ciHSV 

Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)

ciRGB 

Color channels red, green and blue are linearly interpolated.

ciHSV 

Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)

Definition at line 5174 of file qcustomplot.h.

◆ ColorInterpolation [2/2]

Defines the color spaces in which color interpolation between gradient stops can be performed.

See also
setColorInterpolation
Enumerator
ciRGB 

Color channels red, green and blue are linearly interpolated.

ciHSV 

Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)

ciRGB 

Color channels red, green and blue are linearly interpolated.

ciHSV 

Color channels hue, saturation and value are linearly interpolated (The hue is interpolated over the shortest angle distance)

Definition at line 2323 of file qcustomplot.h.

◆ GradientPreset [1/2]

Defines the available presets that can be loaded with loadPreset. See the documentation there for an image of the presets.

Enumerator
gpGrayscale 

Continuous lightness from black to white (suited for non-biased data representation)

gpHot 

Continuous lightness from black over firey colors to white (suited for non-biased data representation)

gpCold 

Continuous lightness from black over icey colors to white (suited for non-biased data representation)

gpNight 

Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)

gpCandy 

Blue over pink to white.

gpGeography 

Colors suitable to represent different elevations on geographical maps

gpIon 

Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)

gpThermal 

Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white

gpPolar 

Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values

gpSpectrum 

An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)

gpJet 

Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)

gpHues 

Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see setPeriodic)

gpGrayscale 

Continuous lightness from black to white (suited for non-biased data representation)

gpHot 

Continuous lightness from black over firey colors to white (suited for non-biased data representation)

gpCold 

Continuous lightness from black over icey colors to white (suited for non-biased data representation)

gpNight 

Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)

gpCandy 

Blue over pink to white.

gpGeography 

Colors suitable to represent different elevations on geographical maps

gpIon 

Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)

gpThermal 

Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white

gpPolar 

Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values

gpSpectrum 

An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)

gpJet 

Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)

gpHues 

Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see setPeriodic)

Definition at line 5187 of file qcustomplot.h.

◆ GradientPreset [2/2]

Defines the available presets that can be loaded with loadPreset. See the documentation there for an image of the presets.

Enumerator
gpGrayscale 

Continuous lightness from black to white (suited for non-biased data representation)

gpHot 

Continuous lightness from black over firey colors to white (suited for non-biased data representation)

gpCold 

Continuous lightness from black over icey colors to white (suited for non-biased data representation)

gpNight 

Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)

gpCandy 

Blue over pink to white.

gpGeography 

Colors suitable to represent different elevations on geographical maps

gpIon 

Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)

gpThermal 

Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white

gpPolar 

Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values

gpSpectrum 

An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)

gpJet 

Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)

gpHues 

Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see setPeriodic)

gpGrayscale 

Continuous lightness from black to white (suited for non-biased data representation)

gpHot 

Continuous lightness from black over firey colors to white (suited for non-biased data representation)

gpCold 

Continuous lightness from black over icey colors to white (suited for non-biased data representation)

gpNight 

Continuous lightness from black over weak blueish colors to white (suited for non-biased data representation)

gpCandy 

Blue over pink to white.

gpGeography 

Colors suitable to represent different elevations on geographical maps

gpIon 

Half hue spectrum from black over purple to blue and finally green (creates banding illusion but allows more precise magnitude estimates)

gpThermal 

Colors suitable for thermal imaging, ranging from dark blue over purple to orange, yellow and white

gpPolar 

Colors suitable to emphasize polarity around the center, with blue for negative, black in the middle and red for positive values

gpSpectrum 

An approximation of the visible light spectrum (creates banding illusion but allows more precise magnitude estimates)

gpJet 

Hue variation similar to a spectrum, often used in numerical visualization (creates banding illusion but allows more precise magnitude estimates)

gpHues 

Full hue cycle, with highest and lowest color red (suitable for periodic data, such as angles and phases, see setPeriodic)

Definition at line 2336 of file qcustomplot.h.

Constructor & Destructor Documentation

◆ QCPColorGradient() [1/3]

QCPColorGradient::QCPColorGradient ( )

Constructs a new, empty QCPColorGradient with no predefined color stops. You can add own color stops with setColorStopAt.

The color level count is initialized to 350.

Definition at line 16444 of file qcustomplot.cpp.

References mColorBuffer, and mLevelCount.

◆ QCPColorGradient() [2/3]

QCPColorGradient::QCPColorGradient ( GradientPreset  preset)

Constructs a new QCPColorGradient initialized with the colors and color interpolation according to preset.

The color level count is initialized to 350.

Definition at line 16458 of file qcustomplot.cpp.

References loadPreset(), mColorBuffer, and mLevelCount.

◆ QCPColorGradient() [3/3]

QCPColorGradient::QCPColorGradient ( GradientPreset  preset = gpCold)

Member Function Documentation

◆ clearColorStops() [1/2]

void QCPColorGradient::clearColorStops ( )

Clears all color stops.

See also
setColorStops, setColorStopAt

Definition at line 16902 of file qcustomplot.cpp.

References mColorBufferInvalidated, and mColorStops.

Referenced by loadPreset().

◆ clearColorStops() [2/2]

void QCPColorGradient::clearColorStops ( )

◆ color() [1/2]

QRgb QCPColorGradient::color ( double  position,
const QCPRange range,
bool  logarithmic = false 
)

◆ color() [2/2]

QRgb QCPColorGradient::color ( double  position,
const QCPRange range,
bool  logarithmic = false 
)

◆ colorInterpolation() [1/2]

ColorInterpolation QCPColorGradient::colorInterpolation ( ) const
inline

Definition at line 5240 of file qcustomplot.h.

◆ colorInterpolation() [2/2]

ColorInterpolation QCPColorGradient::colorInterpolation ( ) const
inline

Definition at line 2388 of file qcustomplot.h.

◆ colorize() [1/3]

void QCPColorGradient::colorize ( const double *  data,
const QCPRange range,
QRgb *  scanLine,
int  n,
int  dataIndexFactor = 1,
bool  logarithmic = false 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

This method is used to quickly convert a data array to colors. The colors will be output in the array scanLine. Both data and scanLine must have the length n when passed to this function. The data range that shall be used for mapping the data value to the gradient is passed in range. logarithmic indicates whether the data values shall be mapped to colors logarithmically.

if data actually contains 2D-data linearized via [row*columnCount + column], you can set dataIndexFactor to columnCount to convert a column instead of a row of the data array, in scanLine. scanLine will remain a regular (1D) array. This works because data is addressed data[i*dataIndexFactor].

Use the overloaded method to additionally provide alpha map data.

The QRgb values that are placed in scanLine have their r, g and b components premultiplied with alpha (see QImage::Format_ARGB32_Premultiplied).

This method is used to quickly convert a data array to colors. The colors will be output in the array scanLine. Both data and scanLine must have the length n when passed to this function. The data range that shall be used for mapping the data value to the gradient is passed in range. logarithmic indicates whether the data values shall be mapped to colors logarithmically.

if data actually contains 2D-data linearized via [row*columnCount + column], you can set dataIndexFactor to columnCount to convert a column instead of a row of the data array, in scanLine. scanLine will remain a regular (1D) array. This works because data is addressed data[i*dataIndexFactor].

Definition at line 16577 of file qcustomplot.cpp.

References data, QCPRange::lower, mColorBuffer, mColorBufferInvalidated, mLevelCount, mPeriodic, QCPRange::size(), updateColorBuffer(), and QCPRange::upper.

Referenced by QCPColorMap::updateMapImage().

◆ colorize() [2/3]

void QCPColorGradient::colorize ( const double *  data,
const QCPRange range,
QRgb *  scanLine,
int  n,
int  dataIndexFactor = 1,
bool  logarithmic = false 
)

◆ colorize() [3/3]

void QCPColorGradient::colorize ( const double *  data,
const unsigned char *  alpha,
const QCPRange range,
QRgb *  scanLine,
int  n,
int  dataIndexFactor = 1,
bool  logarithmic = false 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Additionally to the other overload of colorize, this method takes the array alpha, which has the same size and structure as data and encodes the alpha information per data point.

The QRgb values that are placed in scanLine have their r, g and b components premultiplied with alpha (see QImage::Format_ARGB32_Premultiplied).

Definition at line 16650 of file qcustomplot.cpp.

References data, QCPRange::lower, mColorBuffer, mColorBufferInvalidated, mLevelCount, mPeriodic, rgb, QCPRange::size(), updateColorBuffer(), and QCPRange::upper.

◆ colorStops() [1/2]

QMap<double, QColor> QCPColorGradient::colorStops ( ) const
inline

Definition at line 5239 of file qcustomplot.h.

Referenced by setColorStops().

◆ colorStops() [2/2]

QMap<double, QColor> QCPColorGradient::colorStops ( ) const
inline

Definition at line 2387 of file qcustomplot.h.

◆ inverted() [1/2]

QCPColorGradient QCPColorGradient::inverted ( ) const

Returns an inverted gradient. The inverted gradient has all properties as this QCPColorGradient, but the order of the color stops is inverted.

See also
setColorStops, setColorStopAt

Definition at line 16913 of file qcustomplot.cpp.

References mColorStops, and result.

◆ inverted() [2/2]

QCPColorGradient QCPColorGradient::inverted ( ) const

◆ levelCount() [1/2]

int QCPColorGradient::levelCount ( ) const
inline

Definition at line 5238 of file qcustomplot.h.

◆ levelCount() [2/2]

int QCPColorGradient::levelCount ( ) const
inline

Definition at line 2386 of file qcustomplot.h.

◆ loadPreset() [1/2]

void QCPColorGradient::loadPreset ( GradientPreset  preset)

Clears the current color stops and loads the specified preset. A preset consists of predefined color stops and the corresponding color interpolation method.

The available presets are:

Definition at line 16795 of file qcustomplot.cpp.

References ecvColor::black(), ciHSV, ciRGB, clearColorStops(), gpCandy, gpCold, gpGeography, gpGrayscale, gpHot, gpHues, gpIon, gpJet, gpNight, gpPolar, gpSpectrum, gpThermal, setColorInterpolation(), setColorStopAt(), and ecvColor::white().

Referenced by QCPColorGradient().

◆ loadPreset() [2/2]

void QCPColorGradient::loadPreset ( GradientPreset  preset)

◆ operator!=() [1/2]

bool QCPColorGradient::operator!= ( const QCPColorGradient other) const
inline

Definition at line 5233 of file qcustomplot.h.

◆ operator!=() [2/2]

bool QCPColorGradient::operator!= ( const QCPColorGradient other) const
inline

Definition at line 2381 of file qcustomplot.h.

◆ operator==() [1/2]

bool QCPColorGradient::operator== ( const QCPColorGradient other) const

Definition at line 16468 of file qcustomplot.cpp.

References mColorInterpolation, mColorStops, mLevelCount, and mPeriodic.

◆ operator==() [2/2]

bool QCPColorGradient::operator== ( const QCPColorGradient other) const

◆ periodic() [1/2]

bool QCPColorGradient::periodic ( ) const
inline

Definition at line 5243 of file qcustomplot.h.

◆ periodic() [2/2]

bool QCPColorGradient::periodic ( ) const
inline

Definition at line 2391 of file qcustomplot.h.

◆ setColorInterpolation() [1/2]

void QCPColorGradient::setColorInterpolation ( QCPColorGradient::ColorInterpolation  interpolation)

Sets whether the colors in between the configured color stops (see setColorStopAt) shall be interpolated linearly in RGB or in HSV color space.

For example, a sweep in RGB space from red to green will have a muddy brown intermediate color, whereas in HSV space the intermediate color is yellow.

Definition at line 16529 of file qcustomplot.cpp.

References mColorBufferInvalidated, and mColorInterpolation.

Referenced by loadPreset().

◆ setColorInterpolation() [2/2]

void QCPColorGradient::setColorInterpolation ( ColorInterpolation  interpolation)

◆ setColorStopAt() [1/2]

void QCPColorGradient::setColorStopAt ( double  position,
const QColor &  color 
)

Sets the color the gradient will have at the specified position (from 0 to 1). In between these color stops, the color is interpolated according to setColorInterpolation.

See also
setColorStops, clearColorStops

Definition at line 16517 of file qcustomplot.cpp.

References color(), mColorBufferInvalidated, mColorStops, and position.

Referenced by loadPreset().

◆ setColorStopAt() [2/2]

void QCPColorGradient::setColorStopAt ( double  position,
const QColor &  color 
)

◆ setColorStops() [1/2]

void QCPColorGradient::setColorStops ( const QMap< double, QColor > &  colorStops)

Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the colors are the values of the passed QMap colorStops. In between these color stops, the color is interpolated according to setColorInterpolation.

A more convenient way to create a custom gradient may be to clear all color stops with clearColorStops (or creating a new, empty QCPColorGradient) and then adding them one by one with setColorStopAt.

See also
clearColorStops

Sets at which positions from 0 to 1 which color shall occur. The positions are the keys, the colors are the values of the passed QMap colorStops. In between these color stops, the color is interpolated according to setColorInterpolation.

A more convenient way to create a custom gradient may be to clear all color stops with clearColorStops and then adding them one by one with setColorStopAt.

See also
clearColorStops

Definition at line 16505 of file qcustomplot.cpp.

References colorStops(), mColorBufferInvalidated, and mColorStops.

◆ setColorStops() [2/2]

void QCPColorGradient::setColorStops ( const QMap< double, QColor > &  colorStops)

◆ setLevelCount() [1/2]

void QCPColorGradient::setLevelCount ( int  n)

Sets the number of discretization levels of the color gradient to n. The default is 350 which is typically enough to create a smooth appearance. The minimum number of levels is 2.

Sets the number of discretization levels of the color gradient to n. The default is 350 which is typically enough to create a smooth appearance.

Definition at line 16482 of file qcustomplot.cpp.

References mColorBufferInvalidated, and mLevelCount.

◆ setLevelCount() [2/2]

void QCPColorGradient::setLevelCount ( int  n)

◆ setPeriodic() [1/2]

void QCPColorGradient::setPeriodic ( bool  enabled)

Sets whether data points that are outside the configured data range (e.g. QCPColorMap::setDataRange) are colored by periodically repeating the color gradient or whether they all have the same color, corresponding to the respective gradient boundary color.

As shown in the image above, gradients that have the same start and end color are especially suitable for a periodic gradient mapping, since they produce smooth color transitions throughout the color map. A preset that has this property is gpHues.

In practice, using periodic color gradients makes sense when the data corresponds to a periodic dimension, such as an angle or a phase. If this is not the case, the color encoding might become ambiguous, because multiple different data values are shown as the same color.

Definition at line 16555 of file qcustomplot.cpp.

References mPeriodic.

◆ setPeriodic() [2/2]

void QCPColorGradient::setPeriodic ( bool  enabled)

◆ stopsUseAlpha()

bool QCPColorGradient::stopsUseAlpha ( ) const
protected

Definition at line 16927 of file qcustomplot.cpp.

References mColorStops.

Referenced by updateColorBuffer().

◆ updateColorBuffer() [1/2]

void QCPColorGradient::updateColorBuffer ( )
protected

◆ updateColorBuffer() [2/2]

void QCPColorGradient::updateColorBuffer ( )
protected

Member Data Documentation

◆ mColorBuffer

QVector< QRgb > QCPColorGradient::mColorBuffer
protected

Definition at line 5282 of file qcustomplot.h.

Referenced by color(), colorize(), QCPColorGradient(), and updateColorBuffer().

◆ mColorBufferInvalidated

bool QCPColorGradient::mColorBufferInvalidated
protected

◆ mColorInterpolation

ColorInterpolation QCPColorGradient::mColorInterpolation
protected

Definition at line 5277 of file qcustomplot.h.

Referenced by operator==(), setColorInterpolation(), and updateColorBuffer().

◆ mColorStops

QMap< double, QColor > QCPColorGradient::mColorStops
protected

◆ mLevelCount

int QCPColorGradient::mLevelCount
protected

◆ mPeriodic

bool QCPColorGradient::mPeriodic
protected

Definition at line 5278 of file qcustomplot.h.

Referenced by color(), colorize(), operator==(), and setPeriodic().


The documentation for this class was generated from the following files: