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)[source]

Bases: fsleyes.gl.glimageobject.GLImageObject

The GLMask class encapsulates logic to render an Image instance as a binary mask in OpenGL.

When created, a GLMask instance assumes that the provided Image instance has a Display.overlayType of mask, and that its associated Display instance contains a MaskOpts instance, containing mask-specific display properties.

Textures

A GLMask will use up to two textures:

  • An ImageTexture for 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 GLMask is rendered similarly to a GLVolume - a 2D slice is taken through the 3D image texture. If the MaskOpts.outline property is active, this slice is rendered to an off-screen texture, which is then passed through an edge filter (see the filters module).

Version dependent modules

The GLMask class makes use of the functions defined in the gl14.glmask_funcs or the gl21.glmask_funcs modules, 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)[source]

Create a GLMask.

Parameters
  • image – The Image instance.

  • overlayList – The OverlayList

  • displayCtx – The DisplayContext managing the scene.

  • canvas – The canvas doing the drawing.

  • threedee – 2D or 3D rendering

destroy()[source]

Must be called when this GLMask is no longer needed. Destroys the ImageTexture.

ready()[source]

Returns True if this GLMask is ready to be drawn, False otherwise.

textureReady()[source]

Returns True if the imageTexture is ready to be used, False otherwise.

updateShaderState(*args, **kwargs)[source]

Calls gl14.gllabel_funcs.updateShaderState() or gl21.gllabel_funcs.updateShaderState(), and Notifier.notify(). Uses idle.idleWhen() to ensure that they don’t get called until ready() returns True.

addDisplayListeners()[source]

Adds a bunch of listeners to the Display object, and the associated MaskOpts instance, which define how the mask image should be displayed.

removeDisplayListeners()[source]

Removes all the listeners added by addDisplayListeners().

refreshImageTexture()[source]

Makes sure that the ImageTexture, used to store the Image data, is up to date.

getColour()[source]

Prepares and returns the mask colour for use in the fragment shader.

getThreshold()[source]

Prepares and returns the mask thresholds for use in the fragment shader.

preDraw(xform=None, bbox=None)[source]

Binds the ImageTexture and calls the version-dependent preDraw function.

draw2D(zpos, axes, xform=None, bbox=None)[source]

Calls the version-dependent draw2D function, then applies the edge filter if necessary.

drawAll(axes, zposes, xforms)[source]

Calls the version-dependent drawAll function, then applies the edge filter if necessary.

draw3D(*args, **kwargs)[source]

Does nothing.

postDraw(xform=None, bbox=None)[source]

Unbinds the ImageTexture.

__volumeChanged(*a)

Called when the NiftiOpts.volume changes. Updates the image texture.

__interpChanged(*a)

Called when the MaskOpts.interpolation changes. Updates the image texture.

__imageTextureChanged(*a)

Called when the image texture data has changed. Triggers a refresh.

__imageSyncChanged(*a)

Called when the NiftiOpts.volume property is synchronised or un-synchronised. Calls refreshImageTexture() and updateShaderState().

__module__ = 'fsleyes.gl.glmask'