fsleyes.gl.gllinevector

This module provides the GLLineVector class, for displaying 3D vector Image overlays in line mode.

The GLLineVertices class is also defined in this module, and is used in certain rendering situations - specifically, when running in OpenGL 1.4. See the gl14.gllinevector_funcs and gl21.gllinevector_funcs modules for more details.

class fsleyes.gl.gllinevector.GLLineVector(image, overlayList, displayCtx, canvas, threedee)

Bases: fsleyes.gl.glvector.GLVector

The GLLineVector class encapsulates the logic required to render an Image instance of shape x*y*z*3, or type NIFTI_TYPE_RGB24, as a vector image, where the vector at each voxel is drawn as a line, and coloured in the same way that voxels in the GLRGBVector are coloured. The GLLineVector class assumes that the Display instance associated with the Image overlay holds a reference to a LineVectorOpts instance, which contains GLLineVector-specific display settings. The GLLineVector class is a sub-class of the GLVector class, and uses the functionality provided by GLVector.

In a similar manner to the GLRGBVector, the GLLineVector uses two OpenGL version-specific modules, the gl14.gllinevector_funcs and gl21.gllinevector_funcs modules. It is assumed that these modules define the same functions that are defined by the GLRGBVector version specific modules.

A GLLineVector instance is rendered in different ways depending upon the rendering environment (GL 1.4 vs GL 2.1), so most of the rendering functionality is implemented in the version-specific modules mentioned above.

__init__(image, overlayList, displayCtx, canvas, threedee)

Create a GLLineVector instance.

Parameters
  • image – An Image or DTIFitTensor instance.

  • overlayList – The OverlayList

  • displayCtx – The DisplayContext managing the scene.

  • canvas – The canvas doing the drawing.

  • threedee – 2D or 3D rendering.

destroy()

Must be called when this GLLineVector is no longer needed. Removes some property listeners from the LineVectorOpts instance, calls the OpenGL version-specific destroy function, and calls the GLVector.destroy() method.

getDataResolution(xax, yax)

Overrides GLImageObject.getDataResolution(). Returns a pixel resolution suitable for rendering this GLLineVector.

compileShaders()

Overrides GLVector.compileShaders(). Calls the OpenGL version-specific compileShaders function.

updateShaderState()

Overrides GLVector.updateShaderState(). Calls the OpenGL version-specific updateShaderState function.

preDraw(xform=None, bbox=None)

Overrides GLVector.preDraw(). Calls the base class implementation, and then calls the OpenGL version-specific preDraw function.

draw2D(*args, **kwargs)

Overrides GLObject.draw2D(). Calls the OpenGL version-specific draw2D function.

draw3D(*args, **kwargs)

Overrides GLObject.draw3D(). Calls the OpenGL version-specific draw3D function.

drawAll(*args, **kwargs)

Overrides GLObject.drawAll(). Calls the OpenGL version-specific drawAll function.

postDraw(xform=None, bbox=None)

Overrides GLVector.postDraw(). Calls the base class implementation, and then calls the OpenGL version-specific postDraw function.

__module__ = 'fsleyes.gl.gllinevector'
class fsleyes.gl.gllinevector.GLLineVertices(glvec)

Bases: object

The GLLineVertices class is used in some cases when rendering a GLLineVector. It contains logic to generate vertices for every vector in the vector Image that is being displayed by a GLLineVector instance.

After a GLLineVertices instance has been created, the refresh() method can be used to generate line vector vertices and voxel coordinates for every voxel in the Image. These vertices and coordinates are stored as attributes of the GLLineVertices instance.

Later, when the line vectors from a 2D slice of the image need to be displayed, the getVertices2D() method can be used to extract the vertices and coordinates from the slice.

A GLLineVertices instance is not associated with a specific GLLineVector instance. This is so that a single GLLineVertices instance can be shared between more than one GLLineVector, avoiding the need to store multiple copies of the vertices and voxel coordinates. This means that a GLLineVector instance needs to be passed to most of the methods of a GLLineVertices instance.

__init__(glvec)

Create a GLLineVertices. Vertices are calculated for the given GLLineVector instance.

Parameters

glvec – A GLLineVector which is using this GLLineVertices instance.

destroy()

Should be called when this GLLineVertices instance is no longer needed. Clears references to cached vertices/coordinates.

__hash__()

Returns a hash of this GLLineVertices instance. The hash value is calculated and cached on every call to refresh(), using the calculateHash() method. This method returns that cached value.

calculateHash(glvec)

Calculates and returns a hash value that can be used to determine whether the vertices of this this GLLineVertices instance need to be recalculated. The hash value is based on some properties of the LineVectorOpts instance, associated with the given GLLineVector.

For a GLLineVertices instance called verts, if the following test:

hash(verts) != verts.calculateHash(glvec)

evaluates to False, the vertices need to be refreshed (via a call to refresh()).

refresh(glvec)

(Re-)calculates the vertices of this GLLineVertices instance.

For each voxel, in the Image overlay being displayed by the GLLineVector associated with this GLLineVertices instance, two vertices are generated, which define a line that represents the vector at the voxel.

The vertices are stored as a \(X\times Y\times Z\times 2\times 3\) numpy array, as an attribute of this instance, called vertices.

getVertices2D(glvec, zpos, axes, bbox=None)

Extracts and returns a slice of line vertices, and the associated voxel coordinates, which are in a plane located at the given Z position (in display coordinates).

This method assumes that the refresh() method has already been called.

__dict__ = mappingproxy({'__module__': 'fsleyes.gl.gllinevector', '__doc__': 'The ``GLLineVertices`` class is used in some cases when rendering a\n :class:`GLLineVector`. It contains logic to generate vertices for every\n vector in the vector :class:`.Image` that is being displayed by a\n ``GLLineVector`` instance.\n\n\n After a ``GLLineVertices`` instance has been created, the :meth:`refresh`\n method can be used to generate line vector vertices and voxel\n coordinates for every voxel in the :class:`Image`. These vertices and\n coordinates are stored as attributes of the ``GLLineVertices`` instance.\n\n\n Later, when the line vectors from a 2D slice of the image need to be\n displayed, the :meth:`getVertices2D` method can be used to extract the\n vertices and coordinates from the slice.\n\n\n A ``GLLineVertices`` instance is not associated with a specific\n ``GLLineVector`` instance. This is so that a single ``GLLineVertices``\n instance can be shared between more than one ``GLLineVector``, avoiding\n the need to store multiple copies of the vertices and voxel\n coordinates. This means that a ``GLLineVector`` instance needs to be\n passed to most of the methods of a ``GLLineVertices`` instance.\n ', '__init__': <function GLLineVertices.__init__>, 'destroy': <function GLLineVertices.destroy>, '__hash__': <function GLLineVertices.__hash__>, 'calculateHash': <function GLLineVertices.calculateHash>, 'refresh': <function GLLineVertices.refresh>, 'getVertices2D': <function GLLineVertices.getVertices2D>, '__dict__': <attribute '__dict__' of 'GLLineVertices' objects>, '__weakref__': <attribute '__weakref__' of 'GLLineVertices' objects>})
__module__ = 'fsleyes.gl.gllinevector'
__weakref__

list of weak references to the object (if defined)