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)

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 a wx.glcanvas.GLCanvas canvas.

The LightBoxCanvas class derives from the SliceCanvas class, and is tightly coupled to the SliceCanvas implementation. Various settings, and the current scene displayed on a LightBoxCanvas instance, can be changed through the properties of the LightBoxCanvasOpts instance, available via the opts attribute.

Performance of a LightBoxCanvas instance may be controlled through the SliceCanvasOpts.renderMode property, in the same way as for the SliceCanvas. However, the LightBoxCanvas handles the offscreen render mode differently to the SliceCanvas. Where the ``SliceCanvas uses a separate RenderTexture for every overlay in the OverlayList, the LightBoxCanvas uses a single RenderTexture to render all overlays off-screen.

The LightBoxCanvas class defines the following convenience methods (in addition to those defined in the SliceCanvas class):

canvasToWorld Overrides :meth:.SliceCanvas.canvasToWorld`.
worldToCanvas 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.
getTotalRows Returns the total number of rows that may be displayed.
calcSliceSpacing Calculates and returns a Z-axis slice spacing value suitable for the given overlay.
__init__(overlayList, displayCtx, zax=0)

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()

Overrides SliceCanvas.destroy(). Must be called when this LightBoxCanvas is no longer needed.

Removes some property listeners, makes sure that the off screen RenderTexture (if one exists) is destroyed, and then calls the SliceCanvas.destroy() method.

worldToCanvas(pos)

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)

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.

getTotalRows()

Returns the total number of rows that may be displayed.

calcSliceSpacing(overlay)

Calculates and returns a Z-axis slice spacing value suitable for the given overlay.

_zAxisChanged(*a)

Overrides SliceCanvas._zAxisChanged(). Calls that method, and then resets the sliceSpacing and zrange properties to sensible values.

_topRowChanged(*a)

Called when the topRow property changes. Adjusts display range and refreshes the canvas.

_slicePropsChanged(*a)

Called when any of the slice properties change. Regenerates slice locations and display bounds, and refreshes the canvas.

_renderModeChange(*a)

Overrides SliceCanvas._renderModeChange(). Makes sure that any off-screen RenderTexture is destroyed, and calls the SliceCanvas._renderModeChange() method.

_updateRenderTextures()

Overrides SliceCanvas._updateRenderTextures(). Destroys/creates RenderTexture and RenderTextureStack instances as needed.

_calcNumSlices(*a)

Calculates the total number of slices to be displayed and the total number of rows.

_zPosChanged(*a)

Called when the SliceCanvas.pos z value changes.

Makes sure that the corresponding slice is visible.

_overlayListChanged(*a)

Overrides SliceCanvas._overlayListChanged().

Regenerates slice locations for all overlays, and calls the SliceCanvas._overlayListChanged() method.

_updateZAxisProperties()

Called by the _overlayListChanged() and _overlayBoundsChanged() methods.

Updates the constraints (minimum/maximum values) of the sliceSpacing and zrange properties.

_overlayBoundsChanged(*a)

Overrides SliceCanvas._overlayBoundsChanged().

Called when the DisplayContext.bounds change. Updates the zrange min/max values.

_updateDisplayBounds(*args, **kwargs)

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()

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)

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.

_drawGridLines()

Draws grid lines between all the displayed slices.

_drawSliceHighlight()

Draws a box around the slice which contains the current cursor location.

_drawCursor()

Draws a cursor at the current canvas position (the SliceCanvas.pos property).

_draw(*a)

Draws the current scene to the canvas.

_LightBoxCanvas__prepareSliceTransforms(globj, xforms)

Applies the SliceCanvas.invertX and SliceCanvas.invertY properties to the given transformation matrices, if necessary. Returns the transformations.

__module__ = 'fsleyes.gl.lightboxcanvas'