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 2D GL_DEPTH_COMPONENT24 texture which is used by the RenderTexture class.

A DepthTexture is configured by setting its Texture.shape() property to the desired width/height.

__init__(name)[source]

Create a DepthTexture

Parameters

name – Unique name for this texture

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 current Texture.shape().

__module__ = 'fsleyes.gl.textures.texture2d'
class fsleyes.gl.textures.texture2d.Texture2D(name, **kwargs)[source]

Bases: fsleyes.gl.textures.texture.Texture

The Texture2D class represents a 2D texture. A Texture2D instance can be used in one of two ways:

__init__(name, **kwargs)[source]

Create a Texture2D instance.

Parameters

name – Unique name for this Texture2D.

doRefresh()[source]

Overrides Texture.doRefresh(). Configures this Texture2D. 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. the ImageTexture2D class). It shapes the data, ensuring that it is compatible with a 2D texture.

Parameters
  • datanumpy array containing the data

  • oldShape – 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 and SelectionTexture2D 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) if vertices 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 shape 6 * 3 specifying the region, made up of two triangles, to which this Texture2D should be drawn. If None, 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 the draw() 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 a Texture2D 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 the Texture2D.draw() method.

__module__ = 'fsleyes.gl.textures.texture2d'
getBitmap()[source]

Returns the data stored in this Texture2D as a numpy.uint8 array of shape (height, width, 4).