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.GLObjectThe
GLImageObjectclass is the base class for all GL representations ofNiftiinstances. 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
Niftiobject.overlayList – The :class`.OverlayList`.
displayCtx – The
DisplayContextobject managing the scene.canvas – The canvas doing the drawing.
threedee – Set up for 2D or 3D rendering.
-
property
image¶ The
Niftibeing rendered by thisGLImageObject. This is equivalent toGLObject.overlay().
-
destroy()[source]¶ Must be called when this
GLImageObjectis 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
GLImageObjectin 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
GLVolumeclass). If the canvas that is drawing thisGLImageObjecthas adjusted the projection matrix (e.g. via theSliceCanvas.invertXorSliceCanvas.invertYproperties), 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
GLImageObjectwhich is being drawn by anything other than aSliceCanvasorLightBoxCanvas.
-
generateVertices2D(zpos, axes, bbox=None)[source]¶ Generates vertex coordinates for a 2D slice of the
Image, through the givenzpos, with the optionalbboxapplied 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_funcsandgl21.glvolume_funcs(and other) modules.A tuple of three values is returned, containing:
A
6*3 numpy.float32array containing the vertex coordinatesA
6*3 numpy.float32array containing the voxel coordinates corresponding to each vertexA
6*3 numpy.float32array containing the texture coordinates corresponding to each vertex
-
generateVertices3D= <MagicMock name='mock.utils.memoize.Instanceify()()' id='281473487560816'>¶
-
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.float32array of shape(N, 3), containing the coordinates forNvoxels.
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='281473487560816'>¶
-
clipPlaneVertices= <MagicMock name='mock.utils.memoize.Instanceify()()' id='281473487560816'>¶
-
drawClipPlanes(xform=None, bbox=None)[source]¶ A convenience method for use with overlays being displayed in terms of a
Volume3DOptsinstance.Draws the active clipping planes, as specified by the
Volume3DOptsclipping 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 certainDisplayOptsproperties 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'¶
-
-
class
fsleyes.gl.glimageobject.AuxImageTextureManager(globj, **auximages)[source]¶ Bases:
objectUtility class used by some
GLImageObjectinstances.The
AuxImageTextureManageris used to manage “auxillary”ImageTextureinstances which are used when rendering theGLImageObject. For example,GLVolumeinstances may need to use anImageTextureto store the data for theVolumeOpts.clipImagesetting.-
__init__(globj, **auximages)[source]¶ Create an
AuxImageTextureManager.Note that an initial value must be given for each auxillary texture type.
- Parameters
globj – The
GLImageObjectwhich requires the auxillary image textures.auximages –
auxtype=initial_valuefor each auxillary image texture type. The initial value must be one of:an
ImageNoneA tuple containing an
Image, and a dict containing settings to initialise theImageTexture(passed askwargstoImageTexture.__init__).
-
destroy()[source]¶ Must be calld when this
AuxImageTextureManageris 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
Trueif all auxillary textures are in a usable state,Falseotherwise.
-
registerAuxImage(which, image, **kwargs)[source]¶ Register an auxillary image.
Creates an
ImageTextureto store the image data. Registers a listener with theNiftiOpts.volumeproperty of the image, so the texture can be updated when the image volume changes.- Parameters
which – Name of the auxillary image
image –
Imageobject
All other arguments are passed through to the
refreshAuxTexture()method.
-
deregisterAuxImage(which, refreshTexture=True)[source]¶ De-register an auxillary image. Deregisters the
NiftiOpts.volumelistener that was registered inregisterAuxImage(), and destroys the associatedImageTexture.- Parameters
which – Name of the auxillary image
refreshTexture – Defaults to
True. CallrefreshAuxTexture()to destroy the associatedImageTexture.
-
refreshAuxTexture(which, **kwargs)[source]¶ Create/re-create an auxillary
ImageTexture.The previous
ImageTexture(if one exists) is destroyed. If noImageof typewhichis currently registered, a small dummyImageandImageTextureis created.- Parameters
which – Name of the auxillary image
All other arguments are passed through to the
ImageTexture.__init__method.
-
_AuxImageTextureManager__destroyAuxTexture(which)¶ Destroys the
ImageTexturefor typewhich.
-
__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>})¶
-
__module__= 'fsleyes.gl.glimageobject'¶
-
__weakref__¶ list of weak references to the object (if defined)
-