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.TextureThe
ColourMapTextureclass is aTexturewhich stores a RGB or RGBA colour map.A
ColourMapTexturemaps 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
ColourMapTexturecalculates this transformation, and makes it available via thegetCoordinateTransform()method.The colour map itself can be specified in a number of ways:
- A
numpyarray 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:
setAlphaSet the transparency of all colours in the colour map. setInvertInvert the values in the colour map. setResolutionSet the resolution (number of colours) of this ColourMapTexture.setGammaGamma correction - uses gammaas an exponent to weight the colour map towards the low or high end.setInterpSet the interpolation used by this ColourMapTexture- eitherGL_NEARESTorGL_LINEAR.setBorderSet 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 numpyarray 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
gammaas 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_NEARESTorGL_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:cmapSee setColourMap().invertSee setInvert().interpSee setInterp().alphaSee setAlpha().resolutionSee setResolution().gammaSee setGamma().displayRangeSee setDisplayRange().borderSee 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
ColourMapTextureare changed. Re-configures the texture.
-
__module__= 'fsleyes.gl.textures.colourmaptexture'¶
- A