fsleyes.gl.scene3dcanvas

This module provides the Scene3DCanvas class, which is used by FSLeyes for its 3D view.

class fsleyes.gl.scene3dcanvas.Scene3DCanvas(overlayList, displayCtx)[source]

Bases: object

The Scene3DCanvas is an OpenGL canvas used to draw overlays in a 3D view. Currently only volume and mesh overlay types are supported.

__init__(overlayList, displayCtx)[source]
destroy()[source]

Must be called when this Scene3DCanvas is no longer used.

property destroyed

Returns True if destroy() has been called.

property opts

Returns a reference to the Scene3DCanvasOpts instance.

property lightPos

Takes the values of Scene3DOpts.lightPos and Scene3DOpts.lightDistance, and converts it to a position in the display coordinate system. The Scene3DOpts.lightPos property contains rotations about the centre of the display bounding box, and the Scene3DOpts.lightDistance property specifies the distance of the light from the bounding box centre.

property resetLightPos

By default, the lightPos is updated whenever the DisplayContext.bounds change. This flag can be used to disable this behaviour.

defaultLightPos()[source]

Resets the lightPos property to a sensible value.

property viewMatrix

Returns the view matrix for the current scene - this is an affine matrix which encodes the current Scene3DCanvasOpts.offset, Scene3DCanvasOpts.zoom, Scene3DCanvasOpts.rotation and camera settings.

See __genViewMatrix().

property viewScale

Returns an affine matrix which encodes the current Scene3DCanvasOpts.zoom setting.

property viewOffset

Returns an affine matrix which encodes the current Scene3DCanvasOpts.offset setting.

property viewRotation

Returns an affine matrix which encodes the current Scene3DCanvasOpts.rotation setting.

property viewCamera

Returns an affine matrix which encodes the current camera. transformation. The initial camera orientation in the view shown by a Scene3DCanvas is located on the positive Y axis, is oriented towards the positive Z axis, and is pointing towards the centre of the DisplayContext.displayBounds.

property projectionMatrix

Returns the projection matrix. This is an affine matrix which converts from normalised device coordinates (NDCs, coordinates between -1 and +1) into viewport coordinates. The initial viewport for a Scene3DCanvas is configured by the routines.ortho() function.

See __setViewport().

property invViewProjectionMatrix

Returns the inverse of the model-view-projection matrix, the equivalent of:

invert(projectionMatrix * viewMatrix)

property viewport

Returns a list of three (min, max) tuples which specify the viewport limits of the currently displayed scene.

canvasToWorld(xpos, ypos, near=True)[source]

Transform the given x/y canvas coordinates into the display coordinate system. The calculated coordinates will be located on the near clipping plane.

Parameters

near – If True (the default), the returned coordinate will be located on the near clipping plane. Otherwise, the coordinate will be located on the far clipping plane.

getGLObject(overlay)[source]

Returns the GLObject associated with the given overlay, or None if there is not one.

getGLObjects()[source]

Returns two lists:

  • A list of overlays to be drawn

  • A list of corresponding GLObject instances

The lists are in the order that they should be drawn.

This method also creates GLObject instances for any overlays in the OverlayList that do not have one.

_initGL()[source]

Called when the canvas is ready to be drawn on.

__overlayListChanged(*a)

Called when the OverlayList changes. Destroys/creates GLObject instances as necessary.

__refreshLegendLabels(*a, refresh=True)

Called when the legend labels (anatomical orientations) need to be refreshed - when the selected overlay changes, or when the Scene3DCanvasOpts.legendColour is changed.

__highDpiChanged(*a)

Called when the Scene3DCanvasOpts.highDpi property changes. Calls the GLCanvasTarget.EnableHighDPI() method.

__displayBoundsChanged(*a)

Called when the DisplayContext.bounds change. Resets the Scene3DCanvasOpts.lightPos property.

__registerOverlay(overlay)

Called when a new overlay has been added to the overlay list. Creates a GLObject for it, and registers property listeners.

__deregisterOverlay(overlay)

Called when an overlay has been removed from the overlay list. Dstroys the GLObject for it, and de-registers property listeners.

__genGLObject(overlay)

Create a GLObject for the given overlay, if one doesn’t already exist.

__overlayTypeChanged(value, valid, display, name)

Called when the Display.overlayType of an overlay has changed. Re-generates a GLObject for it.

__genViewMatrix(w, h)

Generate and return a transformation matrix to be used as the model-view matrix. This includes applying the current zoom, rotation and offset settings, and configuring the camera. This method is called by __setViewport().

Parameters
  • w – Canvas width in pixels

  • h – Canvas height in pixels

__setViewport()

Called by _draw(). Configures the viewport and calculates the model-view trasformation matrix.

Returns

True if the viewport was successfully configured, False otherwise.

_draw()[source]

Draws the scene to the canvas.

__drawCursor()

Draws three lines at the current DisplayContext.location.

__drawLegend()

Draws a legend in the bottom left corner of the screen, showing anatomical orientation.

__drawLight()

Draws a representation of the light source.

__drawBoundingBox()

Draws a bounding box around all overlays. Used for debugging.

__annotations__ = {}
__dict__ = mappingproxy({'__module__': 'fsleyes.gl.scene3dcanvas', '__doc__': 'The ``Scene3DCanvas`` is an OpenGL canvas used to draw overlays in a 3D\n    view. Currently only ``volume`` and ``mesh`` overlay types are supported.\n    ', '__init__': <function Scene3DCanvas.__init__>, 'destroy': <function Scene3DCanvas.destroy>, 'destroyed': <property object>, 'opts': <property object>, 'lightPos': <property object>, 'resetLightPos': <property object>, 'defaultLightPos': <function Scene3DCanvas.defaultLightPos>, 'viewMatrix': <property object>, 'viewScale': <property object>, 'viewOffset': <property object>, 'viewRotation': <property object>, 'viewCamera': <property object>, 'projectionMatrix': <property object>, 'invViewProjectionMatrix': <property object>, 'viewport': <property object>, 'canvasToWorld': <function Scene3DCanvas.canvasToWorld>, 'getGLObject': <function Scene3DCanvas.getGLObject>, 'getGLObjects': <function Scene3DCanvas.getGLObjects>, '_initGL': <function Scene3DCanvas._initGL>, '_Scene3DCanvas__overlayListChanged': <function Scene3DCanvas.__overlayListChanged>, '_Scene3DCanvas__refreshLegendLabels': <function Scene3DCanvas.__refreshLegendLabels>, '_Scene3DCanvas__highDpiChanged': <function Scene3DCanvas.__highDpiChanged>, '_Scene3DCanvas__displayBoundsChanged': <function Scene3DCanvas.__displayBoundsChanged>, '_Scene3DCanvas__registerOverlay': <function Scene3DCanvas.__registerOverlay>, '_Scene3DCanvas__deregisterOverlay': <function Scene3DCanvas.__deregisterOverlay>, '_Scene3DCanvas__genGLObject': <function Scene3DCanvas.__genGLObject>, '_Scene3DCanvas__overlayTypeChanged': <function Scene3DCanvas.__overlayTypeChanged>, '_Scene3DCanvas__genViewMatrix': <function Scene3DCanvas.__genViewMatrix>, '_Scene3DCanvas__setViewport': <function Scene3DCanvas.__setViewport>, '_draw': <function Scene3DCanvas._draw>, '_Scene3DCanvas__drawCursor': <function Scene3DCanvas.__drawCursor>, '_Scene3DCanvas__drawLegend': <function Scene3DCanvas.__drawLegend>, '_Scene3DCanvas__drawLight': <function Scene3DCanvas.__drawLight>, '_Scene3DCanvas__drawBoundingBox': <function Scene3DCanvas.__drawBoundingBox>, '__dict__': <attribute '__dict__' of 'Scene3DCanvas' objects>, '__weakref__': <attribute '__weakref__' of 'Scene3DCanvas' objects>, '__annotations__': {}})
__module__ = 'fsleyes.gl.scene3dcanvas'
__weakref__

list of weak references to the object (if defined)