fsleyes.gl.textures.colourmaptexture
¶
This module provides the ColourMapTexture
class, a 1D
Texture
which can be used to store a RGBA colour map.
-
class
fsleyes.gl.textures.colourmaptexture.
ColourMapTexture
(name)¶ Bases:
fsleyes.gl.textures.texture.Texture
The
ColourMapTexture
class is aTexture
which stores a RGB or RGBA colour map.A
ColourMapTexture
maps a data range to to a colour map. The data range may be specified by thesetDisplayRange()
method, and the colour map by thesetColourMap()
method. Alternately, both can be specified with theset()
method.In OpenGL, textures are indexed with a number between 0.0 and 1.0. So in order to map the data range to texture coordinates, an offset/scale transformation must be applied to data values. The
ColourMapTexture
calculates this transformation, and makes it available via thegetCoordinateTransform()
method.The colour map itself can be specified in a number of ways:
- A
numpy
array of size \(N\times 3\) or \(N\times 4\), containing RGB or RGBA colour values, with colour values in the range[0, 1]
. - A function which accepts an array of values in the range
[0, 1]
, and returns an array of size \(N\times 3\) or \(N\times 4\), specifying the RGB/RGBA colours that correspond to the input values.
Some other methods are provided, for configuring the colour map:
setAlpha
Set the transparency of all colours in the colour map. setInvert
Invert the values in the colour map. setResolution
Set the resolution (number of colours) of this ColourMapTexture
.setGamma
Gamma correction - uses gamma
as an exponent to weight the colour map towards the low or high end.setInterp
Set the interpolation used by this ColourMapTexture
- eitherGL_NEAREST
orGL_LINEAR
.setBorder
Set the texture border colour. -
__init__
(name)¶ Create a
ColourMapTexture
.Parameters: name – A unique name for this ColourMapTexture
.
-
setColourMap
(cmap)¶ Set the colour map stored by the
ColourMapTexture
.Parameters: cmap – The colour map, either a numpy
array of size \(N\times 3\) or \(N\times 4\), specifying RGB/RGBA colours, or a function which accepts values in the range[0, 1]
, and generates corresponding RGB/RGBA colours.
-
setResolution
(res)¶ Set the resolution (number of colours) of this
ColourMapTexture
. This setting is only applicable when the colour map is specified as a function (seesetColourMap()
).
-
setAlpha
(alpha)¶ Set the transparency of all colours in the colour map. This setting is only applicable when the colour map is specified as RGB values.
-
setInvert
(invert)¶ Invert the values in the colour map.
-
setGamma
(gamma)¶ Gamma correction - uses
gamma
as an exponent to weight the colour map towards the low or high end. Only applied if the colour map (seesetColourMap()
) is specified as a function.
-
setInterp
(interp)¶ Set the interpolation used by this
ColourMapTexture
- eitherGL_NEAREST
orGL_LINEAR
.
-
setDisplayRange
(drange)¶ Set the data range which corresponds to the colours stored in this
ColourMapTexture
. A matrix which transforms values from from this data range into texture coordinates is available via thegetCoordinateTransform()
method.
-
setBorder
(border)¶ Set the texture border colour. If
None
, the edge colours of the colour map are used as the border.
-
getCoordinateTransform
()¶ Returns a matrix which transforms values from from the colour map data range (see
setDisplayRange()
) into texture coordinates.
-
set
(**kwargs)¶ Set any parameters on this
ColourMapTexture
. Valid keyword arguments are:cmap
See setColourMap()
.invert
See setInvert()
.interp
See setInterp()
.alpha
See setAlpha()
.resolution
See setResolution()
.gamma
See setGamma()
.displayRange
See setDisplayRange()
.border
See setBorder()
.
-
_ColourMapTexture__prepareTextureSettings
()¶ Called by
__refresh()
. Prepares all of the texture settings, and returns a tuple containing:- An array containing the colour map data
- The display range
- The interpolation setting
- The border colour
-
_ColourMapTexture__refresh
()¶ Called when any settings of this
ColourMapTexture
are changed. Re-configures the texture.
-
__module__
= 'fsleyes.gl.textures.colourmaptexture'¶
- A