fsleyes.gl.globject¶
This module provides the GLObject class, which is a superclass
for all FSLeyes OpenGL overlay types. The following classes are
defined in this module:
GLObject |
The GLObject class is a base class for all OpenGL objects displayed in FSLeyes. |
GLSimpleObject |
The GLSimpleObject class is a convenience superclass for simple rendering tasks (probably fixed-function) which are not associated with a specific overlay, and require no setup or initialisation/management of GL memory or state. |
See also the GLImageObject, which is the base class for all
GLObject sub-types that display Nifti overlays.
This module also provides a few functions, most importantly
createGLObject():
getGLObjectType |
This function returns an appropriate GLObject type for the given Display.overlayType value. |
createGLObject |
Create GLObject instance for the given overlay, as specified by the Display.overlayType property. |
-
fsleyes.gl.globject.getGLObjectType(overlayType)¶ This function returns an appropriate
GLObjecttype for the givenDisplay.overlayTypevalue.
-
fsleyes.gl.globject.createGLObject(overlay, overlayList, displayCtx, canvas, threedee=False)¶ Create
GLObjectinstance for the given overlay, as specified by theDisplay.overlayTypeproperty.Parameters: - overlay – An overlay object (e.g. a
Imageinstance). - overlayList – The
OverlayList - displayCtx – The
DisplayContextmanaging the scene. - canvas – The canvas which will be displaying this
GLObject. - threedee – If
True, theGLObjectwill be configured for 3D rendering. Otherwise it will be configured for 2D slice-based rendering.
- overlay – An overlay object (e.g. a
-
class
fsleyes.gl.globject.GLObject(overlay, overlayList, displayCtx, canvas, threedee)¶ Bases:
__main__.MockClassThe
GLObjectclass is a base class for all OpenGL objects displayed in FSLeyes.Instance attributes
The following attributes will always be available on
GLObjectinstances:name: A unique name for thisGLObjectinstance.overlay: The overlay to be displayed.display: TheDisplayinstance describing the- overlay display properties.
opts: TheDisplayOptsinstance describing the- overlay-type specific display properties.
displayCtx: TheDisplayContextmanaging the scene- that this
GLObjectis a part of.
canvas: The canvas which is displaying thisGLObject.- Could be a
SliceCanvas, aLightBoxCanvas, aScene3DCanvas, or some future not-yet-created canvas.
threedee: A boolean flag indicating whether thisGLObject- is configured for 2D or 3D rendering.
Usage
Once you have created a
GLObject:- Do not use the
GLObjectuntil itsready()method returnsTrue. - In order to render the
GLObjectto a canvas, call (in order) thepreDraw(),draw2D()(ordraw3D()), andpostDraw(), methods. Multple calls todraw2D()/draw3D()may occur between calls topreDraw()andpostDraw(). - Once you are finished with the
GLObject, call itsdestroy()method.
Note that a
GLObjectwhich has been created for 2D rendering is not expected be able to render in 3D, nor vice-versa.Update listeners
A
GLObjectinstance will notify registered listeners when its state changes and it needs to be re-drawn. Entities which are interested in changes to aGLObjectinstance may register as update listeners, via theNotifier.register()method. It is the resposibility of sub-classes ofGLObjectto call theNotifier.notify()method to facilitate this notification process.Sub-class resposibilities*
Sub-class implementations must do the following:
Call
__init__(). AGLObject.__init__sub-class method must have the following signature, and must pass all arguments through toGLObject.__init__:def __init__(self, overlay, displayCtx, canvas, threedee)
Call
notify()whenever its OpenGL representation changes.Override the following methods:
getDisplayBoundsThis method must calculate and return a bounding box, in the display coordinate system, which contains the entire GLObject.getDataResolutionThis method must calculate and return a sequence of three values, which defines a suitable pixel resolution, along the display coordinate system (x, y, z)axes, for rendering a 2D slice of thisGLObjectto screen.readyThis method must return TrueorFalseto indicate whether thisGLObjectis ready to be drawn.destroyThis method must be called when this GLObjectis no longer needed.destroyedThis method may be called to test whether a call has been made to destroy().preDrawThis method is called at the start of a draw routine. draw2DThis method is called on GLObjectinstances which are configured for 2D rendering.draw3DThis method is called on GLObjectinstances which are configured for 3D rendering.postDrawThis method is called after the draw2D()/draw3D()methods have been called one or more times.
Alternately, a sub-class could derive from one of the following classes, instead of deriving directly from the
GLObjectclass:GLSimpleObjectThe GLSimpleObjectclass is a convenience superclass for simple rendering tasks (probably fixed-function) which are not associated with a specific overlay, and require no setup or initialisation/management of GL memory or state.-
__init__(overlay, overlayList, displayCtx, canvas, threedee)¶ Create a
GLObject. The constructor adds one attribute to this instance,name, which is simply a unique name for this instance.Subclass implementations must call this method, and should also perform any necessary OpenGL initialisation, such as creating textures.
Parameters: - overlay – The overlay
- overlayList – The
OverlayList - displayCtx – The
DisplayContextmanaging the scene - canvas – The canvas that is displaying this
GLObject. - threedee – Whether this
GLObjectis to be used for 2D or 3D rendering.
-
__del__()¶ Prints a log message.
-
name¶ A unique name for this
GLObject.
-
overlay¶ The overlay being drawn by this
GLObject.
-
canvas¶ The canvas which is drawing this
GLObject.
-
opts¶ The
DisplayOptsinstance containing overlay (type-specific) display properties.
-
overlayList¶ The
OverlayList.
-
displayCtx¶ The
DisplayContextdsecribing thef scene that thisGLObjectis a part of.
-
threedee¶ Property which is
Trueif thisGLObjectwas configured for 3D rendering, orFalseif it was configured for 2D slice rendering.
-
ready()¶ This method must return
TrueorFalseto indicate whether thisGLObjectis ready to be drawn. The method should, for example, make sure that allImageTextureobjects are ready to be used.
-
getDisplayBounds()¶ This method must calculate and return a bounding box, in the display coordinate system, which contains the entire
GLObject. The bounds must be returned as a tuple with the following structure:((xlo, ylo, zlo), (xhi, yhi, zhi))
This method must be implemented by sub-classes.
-
getBoundsLengths()¶ Convenience method which returns a tuple containing the
(x, y, z)lengths of the bounding box which contains theGLObject.
-
getDataResolution(xax, yax)¶ This method must calculate and return a sequence of three values, which defines a suitable pixel resolution, along the display coordinate system
(x, y, z)axes, for rendering a 2D slice of thisGLObjectto screen.This method should be implemented by sub-classes. If not implemented, a default resolution is used. The returned resolution might be used to render this
GLObject, but typically only in a low performance environment where off-screen rendering to aGLObjectRenderTextureis used - see theSliceCanvasdocumentation for more details.Parameters: - xax – Axis to be used as the horizontal screen axis.
- yax – Axis to be used as the vertical screen axis.
-
destroy()¶ This method must be called when this
GLObjectis no longer needed.It should perform any necessary cleaning up, such as deleting texture objects.
Note
Sub-classes which override this method must call this implementation.
-
destroyed()¶ This method may be called to test whether a call has been made to
destroy().It should return
Trueif thisGLObjecthas been destroyed,Falseotherwise.
-
preDraw(xform=None, bbox=None)¶ This method is called at the start of a draw routine.
It should perform any initialisation which is required before one or more calls to the
draw2D()/draw3D()methods are made, such as binding and configuring textures.See
draw2D()for details on thexformandbboxarguments. They are only guaranteed to be passed to thepreDrawmethod in scenarios where only a single call todraw2Dor``draw3D`` is made between calls topreDrawandpostDraw.
-
draw2D(zpos, axes, xform=None, bbox=None)¶ This method is called on
GLObjectinstances which are configured for 2D rendering. It should draw a view of thisGLObject- a 2D slice at the given Z location, which specifies the position along the screen depth axis.Parameters: - zpos – Position along Z axis to draw.
- axes – Tuple containing the
(x, y, z)axes in the display coordinate system Thexandyaxes correspond to the horizontal and vertical display axes respectively, and thezto the depth. - xform – If provided, it must be applied to the model view transformation before drawing.
- bbox – If provided, defines the bounding box, in the display coordinate system, which is to be displayed. Can be used as a performance hint (i.e. to limit the number of things that are rendered).
-
draw3D(xform=None, bbox=None)¶ This method is called on
GLObjectinstances which are configured for 3D rendering. It should draw a 3D view of thisGLObject.Parameters: - xform – If provided, it must be applied to the model view transformation before drawing.
- bbox – If provided, defines the bounding box, in the display coordinate system, which is to be displayed. Can be used as a performance hint (i.e. to limit the number of things that are rendered).
-
drawAll(axes, zposes, xforms)¶ This is a convenience method for 2D lightboxD canvases, where multple 2D slices at different depths are drawn alongside each other.
This method should do the same as multiple calls to the
draw2D()method, one for each of the Z positions and transformation matrices contained in thezposesandxformsarrays (axesis fixed).In some circumstances (hint: the
LightBoxCanvas), better performance may be achieved in combining multiple renders, rather than doing it with separate calls todraw().The default implementation does exactly this, so this method need only be overridden for subclasses which are able to get better performance by combining the draws.
-
postDraw(xform=None, bbox=None)¶ This method is called after the
draw2D()/draw3D()methods have been called one or more times.It should perform any necessary cleaning up, such as unbinding textures.
See the
draw2D()method for details on thexformandbboxarguments.
-
__module__= 'fsleyes.gl.globject'¶
-
class
fsleyes.gl.globject.GLSimpleObject(threedee)¶ Bases:
fsleyes.gl.globject.GLObjectThe
GLSimpleObjectclass is a convenience superclass for simple rendering tasks (probably fixed-function) which are not associated with a specific overlay, and require no setup or initialisation/management of GL memory or state. It is used by theannotationsmodule.All subclasses need to do is implement the
GLObject.draw2D()andGLObject.draw3D()methods. Theannotationsmodule uses theGLSimpleObjectclass.Subclasses should not assume that any of the other methods will ever be called.
Note
The
GLObject.overlay,GLObject.display,GLObject.opts,GLObject.canvas,GLObject.overlayListandGLObject.displayCtxproperties of aGLSimpleObjectare all set toNone.-
__init__(threedee)¶ Create a
GLSimpleObject.
-
ready()¶ Overrides
GLObject.ready(). ReturnsTrue.
-
destroy()¶ Overrides
GLObject.destroy(). Does nothing.
-
destroyed()¶ Overrides
GLObject.destroy(). ReturnsTrueifdestroy()hs been called,Falseotherwise.
-
__module__= 'fsleyes.gl.globject'¶
-
preDraw(*args, **kwargs)¶ Overrides
GLObject.preDraw(). Does nothing.
-
postDraw(*args, **kwargs)¶ Overrides
GLObject.postDraw(). Does nothing.
-