fsleyes.gl.lightboxcanvas
¶
This module provides the LightBoxCanvas
class, which is a
SliceCanvas
that displays multiple 2D slices along a single axis
from a collection of 3D overlays.
- class fsleyes.gl.lightboxcanvas.LightBoxCanvas(overlayList, displayCtx, zax=0)[source]¶
Bases:
fsleyes.gl.slicecanvas.SliceCanvas
The
LightBoxCanvas
represents an OpenGL canvas which displays multiple slices from a collection of 3D overlays. The slices are laid out on the same canvas along rows and columns, with the slice at the minimum Z position translated to the top left of the canvas, and the slice with the maximum Z value translated to the bottom right.Note
The
LightBoxCanvas
class is not intended to be instantiated directly - use one of these subclasses, depending on your use-case:OSMesaLightBoxCanvas
for static off-screen rendering of a scene using OSMesa.WXGLLightBoxCanvas
for interactive rendering on awx.glcanvas.GLCanvas
canvas.
The
LightBoxCanvas
class derives from theSliceCanvas
class, and is tightly coupled to theSliceCanvas
implementation. Various settings, and the current scene displayed on aLightBoxCanvas
instance, can be changed through the properties of theLightBoxCanvasOpts
instance, available via theopts
attribute.Performance of a
LightBoxCanvas
instance may be controlled through theSliceCanvasOpts.renderMode
property, in the same way as for theSliceCanvas
. However, theLightBoxCanvas
handles theoffscreen
render mode differently to theSliceCanvas. Where the ``SliceCanvas
uses a separateRenderTexture
for every overlay in theOverlayList
, theLightBoxCanvas
uses a singleRenderTexture
to render all overlays off-screen.The
LightBoxCanvas
class defines the following convenience methods (in addition to those defined in theSliceCanvas
class):Overrides :meth:.SliceCanvas.canvasToWorld`.
Given an x/y/z location in the display coordinate system, converts it into an x/y position, in the coordinate system of this
LightBoxCanvas
.Returns the total number of rows that may be displayed.
Calculates and returns a Z-axis slice spacing value suitable for the given overlay.
- __init__(overlayList, displayCtx, zax=0)[source]¶
Create a
LightBoxCanvas
object.- Parameters
overlayList – An
OverlayList
object which contains a list of overlays to be displayed.displayCtx – A
DisplayContext
object which defines how that overlay list is to be displayed.zax – Display coordinate system axis to be used as the ‘depth’ axis. Can be changed via the
SliceCanvas.zax
property.
- destroy()[source]¶
Overrides
SliceCanvas.destroy()
. Must be called when thisLightBoxCanvas
is no longer needed.Removes some property listeners, makes sure that the off screen
RenderTexture
(if one exists) is destroyed, and then calls theSliceCanvas.destroy()
method.
- worldToCanvas(pos)[source]¶
Given an x/y/z location in the display coordinate system, converts it into an x/y position, in the coordinate system of this
LightBoxCanvas
.
- canvasToWorld(xpos, ypos)[source]¶
Overrides :meth:.SliceCanvas.canvasToWorld`.
Given pixel x/y coordinates on this canvas, translates them into the corresponding display space x/y/z coordinates. Returns a 3-tuple containing the (x, y, z) display system coordinates. If the given canvas position is out of the
SliceCanvas.displayBounds
,None
is returned.
- calcSliceSpacing(overlay)[source]¶
Calculates and returns a Z-axis slice spacing value suitable for the given overlay.
- _zAxisChanged(*a)[source]¶
Overrides
SliceCanvas._zAxisChanged()
. Calls that method, and then resets thesliceSpacing
andzrange
properties to sensible values.
- _topRowChanged(*a)[source]¶
Called when the
topRow
property changes. Adjusts display range and refreshes the canvas.
- _slicePropsChanged(*a)[source]¶
Called when any of the slice properties change. Regenerates slice locations and display bounds, and refreshes the canvas.
- _renderModeChange(*a)[source]¶
Overrides
SliceCanvas._renderModeChange()
. Makes sure that any off-screenRenderTexture
is destroyed, and calls theSliceCanvas._renderModeChange()
method.
- _updateRenderTextures()[source]¶
Overrides
SliceCanvas._updateRenderTextures()
. Destroys/createsRenderTexture
andRenderTextureStack
instances as needed.
- _calcNumSlices(*a)[source]¶
Calculates the total number of slices to be displayed and the total number of rows.
- _zPosChanged(*a)[source]¶
Called when the
SliceCanvas.pos
z
value changes.Makes sure that the corresponding slice is visible.
- _overlayListChanged(*a)[source]¶
Overrides
SliceCanvas._overlayListChanged()
.Regenerates slice locations for all overlays, and calls the
SliceCanvas._overlayListChanged()
method.
- _updateZAxisProperties()[source]¶
Called by the
_overlayListChanged()
and_overlayBoundsChanged()
methods.Updates the constraints (minimum/maximum values) of the
sliceSpacing
andzrange
properties.
- _overlayBoundsChanged(*a)[source]¶
Overrides
SliceCanvas._overlayBoundsChanged()
.Called when the
DisplayContext.bounds
change. Updates thezrange
min/max values.
- _updateDisplayBounds(*args, **kwargs)[source]¶
Overrides
SliceCanvas._updateDisplayBounds()
.Called on canvas resizes, display bound changes and lightbox slice property changes. Calculates the required bounding box that is to be displayed, in display coordinates.
- _genSliceLocations()[source]¶
Called when any of the slice display properties change.
For every overlay in the overlay list, generates a list of transformation matrices, and a list of slice indices. The latter specifies the slice indices from the overlay to be displayed, and the former specifies the transformation matrix to be used to position the slice on the canvas.
- _calculateSliceTransform(overlay, sliceno)[source]¶
Calculates a transformation matrix for the given slice number in the given overlay.
Each slice is displayed on the same canvas, but is translated to a specific row/column. So translation matrix is created, to position the slice in the correct location on the canvas.
- __prepareSliceTransforms(globj, xforms)¶
Applies the
SliceCanvas.invertX
andSliceCanvas.invertY
properties to the given transformation matrices, if necessary. Returns the transformations.
- _drawSliceHighlight()[source]¶
Draws a box around the slice which contains the current cursor location.
- _drawCursor()[source]¶
Draws a cursor at the current canvas position (the
SliceCanvas.pos
property).
- __module__ = 'fsleyes.gl.lightboxcanvas'¶