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:
objectThe
Scene3DCanvasis an OpenGL canvas used to draw overlays in a 3D view. Currently onlyvolumeandmeshoverlay types are supported.- property opts
Returns a reference to the
Scene3DCanvasOptsinstance.
- property lightPos
Takes the values of
Scene3DOpts.lightPosandScene3DOpts.lightDistance, and converts it to a position in the display coordinate system. TheScene3DOpts.lightPosproperty contains rotations about the centre of the display bounding box, and theScene3DOpts.lightDistanceproperty specifies the distance of the light from the bounding box centre.
- property resetLightPos
By default, the
lightPosis updated whenever theDisplayContext.boundschange. This flag can be used to disable this behaviour.
- property viewMatrix
Returns the view matrix for the current scene - this is an affine matrix which encodes the current
Scene3DCanvasOpts.offset,Scene3DCanvasOpts.zoom,Scene3DCanvasOpts.rotationand camera settings.See
__genViewMatrix().
- property viewScale
Returns an affine matrix which encodes the current
Scene3DCanvasOpts.zoomsetting.
- property viewOffset
Returns an affine matrix which encodes the current
Scene3DCanvasOpts.offsetsetting.
- property viewRotation
Returns an affine matrix which encodes the current
Scene3DCanvasOpts.rotationsetting.
- property viewCamera
Returns an affine matrix which encodes the current camera. transformation. The initial camera orientation in the view shown by a
Scene3DCanvasis located on the positive Y axis, is oriented towards the positive Z axis, and is pointing towards the centre of theDisplayContext.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
Scene3DCanvasis configured by theroutines.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
GLObjectassociated with the given overlay, orNoneif there is not one.
- getGLObjects()[source]
Returns two lists:
A list of overlays to be drawn
A list of corresponding
GLObjectinstances
The lists are in the order that they should be drawn.
This method also creates
GLObjectinstances for any overlays in theOverlayListthat do not have one.
- __overlayListChanged(*a)
Called when the
OverlayListchanges. Destroys/createsGLObjectinstances 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.legendColouris changed.
- __highDpiChanged(*a)
Called when the
Scene3DCanvasOpts.highDpiproperty changes. Calls theGLCanvasTarget.EnableHighDPI()method.
- __displayBoundsChanged(*a)
Called when the
DisplayContext.boundschange. Resets theScene3DCanvasOpts.lightPosproperty.
- __registerOverlay(overlay)
Called when a new overlay has been added to the overlay list. Creates a
GLObjectfor it, and registers property listeners.
- __deregisterOverlay(overlay)
Called when an overlay has been removed from the overlay list. Dstroys the
GLObjectfor it, and de-registers property listeners.
- __genGLObject(overlay)
Create a
GLObjectfor the given overlay, if one doesn’t already exist.
- __overlayTypeChanged(value, valid, display, name)
Called when the
Display.overlayTypeof an overlay has changed. Re-generates aGLObjectfor it.
- __genViewMatrix(w, h)
Generate and return a transformation matrix to be used as the model-view matrix. This includes applying the current
zoom,rotationandoffsetsettings, 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
Trueif the viewport was successfully configured,Falseotherwise.
- __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)