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 ofNifti
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 thisGLImageObject
. This is equivalent toGLObject.overlay()
.
-
destroy
()[source]¶ Must be called when this
GLImageObject
is no longer needed. Removes some property listeners.
-
getDisplayBounds
()[source]¶ Returns the bounds of the
Image
(see theDisplayOpts.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 thisGLImageObject
has adjusted the projection matrix (e.g. via theSliceCanvas.invertX
orSliceCanvas.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 aSliceCanvas
orLightBoxCanvas
.
-
generateVertices2D
(zpos, axes, bbox=None)[source]¶ Generates vertex coordinates for a 2D slice of the
Image
, through the givenzpos
, with the optionalbbox
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
andgl21.glvolume_funcs
(and other) modules.A tuple of three values is returned, containing:
A
6*3 numpy.float32
array containing the vertex coordinatesA
6*3 numpy.float32
array containing the voxel coordinates corresponding to each vertexA
6*3 numpy.float32
array containing the texture coordinates corresponding to each vertex
-
generateVertices3D
= <MagicMock name='mock.utils.memoize.Instanceify()()' id='139656520512080'>¶
-
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 forN
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='139656520512080'>¶
-
clipPlaneVertices
= <MagicMock name='mock.utils.memoize.Instanceify()()' id='139656520512080'>¶
-
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 certainDisplayOpts
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 theGLImageObject
. For example,GLVolume
instances may need to use anImageTexture
to store the data for theVolumeOpts.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 theImageTexture
(passed askwargs
toImageTexture.__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
¶
-
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 theNiftiOpts.volume
property of the image, so the texture can be updated when the image volume changes.- Parameters
which – Name of the auxillary image
image –
Image
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 inregisterAuxImage()
, and destroys the associatedImageTexture
.- Parameters
which – Name of the auxillary image
refreshTexture – Defaults to
True
. CallrefreshAuxTexture()
to destroy the associatedImageTexture
.
-
__destroyAuxTexture
(which)¶ Destroys the
ImageTexture
for typewhich
.
-
refreshAuxTexture
(which, **kwargs)[source]¶ Create/re-create an auxillary
ImageTexture
.The previous
ImageTexture
(if one exists) is destroyed. If noImage
of typewhich
is currently registered, a small dummyImage
andImageTexture
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)
-