fsleyes.gl.glmask¶
This module provides the GLMask class, which implements
functionality for rendering an Image overlay as a binary mask.
-
class
fsleyes.gl.glmask.GLMask(image, overlayList, displayCtx, canvas, threedee)¶ Bases:
fsleyes.gl.glimageobject.GLImageObjectThe
GLMaskclass encapsulates logic to render anImageinstance as a binary mask in OpenGL.When created, a
GLMaskinstance assumes that the providedImageinstance has aDisplay.overlayTypeofmask, and that its associatedDisplayinstance contains aMaskOptsinstance, containing mask-specific display properties.Textures
A
GLMaskwill use up to two textures:- An
ImageTexturefor storing the 3D image data. This texture is bound to texture unit 0. - A
RenderTexture, used for edge filtering if necessary. This texture will be bound to texture unit 1.
2D rendering
On 2D canvases, A
GLMaskis rendered similarly to aGLVolume- a 2D slice is taken through the 3D image texture. If theMaskOpts.outlineproperty is active, this slice is rendered to an off-screen texture, which is then passed through an edge filter (see thefiltersmodule).Version dependent modules
The
GLMaskclass makes use of the functions defined in thegl14.glmask_funcsor thegl21.glmask_funcsmodules, which provide OpenGL version specific details for rendering.These version dependent modules must provide the following functions:
init(GLMask)Perform any necessary initialisation. destroy(GLMask)Perform any necessary cleanup compileShaders(GLMask)(Re-)compile the shader program updateShaderState(GLMask)Update the shader program state draw2D(GLMask, ...)Draw a slice of the image drawAll(GLMask, ...)Draw multiple slices of the image -
__init__(image, overlayList, displayCtx, canvas, threedee)¶ Create a
GLMask.Parameters: - image – The
Imageinstance. - overlayList – The
OverlayList - displayCtx – The
DisplayContextmanaging the scene. - canvas – The canvas doing the drawing.
- threedee – 2D or 3D rendering
- image – The
-
destroy()¶ Must be called when this
GLMaskis no longer needed. Destroys theImageTexture.
-
ready()¶ Returns
Trueif thisGLMaskis ready to be drawn,Falseotherwise.
-
textureReady()¶ Returns
Trueif theimageTextureis ready to be used,Falseotherwise.
-
updateShaderState(*args, **kwargs)¶ Calls
gl14.gllabel_funcs.updateShaderState()orgl21.gllabel_funcs.updateShaderState(), andNotifier.notify(). Usesidle.idleWhen()to ensure that they don’t get called untilready()returnsTrue.
-
addDisplayListeners()¶ Adds a bunch of listeners to the
Displayobject, and the associatedMaskOptsinstance, which define how the mask image should be displayed.
-
removeDisplayListeners()¶ Removes all the listeners added by
addDisplayListeners().
-
refreshImageTexture()¶ Makes sure that the
ImageTexture, used to store theImagedata, is up to date.
-
getColour()¶ Prepares and returns the mask colour for use in the fragment shader.
-
getThreshold()¶ Prepares and returns the mask thresholds for use in the fragment shader.
-
preDraw(xform=None, bbox=None)¶ Binds the
ImageTextureand calls the version-dependentpreDrawfunction.
-
draw2D(zpos, axes, xform=None, bbox=None)¶ Calls the version-dependent
draw2Dfunction, then applies the edge filter if necessary.
-
drawAll(axes, zposes, xforms)¶ Calls the version-dependent
drawAllfunction, then applies the edge filter if necessary.
-
draw3D(*args, **kwargs)¶ Does nothing.
-
postDraw(xform=None, bbox=None)¶ Unbinds the
ImageTexture.
-
_GLMask__imageSyncChanged(*a)¶ Called when the
NiftiOpts.volumeproperty is synchronised or un-synchronised. CallsrefreshImageTexture()andupdateShaderState().
-
_GLMask__imageTextureChanged(*a)¶ Called when the image texture data has changed. Triggers a refresh.
-
_GLMask__interpChanged(*a)¶ Called when the
MaskOpts.interpolationchanges. Updates the image texture.
-
_GLMask__volumeChanged(*a)¶ Called when the
NiftiOpts.volumechanges. Updates the image texture.
-
__module__= 'fsleyes.gl.glmask'¶
- An