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 ofX,YorZ, indicating the ortho canvas that the annotation is drawn on
<type>is the annotation type, one ofPoint,Line,Arrow,Rect,EllipseorTextAnnotation.
key=valuecontains 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-TrueorFalse, whetherzminandzmaxshould 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
xX coordinate
yY coordinate
LineandArrow
x1X coordinate of first point
y1Y coordinate of first point
x2X coordinate of second point
y2Y coordinate of second point
RectandEllipse
filledTrueorFalse, whether the rectangle/ellipse is filled
borderTrueorFalse, whether the rectangle/ellipse is drawn with a border
xX coordinate of one corner of the rectangle, or the ellipse centre
yY coordinate of one corner of the rectangle, or the ellipse centre
wRectangle width, relative tox, or horizontal radius of elliipse
hRectangle height, relative toy, or vertical radius of elliipse
TextAnnotation
textDisplayed text, quoted withshlex.quote
fontSizeFont size in points (relative to the canvas scaling that was in place at the time that the text was created)
xBottom left X coordinate of text
yBottom left Y coordinate of text
-
class
fsleyes.plugins.tools.saveannotations.SaveAnnotationsAction(overlayList, displayCtx, ortho)[source]¶ Bases:
fsleyes.actions.base.ActionThe
SaveAnnotationsActionallos the user to save annotations that have been added to anOrthoPanelto a file.-
static
ignoreTool()[source]¶ This action is not intended to be loaded as a FSLeyes plugin. Rather, it is used directly by the
AnnotationPanelclass.
-
static
supportedViews()[source]¶ This action is only intended to work with
OrthoPanelviews.
-
__init__(overlayList, displayCtx, ortho)[source]¶ Create a
SaveAnnotationsAction.- Parameters
overlayList – The
OverlayListdisplayCtx – The
DisplayContextortho – The
OrthoPanel.
-
__saveAnnotations()¶ Show a dialog prompting the user for a file to save to, then serialises all annotations, and saves them to that file.
-
__module__= 'fsleyes.plugins.tools.saveannotations'¶
-
static
-
class
fsleyes.plugins.tools.saveannotations.LoadAnnotationsAction(overlayList, displayCtx, ortho)[source]¶ Bases:
fsleyes.actions.base.ActionThe
LoadAnnotationsActionallos the user to load annotations from a file into anOrthoPanel.-
static
ignoreTool()[source]¶ This action is not intended to be loaded as a FSLeyes plugin. Rather, it is used directly by the
AnnotationPanelclass.
-
static
supportedViews()[source]¶ This action is only intended to work with
OrthoPanelviews.
-
__init__(overlayList, displayCtx, ortho)[source]¶ Create a
SaveAnnotationsAction.- Parameters
overlayList – The
OverlayListdisplayCtx – The
DisplayContextortho – The
OrthoPanel.
-
__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.
-
__module__= 'fsleyes.plugins.tools.saveannotations'¶
-
static
-
fsleyes.plugins.tools.saveannotations.saveAnnotations(ortho: fsleyes.views.orthopanel.OrthoPanel, filename: Union[pathlib.Path, str])[source]¶ Saves annotations on the canvases of the
OrthoPanelto the specifiedfilename.
-
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 theOrthoPanel.
-
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
OrthoPanelto a string representation.- Parameters
allAnnots – Dictionary where the keys are one of
'X','Y'or'Z', and the values are lists ofAnnotationObjectinstances 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
AnnotationObjectto 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 createAnnotationObjectinstances from them. TheAnnotationObjectinstances are created, but not added to theAnnotations.- Parameters
s – String containing serialised annotations
annots – Dictionary where the keys are one of
'X','Y'or'Z', and the values are theAnnotationsinstances for eachOrthoPanelcanvas.
- 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
AnnotationObjectinstance.- Parameters
s – String containing serialised annotation
annots – Dictionary where the keys are one of
'X','Y'or'Z', and the values are theAnnotationsinstance for eachOrthoPanelcanvas.
- Returns
Tuple containing:
An
AnnotationObjectinstance'X','Y'or'Z', denoting the canvas that theAnnotationObjectis to be drawn on.