fsleyes.gl.glvector¶
This module provides the GLVectorBase and GLVector
classes. The GLVectorBase class encapsulate the logic for rendering
overlays which contain directional data, and the GLVector class
specifically conatins logic for displaying Image overlays with
shape X*Y*Z*3, or of type NIFTI_TYPE_RGB24.
-
class
fsleyes.gl.glvector.GLVectorBase(overlay, overlayList, displayCtx, canvas, threedee, init=None, preinit=None)[source]¶ Bases:
fsleyes.gl.glimageobject.GLImageObjectThe
GLVectorBaseclass encapsulates the logic for renderingNiftioverlay types which represent directional data (and which are described by aVectorOptsinstance). TheGLVectorBaseclass is a sub-class ofGLImageObject.The
GLVectorBaseclass is a base class which is not intended to be instantiated directly. TheGLRGBVector,GLLineVector,GLTensor, andGLSHsubclasses should be used instead. These subclasses share the functionality provided by this class. See also theGLVectorclass, which is also a base class.Colouring
A
GLVectorBasecan be coloured in one of two ways:Each voxel is coloured according to the orientation of the vector. A custom fragment shader program looks up the
xyzvector values, and combines three colours (corresponding to thexyzdirections) to form the final fragment colour. The colours for each component are specified by theVectorOpts.xColour,VectorOpts.yColour, andVectorOpts.zColourproperties. If the image being displayed contains directional data (e.g. is aX*Y*Z*3vector image), you should use theGLVectorclass.Each voxel is coloured according to the values contained in another image, which are used to look up a colour in a colour map. The image and colour map are respectively specified by the
VectorOpts.colourImageandVectorOpts.cmapproperties.
In either case, the brightness or transparency of each vector colour may be modulated by another image, specified by the
VectorOpts.modulateImageandVectorOpts.modulateModeproperties. This modulation image is stored as a 3D single-channelImageTexture.Finally, vector voxels may be clipped according to the values of another image, specified by the
VectorOpts.clipImageproperty. This clipping image is stored as a 3D single-channelImageTexture, and the clipping thresholds specified by theVectorOpts.clippingRangeproperty.Textures
The
GLVectorBaseclass configures its textures in the following manner:modulateTexturegl.GL_TEXTURE0clipTexturegl.GL_TEXTURE1colourTexturegl.GL_TEXTURE2cmapTexturegl.GL_TEXTURE3-
__init__(overlay, overlayList, displayCtx, canvas, threedee, init=None, preinit=None)[source]¶ Create a
GLVectorBaseobject bound to the given overlay and display.Initialises the OpenGL data required to render the given vector overlay. This method does the following:
Creates the modulate, clipping and colour image textures.
Adds listeners to the
DisplayandVectorOptsinstances, so the textures and geometry can be updated when necessary.
- Parameters
overlay – A
Niftiobject.overlayList – The
OverlayListdisplayCtx – A
DisplayContextobject which describes how the overlay is to be displayed.canvas – The canvas doing the drawing.
threedee – 2D or 3D rendering.
init – An optional function to be called when all of the
ImageTextureinstances associated with thisGLVectorBasehave been initialised.preinit – An optional functiono be called after this
GLVectorBasehas configured itself, but beforeinitis called. Used byGLVector.
-
destroy()[source]¶ Must be called when this
GLVectorBaseis no longer needed. Deletes the GL textures, and deregisters the listeners configured in__init__().
-
property
modulateTexture¶ Returns the
ImageTexturefor theVectorOpts.modulateImage.
-
property
clipTexture¶ Returns the
ImageTexturefor theVectorOpts.clipImage.
-
property
colourTexture¶ Returns the
ImageTexturefor theVectorOpts.colourImage.
-
addListeners()[source]¶ Called by
__init__(). Adds listeners to properties of theDisplayandVectorOptsinstances, so that the GL representation can be updated when the display properties change.
-
removeListeners()[source]¶ Called by
destroy(). Removes all property listeners added by theaddListeners()method.
-
compileShaders()[source]¶ This method must be provided by subclasses (e.g.g the
GLRGBVectorandGLLineVectorclasses), and must compile the vertex/fragment shaders used to render thisGLVectorBase. .
-
updateShaderState()[source]¶ This method must be provided by subclasses (e.g. the
GLRGBVectorandGLLineVectorclasses), and must update the state of the vertex/fragment shader programs. It must returnTrueif the shader state was updated,Falseotherwise.
-
asyncUpdateShaderState(*args, **kwargs)[source]¶ Calls
updateShaderState()and thenNotifier.notify(), usingidle.idleWhen()function to make sure that it is only called whenready()returnsTrue.
-
refreshColourMapTexture(colourRes=256)[source]¶ Called when the component colour maps need to be updated, when one of the
VectorOpts.xColour,yColour,zColour,cmap,suppressX,suppressY, orsuppressZproperties change.Regenerates the colour map texture.
-
getVectorColours()[source]¶ Prepares the colours that represent each direction.
- Returns:
a
numpyarray of size(3, 4)containing the RGBA colours that correspond to thex,y, andzvector directions.A
numpyarray of shape(4, 4)which encodes a scale and offset to be applied to the vector value before it is combined with the colours, encoding the current brightness and contrast settings.
-
getClippingRange()[source]¶ Returns the
clippingRange, suitable for use in the fragment shader. The returned values are transformed into the clip image texture value range, so the fragment shader can compare texture values directly to it.
-
getModulateRange()[source]¶ Returns the
modulateRange, suitable for use in the fragment shader. The returned values are transformed into the modulate image texture value range, so the fragment shader can compare texture values directly to it.
-
getAuxTextureXform(which)[source]¶ Generates and returns a transformation matrix which can be used to transform texture coordinates from the vector image to the specified auxillary image (
'clip','modulate'or'colour').
-
preDraw(xform=None, bbox=None)[source]¶ Must be called by subclass implementations.
Ensures that all of the textures managed by this
GLVectorBaseare bound to their corresponding texture units.
-
postDraw(xform=None, bbox=None)[source]¶ Must be called by subclass implementations.
Unbinds all of the textures managed by this
GLVectorBase.
-
__cmapPropChanged(*a)¶ Called when a
DisplayorVectorOptsproperty affecting the vector colour map settings changes. CallsrefreshColourMapTexture()andasyncUpdateShaderState().
-
registerAuxImage(which, image, onReady=None, **kwargs)[source]¶ Registers the given auxillary image with the
AuxImageTextureManager.
-
__colourImageChanged(*a)¶ Called when the
VectorOpts.colourImagechanges. Registers with the new image, and refreshes textures as needed.
-
__modImageChanged(*a)¶ Called when the
VectorOpts.modulateImagechanges. Registers with the new image, and refreshes textures as needed.
-
__clipImageChanged(*a)¶ Called when the
VectorOpts.clipImagechanges. Registers with the new image, and refreshes textures as needed.
-
__textureChanged(*a)¶ Called when any of the
ImageTextureinstances containing clipping, modulation or colour data, are refreshed. Notifies listeners of thisGLVectorBase(via theNotifierbase class).
-
__module__= 'fsleyes.gl.glvector'¶
-
class
fsleyes.gl.glvector.GLVector(image, *args, **kwargs)[source]¶ Bases:
fsleyes.gl.glvector.GLVectorBaseThe
GLVectorclass is a sub-class ofGLVectorBase, which contains some additional logic for renderingImageoverlays with a shapeX*Y*Z*3, or of typeNIFTI_TYPE_RGB24, and which contain directional data.By default , the
imageoverlay passed to__init__()is assumed to be anImageinstance which contains vector data. If this is not the case, thevectorImageparameter may be used to pass in theImagethat contains the vector data.This vector image is stored on the GPU as a 3D RGB
ImageTexture, where theRchannel contains thexvector values, theGchannel theyvalues, and theBchannel thezvalues.This texture is bound to texture unit
gl.GL_TEXTURE4in thepreDraw()method.-
__init__(image, *args, **kwargs)[source]¶ Create a
GLVector. All of the arguments documented here are optional, but if provided, must be passed as keyword arguments. All other arguments are passed through toGLVectorBase.__init__().The
image, (orvectorImage) argument is assumed to be anImageinstance of shape(X, Y, Z, 3), or of typeNIFTI_TYPE_RGB24, which contains the vector data. If the former, the vector data is assumed to be in the range[-1, 1]. If the latter, the vector data is, by definition, in the range[0, 255]- this is assumed to map directly to the range[-1, 1].- Parameters
vectorImage – If
None, theimageis assumed to be anImageinstance which contains the vector data. If this is not the case, thevectorImageparameter can be used to specify anImageinstance which does contain the vector data.prefilter – An optional function which filters the data before it is stored as a 3D texture. See
Texture3D. Regardless of whether this function is provided, the data is always transposed so that the fourth dimension is the fastest changing, before being transferred to the GPU.prefilterRange – If the provided
prefilterfunction will cause the range of the data to change, this function must be provided, and must, given the original data range, return a suitably adjusted adjust data range.
-
destroy()[source]¶ Overrides
GLVectorBase.destroy(). Must be called when thisGLVectoris no longer needed. CallsGLVectorBase.destroy(), and destroys the vector image texture.
-
texturesReady()[source]¶ Overrides
GLVectorBase.texturesReady(). ReturnsTrueif all of the textures managed by thisGLVectorare ready to be used,Falseotherwise.
-
refreshImageTexture(interp=<MagicMock name='mock.GL.GL_NEAREST' id='4058093072'>)[source]¶ Called by
__init__(), and when theImageTextureneeds to be updated. (Re-)creates theImageTexture, using theresourcesmodule so that the texture can be shared by other users.- Parameters
interp – Interpolation method (
GL_NEARESTorGL_LINEAR). Used by sub-class implementations (seeGLRGBVector).
-
preDraw(xform=None, bbox=None)[source]¶ Overrides
GLVectorBase(). Binds the vector image texture.
-
postDraw(xform=None, bbox=None)[source]¶ Overrides
GLVectorBase(). Unbinds the vector image texture.
-
__textureChanged(*a)¶ Called when the
ImageTextureinstance containing the vector data is are refreshed. Notifies listeners of thisGLVector(via theNotifierbase class).
-
__module__= 'fsleyes.gl.glvector'¶
-