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)

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)

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.
image

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

destroy()

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

destroyed()

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

getDisplayBounds()

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

getDataResolution(xax, yax)

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

frontFace()

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)

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='139845833549472'>
generateVoxelCoordinates2D(zpos, axes, bbox=None, space='voxel')

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')

See the pointGrid3D() function.

note: Not implemented properly yet.

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

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).
_GLImageObject__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.

_GLImageObject__clip3DChanged(*a)

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

See the __boundsChanged() method.

__module__ = 'fsleyes.gl.glimageobject'