fsleyes.displaycontext.displaycontext¶
This module provides the DisplayContext class, which defines
general display settings for displaying the overlays in a
OverlayList.
-
exception
fsleyes.displaycontext.displaycontext.InvalidOverlayError[source]¶ Bases:
ExceptionAn error raised by the
DisplayContext.getDisplay()andDisplayContext.getOpts()methods to indicate that the specified overlay is not in theOverlayList.-
__module__= 'fsleyes.displaycontext.displaycontext'¶
-
__weakref__¶ list of weak references to the object (if defined)
-
-
class
fsleyes.displaycontext.displaycontext.DisplayContext(overlayList, parent=None, defaultDs='ref', **kwargs)[source]¶ Bases:
__main__.docbuilder.run.<locals>.MockClassA
DisplayContextinstance contains a number of properties defining how the overlays in anOverlayListare to be displayed, and related contextual information.A
DisplayContextinstance is responsible for creating and destroyingDisplayinstances for every overlay in theOverlayList. TheseDisplayinstances, and the correspondingDisplayOptsinstances (which, in turn, are created/destroyed byDisplayinstances) can be accessed with thegetDisplay()andgetOpts()method respectively.A number of other useful methods are provided by a
DisplayContextinstance:Returns the
Displayinstance for the specified overlay (or overlay index).Returns the
DisplayOptsinstance associated with the specified overlay.Convenience method which returns the reference image associated with the given overlay, or
Noneif there is no reference image.Returns
Trueif the currentdisplaySpacealigns with a radiological orientation.Selects the specified
overlay.Returns the currently selected overlay object, or
Noneif there are no overlays.Returns the order in which the given overlay (or an index into the
OverlayListlist) should be displayed (see theoverlayOrderproperty).Returns a list of overlay objects from the
OverlayListlist, sorted into the order that they should be displayed, as defined by theoverlayOrderproperty.This method can be used as a context manager to suppress notification for all
DisplayandDisplayOptsproperties related to the givenoverlay.Suppresses notification for all
DisplayandDisplayOptsproperties associated with the givenoverlay.Enables notification for all
DisplayandDisplayOptsproperties associated with the givenoverlay.This property controls how the
displaySpaceis initialised when overlays are added to a previously emptyOverlayList.Detaches the
displaySpaceandboundsproperties, and all relatedDisplayOptsproperties, from the parentDisplayContext.-
selectedOverlay= <MagicMock name='mock.Int()' id='4116300320'>¶ Index of the currently ‘selected’ overlay.
Note
The value of this index is in relation to the
OverlayList, rather than to theoverlayOrderlist.If you’re interested in the currently selected overlay, you must also listen for changes to the
OverlayList.imageslist as, if the list changes, theselectedOverlayindex may not change, but the overlay to which it points may be different.
-
location= <MagicMock name='mock.Point()' id='4116283672'>¶ The location property contains the currently selected 3D location (xyz) in the display coordinate system. Different
DisplayContextinstances may be using different display coordinate systems - see thedisplaySpaceproperty.
-
worldLocation= <MagicMock name='mock.Point()' id='4116283672'>¶ The
locationproperty contains the currently selected 3D location (xyz) in the current display coordinate system. Whenever thelocationchanges, it gets transformed into the world coordinate system, and propagated to this property. The location of differentDisplayContextinstances is synchronised through this property.Note
If any
NiftiOpts.transformproperties have been modified independently of thedisplaySpace, this value will be invalid.
-
bounds= <MagicMock name='mock.Bounds()' id='4116394552'>¶ This property contains the min/max values of a bounding box (in display coordinates) which is big enough to contain all of the overlays in the
OverlayList.Warning
This property shouid be treated as read-only.
-
overlayOrder= <MagicMock name='mock.List()' id='4116324920'>¶ A list of indices into the
OverlayList.overlayslist, defining the order in which the overlays are to be displayed.See the
getOrderedOverlays()method.
-
overlayGroups= <MagicMock name='mock.List()' id='4116324920'>¶ A list of
OverlayGroupinstances, each of which defines a group of overlays which share display properties.By default there is one overlay group, to which all new overlays are initially added. The
OverlayListPanelallows the user to add/remove overlays from this default group.
-
syncOverlayDisplay= <MagicMock name='mock.Boolean()' id='4117273880'>¶ If this
DisplayContextinstance has a parent (seeprops.syncable), and this property isTrue, the properties of theDisplayandDisplayOptsinstances for every overlay managed by thisDisplayContextinstance will be synchronised to those of the parent instance. Otherwise, the display properties for every overlay will be unsynchronised from the parent.Properties which control the current volume/timepoint in a 4D data set are not managed by this property - see the :attr:
syncOverlayVolumeproperty.Synchronisation of the following properties between child and parent
DisplayContextinstances is also controlled by this flag:Note
This property is accessed by the
Displayclass, in its constructor, and when it creates newDisplayOptsinstances, to set initial sync states.
-
syncOverlayVolume= <MagicMock name='mock.Boolean()' id='4117273880'>¶ This property performs the same task as the
syncOverlayDisplayproperty, but it only affectsDisplayOptsproperties which control the current volume/timepoint in a 4D overlay.
-
displaySpace= <MagicMock name='mock.Choice()' id='4117029600'>¶ The space in which overlays are displayed. This property defines the display coordinate system for this
DisplayContext. When it is changed, theNiftiOpts.transformproperty of allNiftioverlays in theOverlayListis updated. It has two settings, described below. The options for this property are dynamically added by__updateDisplaySpaceOptions().World space (a.k.a.
'world')All
Niftioverlays are displayed in the space defined by their affine transformation matrix - theNiftiOpts.transformproperty for everyNiftioverlay is set toaffine.Scaled-voxel space (a.k.a.
'scaledVoxel')All
Niftioverlays are displayed in a scaled-voxel coordinate system, with origin set to the centre of voxel(0, 0, 0), and voxels scaled by image pixdims. This is accomplished by setting theNiftiOpts.transformproperty for everyNiftioverlay topixdim.Reference image space
A single
Niftioverlay is selected as a reference image, and is displayed in scaled voxel space (with a potential L/R flip for neurological images - itsNiftiOpts.transformis set topixdim-flip). All otherNiftioverlays are transformed into this reference space - theirNiftiOpts.transformproperty is set toreference, which results in them being transformed into the scaled voxel space of the reference image.
Note
The
NiftiOpts.transformproperty of anyNiftioverlay can be set independently of this property. However, whenever this property changes, it will change thetransformproperty for everyNifti, in the manner described above.The
defaultDisplaySpace()can be used to control how thedisplaySpaceis initialised.
-
radioOrientation= <MagicMock name='mock.Boolean()' id='4117273880'>¶ If
True, 2D views will show images in radiological convention (i.e.subject left on the right of the display). Otherwise, they will be shown in neurological convention (subject left on the left).Note
This setting is not enforced by the
DisplayContext. It is the responsibility of theOrthoPanelandLightBoxPanel(and other potential future 2D view panels) to implement the flip.
-
autoDisplay= <MagicMock name='mock.Boolean()' id='4117273880'>¶ If
True, whenever an overlay is added to theOverlayList, theautodisplaymodule will be used to automatically configure its display settings. Note that theDisplayContextdoes not perform this configuration - this flag is used by other modules (e.g. theOverlayListPaneland theOpenFileAction).
-
loadInMemory= <MagicMock name='mock.Boolean()' id='4117273880'>¶ If
True, allImageinstances will be loaded into memory, regardless of their size. Otherwise (the default), large compressedImageoverlays may be kept on disk.Note
Changing the value of this property will not affect existing
Imageoverlays.Note
This property may end up being used in a more general sense by any code which needs to decide whether to do things in a more or less memory-intensive manner.
-
__init__(overlayList, parent=None, defaultDs='ref', **kwargs)[source]¶ Create a
DisplayContext.- Parameters
overlayList – An
OverlayListinstance.parent – Another
DisplayContextinstance to be used as the parent of this instance, passed to theSyncableHasPropertiesconstructor.defaultDs – Initial value for the
defaultDisplaySpace(). Either'ref'or'world'. If'ref'(the default), when overlays are added to an empty list, thedisplaySpacewill be set to the firstNiftioverlay. Otherwise ('world'), the display space will be set to'world'.
All other arguments are passed through to the
SyncableHasPropertiesconstructor, in addition to the following:The
syncOverlayDisplay,,syncOverlayVolume,location, andboundsproperties are added to thenobindargumentThe
overlayGroups,autoDisplayandloadInMemoryproperties are added to thenounbindargument.
-
destroy()[source]¶ This method must be called when this
DisplayContextis no longer needed.When a
DisplayContextis destroyed, all of theDisplayinstances managed by it are destroyed as well.
-
property
destroyed¶ Returns
Trueif thisDisplayContexthas been, or is being, destroyed,Falseotherwise.
-
getDisplay(overlay, **kwargs)[source]¶ Returns the
Displayinstance for the specified overlay (or overlay index).If the overlay is not in the
OverlayList, anInvalidOverlayErroris raised. Otheriwse, if aDisplayobject does not exist for the given overlay, one is created.If this
DisplayContexthas been destroyed, aValueErroris raised.- Parameters
overlay – The overlay to retrieve a
Displayinstance for, or an index into theOverlayList.
All other keyword arguments are assumed to be
name=valuepairs, containing initial property values.
-
getOpts(overlay)[source]¶ Returns the
DisplayOptsinstance associated with the specified overlay. SeegetDisplay()andDisplay.opts()for more details.
-
getReferenceImage(overlay)[source]¶ Convenience method which returns the reference image associated with the given overlay, or
Noneif there is no reference image.See the
DisplayOpts.referenceImagemethod.
-
displaySpaceIsRadiological()[source]¶ Returns
Trueif the currentdisplaySpacealigns with a radiological orientation. A radiological orientation is one in which anatomical right is shown on the left of the screen, i.e.:The X axis corresponds to right -> left
The Y axis corresponds to posterior -> anterior
The Z axis corresponds to inferior -> superior
-
selectOverlay(overlay)[source]¶ Selects the specified
overlay. Raises anIndexErrorif the overlay is not in the list.If you want to select an overlay by its index in the
OverlayList, you can just assign to theselectedOverlayproperty directly.
-
getSelectedOverlay()[source]¶ Returns the currently selected overlay object, or
Noneif there are no overlays.
-
getOverlayOrder(overlay)[source]¶ Returns the order in which the given overlay (or an index into the
OverlayListlist) should be displayed (see theoverlayOrderproperty).Raises an
IndexErrorif the overlay is not in the list.
-
getOrderedOverlays()[source]¶ Returns a list of overlay objects from the
OverlayListlist, sorted into the order that they should be displayed, as defined by theoverlayOrderproperty.
-
freeze(overlay)[source]¶ This method can be used as a context manager to suppress notification for all
DisplayandDisplayOptsproperties related to the givenoverlay:with displayCtx.freeze(overlay): # Do stuff which might trigger unwanted # Display/DisplayOpts notifications
See
freezeOverlay()andthawOverlay().
-
freezeOverlay(overlay)[source]¶ Suppresses notification for all
DisplayandDisplayOptsproperties associated with the givenoverlay. CallthawOverlay()to re-enable notification.See also the
freeze()method, which can be used as a context manager to automatically call this method andthawOverlay.
-
thawOverlay(overlay)[source]¶ Enables notification for all
DisplayandDisplayOptsproperties associated with the givenoverlay.
-
__module__= 'fsleyes.displaycontext.displaycontext'¶
-
property
defaultDisplaySpace¶ This property controls how the
displaySpaceis initialised when overlays are added to a previously emptyOverlayList. If thedefaultDisplaySpaceis set to'ref', thedisplaySpacewill be initialised to the firstNiftioverlay. Otherwise (thedefaultDisplaySpaceis set to'world'), thedisplaySpacewill be set to'world'.
-
detachDisplaySpace()[source]¶ Detaches the
displaySpaceandboundsproperties, and all relatedDisplayOptsproperties, from the parentDisplayContext.This allows this
DisplayContextto use a display coordinate system that is completely independent from other instances, and is not affected by changes to the parent properties.This is an irreversible operation.
-
__overlayListChanged(*a)¶ Called when the
OverlayList.overlaysproperty changes.Ensures that a
DisplayandDisplayOptsobject exists for every image, updates theboundsproperty, makes sure that theoverlayOrderproperty is consistent, and updates constraints on theselectedOverlayproperty.
-
__updateDisplaySpaceOptions()¶ Updates the
displaySpaceproperty so it is synchronised with the current contents of theOverlayListThis method is called by the
__overlayListChanged()method.
-
__setTransform(image)¶ Sets the
NiftiOpts.transformproperty associated with the givenNiftioverlay to a sensible value, given the current value of thedisplaySpaceproperty.Called by the
__displaySpaceChanged()method, and by__overlayListChanged()for anyImageoverlays which have been newly added to theOverlayList.- Parameters
image – An
Imageoverlay.
-
__displaySpaceChanged(*a)¶ Called when the
displaySpaceproperty changes. Updates theNiftiOpts.transformproperty for allNiftioverlays in theOverlayList.
-
__syncOverlayOrder()¶ Ensures that the
overlayOrderproperty is up to date with respect to theOverlayList.
-
__overlayBoundsChanged(value, valid, opts, name)¶ Called when the
DisplayOpts.boundsproperty of any overlay changes. Updates theboundsproperty and preserves the displaylocationin terms of theworldLocation.
-
__syncOverlayDisplayChanged(*a)¶ Called when the
syncOverlayDisplayproperty changes.Synchronises or unsychronises the
DisplayandDisplayOptsinstances for every overlay to/from their parent instances.
-
__syncOverlayVolumeChanged(*a)¶ Called when the
syncOverlayVolumeproperty changes.Synchronises or unsychronises the volume/timepoint properties of the
DisplayandDisplayOptsinstances for every overlay.
-
__updateBounds(*a)¶ Called when the overlay list changes, or when any overlay display transform is changed. Updates the
boundsproperty so that it is big enough to contain all of the overlays (as defined by theirDisplayOpts.boundsproperties).
-
__locationChanged(*a)¶ Called when the
locationproperty changes. Propagates the new location to theworldLocationproperty.
-
__worldLocationChanged(*a)¶ Called when the
worldLocationproperty changes. Propagates the new location to thelocationproperty.
-
__propagateLocation(dest)¶ Called by the
__locationChanged()and__worldLocationChanged()methods. Thedestargument may be either'world'(theworldLocationis updated from thelocation), or'display'(vice-versa).
-