fsleyes.plugins.tools.saveannotations

This module provides the LoadAnnotationsAction and SaveAnnotationsAction classes, both FSLeyes actions which can be used to save/load annotations to/from a file. This module is tightly coupled to the implementations of the specific AnnotationObject types that are supported:

The SaveAnnotationsAction class is an action which is added to the FSLeyes Tools menu, and which allows the user to save all annotations that have been added to the canvases of an OrthoPanel to a file. This file can then be loaded back in via the LoadAnnotationsAction.

The logic for serialising and deserialising annotations to/from string representations is also implemented in this module.

A FSLeyes annotations file is a plain text file where each line contains a description of one AnnotationObject. An example of a FSLeyes annotation file is:

X Line lineWidth=4 colour=#0090a0 alpha=100 honourZLimits=False zmin=89.0  zmax=90.0  x1=48.7 y1=117.4 x2=39.1 y2=65.5
Y Rect lineWidth=4 colour=#ff0800 alpha=100 honourZLimits=False zmin=107.0 zmax=108.0 filled=False border=True x=43.3 y=108.1 w=71.5 h=-62.7
Y TextAnnotation lineWidth=5 colour=#e383ff alpha=100 honourZLimits=False zmin=107.0 zmax=108.0 text='' fontSize=20 x=10.9 y=154.2

Each line has the form:

<canvas> <type> key=value [key=value ...]

where:

  • <canvas> is one of X, Y or Z, indicating the ortho canvas that the annotation is drawn on

  • <type> is the annotation type, one of Point, Line, Arrow, Rect, Ellipse or TextAnnotation.

  • key=value contains the name and value of one property of the annotation.

The following key-value pairs are set for all annotation types:

  • colour - Annotation colour, as string of the form #RRGGBB

  • lineWidth - Line width in pixels

  • alpha - Transparency, between 0 and 10

  • honourZLimits - True or False, whether zmin and zmax should be applied

  • zmin - Minimum depth value, as a floating point number

  • zmax - Maximum depth value, as a floating point number

The following additional key-value pairs are set for specific annotation types. All coordinates and lengths are relative to the display coordinate system:

  • Point

  • x X coordinate

  • y Y coordinate

  • Line and Arrow

  • x1 X coordinate of first point

  • y1 Y coordinate of first point

  • x2 X coordinate of second point

  • y2 Y coordinate of second point

  • Rect and Ellipse

  • filled True or False, whether the rectangle/ellipse is filled

  • border True or False, whether the rectangle/ellipse is drawn with a border

  • x X coordinate of one corner of the rectangle, or the ellipse centre

  • y Y coordinate of one corner of the rectangle, or the ellipse centre

  • w Rectangle width, relative to x, or horizontal radius of elliipse

  • h Rectangle height, relative to y, or vertical radius of elliipse

  • TextAnnotation

  • text Displayed text, quoted with shlex.quote

  • fontSize Font size in points (relative to the canvas scaling that was in place at the time that the text was created)

  • x Bottom left X coordinate of text

  • y Bottom left Y coordinate of text

class fsleyes.plugins.tools.saveannotations.SaveAnnotationsAction(overlayList, displayCtx, ortho)[source]

Bases: fsleyes.actions.base.Action

The SaveAnnotationsAction allos the user to save annotations that have been added to an OrthoPanel to a file.

static ignoreTool()[source]

This action is not intended to be loaded as a FSLeyes plugin. Rather, it is used directly by the AnnotationPanel class.

static supportedViews()[source]

This action is only intended to work with OrthoPanel views.

__init__(overlayList, displayCtx, ortho)[source]

Create a SaveAnnotationsAction.

Parameters
__saveAnnotations()

Show a dialog prompting the user for a file to save to, then serialises all annotations, and saves them to that file.

__annotations__ = {}
__module__ = 'fsleyes.plugins.tools.saveannotations'
class fsleyes.plugins.tools.saveannotations.LoadAnnotationsAction(overlayList, displayCtx, ortho)[source]

Bases: fsleyes.actions.base.Action

The LoadAnnotationsAction allos the user to load annotations from a file into an OrthoPanel.

static ignoreTool()[source]

This action is not intended to be loaded as a FSLeyes plugin. Rather, it is used directly by the AnnotationPanel class.

static supportedViews()[source]

This action is only intended to work with OrthoPanel views.

__init__(overlayList, displayCtx, ortho)[source]

Create a SaveAnnotationsAction.

Parameters
__loadAnnotations()

Show a dialog prompting the user for a file to load, then loads the annotations contained in the file and adds them to the OrthoPanel.

__annotations__ = {}
__module__ = 'fsleyes.plugins.tools.saveannotations'
fsleyes.plugins.tools.saveannotations.saveAnnotations(ortho: fsleyes.views.orthopanel.OrthoPanel, filename: Union[pathlib.Path, str])[source]

Saves annotations on the canvases of the OrthoPanel to the specified filename.

fsleyes.plugins.tools.saveannotations.loadAnnotations(ortho: fsleyes.views.orthopanel.OrthoPanel, filename: Union[pathlib.Path, str])[source]

Loads annotations from the specified filename, and add them to the canvases of the OrthoPanel.

fsleyes.plugins.tools.saveannotations.serialiseAnnotations(allAnnots: Dict[str, List[fsleyes.gl.annotations.AnnotationObject]]) str[source]

Serialise all of the annotations for each canvas of an OrthoPanel to a string representation.

Parameters

allAnnots – Dictionary where the keys are one of 'X', 'Y' or 'Z', and the values are lists of AnnotationObject instances to be serialised.

Returns

String containing serialised annotations

fsleyes.plugins.tools.saveannotations.serialiseAnnotation(obj: fsleyes.gl.annotations.AnnotationObject, canvas: str) str[source]

Convert the given AnnotationObject to a string representation.

fsleyes.plugins.tools.saveannotations.deserialiseAnnotations(s: str, annots: Dict[str, fsleyes.gl.annotations.Annotations]) Dict[str, List[fsleyes.gl.annotations.AnnotationObject]][source]

Deserialise all of the annotation specifications in the string s, and create AnnotationObject instances from them. The AnnotationObject instances are created, but not added to the Annotations.

Parameters
  • s – String containing serialised annotations

  • annots – Dictionary where the keys are one of 'X', 'Y' or 'Z', and the values are the Annotations instances for each OrthoPanel canvas.

Returns

Dictionary of {canvas : [AnnotationObject]} mappings.

fsleyes.plugins.tools.saveannotations.deserialiseAnnotation(s: str, annots: Dict[str, fsleyes.gl.annotations.Annotations]) fsleyes.gl.annotations.AnnotationObject[source]

Deserialises the annotation specification in the provided string, and creates an AnnotationObject instance.

Parameters
  • s – String containing serialised annotation

  • annots – Dictionary where the keys are one of 'X', 'Y' or 'Z', and the values are the Annotations instance for each OrthoPanel canvas.

Returns

Tuple containing: