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

__init__(overlayList, displayCtx)[source]

Initialize self. See help(type(self)) for accurate signature.

destroy()[source]
property destroyed
property opts

Returns a reference to the Scene3DCanvasOpts instance.

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.

_draw()[source]

Draws the scene to the canvas.

_Scene3DCanvas__deregisterOverlay(overlay)
_Scene3DCanvas__displayBoundsChanged(*a)

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

_Scene3DCanvas__drawBoundingBox()
_Scene3DCanvas__drawCursor()

Draws three lines at the current DisplayContext.location.

_Scene3DCanvas__drawLegend()

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

_Scene3DCanvas__drawLight()
_Scene3DCanvas__genGLObject(overlay)
_Scene3DCanvas__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

_Scene3DCanvas__highDpiChanged(*a)

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

_Scene3DCanvas__overlayListChanged(*a)

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

_Scene3DCanvas__overlayTypeChanged(value, valid, display, name)
_Scene3DCanvas__registerOverlay(overlay)
_Scene3DCanvas__setViewport()

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

Returns

True if the viewport was successfully configured, False otherwise.

__dict__ = mappingproxy({'__module__': 'fsleyes.gl.scene3dcanvas', '__init__': <function Scene3DCanvas.__init__>, 'destroy': <function Scene3DCanvas.destroy>, 'destroyed': <property object>, 'opts': <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__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>, '__doc__': None})
__module__ = 'fsleyes.gl.scene3dcanvas'
__weakref__

list of weak references to the object (if defined)