fsleyes.gl.textures.texture2d
¶
This module provides the Texture2D
and DepthTexture
classes.
-
class
fsleyes.gl.textures.texture2d.
DepthTexture
(name)[source]¶ Bases:
fsleyes.gl.textures.texture.Texture
The
DepthTexture
class is a 2DGL_DEPTH_COMPONENT24
texture which is used by theRenderTexture
class.A
DepthTexture
is configured by setting itsTexture.shape()
property to the desired width/height.-
property
dtype
¶ Overrides
Texture.dtype()
.
-
property
textureType
¶ Overrides
Texture.textureType()
.
-
property
baseFormat
¶ Overrides
Texture.baseFormat()
.
-
property
internalFormat
¶ Overrides
Texture.internalFormat()
.
-
property
data
¶ Returns the data that has been passed to the
set()
method.
-
doRefresh
()[source]¶ Refreshes this
DepthTexture
based on the currentTexture.shape()
.
-
__module__
= 'fsleyes.gl.textures.texture2d'¶
-
property
-
class
fsleyes.gl.textures.texture2d.
Texture2D
(name, **kwargs)[source]¶ Bases:
fsleyes.gl.textures.texture.Texture
The
Texture2D
class represents a 2D texture. ATexture2D
instance can be used in one of two ways:Setting the texture data via the
Texture.data()
method, and then drawing it to a scene viadraw()
ordrawOnBounds()
.Setting the texture size via
Texture.shape()
, and then drawing to it by some other means (see e.g. theRenderTexture
class, a sub-class ofTexture2D
).
-
__init__
(name, **kwargs)[source]¶ Create a
Texture2D
instance.- Parameters
name – Unique name for this
Texture2D
.
-
doRefresh
()[source]¶ Overrides
Texture.doRefresh()
. Configures thisTexture2D
. This includes setting up interpolation, and setting the texture size and data.
-
shapeData
(data, oldShape=None)[source]¶ Overrides
Texture.shapeData()
.This method is used by
Texture2D
sub-classes which are used to store 3D image data (e.g. theImageTexture2D
class). It shapes the data, ensuring that it is compatible with a 2D texture.- Parameters
data –
numpy
array containing the dataoldShape – Original data shape; if not provided, is taken from
data
.
-
texCoordXform
(origShape)[source]¶ Overrides
Texture.texCoordXform()
.Returns an affine matrix which encodes a rotation that maps the two major axes of the image voxel coordinate system to the first two axes of the texture coordinate system.
This method is used by sub-classes which are being used to store 3D image data, e.g. the
ImageTexture2D
andSelectionTexture2D
classes.If this texture does not have any data yet, this method will return
None
.
-
doPatch
(data, offset)[source]¶ Overrides
Texture.doPatch()
. Updates part of the texture data.
-
__prepareCoords
(vertices, xform=None)¶ Called by
draw()
. Prepares vertices, texture coordinates and indices for drawing the texture.If
vertices is None
, it is assumed that the caller has already assigned vertices and texture coordinates, either via a shader, or via vertex/texture coordinate pointers. In this case,- Returns
A tuple containing the vertices, texture coordinates, and indices, or
(None, None, indices)
ifvertices is None
-
draw
(vertices=None, xform=None, textureUnit=None)[source]¶ Draw the contents of this
Texture2D
to a region specified by the given vertices. The texture is bound to texture unit 0.- Parameters
vertices – A
numpy
array of shape6 * 3
specifying the region, made up of two triangles, to which thisTexture2D
should be drawn. IfNone
, it is assumed that the vertices and texture coordinates have already been configured (e.g. via a shader program).xform – A transformation to be applied to the vertices. Ignored if
vertices is None
.textureUnit – Texture unit to bind to. Defaults to
gl.GL_TEXTURE0
.
-
drawOnBounds
(zpos, xmin, xmax, ymin, ymax, xax, yax, *args, **kwargs)[source]¶ Draws the contents of this
Texture2D
to a rectangle. This is a convenience method which creates a set of vertices, and passes them to thedraw()
method.- Parameters
zpos – Position along the Z axis, in the display coordinate system.
xmin – Minimum X axis coordinate.
xmax – Maximum X axis coordinate.
ymin – Minimum Y axis coordinate.
ymax – Maximum Y axis coordinate.
xax – Display space axis which maps to the horizontal screen axis.
yax – Display space axis which maps to the vertical screen axis.
All other arguments are passed to the
draw()
method.
-
classmethod
generateVertices
(zpos, xmin, xmax, ymin, ymax, xax, yax, xform=None)[source]¶ Generates a set of vertices suitable for passing to the
Texture2D.draw()
method, for drawing aTexture2D
to a 2D canvas.- Parameters
zpos – Position along the Z axis, in the display coordinate system.
xmin – Minimum X axis coordinate.
xmax – Maximum X axis coordinate.
ymin – Minimum Y axis coordinate.
ymax – Maximum Y axis coordinate.
xax – Display space axis which maps to the horizontal screen axis.
yax – Display space axis which maps to the vertical screen axis.
xform – Transformation matrix to appply to vertices.
-
classmethod
generateTextureCoords
()[source]¶ Generates a set of texture coordinates for drawing a
Texture2D
. This function is used by theTexture2D.draw()
method.
-
__module__
= 'fsleyes.gl.textures.texture2d'¶