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.SliceCanvasThe
LightBoxCanvasrepresents 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
LightBoxCanvasclass is not intended to be instantiated directly - use one of these subclasses, depending on your use-case:OSMesaLightBoxCanvasfor static off-screen rendering of a scene using OSMesa.WXGLLightBoxCanvasfor interactive rendering on awx.glcanvas.GLCanvascanvas.
The
LightBoxCanvasclass derives from theSliceCanvasclass, and is tightly coupled to theSliceCanvasimplementation. Various settings, and the current scene displayed on aLightBoxCanvasinstance, can be changed through the properties of theLightBoxCanvasOptsinstance, available via theoptsattribute.Performance of a
LightBoxCanvasinstance may be controlled through theSliceCanvasOpts.renderModeproperty, in the same way as for theSliceCanvas. However, theLightBoxCanvashandles theoffscreenrender mode differently to theSliceCanvas. Where the ``SliceCanvasuses a separateRenderTexturefor every overlay in theOverlayList, theLightBoxCanvasuses a singleRenderTextureto render all overlays off-screen.The
LightBoxCanvasclass defines the following convenience methods (in addition to those defined in theSliceCanvasclass):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
LightBoxCanvasobject.- Parameters
overlayList – An
OverlayListobject which contains a list of overlays to be displayed.displayCtx – A
DisplayContextobject 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.zaxproperty.
-
destroy()[source]¶ Overrides
SliceCanvas.destroy(). Must be called when thisLightBoxCanvasis 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,Noneis 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 thesliceSpacingandzrangeproperties to sensible values.
-
_topRowChanged(*a)[source]¶ Called when the
topRowproperty 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-screenRenderTextureis destroyed, and calls theSliceCanvas._renderModeChange()method.
-
_updateRenderTextures()[source]¶ Overrides
SliceCanvas._updateRenderTextures(). Destroys/createsRenderTextureandRenderTextureStackinstances 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.poszvalue 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
sliceSpacingandzrangeproperties.
-
_overlayBoundsChanged(*a)[source]¶ Overrides
SliceCanvas._overlayBoundsChanged().Called when the
DisplayContext.boundschange. Updates thezrangemin/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.
-
_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.posproperty).
-
_LightBoxCanvas__prepareSliceTransforms(globj, xforms)¶ Applies the
SliceCanvas.invertXandSliceCanvas.invertYproperties to the given transformation matrices, if necessary. Returns the transformations.
-
__module__= 'fsleyes.gl.lightboxcanvas'¶