Describes a color spectrum that maps a floating point number in the range [0,1] to a specific color.
#include <DataAnalysis/Color/colorspectrum.h>
◆ PointInterpolationMode
Enumerator |
---|
NearestNeighbour | |
Linear | |
◆ ColorSpectrum() [1/2]
The default color spectrum is blue through to red, roughly corresponding to a typical color bar used in plot legends.
◆ ColorSpectrum() [2/2]
◆ ~ColorSpectrum()
◆ addEquallySpacedColors()
void addEquallySpacedColors |
( |
const QVector< QColor > & |
colors | ) |
|
- Parameters
-
colors | The array of colors to use |
This replaces any existing points
◆ addPoint()
void addPoint |
( |
double |
value, |
|
|
const QColor & |
color |
|
) |
| |
- Parameters
-
value | The interpolation value for the point being added. This must be in the range [0,1]. If it is not, it will be forced to this range. |
color | The color to assign to the specified value. |
If value already exists in the set of points for this spectrum, the existing point will have its color updated. Otherwise, a new point will be inserted at the appropriate sort order for value.
◆ canSerialize()
bool canSerialize |
( |
| ) |
const |
|
overridevirtual |
- Returns
- True if this object can be serialized.
For objects that can be serialized, the save and load functions will be used to do the serialization. If this function returns false, both load() and save() must also return false.
Implements Serialize.
◆ clearPoints()
Clears all points from the spectrum. A spectrum with no points is invalid and will always return an invalid color from getColor().
◆ getAsBrush()
QBrush getAsBrush |
( |
int |
pixels, |
|
|
Qt::Orientation |
orientation |
|
) |
| const |
- Parameters
-
pixels | Specifies how many pixels the spectrum should span. |
orientation | The desired orientation of the spectrum. The direction specified here will be the direction in which the color varies. For example, if orientation is Qt::Horizontal, the brush will vary the color left to right and the color at any given horizontal location will be constant vertically.
QBrush spectrumBrush(spectrum.getAsBrush(length, Qt::Vertical));
QTransform transform;
transform.scale(1, -1);
spectrumBrush.setTransform(transform);
painter.fillRect(0, 0, 15, 100, spectrumBrush);
|
If orientation is Qt::Horizontal, then pixels is the width of the spectrum. If orientation is Qt::Vertical, then pixels is the height of the spectrum.
- Returns
- A QBrush representing this color spectrum.
◆ getAsImage()
QImage getAsImage |
( |
int |
pixels, |
|
|
Qt::Orientation |
orientation |
|
) |
| const |
- Parameters
-
pixels | Specifies how many pixels the spectrum should span. |
orientation | The desired orientation of the spectrum. The direction specified here will be the direction in which the color varies. For example, if orientation is Qt::Horizontal, the brush will vary the color left to right and the color at any given horizontal location will be constant vertically. |
If orientation is Qt::Horizontal, then pixels is the width of the spectrum. If orientation is Qt::Vertical, then pixels is the height of the spectrum.
- Returns
- A 1 dimensional image representing this color spectrum.
◆ getColor()
QColor getColor |
( |
double |
value | ) |
const |
- Parameters
-
value | The value for which a color should be determined. This value should be in the range [0,1] and if it falls outside this range, it will be forced to the closest end point. |
- Returns
- The interpolated color for the specified value. If value lies before the first point or after the last point, it will have the same color as the first or last point respectively. In other words, color is interpolated between points, but never extrapolated beyond points in either direction.
◆ getColorAtPoint()
QColor getColorAtPoint |
( |
unsigned |
index | ) |
const |
- Parameters
-
index | The index of the point whose color is desired. It must be less than the number of points returned from getNumPoints(). |
- Returns
- The color of the point at the specified index.
◆ getNumPoints()
unsigned getNumPoints |
( |
| ) |
const |
- Returns
- The number of points defined in this color spectrum.
Every point in the spectrum has a different key value, so the return value is also the number of unique keys in the spectrum.
◆ getPointInterpolationMode()
◆ getValueAtPoint()
double getValueAtPoint |
( |
unsigned |
index | ) |
const |
- Parameters
-
index | The index of the point whose value is desired. It must be less than the number of points returned from getNumPoints(). |
- Returns
- The value of the point at the specified index.
◆ invert()
This inverts the colour scheme, so current point 0 maps to the end and vice-versa
◆ load()
- Parameters
-
item | Supplies the state to be loaded into this object. |
This function will load the state of this object from item. For many object types, this is most easily implemented in terms of the object's input operator (>>).
It would be reasonable for subclass implementations to assume that the data provided in item is in the same form as would have been saved from a call to save.
- Returns
- If the state of the object could not be loaded, the function returns false. A return value of true implies that the object state was successfully loaded. If canSerialize() returns false, this function must do nothing except return false as well.
Implements Serialize.
◆ operator!=()
- Parameters
-
s | The spectrum to compare against. |
- Returns
- True if s and this spectrum are not the same.
◆ operator=()
- Parameters
-
spec | The surface specifier to assign to this one. |
◆ operator==()
- Parameters
-
s | The spectrum to compare against. |
- Returns
- True if s and this spectrum are the same.
◆ removePoint()
void removePoint |
( |
unsigned |
index | ) |
|
- Parameters
-
index | The index of the point to remove. It must be less than the number of points returned from getNumPoints(). |
◆ save()
- Parameters
-
item | Where to save the state of this object. |
This function will serialise the object by saving it to item. For most object types, this is most easily implemented in terms of the object's output operator (<<).
It is allowable for an object to only serialize part of itself. This would be useful if the data it represents has a set of defaults and only those values different to the defaults need to be serialized. Such an implementation then needs to be careful how it handles the complimentary load member function.
- Returns
- If an object could not be serialised or if the underlying object type does not support serialisation, this function should return false. A return value of true implies that the object was successfully saved to item. If canSerialize() returns false, this function must do nothing except return false as well.
Implements Serialize.
◆ setPointInterpolationMode()
Sets the interpolation mode of the color spectrum. The interpolation mode controls how numbers are mapped to colors.
- Parameters
-
mode | The desired interpolation mode of the color spectrum. |