fsleyes.gl.annotations
This module provides the Annotations class, which implements
functionality to draw annotations (lines, text, etc)
The Annotations class is used by the SliceCanvas,
LightBoxCanvas, and Scene3DCanvas classes, and users of
those classes, to annotate the canvas.
Not all annotation types currently support being drawn on a
Scene3DCanvas.
All annotations derive from the AnnotationObject base class. The
following annotation types are defined:
The |
|
The |
|
The |
|
The |
|
The |
|
A |
|
A |
- class fsleyes.gl.annotations.Annotations(*args, **kwargs)[source]
Bases:
HasPropertiesAn
Annotationsobject provides functionality to draw annotations on an OpenGL canvas. Annotations may be enqueued via any of theline(),rect(),ellpse(),point(),selection()orobj(), methods, and de-queued via thedequeue()method.Annotations can be enqueued in one of three ways, using the hold and fixed parameters:
Transient: When calling
line,rect, etc, passinghold=False` enqueues the annotation for the next call to :meth:`draw`. After the annotation is drawn, it is removed from the queue, and would need to be re-queued to draw it again. The ``fixedparameter has no effect for transient annotations.Fixed: When calling
line,rect, etc, passinghold=Trueand`fixed=Trueenqueues the annotation for all subsequent calls todraw(). Fixed annotations are stored in an internal, inaccessible queue, so if you need to manipulate a fixed annotation, you need to maintain your own reference to it.**Persistent`**: When calling ``line`,
rect, etc, passinghold=Trueandfixed=Falseadds the annotation to the accessibleannotationslist.
Transient annotations are intended for one-off annotations, e.g. a cursor mark at the current mouse location.
Fixed annotations are intended for persistent annotations which are intended to be immutable, i.e. that cannot be directly manipulated by the user, e.g. anatomical orientation labels on the canvases of an
OrthoPanel.Persistent annotations are intended for persistent annotations which are intended to be manipulated by the user - these annotations are used by the
AnnotationPanelin conjunction with theOrthoAnnotateProfile.After annotations have been enqueued in one of the above manners, a call to
draw2D()ordraw3D()will draw each annotation on the canvas, and clear the transient queue. The default value forholdisFalse, andfixedisTrue,Annotations can be queued by one of the helper methods on the
Annotationsobject (e.g.line()orrect()), or by manually creating anAnnotationObjectand passing it to theobj()method.- annotations
Contains all persistent
AnnotationObjectinstances, which have been added to the queue withhold=Trueandfixed=False.
- __init__(canvas)[source]
Creates an
Annotationsobject.- Parameters:
canvas – The
SliceCanvasthat owns thisAnnotationsobject.
- property canvas
Returns a ref to the canvas that owns this
Annotationsinstance.
- destroy()[source]
Must be called when this
Annotationsobject is no longer needed.
- property defaultShader
Returns a shader program used by most
AnnotationObjecttypes.
- __create(atype, *args, **kwargs)
Used by the annotation creation methods below. Creates and enqueues an annotation of type
atype.
- selection(*args, **kwargs)[source]
Queues a selection for drawing - see the
VoxelSelectionclass.
- text(*args, **kwargs)[source]
Queues a text annotation for drawing - see the
TextAnnotationclass.
- obj(obj, hold=False, fixed=True)[source]
Queues the given
AnnotationObjectfor drawing.- Parameters:
hold – If
True, the givenAnnotationObjectwill be added to the fixed or persistent queues, and will remain there until it is explicitly removed. Otherwise (the default), the object will be added to the transient queue, and removed from the queue after it has been drawn.fixed – If
True(the default), andhold=True, the givenAnnotationObjectwill be added to the fixed queue, and will remain there until it is explicitly removed. Otherwise, the object will be added to the persistent queue and, again, will remain there until it is explicitly removed. Has no effect whenhold=False.
- dequeue(obj, hold=False, fixed=True)[source]
Removes the given
AnnotationObjectfrom the appropriate queue, but does not call itsGLObject.destroy()method - this is the responsibility of the caller.
- clear()[source]
Clears all queues, and calls the
GLObject.destroy()method on every object in the queue.
- draw2D(zpos, axes)[source]
Draws all enqueued annotations. Fixed annotations are drawn first, then persistent, then transient - i.e. transient annotations will be drawn on top of persistent, which will be drawn on to of fixed.
- Parameters:
zpos – Position along the Z axis, above which all annotations should be drawn.
axes – Display coordinate system axis mapping to the screen coordinate system.
- draw3D(xform=None)[source]
Draws all enqueued annotations. Fixed annotations are drawn first, then persistent, then transient - i.e. transient annotations will be drawn on top of persistent, which will be drawn on to of fixed.
- Parameters:
xform
- __annotations__ = {}
- __module__ = 'fsleyes.gl.annotations'
- class fsleyes.gl.annotations.AnnotationObject(*args, **kwargs)[source]
Bases:
GLSimpleObject,HasPropertiesBase class for all annotation objects. An
AnnotationObjectis drawn by anAnnotationsinstance. TheAnnotationObjectcontains some attributes which are common to all annotation types:colourAnnotation colour
alphaTransparency
enabledWhether the annotation should be drawn or not.
lineWidthAnnotation line width (if the annotation is made up of lines)
expiryTime (in seconds) after which the annotation will expire and not be drawn.
zminMinimum z value below which this annotation will not be drawn.
zmaxMaximum z value above which this annotation will not be drawn.
creationTime of creation.
All of these attributes can be modified directly, after which you should trigger a draw on the owning
SliceCanvasto refresh the annotation. You shouldn’t touch theexpiryorcreationattributes though.Subclasses must, at the very least, override the
globject.GLObject.vertices2D()method.- __init__(annot, colour=None, alpha=None, lineWidth=None, enabled=None, expiry=None, honourZLimits=None, zmin=None, zmax=None, occlusion=None, applyMvp=None, **kwargs)[source]
Create an
AnnotationObject.- Parameters:
annot – The
Annotationsobject that created thisAnnotationObject.colour – RGB/RGBA tuple specifying the annotation colour.
alpha – Opacity.
lineWidth – Line width to use for the annotation.
enabled – Initially enabled or disabled.
expiry – Time (in seconds) after which this annotation should be expired and not drawn.
honourZLimits – Whether to enforce
zmin/zmax.zmin – Minimum z value below which this annotation should not be drawn.
zmax – Maximum z value above which this annotation should not be drawn.
occlusion – Whether to draw with depth testing.
applyMvp – Whether to apply the canvas MVP matrix.
Any other arguments are ignored.
- colour
Annotation colour.
- alpha
Opacity.
- lineWidth
Line width in pixels (approx), for annotations which are drawn with lines. See also the
normalisedLineWidth()method.
- enabled
Whether to draw this annotation or not.
- honourZLimits
If True, the
zmin/zmaxproperties are enforced. Otherwise (the default) they are ignored, and the annotation is always drawn.Only relevant when being drawn via
draw2D().
- zmin
Minimum z value below which this annotation will not be drawn. Only relevant when being drawn via
draw2D().
- zmax
Maximum z value below which this annotation will not be drawn. Only relevant when being drawn via
draw2D().
- applyMvp
If
True(the default), it is assumed that the annotation coordinates are specified in the display coordinate system, and therefore that they should be transformed by theSliceCanvas.mvpMatrix()(orScene3DCanvas.mvpMatrix()). IfFalse, it is assumed that the annotation coordinates are in normalised device coordinates. Not honoured by all annotation types.
- destroy()[source]
Must be called when this
AnnotationObjectis no longer needed. The default implementation does nothing, but may be overridden by sub-classes.
- resetExpiry()[source]
Resets the expiry for this
AnnotationObjectso that it is valid from the current time.
- hit(x, y)[source]
Return
Trueif the given X/Y point is within the bounds of this annotation,Falseotherwise. Must be implemented by sub-classes, but only those annotations which are drawn by theOrthoAnnotateProfile.Only relevant for annotations drawn on a
SliceCanvas()of anOrthoPanel.- Parameters:
x – X coordinate (in display coordinates).
y – Y coordinate (in display coordinates).
- move(x, y)[source]
Move this annotation acording to
(x, y), which is specified as an offset relative to the current location. Must be implemented by sub-classes, but only those annotations which are drawn by theOrthoAnnotateProfile.Only relevant for annotations drawn on a
SliceCanvas()of anOrthoPanel.- Parameters:
x – X coordinate (in display coordinates).
y – Y coordinate (in display coordinates).
- expired(now)[source]
Returns
Trueif thisAnnotationhas expired,Falseotherwise.- Parameters:
now – The current time
- property normalisedLineWidth
Returns the
lineWidth, converted into units proportional to either display coordinates (ifapplyMvpisTrue), or normalised device coordinates (ifapplyMvpisFalse).
- vertices2D(zpos, axes)[source]
Must be implemented by sub-classes which rely on the default
draw2D()implementation. Generates and returns verticws to display this annotation. The exact return type may differ depending on the annotation type.
- vertices3D()[source]
Must be implemented by sub-classes which rely on the default
draw3D()implementation. Generates and returns verticws to display this annotation. The exact return type may differ depending on the annotation type.
- draw2D(canvas, zpos, axes, xform=None)[source]
Draw this annotation on a 2D plane. This method implements a default routine used by most annotation types - the annotation is drawn using vertices returned by the overridden
vertices2D()method.This method may be overridden by sub-classes which require a different routine.
- draw3D(canvas, xform=None)[source]
Draw this annotation in 3D. This method implements a default routine used by most annotation types - the annotation is drawn using vertices returned by the overridden
vertices3D()method.This method may be overridden by sub-classes which require a different routine.
- __annotations__ = {}
- __module__ = 'fsleyes.gl.annotations'
- class fsleyes.gl.annotations.Point(*args, **kwargs)[source]
Bases:
AnnotationObjectThe
Pointclass is anAnnotationObjectwhich represents a point, drawn as a small crosshair. The size of the point is proportional to theAnnotationObject.lineWidth.- __init__(annot, x, y, z=None, **kwargs)[source]
Create a
Pointannotation.The
xycoordinate tuple should be in relation to the axes which map to the horizontal/vertical screen axes on the target canvas.- Parameters:
annot – The
Annotationsobject that owns thisPoint.x – X coordinates of the point
y – Y coordinates of the point
z – Z coordinates, if this
Pointis being drawn viadraw3D().
All other arguments are passed through to
AnnotationObject.__init__().
- __annotations__ = {}
- __module__ = 'fsleyes.gl.annotations'
- class fsleyes.gl.annotations.Line(*args, **kwargs)[source]
Bases:
AnnotationObjectThe
Lineclass is anAnnotationObjectwhich represents a 2D line.- __init__(annot, x1, y1, x2, y2, z1=None, z2=None, **kwargs)[source]
Create a
Lineannotation.The
xy1andxy2coordinate tuples should be in relation to the axes which map to the horizontal/vertical screen axes on the target canvas.- Parameters:
annot – The
Annotationsobject that owns thisLine.x1 – X coordinate of one endpoint.
y1 – Y coordinate of one endpoint.
x2 – X coordinate of the other endpoint.
y2 – Y coordinate of the second endpoint.
All other arguments are passed through to
AnnotationObject.__init__().
- vertices2D(zpos, axes)[source]
Returns a set of vertices for drawing this line on a 2D plane, with the
GL_TRIANGLESprimitive.
- vertices3D()[source]
Returns a set of vertices for drawing this line in a 3D space, with the
GL_TRIANGLESprimitive.
- __annotations__ = {}
- __module__ = 'fsleyes.gl.annotations'
- class fsleyes.gl.annotations.Arrow(*args, **kwargs)[source]
Bases:
LineThe
Arrowclass is anAnnotationObjectwhich represents a 2D line with an arrow head at one end. The size of the is proportional to the currentAnnotationObject.lineWidth.- __annotations__ = {}
- __module__ = 'fsleyes.gl.annotations'
- class fsleyes.gl.annotations.BorderMixin[source]
Bases:
objectMixin for
AnnotationObjectclasses which display a shape which can be filled or unfilled, and can have a border or no border.- filled
Whether to fill the rectangle.
- border
Whether to draw a border around the rectangle.
- __dict__ = mappingproxy({'__module__': 'fsleyes.gl.annotations', '__doc__': 'Mixin for ``AnnotationObject`` classes which display a shape which\n can be filled or unfilled, and can have a border or no border.\n ', 'filled': <fsleyes_props.properties_types.Boolean object>, 'border': <fsleyes_props.properties_types.Boolean object>, 'draw2D': <function BorderMixin.draw2D>, '__dict__': <attribute '__dict__' of 'BorderMixin' objects>, '__weakref__': <attribute '__weakref__' of 'BorderMixin' objects>, '__annotations__': {}})
- __module__ = 'fsleyes.gl.annotations'
- __weakref__
list of weak references to the object
- class fsleyes.gl.annotations.Rect(*args, **kwargs)[source]
Bases:
BorderMixin,AnnotationObjectThe
Rectclass is anAnnotationObjectwhich represents a 2D rectangle.- __init__(annot, x, y, w, h, filled=True, border=True, **kwargs)[source]
Create a
Rectannotation.- Parameters:
annot – The
Annotationsobject that owns thisRect.x – X coordinate of one corner of the rectangle, in the display coordinate system.
y – Y coordinate of one corner of the rectangle, in the display coordinate system.
w – Rectangle width (actually an offset relative to
x)h – Rectangle height (actually an offset relative to
y)filled – If
True, the rectangle is filledborder – If
True, a border is drawn around the rectangle.
All other arguments are passed through to
AnnotationObject.__init__().Note that if
filled=Falseandborder=False, nothing will be drawn. The.AnnotationObject.alphavalue is ignored when drawing the border.
- __fill(zpos, xax, yax, zax, bl, br, tl, tr)
Generate the rectangle fill.
- __border(zpos, xax, yax, zax, bl, br, tl, tr)
Generate the rectangle outline.
- __annotations__ = {}
- __module__ = 'fsleyes.gl.annotations'
- class fsleyes.gl.annotations.Ellipse(*args, **kwargs)[source]
Bases:
BorderMixin,AnnotationObjectThe
Ellipseclass is anAnnotationObjectwhich represents a ellipse.- __init__(annot, x, y, w, h, npoints=60, filled=True, border=True, **kwargs)[source]
Create an
Ellipseannotation.- Parameters:
annot – The
Annotationsobject that owns thisEllipse.x – X coordinate of ellipse centre, in the display coordinate system.
y – Y coordinate of ellipse centre, in the display coordinate system.
w – Horizontal radius.
h – Vertical radius.
npoints – Number of vertices used to draw the ellipse outline.
filled – If
True, the ellipse is filledborder – If
True, a border is drawn around the ellipse
All other arguments are passed through to
AnnotationObject.__init__().
- __annotations__ = {}
- __module__ = 'fsleyes.gl.annotations'
- class fsleyes.gl.annotations.VoxelSelection(*args, **kwargs)[source]
Bases:
AnnotationObjectA
VoxelSelectionis anAnnotationObjectwhich draws selected voxels from aselection.Selectioninstance. ASelectionTextureis used to draw the selected voxels.- __init__(annot, selection, overlay, offsets=None, **kwargs)[source]
Create a
VoxelSelectionannotation.- Parameters:
annot – The
Annotationsobject that owns thisVoxelSelection.selection – A
selection.Selectioninstance which defines the voxels to be highlighted.overlay – A
Niftiinstance which is used for its voxel-to-display transformation matrices.offsets – If
None(the default), theselectionmust have the same shape as the image data being annotated. Alternately, you may setoffsetsto a sequence of three values, which are used as offsets for the xyz voxel values. This is to allow for a sub-space of the full image space to be annotated.
All other arguments are passed through to the
AnnotationObject.__init__()method.
- __createShader()
Called by
__init__(). Creates a shader program.
- destroy()[source]
Must be called when this
VoxelSelectionis no longer needed. Destroys theSelectionTexture.
- __annotations__ = {}
- __module__ = 'fsleyes.gl.annotations'
- property texture
Return the
SelectionTextureused by thisVoxelSelection.
- vertices2D(zpos, axes)[source]
Returns vertices and texture coordinates to draw this
VoxelSelection.
- draw2D(canvas, zpos, axes)[source]
Draw a
VoxelSelectionannotation.
- class fsleyes.gl.annotations.TextAnnotation(*args, **kwargs)[source]
Bases:
AnnotationObjectA
TextAnnotationis anAnnotationObjectwhich draws afsleyes.gl.text.Textobject.The
Textclass allows the text position to be specified as either x/y proportions, or as absolute pixels. TheTextAnnotationclass adds an additional option to specify the location in terms of a 3D position in the display coordinate system.This can be achieved by setting
coordinatesto'display', and settingposto the 3D position in the display coordinate system.- __annotations__ = {}
- __module__ = 'fsleyes.gl.annotations'
- __init__(annot, text=None, x=None, y=None, off=None, coordinates='proportions', fontSize=10, halign=None, valign=None, colour=None, **kwargs)[source]
Create a
TextAnnotation.- Parameters:
annot – The
Annotationsobject that owns thisTextAnnotation.
See the
Textclass for details on the other arguments.
- text
Text to draw.
- fontSize
Text font size in points. The size of the text annotation is kept proportional to the canvas zoom level.
- property gltext