fsleyes.profiles.orthoeditprofile¶
This module provides the OrthoEditProfile class, an interaction
Profile for OrthoPanel views.
-
class
fsleyes.profiles.orthoeditprofile.OrthoEditProfile(viewPanel, overlayList, displayCtx)[source]¶ Bases:
fsleyes.profiles.orthoviewprofile.OrthoViewProfileThe
OrthoEditProfileclass is an interaction profile for use with theOrthoPanelclass. It gives the user the ability to make changes toImageoverlays, by using the functionality of theeditorpackage.Modes
The
OrthoEditProfilehas the following modes, in addition to those already defined by theOrthoViewProfile:selSelect mode. The user is able to manually add voxels to the selection using a cursor. The cursor size can be changed with the
selectionSizeproperty, and the cursor can be toggled between a 2D square and a 3D cube via theselectionIs3Dproperty. If thedrawModeproperty isTrue, selected voxels are immediately filled with thefillValuewhen the mouse is released.deselDeselect mode. Identical to
selmode, except that the cursor is used to remove voxels from the selection. If thedrawModeproperty isTrue, selected voxels are immediately set to 0 when the mouse is released.chsizeChange-size mode. The use can change the
selectionSizeattribute via the mouse wheel.selintSelect by intensity mode. The user can select a voxel, and grow the selected region based on its intensity.
fillFill mode. The user can click on a voxel and set its selected state, and the state of adjacent voxels. Restricted to 2D (see
selectionIs3D).chthresChange-threshold mode. The user can change the
intensityThresvia the mouse wheel.chradChange-radius mode. The user can change the
searchRadiusvia the mouse wheel.Actions
The
OrthoEditProfiledefines the following actions, on top of those already defined by theOrthoViewProfile:Un-does the most recent change to the selection or to the
Imagedata.Re-does the most recent undone change to the selection or to the
Imagedata.Clears the current selection.
Fills the current selection with the
fillValue.Inverts the current selection.
Fills the current selection with zero.
Copies the data within the selection from the currently selected overlay, and stores it in an internal “clipboard”.
Pastes the data currently stored in the clipboard into the currently selected image, if possible.
Annotations
The
OrthoEditProfileclass usesannotationson theSliceCanvaspanels, displayed in theOrthoPanel, to display information to the user. Two annotations are used:The cursor annotation. This is a
Rectannotation representing a cursor at the voxel, or voxels, underneath the current mouse location.The selection annotation. This is a
VoxelSelectionannotation which displays theSelection.
The display space
The
OrthoEditProfileclass has been written in a way which requires theImageinstance that is being edited to be displayed in scaled voxel (a.k.a.pixdim) space. TheOrthoEditToolBaruses aDisplaySpaceWarningwidget to warn the user if theDisplayContext.displaySpaceis not set appropriately.-
selectionCursorColour= <MagicMock name='mock.Colour()' id='281473498033216'>¶ Colour used for the cursor annotation.
-
selectionOverlayColour= <MagicMock name='mock.Colour()' id='281473498033216'>¶ Colour used for the selection annotation, which displays the voxels that are currently selected.
-
showSelection= <MagicMock name='mock.Boolean()' id='281473497326640'>¶ When
drawModeisFalse,` the selection overlay can be hidden by setting this to ``False.
-
selectionSize= <MagicMock name='mock.Int()' id='281473494293760'>¶ In
selanddeselmodes, defines the size of the selection cursor.
-
selectionIs3D= <MagicMock name='mock.Boolean()' id='281473497326640'>¶ In
selanddeselmode, toggles the cursor between a 2D square and a 3D cube. Inselintmode, toggles the selection space between the current slice, and the full 3D volume.
-
fillValue= <MagicMock name='mock.Real()' id='281473497926576'>¶ The value used when drawing/filling voxel values - all voxels in the selection will be filled with this value.
-
eraseValue= <MagicMock name='mock.Real()' id='281473497926576'>¶ The value used when erasing voxel values - all voxels in the selection will be filled with this value.
-
drawMode= <MagicMock name='mock.Boolean()' id='281473497326640'>¶ If
True, when inselordeselmode, clicks and click+ drags cause the image to be immediately modified. Otherwise, editing is a two stage process (as described in theEditorclass documentation).This setting is enabled by default, because it causes FSLeyes to behave like FSLView. However, all advanced editing/selection capabilities are disabled when
drawModeisTrue.
-
intensityThres= <MagicMock name='mock.Real()' id='281473497926576'>¶ In
selintmode, the maximum distance, in intensity, that a voxel can be from the seed location, in order for it to be selected. Passed as theprecisionargument to theSelection.selectByValue()method.
-
intensityThresLimit= <MagicMock name='mock.Real()' id='281473497926576'>¶ This setting controls the maximum value for the
itensityThresproperty. It is set automatically from the data when anImageis first selected, but can also be manually controlled via this property.
-
localFill= <MagicMock name='mock.Boolean()' id='281473497326640'>¶ In
selintmode, if this property isTrue, voxels can only be selected if they are adjacent to an already selected voxel. Passed as thelocalargument to theSelection.selectByValue()method.
-
limitToRadius= <MagicMock name='mock.Boolean()' id='281473497326640'>¶ In
selintmode, if this property isTrue, the search region will be limited to a sphere (in the voxel coordinate system) with its radius specified by thesearchRadiusproperty.
-
searchRadius= <MagicMock name='mock.Real()' id='281473497926576'>¶ In
selintmode, iflimitToRadiusis true, this property specifies the search sphere radius. Passed as thesearchRadiusargument to theSelection.selectByValue()method.
-
targetImage= <MagicMock name='mock.Choice()' id='281473498355456'>¶ By default, all modifications that the user makes will be made on the currently selected overlay (the
DisplayContext.selectedOverlay). However, this property can be used to select a different image as the target for modifications.This proprty is mostly useful when in
selintmode - the selection can be made based on the voxel intensities in the currently selected image, but the selection can be filled in another iamge (e.g. a mask/label image).This property is updated whenever the
OverlayListor the currently selected overlay changes, so that it contains all other overlays which have the same dimensions as the selected overlay.
-
__init__(viewPanel, overlayList, displayCtx)[source]¶ Create an
OrthoEditProfile.- Parameters
viewPanel – The
OrthoPanelinstance.overlayList – The
OverlayListinstance.displayCtx – The
DisplayContextinstance.
-
locationFollowsMouse= <MagicMock name='mock.Boolean()' id='281473497326640'>¶ If
True, when the user is drawing/erasing/selectiong by clicking and dragging with the mouse, theDisplayContext.locationis updated to track the mouse.Users running on a slower machine may wish to disable this option.
-
destroy()[source]¶ Removes some property listeners, destroys the
Editorinstances, and callsOrthoViewProfile.destroy().
-
deregister()[source]¶ Destroys all
annotations, and callsOrthoViewProfile.deregister().
-
currentOverlay()[source]¶ Returns the overlay that is currently registered with this
OrthoEditProfile.
-
editor(overlay)[source]¶ Return the
Editorassociated with the given overlay. Raises aKeyErrorif there is no editor fo the overlay.
-
createMask()[source]¶ Create a 3D mask which has the same size as the currently selected overlay, and insert it into the overlay list.
-
clearSelection()[source]¶ Clears the current selection. See
Editor.clearSelection().
-
fillSelection()[source]¶ Fills the current selection with the
fillValue. SeeEditor.fillSelection().
-
invertSelection()[source]¶ Inverts the current selection. See
Editor.invertSelection().
-
eraseSelection()[source]¶ Fills the current selection with zero. See
Editor.fillSelection().
-
copySelection()[source]¶ Copies the data within the selection from the currently selected overlay, and stores it in an internal “clipboard”.
-
pasteSelection()[source]¶ Pastes the data currently stored in the clipboard into the currently selected image, if possible.
-
undo()[source]¶ Un-does the most recent change to the selection or to the
Imagedata. SeeEditor.undo().
-
redo()[source]¶ Re-does the most recent undone change to the selection or to the
Imagedata. SeeEditor.redo().
-
isEditable= <MagicMock name='mock.utils.deprecated.deprecated()()' id='281473495817568'>¶
-
_selModeMouseMove(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse motion events in
selmode.Draws a cursor annotation at the current mouse location (see
__draweCursorAnnotation()).
-
_selModeLeftMouseDown(ev, canvas, mousePos, canvasPos, add=True, mode='sel')[source]¶ Handles mouse down events in
selmode.Starts an
Editorchange group, and adds to the currentSelection.This method is also used by
_deselModeLeftMouseDown(), which may set theaddparameter toFalse.- Parameters
add – If
True(default) a block at the cursor is added to the selection. Otherwise it is removed.mode – The current profile mode (defaults to
'sel').
-
_selModeLeftMouseDrag(ev, canvas, mousePos, canvasPos, add=True, mode='sel')[source]¶ Handles mouse drag events in
selmode.Adds to the current
Selection.This method is also used by
_deselModeLeftMouseDown(), which may set theaddparameter toFalse.- Parameters
add – If
True(default) a block at the cursor is added to the selection. Otherwise it is removed.mode – The current profile mode (defaults to
'sel').
-
_selModeLeftMouseUp(ev, canvas, mousePos, canvasPos, fillValue=None)[source]¶ Handles mouse up events in
selmode.Ends the
Editorchange group that was started in the_selModeLeftMouseDown()method.This method is also used by
_deselModeLeftMouseUp(), which setsfillValuetoeraseValue.
-
_selModeMouseLeave(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse leave events in
selmode. Makes sure that the selection cursor annotation is not shown on any canvas.
-
_OrthoEditProfile__applySelection(canvas, voxel, add=True, combine=False, from_=None)¶ Called by
selmode mouse handlers. Adds/removes a block of voxels, centred at the specified voxel, to/from the currentSelection.- Parameters
canvas – The source
SliceCanvas.voxel – Coordinates of centre voxel.
add – If
Truea block is added to the selection, otherwise it is removed.combine – Tell the
Selectionobject to combine this change with the most recent one.from – If provided, use the
Selection.selectLine()orSelection.deselectLine()methods - should be another voxel coordinate.
-
_OrthoEditProfile__destroyAnnotations()¶ Called by other methods. Destroys the
SelectionAnnotationandRectcursor annotation objects, if they exist.
-
_OrthoEditProfile__drawCursorAnnotation(canvas, voxel, blockSize=None)¶ Draws the cursor annotation. Highlights the specified voxel with a
Rectannotation.This is used by mouse motion event handlers, so the user can see the possible selection, and thus what would happen if they were to click.
- Parameters
canvas – The
SliceCanvason which to make the annotation.voxel – Voxel which is at the centre of the cursor.
blockSize – Size of the cursor square/cube.
-
_OrthoEditProfile__drawModeChanged(*a)¶ Called when the
drawModechanges. Updates the enabled state of various actions that are irrelevant when in draw mode.
-
_OrthoEditProfile__dynamicRefreshCanvases(ev, canvas, mousePos=None, canvasPos=None)¶ Called by mouse event handlers when the user is interacting with a canvas.
If
locationFollowsMouseisTrue, theDisplayContext.locationis set to the current mouse location.
-
_OrthoEditProfile__getSelectionMerger()¶ This method is called just before a select-by-intensity selection is about to happen. It rteturns one of three values:
The string
'clear', indicating that the whole selection (or the whole slice, ifselectionIs3DisFalse) needs to be cleared.The value
Noneindicating that the selection does not need to be cleared, and a merge does not need to be made.A tuple containing the
(offset, size)of a previous change to the selection, specifying the portion of the selection which needs to be cleared, and which can be subsequently merged with a new selection.
-
_OrthoEditProfile__getTargetImageEditor(srcEditor)¶ If the
targetImageis set to an image other than the currently selected one, this method returns anEditorfor the target image.
-
_OrthoEditProfile__getVoxelLocation(canvasPos)¶ Returns the voxel location, for the currently selected overlay, which corresponds to the specified canvas position. Returns
Noneif the current canvas position is out of bounds for the current overlay.
-
_OrthoEditProfile__hideCursorAnnotation()¶ Configures all of the
Rectcursor annotations so that they will not be shown on the next canvas refresh.
-
_OrthoEditProfile__modeChanged(*a)¶ Called when the
Profile.modechanges. If the mode is changed to'fill', theselectionIs3Doption is set toFalse.
-
_OrthoEditProfile__recordSelectionMerger(mode, offset, size)¶ This method is called whenever a change is made to the
Selectionobject. It stores some information which is used to improve subsequent selection performance when inselintmode, and whenlimitToRadiusisTrue.Basically, if the current selection is limited by radius, and a new, similarly limited selection is made, we do not need to clear the entire selection before making the new selection - we just need to clear the cuboid region in which the previous selection was located.
This behaviour is referred to as a ‘merge’ because, ultimately, the region of the first selection is merged with the region of the second selection, and only this part of the
Selectionimage is refreshed.This method (and the
__getSelectionMerger()method) contains some simple, but awkward, logic which figures out when a merge can happen and, conversely, when the full selection does need to be cleared.- Parameters
offset – Offset into the selection array of the change.
size – Shape of the change.
-
_OrthoEditProfile__refreshCanvases()¶ Short cut to refresh the canvases of the
OrthoPanel.Note
This is done instead of calling
OrthoPanel.Refreshbecause the latter introduces flickering.
-
_OrthoEditProfile__selectedOverlayChanged(*a)¶ Called when either the
OverlayListorDisplayContext.selectedOverlaychange.Destroys all old
annotations. If the newly selected overlay is anImage, new annotations are created.
-
_OrthoEditProfile__selectionColoursChanged(*a)¶ Called when either of the
selectionOverlayColourorselectionCursorColourproperties change.Updates the
annotationscolours accordingly.
-
_OrthoEditProfile__selintPropertyChanged(*a)¶ Called when the
intensityThres,localFill,limitToRadius, orsearchRadiusproperties change. Re-runs select-by-intensity (via__selintSelect()), with the new settings.
-
_OrthoEditProfile__selintSelect(voxel, canvas)¶ Selects voxels by intensity, using the specified
voxelas the seed location.Called by the
_selintModeLeftMouseDown(),_selintModeLeftMouseDrag(),_selintModeLeftMouseWheel(), and__selintPropertyChanged()methods. SeeSelection.selectByValue().
-
_OrthoEditProfile__selintThresLimitChanged(*a)¶ Called when the
intensityThresLimitchanges. Updates the maximum value on theintensityThresaccordingly.
-
_OrthoEditProfile__setCopyPasteState()¶ Enables/disables the
copySelection()/pasteSelection()actions as needed.
-
_OrthoEditProfile__setPropertyLimits()¶ Called by the
__selectedOverlayChanged()method.
-
_OrthoEditProfile__showSelectionChanged(*a)¶ Called when the
showSelectionproperty changes. Shows/ hides theVoxelSelectionannotations accordingly.
-
_OrthoEditProfile__targetImageChanged(*a)¶ Called every time the
targetImageis changed. Makes sure that anEditorinstance for the selected target image exists.
-
_OrthoEditProfile__updateTargetImage()¶ Resets the value and choices on the
targetImage. It is populated with allImageinstances which are in the same space as the currently selected overlay.
-
__module__= 'fsleyes.profiles.orthoeditprofile'¶
-
_deselModeLeftMouseDown(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse down events in
deselmode.Calls
_selModeLeftMouseDown().
-
_deselModeLeftMouseDrag(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse drag events in
deselmode.Calls
_selModeLeftMouseDrag().
-
_deselModeLeftMouseUp(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse up events in
deselmode.Calls
_selModeLeftMouseUp().
-
_chsizeModeMouseWheel(ev, canvas, wheelDir, mousePos, canvasPos)[source]¶ Handles mouse wheel events in
chsizemode.Increases/decreases the current
selectionSize.
-
_selintModeMouseMove(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse motion events in
selintmode. Draws a selection annotation at the current location (see__drawCursorAnnotation()).
-
_selintModeLeftMouseDown(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse down events in
selintmode.Starts an
Editorchange group, then clears the current selection, and selects voxels by intensity (see__selintSelect()).
-
_selintModeLeftMouseDrag(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse drag events in
selintmode.A select-by-intensity is re-run with the current mouse location. See the
__selintSelect()method.
-
_selintModeLeftMouseUp(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse up events in
selintmode. Ends theEditorchange group that was started in the_selintModeLeftMouseDown()method.
-
_selintModeMouseLeave(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse leave events in
selintmode. Makes sure that the selection cursor annotation is not shown on any canvas.
-
_fillModeMouseMove(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse motion events in
fillmode. Draws a selection annotation at the current location (see__drawCursorAnnotation()).
-
_fillModeLeftMouseDown(ev, canvas, mousePos, canvasPos)[source]¶ Handles mouse down events in
fillmode. CallsSelection.invertRegion()at the current location.
-
_chthresModeMouseWheel(ev, canvas, wheel, mousePos, canvasPos)[source]¶ Handles mouse wheel events in
chthresmode.The
intensityThresvalue is decreased/increased according to the mouse wheel direction. If the mouse button is down, select-by-intensity is re-run at the current mouse location.
-
_chradModeMouseWheel(ev, canvas, wheel, mousePos, canvasPos)[source]¶ Handles mouse wheel events in
chradmode.The
searchRadiusvalue is decreased/increased according to the mouse wheel direction. If the mouse button is down, select-by-intensity is re-run at the current mouse location.