fsleyes.gl.textures.imagetexture
¶
This module provides the ImageTexture
and ImageTexture2D
classes, Texture3D
and Texture2D
classes for storing an
Image
instance.
-
fsleyes.gl.textures.imagetexture.
createImageTexture
(name, image, *args, **kwargs)[source]¶ Creates and returns an appropriate texture type (either
ImageTexture
orImageTexture2D
) for the given image.
-
class
fsleyes.gl.textures.imagetexture.
ImageTextureBase
(image, nvals, ndims)[source]¶ Bases:
object
Base class shared by the
ImageTexture
andImageTexture2D
classes. Contains logic for retrieving a specific volume from a 3D + time or 2D + timeImage
, and for retrieving a specific channel from an RGB(A)Image
.-
static
validateShape
(image, texnvals, texndims)[source]¶ Called by
__init__()
. Makes sure that the specified texture settings (number of dimensions, and number of values per texture element) are compatible with the image.- Parameters
image –
Image
texnvals – Number of values per texture element
texndims – Number of texture dimensions
- Raises
RuntimeError
if the texture properties are not compatible with the image
-
__init__
(image, nvals, ndims)[source]¶ Create an
ImageTextureBase
- Parameters
image – The
Image
nvals – Number of values per texture element
ndims – Number of texture dimensions
-
property
image
¶ Returns the
Image
managed by thisImageTextureBase
.
-
property
volume
¶ For
Image
instances with more than three dimensions, specifies the indices for the fourth and above dimensions with which to extract the 3D texture data. If the image has four dimensions, this may be a scalar, otherwise it must be a sequence of (Image.ndim - 3
) the correct length.
-
property
channel
¶ For
Image
instances with multiple values per voxel, such asRGB24
orRGBA32
images, this option allows the channel to be selected.
-
prepareSetArgs
(**kwargs)[source]¶ Called by sub-classes in their
Texture2D.set()
/Texture3D.set()
override.Prepares arguments to be passed through to the underlying
set
method. This method accepts any parameters that are accepted byTexture3D.set()
, plus the following:volume
See
volume()
.channel
See
channel()
.volRefresh
If
True
(the default), the texture data will be refreshed even if thevolume
andchannel
parameters haven’t changed. Otherwise, ifvolume
andchannel
haven’t changed, the texture will not be refreshed.- Returns
True
if any settings have changed and theImageTexture
is to be refreshed ,False
otherwise.
-
__getData
(volume, channel)¶ Extracts data from the
Image
for use as texture data.For textures with multiple values per element (either by volume, or by channel), the data is arranged appropriately, i.e. with the value as the first dimension.
- Parameters
volume – Volume index/indices, for images with more than three dimensions.
channel – Channel, for RGB(A) images.
-
__imageDataChanged
(image, topic, sliceobj)¶ Called when the
Image
notifies about a data changes. Triggers an image texture refresh via a call toset()
.- Parameters
image – The
Image
instancetopic – The string
'data'
sliceobj – Slice object specifying the portion of the image that was changed.
-
__dict__
= mappingproxy({'__module__': 'fsleyes.gl.textures.imagetexture', '__doc__': 'Base class shared by the :class:`ImageTexture` and\n :class:`ImageTexture2D` classes. Contains logic for retrieving a\n specific volume from a 3D + time or 2D + time :class:`.Image`, and\n for retrieving a specific channel from an RGB(A) ``Image``.\n ', 'validateShape': <staticmethod object>, '__init__': <function ImageTextureBase.__init__>, 'destroy': <function ImageTextureBase.destroy>, 'image': <property object>, 'volume': <property object>, 'channel': <property object>, 'prepareSetArgs': <function ImageTextureBase.prepareSetArgs>, '_ImageTextureBase__getData': <function ImageTextureBase.__getData>, '_ImageTextureBase__imageDataChanged': <function ImageTextureBase.__imageDataChanged>, '__dict__': <attribute '__dict__' of 'ImageTextureBase' objects>, '__weakref__': <attribute '__weakref__' of 'ImageTextureBase' objects>, '__annotations__': {}})¶
-
__module__
= 'fsleyes.gl.textures.imagetexture'¶
-
__weakref__
¶ list of weak references to the object (if defined)
-
static
-
class
fsleyes.gl.textures.imagetexture.
ImageTexture
(name, image, **kwargs)[source]¶ Bases:
fsleyes.gl.textures.imagetexture.ImageTextureBase
,fsleyes.gl.textures.texture3d.Texture3D
The
ImageTexture
class contains the logic required to create and manage a 3D texture which represents aImage
instance.Once created, the
Image
instance is available as an attribute of anImageTexture
object, calledimage
. See theTexture3D
documentation for more details.For multi-valued (e.g. RGB) textures, the
Texture3D
class requires data to be passed as a(C, X, Y, Z)
array (forC
values). If anImageTexture
is created with an image of typeNIFTI_TYPE_RGB24
orNIFTI_TYPE_RGBA32
, it will take care of re-arranging the image data so that it has the shape required by theTexture3D
class.-
threadedDefault
= None¶ Default value used for the
threaded
argument passed to__init__()
. When this is set toNone
, the default value will be the value offsl.utils.platform.Platform.haveGui
.
-
classmethod
enableThreading
(enable=True)[source]¶ Context manager which can be used to temporarily set the default value of the
threaded
argument passedto__init__()
.
-
__init__
(name, image, **kwargs)[source]¶ Create an
ImageTexture
. A listener is added to theImage.data
property, so that the texture data can be refreshed whenever the image data changes - see the__imageDataChanged()
method.- Parameters
name – A name for this
imageTexure
.image – The
Image
instance.volume – Initial volume index/indices, for >3D images.
All other arguments are passed through to the
Texture3D.__init__()
method, and thus used as initial texture settings.Note
The default value of the
threaded
parameter is set to the value ofthreadedDefault
.
-
set
(**kwargs)[source]¶ Overrides
Texture3D.set()
. Passes all arguments through theprepareSetArgs()
method, then passes them on toTexture3D.set()
.- Returns
True
if any settings have changed and theImageTexture
is to be refreshed ,False
otherwise.
-
__module__
= 'fsleyes.gl.textures.imagetexture'¶
-
-
class
fsleyes.gl.textures.imagetexture.
ImageTexture2D
(name, image, **kwargs)[source]¶ Bases:
fsleyes.gl.textures.imagetexture.ImageTextureBase
,fsleyes.gl.textures.texture2d.Texture2D
The
ImageTexture2D
class is the 2D analogue of theImageTexture
class, for managing a 2D texture which represents anImage
instance.-
__module__
= 'fsleyes.gl.textures.imagetexture'¶
-