fsleyes.gl.glimageobject

This module provides the GLImageObject class, a sub-class of GLObject, and the base class for all OpenGL objects which display data from Nifti overlays.

class fsleyes.gl.glimageobject.GLImageObject(overlay, overlayList, displayCtx, canvas, threedee)[source]

Bases: fsleyes.gl.globject.GLObject

The GLImageObject class is the base class for all GL representations of Nifti instances. It contains some convenience methods for drawing volumetric image data.

Some useful methods for 2D rendering:

.. autsummary::
   :nosignatures:

   frontFace
   generateVertices2D
   generateVoxelCoordinates2D

Some useful methods for 3D rendering:

.. autsummary::
   :nosignatures:

   generateVertices3D
   generateVoxelCoordinates3D
   get3DClipPlane
   clipPlaneVertices
   drawClipPlanes
__init__(overlay, overlayList, displayCtx, canvas, threedee)[source]

Create a GLImageObject.

Parameters
  • image – A Nifti object.

  • overlayList – The :class`.OverlayList`.

  • displayCtx – The DisplayContext object managing the scene.

  • canvas – The canvas doing the drawing.

  • threedee – Set up for 2D or 3D rendering.

property image

The Nifti being rendered by this GLImageObject. This is equivalent to GLObject.overlay().

destroy()[source]

Must be called when this GLImageObject is no longer needed. Removes some property listeners.

property destroyed

Returns True if destroy() has been called, False otherwise.

getDisplayBounds()[source]

Returns the bounds of the Image (see the DisplayOpts.bounds() property).

getDataResolution(xax, yax)[source]

Returns a suitable screen resolution for rendering this GLImageObject in 2D.

frontFace()[source]

Convenience method for 2D rendering.

Image slices are generally drawn onto a 2D plane which is parallel to the viewing plane (see the GLVolume class). If the canvas that is drawing this GLImageObject has adjusted the projection matrix (e.g. via the SliceCanvas.invertX or SliceCanvas.invertY properties), the front or back face of this plane may be facing the viewing plane.

So if face-culling is desired, this method returns the face that is facing away from the viewing plane, i.e. the face that can safely be culled.

Note

This will raise an error if called on a GLImageObject which is being drawn by anything other than a SliceCanvas or LightBoxCanvas.

generateVertices2D(zpos, axes, bbox=None)[source]

Generates vertex coordinates for a 2D slice of the Image, through the given zpos, with the optional bbox applied to the coordinates.

This is a convenience method for generating vertices which can be used to render a slice through a 3D texture. It is used by the gl14.glvolume_funcs and gl21.glvolume_funcs (and other) modules.

A tuple of three values is returned, containing:

  • A 6*3 numpy.float32 array containing the vertex coordinates

  • A 6*3 numpy.float32 array containing the voxel coordinates corresponding to each vertex

  • A 6*3 numpy.float32 array containing the texture coordinates corresponding to each vertex

generateVertices3D = <MagicMock name='mock.utils.memoize.Instanceify()()' id='140735708004064'>
generateVoxelCoordinates2D(zpos, axes, bbox=None, space='voxel')[source]

Generates a 2D grid of voxel coordinates along the XY display coordinate system plane, at the given zpos.

Parameters
  • zpos – Position along the display coordinate system Z axis.

  • axes – Axis indices.

  • bbox – Limiting bounding box.

  • space – Either 'voxel' (the default) or 'display'. If the latter, the returned coordinates are in terms of the display coordinate system. Otherwise, the returned coordinates are integer voxel coordinates.

Returns

A numpy.float32 array of shape (N, 3), containing the coordinates for N voxels.

See the pointGrid() function.

generateVoxelCoordinates3D(bbox, space='voxel')[source]

See the pointGrid3D() function.

note: Not implemented properly yet.

get3DClipPlane = <MagicMock name='mock.utils.memoize.Instanceify()()' id='140735708004064'>
clipPlaneVertices = <MagicMock name='mock.utils.memoize.Instanceify()()' id='140735708004064'>
drawClipPlanes(xform=None, bbox=None)[source]

A convenience method for use with overlays being displayed in terms of a Volume3DOpts instance.

Draws the active clipping planes, as specified by the Volume3DOpts clipping properties.

Parameters
  • xform – A transformation matrix to apply to the clip plane vertices before drawing them.

  • bbox – A bounding box by which the clip planes can be limited (not currently honoured).

__boundsChanged(*a)

Called when any change to the overlay bounds change.

Some of the methods on this class use the fsl.utils.memoize.memoize() decorator to cache previously calculated values. When certain DisplayOpts properties change, these cached values need to be invalidated. This method does that.

__clip3DChanged(*a)

Called when any change to the 3D clipping properties change.

See the __boundsChanged() method.

__module__ = 'fsleyes.gl.glimageobject'
class fsleyes.gl.glimageobject.AuxImageTextureManager(globj, **auximages)[source]

Bases: object

Utility class used by some GLImageObject instances.

The AuxImageTextureManager is used to manage “auxillary” ImageTexture instances which are used when rendering the GLImageObject. For example, GLVolume instances may need to use an ImageTexture to store the data for the VolumeOpts.clipImage setting.

__init__(globj, **auximages)[source]

Create an AuxImageTextureManager.

Note that an initial value must be given for each auxillary texture type.

Parameters
  • globj – The GLImageObject which requires the auxillary image textures.

  • auximages

    auxtype=initial_value for each auxillary image texture type. The initial value must be one of:

    • an Image

    • None

    • A tuple containing an Image, and a dict containing settings to initialise the ImageTexture (passed as kwargs to ImageTexture.__init__).

destroy()[source]

Must be calld when this AuxImageTextureManager is no longer needed. Clears references and destroys texture objects.

property name
property globj
property image
property opts
property displayCtx
texture(which)[source]
textureXform(which)[source]

Generates and returns a transformation matrix which can be used to transform texture coordinates from the main image to the specified auxillary image.

texturesReady()[source]

Returns True if all auxillary textures are in a usable state, False otherwise.

registerAuxImage(which, image, **kwargs)[source]

Register an auxillary image.

Creates an ImageTexture to store the image data. Registers a listener with the NiftiOpts.volume property of the image, so the texture can be updated when the image volume changes.

Parameters
  • which – Name of the auxillary image

  • imageImage object

All other arguments are passed through to the refreshAuxTexture() method.

deregisterAuxImage(which, refreshTexture=True)[source]

De-register an auxillary image. Deregisters the NiftiOpts.volume listener that was registered in registerAuxImage(), and destroys the associated ImageTexture.

Parameters
  • which – Name of the auxillary image

  • refreshTexture – Defaults to True. Call refreshAuxTexture() to destroy the associated ImageTexture.

__destroyAuxTexture(which)

Destroys the ImageTexture for type which.

refreshAuxTexture(which, **kwargs)[source]

Create/re-create an auxillary ImageTexture.

The previous ImageTexture (if one exists) is destroyed. If no Image of type which is currently registered, a small dummy Image and ImageTexture is created.

Parameters

which – Name of the auxillary image

All other arguments are passed through to the ImageTexture.__init__ method.

__dict__ = mappingproxy({'__module__': 'fsleyes.gl.glimageobject', '__doc__': 'Utility class used by some :class:`GLImageObject` instances.\n\n The ``AuxImageTextureManager`` is used to manage "auxillary"\n :class:`.ImageTexture` instances which are used when rendering the\n ``GLImageObject``. For example, :class:`.GLVolume` instances may need to\n use an ``ImageTexture`` to store the data for the\n :attr:`.VolumeOpts.clipImage` setting.\n ', '__init__': <function AuxImageTextureManager.__init__>, 'destroy': <function AuxImageTextureManager.destroy>, 'name': <property object>, 'globj': <property object>, 'image': <property object>, 'opts': <property object>, 'displayCtx': <property object>, 'texture': <function AuxImageTextureManager.texture>, 'textureXform': <function AuxImageTextureManager.textureXform>, 'texturesReady': <function AuxImageTextureManager.texturesReady>, 'registerAuxImage': <function AuxImageTextureManager.registerAuxImage>, 'deregisterAuxImage': <function AuxImageTextureManager.deregisterAuxImage>, '_AuxImageTextureManager__destroyAuxTexture': <function AuxImageTextureManager.__destroyAuxTexture>, 'refreshAuxTexture': <function AuxImageTextureManager.refreshAuxTexture>, '__dict__': <attribute '__dict__' of 'AuxImageTextureManager' objects>, '__weakref__': <attribute '__weakref__' of 'AuxImageTextureManager' objects>, '__annotations__': {}})
__module__ = 'fsleyes.gl.glimageobject'
__weakref__

list of weak references to the object (if defined)