Common base API

Inheritance diagram of anatomist.base.Anatomist

General interface of pyanatomist API. It describes classes and methods that are shared by all implementations: the set of Anatomist features available throught this API.

Several implementations exist depending on the mean of driving Anatomist (Sip bindings C++/Python or commands via socket).

class anatomist.base.Anatomist
class anatomist.base.Anatomist.AObject
class anatomist.base.Anatomist.AWindow
class anatomist.base.Anatomist(*args, **kwargs)[source]

Interface to communicate with an Anatomist Application. This class is virtual, some methods are not implemented. It is the base class of Anatomist classes in each implementation.

This class is a Singleton, so there is only one global instance of this class. The first time the constructor is called, an instance is created. Each next time, the same instance is returned. It is also possible to ask for anatomist instance without creating an instance if it does not exit. To do this, use the constructor with create=False as parameter :

>>> a=anatomist.Anatomist(create=False)

will return the current instance or None if no instance exists.

This class can notify anatomist events. To call a function when an event occurs, add a listener to one of Anatomist’s notifiers.

For example:

>>> anatomist.onLoadNotifier.add(listener)

listener must be a callback function that accepts two parameters : the event name (string) and a dictionary of parameters describing the event.

onLoadNotifier

Notifies object loading. Event parameters: {'filename': string, 'object': AObject, 'type': string}

Type

soma.notification.ObservableNotifier

onDeleteNotifier

Notifies object deletion. Event parameters: {'object': AObject}

Type

soma.notification.ObservableNotifier

onFusionNotifier

Notifies objects fusion. Event parameters: {'children': list of AObject, 'method': string, 'object': AObject, 'type': string}

Type

soma.notification.ObservableNotifier

onCreateWindowNotifier

Notifies window creation. Event parameters: {'type': string, 'window': AWindow }

Type

soma.notification.ObservableNotifier

onCloseWindowNotifier

Notifies window closing. Event parameters: {'window': AWindow}

Type

soma.notification.ObservableNotifier

onAddObjectNotifier

Notifies object adding in window. Event parameters: {'object': AObject, 'window': AWindow}

Type

soma.notification.ObservableNotifier

onRemoveObjectNotifier

Notifies object removing from window. Event parameters: {'object': AObject, 'window': AWindow}

Type

soma.notification.ObservableNotifier

onCursorNotifier

Notifies cursor position change. Event parameters: {'position': float vector size 4, 'window': AWindow}

Type

soma.notification.ObservableNotifier

onExitNotifier

Notifies that Anatomist application exits.

Type

soma.notification.ObservableNotifier

centralRef

Anatomist central referential (talairach acpc ref)

Type

Referential

mniTemplateRef

Template mni referential (used by spm)

These two referentials and transformation between them are always loaded in anatomist.

Type

Referential

defaultRefType

Reference type taken by default on anatomist objects. Strong means that objects or windows cannot be deleted while a reference exist on it.

Type

str

lock

Enable to take a lock on anatomist singleton instance

Type

threading.RLock()

The __init__ method of Singleton derived class should do nothing. Derived classes must define __singleton_init__() instead of __init__.

class AGraph(anatomistinstance, internalRep=None, *args, **kwargs)[source]

Graph object in Anatomist.

If internal rep is given as parameter, the corresponding anatomist object already exists: take a reference on it (to prevent its deletion).

createNode(name=None, syntax=None, with_bucket=None, duplicate=True)[source]

Creates a new node with optionally an empty bucket inside and adds it in the graph.

Parameters
  • name (str) – node name. default is RoiArg.

  • syntax (str) – node syntax attribute. default is roi.

  • with_bucket (bool) – if True, creates an empty bucket in the node and returns it with the node. default is None, so the bucket is created but not returned

  • duplicate (bool) – enables duplication of nodes with the same name attribute.

Returns

node – (the created node, the created bucket) or only the created node if with_bucket is False

Return type

(AObject, AObject)

class AItem(anatomistinstance, internalRep=None, refType=None, *args, **kwargs)[source]

Base class for representing an object in Anatomist application.

anatomistinstance

Reference to Anatomist object which created this object. Useful because some methods defined in AItem objects will need to send a command to the Anatomist application.

Type

Anatomist

internalRep

Representation of this object in anatomist application.

Type

object

ref

Indicates if a reference has been taken on the corresponding anatomist object. If True, the reference is released on deleting this item.

Type

bool

refType

Type of reference taken on the object : Weak (reference counter not incremented), WeakShared (reference counter incremented but the object can be deleted even if it remains references) or Strong (reference counter is incremented, the object cannot be deleted since there are references on it). If it is not specified, Anatomist.defaultRefType is used.

Type

str

getInfo()[source]

Gets information about this object.

Returns

info – information about the object (property -> value)

Return type

dictionary

getInfos()[source]

Obsolete - now use getInfo()

getInternalRep()[source]

Returns internal representation of the object (implementation dependant).

getRef(refType)[source]

Get a reference of type refType on this object.

Returns

ref – A copy of current object with a reference of type refType on anatomist object.

Return type

AItem

releaseAppRef()[source]

Release anatomist application reference on this object: so object life is controled by references on it. If there is no more references on the object, it is deleted. Used when an object is created by python api. It is not owned by anatomist application.

releaseRef()[source]

Release a reference on this object.

takeAppRef()[source]

Take anatomist application reference on this object : so object life is controled the normal way by Anatomist. Inverse of releaseAppRef(). The object is now owned by anatomist application.

takeRef()[source]

Take a reference on this object.

class AObject(anatomistinstance, internalRep=None, *args, **kwargs)[source]

Represents an object in Anatomist application.

Following information can be obtained using ObjectInfo command :

objectType

object type. For example: volume, bucket, graph, texture…

Type

str

children

List of objects which are children of current object (for example: nodes in a graph). Can be empty.

Type

list of Anatomist.AObject

filename

Name of the file from which the object has been loaded. May be None.

Type

str

name

Name of the object presented in Anatomist window.

Type

str

copy

True indicates that this object is a copy of another object, otherwise it is the original object.

Type

bool

material

Object material parameters

Type

Anatomist.Material

referential

Referential assigned to this object.

Type

Anatomist.Referential

If internal rep is given as parameter, the corresponding anatomist object already exists: take a reference on it (to prevent its deletion).

addInWindows(windows, temporary=False, position=- 1)[source]

Adds the object in windows. Windows must already exist.

Parameters
  • windows (list of Anatomist.AWindow) – List of windows in which the object must be added

  • temporary (bool (optional)) – temporary object do not affect the view boundaries and camera settings

  • position (int (optional)) – insert objects as this order number

applyBuiltinReferential()

Extract information about referential and transformations from the header of the object and assign the found referential.

assignReferential(referential)[source]

Assign a referential to object. The referential must exist. To create a new Referential, execute createReferential, to assign the central referential, first get it with Anatomist.centralRef attribute.

Parameters

referential (Referential) – The referential to be assigned to the object

delete()[source]

Deletes object

exportTexture(filename, time=None)[source]

Saves the texture of an object to a file

Parameters
  • filename (str) – File in which the texture must be written

  • time (float) – For temporal objects, if this parameter is mentionned the texture will be extracted at this time. if not mentionned, all times will be extracted and the texture will be a temporal object.

extractTexture(time=None)[source]

Extract the object texture to create a new texture object.

Parameters

time (float) – For temporal objects, if this parameter is mentionned the texture will be extracted at this time. if not mentionned, All times will be extracted and the texture will be a temporal object. In socket implementation, it is necessary to get a new id for the texture object and to pass it to the command.

Returns

texture – The newly created texture object

Return type

AObject

generateTexture(dimension=1)[source]

Generates an empty texture (value 0 everywhere) for a mesh object.

Parameters

dimension (int) – Texture dimension (1 or 2)

Returns

texture – The newly created texture object

Return type

AObject

getWindows()[source]

Gets windows that contain this object.

Returns

windows – Open windows that contain this object.

Return type

list of Anatomist.AWindow

loadReferentialFromHeader()[source]

Extract information about referential and transformations from the header of the object and assign the found referential.

reload()[source]

Reload this object already in memory reading its file.

removeFromWindows(windows)[source]

Removes object from windows.

Parameters

windows (list of Anatomist.AWindow) – List of windows from which the object must be removed

save(filename=None)[source]

Saves object in a file.

Parameters

filename (str) – File in which the object will be written. If not mentionned, the object is saved in the file from which it has been loaded.

setMaterial(material=None, refresh=True, ambient=None, diffuse=None, emission=None, specular=None, shininess=None, lighting=None, smooth_shading=None, polygon_filtering=None, depth_buffer=None, face_culling=None, polygon_mode=None, unlit_color=None, line_width=None, ghost=None, front_face=None, selectable_mode=None, use_shader=None, shader_color_normals=None, normal_is_direction=None)[source]

Changes object material properties.

Parameters
  • material (Material) – Material characteristics, including render properties. The material may be specified as a Material object, or as its various properties (ambient, diffuse, etc.). If both a material parameter and other properties are specified, the material is used as a base, and properties are used to modify it

  • refresh (bool) – If True, force windows refreshing

  • ambient (list) – RGB[A] vector: float values between 0 and 1.

  • diffuse (list) – RGB[A] vector: float values between 0 and 1. This parameter corresponds to the “standard” notion of color

  • emission (list) – RGB[A] vector: float values between 0 and 1.

  • specular (list) – RGB[A] vector: float values between 0 and 1.

  • shininess (float) – 0-124

  • lighting (int) – enables (1) or disables (0) objects lighting/shading. Setting this value to -1 goes back to the default mode (globally set at the view/scene level).

  • smooth_shading (int) – (tristate: 0/1/-1) smooth or flat polygons mode

  • polygon_filtering (int) – (tristate: 0/1/-1) filtering (antialiasing) of lines/polygons

  • depth_buffer (int) – (tristate: 0/1/-1) enables/disables writing in the Z-buffer. You can disable it if you want to click “through” an object (but it may have strange effects on the rendering)

  • face_culling (int) – (tristate: 0/1/-1) don’t draw polygons seen from the back side. The best is to enable it for transparent objects, and to disable it for “open” (on which both sides may be seen) and opaque meshes. For objects both open and transparent, there is no perfoect setting…

  • polygon_mode (string) – polygons rendering mode: “normal”, “wireframe”, “outline” (normal + wireframe), “hiddenface_wireframe” (wireframe with hidden faces), “default” (use the global view settings), “ext_outlined” (thickened external boundaries + normal rendering).

  • unlit_color (RGB[A] vector: float values between 0 and 1.) – color used for lines when lighting is off. For now it only affects polygons boundaries in “outlined” or “ext_outlined” polygon modes.

  • line_width (float) – Lines thickness (meshes, segments, wireframe rendering modes). A null or negative value fallsback to default (1 in principle).

  • front_face (string) – Specifies if the mesh(es) polygons external face is the clockwise or counterclockwise side. Normally in Aims/Anatomist indirect referentials, polygons are in clockwise orientation. Values are “clockwise”, “counterclockwise”, or “neutral” (the default).

  • selectable_mode (string) –

    New in Anatomist 4.5. Replaces the ghost property.

    always_selectable:

    object is selecatble whatever its opacity.

    ghost:

    object is not selectable.

    selectable_when_opaque:

    object is selectable when totally opaque (this is the default in Anatomist).

    selectable_when_not_totally_transparent:

    object is selectable unless opacity is zero.

  • use_shader (int) – enable or disable the use of OpenGL shaders for this object.

  • shader_color_normals (int) – when shaders are enabled, normals can be represented as colors on the object.

  • normal_is_direction (int) – when shaders are enabled and shader_color_normals is set, normals may be pre-calculates as mesh direction, on a “line” mesh (polygons are lines, not triangles).

setPalette(palette=None, minVal=None, maxVal=None, palette2=None, minVal2=None, maxVal2=None, mixMethod=None, linMixFactor=None, palette1Dmapping=None, absoluteMode=False, zeroCentered1=None, zeroCentered2=None)[source]

Assign a palette to object, or change its characteristics (scaling etc).

Parameters
  • palette (Anatomist.APalette or str (name)) – Principal palette to apply

  • minVal (float) – Minimum object texture value mapped to the lower bound of the palette, by default in relative proportional mode.

  • maxVal (float) –

    Minimum object texture value mapped to the lower bound of the palette.

    By default minVal, maxVal, minVal2 and maxVal2 are relative values expressed in proportion of object texture extrema: [0-1] corresponds to the whole object dynamics. If absoluteMode is True, then values are in object texture values space. The range [minVal-maxVal] is mapped to the while palette, thus any value below or over these extrema will get the first or last (resp.) color of the palette. Values outside [0-1] may be used, meaning that not all the palette colors range will be mapped to the texture values.

  • palette2 (APalette) – Second palette, for 2D textures

  • minVal2 (float (0 - 1)) – Second palette value to affect to object texture second component min value

  • maxVal2 (float (0 - 1)) – Second palette value to assign to object texture second component max value

  • mixMethod (string) – Method to mix two palettes in a 2D palette: linear or geometric

  • linMixFactor (float) – mix factor for the linear method

  • palette1Dmapping (string) – way of using 2D palette for 1D texture : FirstLine or Diagonal

  • absoluteMode (bool) – if True, min/max values are supposed to be absolute values (in regard to objects texture) rather than proportions

  • zeroCentered1 (bool) – min/max should be updated to keep absolute value 0 at the center of the palette (for palette 1).

  • zeroCentered2 (bool) – min/max should be updated to keep absolute value 0 at the center of the palette (for palette 2).

class APalette(name, anatomistinstance, internalRep=None, *args, **kwargs)[source]
name

Palette name. Must be unique, it is the palette identifier.

Type

str

setColors(colors, color_mode='RGB')[source]

Modifies a palette (colors).

Parameters
  • colors (list of int) – Color vectors, in line (a list of R, G, B, R, G, B… or R, G, B, A, ..), as int 8 bit values

  • color_mode (str) – 'RGB' or 'RGBA'

class AWindow(anatomistinstance, internalRep=None, *args, **kwargs)[source]

Represents an anatomist window.

windowType

Window type ('axial', 'sagittal', …)

Type

str

group

The group which this window belongs to.

Type

Anatomist.AWindowsGroup

objects

The window contains these objects.

Type

List of Anatomist.AObject

block

The block in which the window is contained, None if it is not in a block.

Type

Anatomist.AWindowsBlock

If internal rep is given in parameter, the corresponding anatomist window already exists : take a reference on it (to prevent its deletion).

activateAction(action_type, method, **kwargs)[source]

Triggers window action activation.

New in Anatomist 4.5.

Parameters
  • action_type (str (mandatory)) – type of action: “key_press”, “key_release”, “mouse_press”, “mouse_release”, “mouse_double_click”, “mouse_move”. Additional parameters depend on the action type: * key actions do not use any; * mouse actions need x and y keyword parameters

  • method (str (mandatory)) – action method name, as registered in the active control. Deteremines what will actually be done.

  • x (int (optional)) – x mouse coord, for mouse actions only.

  • y (int (optional)) – y mouse coord, for mouse actions only.

addObjects(objects, add_children=False, add_graph_nodes=True, add_graph_relations=False, temporary=False, position=- 1)[source]

Adds objects in window.

Parameters
  • objects (list of Anatomist.AObject) – List of objects to add

  • temporary (bool (optional)) – temporary object do not affect the view boundaries and camera settings

  • position (int (optional)) – insert objects as this order number

assignReferential(referential)[source]

Assign a referential to window. The referential must exist. To create a new Referential, execute createReferential, to assign the central referential, first get it with Anatomist.centralRef attribute.

Parameters

referential (Anatomist.Referential) – The referential to assign to objects and/or windows

camera(zoom=None, observer_position=None, view_quaternion=None, slice_quaternion=None, force_redraw=None, cursor_position=None, boundingbox_min=None, boundingbox_max=None, slice_orientation=None)[source]

Sets the point of view, zoom, cursor position for a 3D window.

Parameters
  • zoom (float) – Zoom factor, default is 1

  • observer_position (float vector, size 3) – Camera position

  • view_quaternion (float vector, size 4, normed) – View rotation

  • slice_quaternion (float vector, size 4, normed) – Slice plan rotation

  • force_redraw (bool) – If True, refresh printing immediatly, default is False

  • cursor_position (float vector) – Linked cursor position

  • boundingbox_min (float vector) – Bounding box min values

  • boundingbox_max (float vector) – Bounding box max values

  • slice_orientation (float vector, size 3) – Slice plane orientation, normal to the plane

close()[source]

Closes window.

getReferential()[source]

Get the referential attached to the window (the coordinates system used for 3D positions in this window)

moveLinkedCursor(position)[source]

Changes cursor position in this window and all linked windows (same group).

Parameters

position (float vector, size 3) – Cursor new position

removeObjects(objects)[source]

Removes objects from window.

Parameters

objects (list of Anatomist.AObject) – List of objects to remove

setControl(control)[source]

Changes the selected button in windows menu. Examples of controls : 'PaintControl', 'NodeSelectionControl', 'Default 3D Control', 'Selection 3D', 'Flight Control', 'ObliqueControl', 'TransformationControl', 'CutControl', 'Browser Selection', 'RoiControl'

showToolbox(show=True)[source]

Shows or hides the toolbox frame of a window.

Parameters

show (bool) – If True, the window’s toolbox frame is shown, else it is hidden.

snapshot(filename, width=None, height=None)[source]

Take a snapshot of the window 3D contents and save it into a file

Equivalent to:

window.windowConfig(snapshot=filename, snapshot_width=width,
                    snapshot_height=height)
Parameters
  • filename (str) – file name to save the snapshot into

  • width (int) – width of the snapshot. If unspecified, or if framebuffer rendering is not supported by the OpenGL implementation, the width will always be the actual visible window width.

  • height (int) – height of the snapshot. If unspecified, or if framebuffer rendering is not supported by the OpenGL implementation, the height will always be the actual visible window height.

windowConfig(clipping=None, clip_distance=None, cursor_visibility=None, face_culling=None, flat_shading=None, fog=None, geometry=None, iconify=None, light=None, linkedcursor_on_slider_change=None, perspective=None, perspective_angle=None, perspective_auto_far_plane=None, perspective_far_distance=None, perspective_near_ratio=None, polygon_filtering=None, polygon_mode=None, polygons_depth_sorting=None, raise_window=None, record_basename=None, record_mode=None, snapshot=None, transparent_depth_buffer=None, view_size=None, fullscreen=None, show_cursor_position=None, show_toolbars=None, snapshot_width=None, snapshot_height=None)[source]

Settings for windows (includes various settings)

Parameters
  • clipping (int (optional)) – number of clipping planes: 0, 1 or 2

  • clip_distance (float (optional)) – distance between the slice plane and the clipping planes

  • cursor_visibility (int (optional)) – makes visible (1) or invisible (0) the linked cursor in the chosen windows. The value -1 sets back the global setting (of the preferences)

  • face_culling (int (optional)) – enables (1) or disables (0) the elimination of polygons seen from the bottom face

  • flat_shading (int (optional)) – enables (1) or disables (0) rendering in “flat shading” mode (without color smoothing)

  • fog (int (optional)) – enables (1) or disables (0) fog

  • geometry (list of int (optional)) – position and size of the window (external size). If sizes are zero or not specified, the current window size is not changed

  • iconify (int (optional)) – iconifies (or hides) windows

  • light (dict (optional)) –

    Windows lighting settings. This dictionary may include the following parameters: ubublle

    • ambient: ambiant lighting settings (list of float, 4 elements)

    • diffuse: diffuse lighting settings (list of float, 4 elements)

    • specular: specular lighting settings (list of float, 4 elements)

    • background: background color (list of float, 4 elements)

    • position: light position (list of float, 4 elements)

    • spot_direction: spot light direction (list of float, 3 elements)

    • spot_exponent: spot light intensity exponent (float)

    • spot_cutoff: spot light cutoff angle (float)

    • attenuation_offset: light attenuation, offset part ( float)

    • attenuation_linear: light attenuation, linear coefficient (float)

    • attenuation_quadratic: light attenuation, quadratic coefficient (float)

    • model_ambient: don’t really know… (list of float, 4 elements)

    • model_local_viewer: don’t really know… (float)

    • model_two_side: don’t really know (float)

  • linkedcursor_on_slider_change (int (optional)) – enables or disables the mode when slice/time sliders act as linked cursor actions (with propagation to other views)

  • perspective (int (optional)) – enables (1) or disables (0) the perspective rendering mode

  • perspective_angle (float (optional)) – set the perspective view angle (low: more isometric, high: more distorted). Only used when perspective is enabled.

  • perspective_auto_far_plane (int (optional)) – enables (1) or disables (0) the automatic perspective far clipping plane setup. Only used when perspective is enabled.

  • perspective_far_distance (float (optional)) – set the clipping distance from the eye. Only used when perspective is enabled and perspective_auto_far_plane is disabled.

  • perspective_near_ratio (float (optional)) – set the minimum ratio between the near clipping plane distance and the far one. Objects nearer than this near plane will not be displayed. But reducing this ratio lowers the precision of the depth buffer. Default is 0.01. Only used when perspective is enabled.

  • polygon_filtering (int (optional)) – enables (1) or disables (0) polygons and lines smoothing (anti- aliasing)

  • polygon_mode (string (optional)) – polygons rendering mode: “normal”, “wireframe”, “outline” (normal + wireframe), “hiddenface_wireframe” (wireframe with hidden faces)

  • polygons_depth_sorting (int (optional)) – enables (1) or disables (0) polygons sortig along depth on transparent objects to allow a better rendering. This mode has a large impact on performances, so use it with care.

  • raise_window (int (optional)) – unicognifies windows and make them move to the top of the desktop. Note that this parameter has a different name as the anatomist command interface (is was “raise” there) because “raise” is a reserved keyword in Python and cannot be used here.

  • record_basename (string (optional):) – base filename of images written using the film recording mode (ex: /tmp/toto.jpg). Images will actually have numbers appended before the extension

  • record_mode (int (optional)) – enables (1) or disables (0) the images recording mode (film) of 3D windows. To enable it, record_basename must also be specified

  • snapshot (string (optional)) – Saves the image of the view in the specified file. If windows contains several values, then several images have to be saved: in this case, snapshot is a list of filenames separated by space characters: so the file name/path must not contain any space character (this restriction doesn’t apply if a single window is used). Node: escape character (”“) are not supported yet.

  • snapshot_width (int (optional)) – Snapshot or recorded images width. If unspecified, fit the window size. New in Anatomist 4.6.

  • snapshot_height (int (optional)) – Snapshot or recorded images height. If unspecified, fit the window size. New in Anatomist 4.6.

  • transparent_depth_buffer (int (optional)) – enables (1) or disables (0) writing of transparent objects in the depth buffer. Useful if you want to click across transparents objects (but the rendering can be wrong)

  • view_size (list of int (optional)) – size of the rendering zone (3D rendering widget). This parameter has a higher priority than sizes given using geometry if both are specified

  • fullscreen (int (optional)) – enables or disables the fullscreen mode

  • show_cursor_position (int (optional)) – shows or hides the status bar at the bottom of the window, showing the cursor position and a current object value at this position.

  • show_toolbars (int (optional)) – shows or hides everything around the 3D view (menus, buttons bars, status bar, referential…)

class AWindowsBlock(anatomistinstance=None, internalRep=None, nbCols=0, nbRows=0, *args, **kwargs)[source]

A window containing other windows.

nbCols

Number of columns of the windows block

Type

int

class AWindowsGroup(anatomistinstance, internalRep=None, *args, **kwargs)[source]

A group containing several windows which are linked. Moving cursor in one window moves it in all linked windows. Its internalRep is the group id (int).

addToSelection(objects)[source]

Adds objects to this windows group’s current selection.

Parameters

objects (list of Anatomist.AObject) – Objects to add to selection

addToSelectionByNomenclature(nomenclature, names)[source]

Adds objects to this windows group’s current selection, given their name in a nomenclature.

Parameters
  • nomenclature (AObject) – Tree with names and labels associated to nodes.

  • names (list of str) – Names of elements to add to selection.

getSelection()[source]
Returns

objects – Objects that are selected in this windows group

Return type

list of Anatomist.AObject

isSelected(object)[source]
Parameters

object (AObject) – An object in this windows group

Returns

selectedTrue if the object is selected in this windows group

Return type

bool

setSelection(objects)[source]

Initializes selection with given objects for this windows group.

Parameters

objects (list of Anatomist.AObject) – Objects to select

setSelectionByNomenclature(nomenclature, names)[source]

Selects objects giving their name in a nomenclature. In anatomist graphical interface, it is done by clicking on items of a nomenclature opened in a browser.

Parameters
  • nomenclature (AObject) – tree with names and labels associated to nodes.

  • names (list of str) – Names of elements to select.

toggleSelection(objects)[source]

Inverses selection in this windows group. Selected objects becomes unselected, unselected objects become selected.

toggleSelectionByNomenclature(nomenclature, names)[source]

Removes objects from this windows group’s selection, given their name in a nomenclature.

Parameters
  • nomenclature (AObject) – Tree with names and labels associated to nodes.

  • names (list of str) – Names of elements to unselect.

unSelect(objects)[source]

Removes objects from this windows group selection.

Parameters

objects (list of Anatomist.AObject) – Objects to unselect

class Material(ambient=None, diffuse=None, emission=None, shininess=None, specular=None, lighting=None, smooth_shading=None, polygon_filtering=None, depth_buffer=None, face_culling=None, polygon_mode=None, unlit_color=None, line_width=None, ghost=None, front_face=None, selectable_mode=None, use_shader=None, shader_color_normals=None, normal_is_direction=None)[source]
ambient

RGB[A] vector: float values between 0 and 1.

Type

list

diffuse

RGB[A] vector: float values between 0 and 1. This parameter corresponds to the “standard” notion of color

Type

list

emission

RGB[A] vector: float values between 0 and 1.

Type

list

specular

RGB[A] vector: float values between 0 and 1.

Type

list

shininess

0-124

Type

float

lighting

enables (1) or disables (0) objects lighting/shading. Setting this value to -1 goes back to the default mode (globally set at the view/scene level).

Type

int

smooth_shading

(tristate: 0/1/-1) smooth or flat polygons mode

Type

int

polygon_filtering

(tristate: 0/1/-1) filtering (antialiasing) of lines/polygons

Type

int

depth_buffer

(tristate: 0/1/-1) enables/disables writing in the Z-buffer. You can disable it if you want to click “through” an object (but it may have strange effects on the rendering)

Type

int

face_culling

(tristate: 0/1/-1) don’t draw polygons seen from the back side. The best is to enable it for transparent objects, and to disable it for “open” (on which both sides may be seen) and opaque meshes. For objects both open and transparent, there is no perfoect setting…

Type

int

polygon_mode

polygons rendering mode: “normal”, “wireframe”, “outline” (normal + wireframe), “hiddenface_wireframe” (wireframe with hidden faces), “default” (use the global view settings), “ext_outlined” (thickened external boundaries + normal rendering).

Type

string

unlit_color

color used for lines when lighting is off. For now it only affects polygons boundaries in “outlined” or “ext_outlined” polygon modes.

Type

RGB[A] vector: float values between 0 and 1.

line_width

Lines thickness (meshes, segments, wireframe rendering modes). A null or negative value fallsback to default (1 in principle).

Type

float

front_face

Specifies if the mesh(es) polygons external face is the clockwise or counterclockwise side. Normally in Aims/Anatomist indirect referentials, polygons are in clockwise orientation. Values are “clockwise”, “counterclockwise”, or “neutral” (the default).

Type

string

selectable_mode

New in Anatomist 4.5. Replaces the ghost property.

always_selectable:

object is selecatble whatever its opacity.

ghost:

object is not selectable.

selectable_when_opaque:

object is selectable when totally opaque (this is the default in Anatomist).

selectable_when_not_totally_transparent:

object is selectable unless opacity is zero.

Type

string

use_shader

enable or disable the use of OpenGL shaders for this object.

Type

int

shader_color_normals

when shaders are enabled, normals can be represented as colors on the object.

Type

int

normal_is_direction

when shaders are enabled and shader_color_normals is set, normals may be pre-calculates as mesh direction, on a “line” mesh (polygons are lines, not triangles).

Type

int

class Referential(anatomistinstance, internalRep=None, uuid=None, *args, **kwargs)[source]
refUuid

A unique id representing this referential Two referentials are equal if they have the same uuid.

Type

str

class Transformation(anatomistinstance, internalRep=None, *args, **kwargs)[source]

This objects contains information to convert coordinates from one referential to another.

save(filename)[source]

Saves transformation in a file.

Parameters

filename (str) – File in which the transformation will be written.

addObjects(objects, windows, add_children=False, add_graph_nodes=True, add_graph_relations=False, temporary=False, position=- 1)[source]

Adds objects in windows. The objects and windows must already exist.

Parameters
  • objects (list of AObject) – List of objects to add

  • windows (list of AWindow) – List of windows in which the objects must be added

  • add_children (bool (optional)) – if children objects should also be added individually after their parent

  • add_graph_relations (bool (optional)) – if graph relations should be also be added

  • temporary (bool (optional)) – temporary object do not affect the view boundaries and camera settings

  • position (int (optional)) – insert objects as this order number

applyBuiltinReferential(objects)

Extracts referentials / transformations from objects headers when they contain such information, and assign them.

Parameters

objects (list of AObject) – Objects which referential information must be loaded

assignReferential(referential, elements)[source]

Assign a referential to objects and/or windows. The referential must exist. To create a new Referential, execute createReferential, to assign the central referential, first get it with Anatomist.centralRef attribute.

Parameters
  • referential (Referential) – The referential to assign to objects and/or windows

  • elements (list of AItem) – Objects or windows which referential must be changed. The corresponding command tree contains an attribute central_ref to indicate if the referential to assign is anatomist central ref, because this referential isn’t referenced by an id. In the socket implementation, Referential object must have an attribute central_ref, in order to create the command message. In direct impl, it is possible to access directly to the central ref object.

camera(windows, zoom=None, observer_position=None, view_quaternion=None, slice_quaternion=None, force_redraw=False, cursor_position=None, boundingbox_min=None, boundingbox_max=None, slice_orientation=None)[source]

Sets the point of view, zoom, cursor position for 3D windows.

Parameters
  • windows (list of AWindow) – Windows which options must be changed

  • zoom (float) – Zoom factor, default is 1

  • observer_position (float vector, size 3) – Camera position

  • view_quaternion (float vector, size 4, normed) – View rotation

  • slice_quaternion (float vector, size 4, normed) – Slice plane rotation

  • force_redraw (bool) – If True, refresh printing immediatly, default is False

  • cursor_position (float vector) – Linked cursor position

  • boundingbox_min (float vector) – Bounding box min values

  • boundingbox_max (float vector) – Bounding box max values

  • slice_orientation (float vector, size 3) – Slice plane orientation, normal to the plane

close()[source]

Exits Anatomist application. if anatomist is closed, the singleton instance is deleted. So next time the constructor is called, a new instance will be created.

closeWindows(windows)[source]

Closes windows.

Parameters

windows (list of AWindow) – Windows to be closed

convertParamsToIDs(params)[source]

Converts current api objects to corresponding anatomist object representation. This method must be called before sending a command to anatomist application on command parameters.

Parameters

params (dict or list) – Elements to convert

Returns

elements – Converted elements

Return type

dict or list

convertSingleObjectParamsToIDs(item)[source]

Converts current api object to corresponding anatomist object representation.

Parameters

item (AItem) – Element to convert

Returns

elements – Converted elements

Return type

dict or list

createControlWindow()[source]

Creates anatomist main window. Currently it is done automatically.

createGraph(object, name=None, syntax=None, filename=None)[source]

Creates a graph associated to an object (volume for example). This object initializes the graph dimensions (voxel size, extrema).

Parameters
  • object (AObject) – The new graph is based on this object

  • name (str) – Graph name. default is 'RoiArg'.

  • syntax (str) – Graph syntactic attribute. default is 'RoiArg'.

  • filename (str) – Filename used for saving. Default is None.

Returns

graph – The new graph object

Return type

AGraph

createPalette(name)[source]

Creates an empty palette and adds it in the palettes list.

Parameters

name (str) – Name of the new palette

Returns

palette – The newly created palette

Return type

APalette

createReferential(filename=None)[source]

This command does not exist in Anatomist because the command AssignReferential can create a new referential if needed. But the way of creating a new referential depends on the connection with Anatomist, so it seems to be better to encapsulate this step on another command. So referentials are treated the same as other objects. (LoadObject -> addAobject | createReferential -> assignReferential)

Parameters

filename (str) – Name of a file (minf file, extension .referential) containing information about the referential: its name and uuid

Returns

ref – The newly created referential

Return type

Referential

createTransformation(matrix, origin, destination)[source]

Creates a transformation from a referential to another. The transformation informations are given in a matrix.

Parameters
  • matrix (float vector, size 12) – Transformation matrix (4 lines, 3 colons; 1st line: translation, others: rotation)

  • origin (Referential) – Origin of the transformation

  • destination (Referential) – Referential after applying transformation

Returns

trans – New transformation

Return type

Transformation

createWindow(wintype, geometry=None, block=None, no_decoration=None, options=None)[source]

Creates a new window and opens it.

Parameters
  • wintype (str) – Type of window to open ("Axial", "Sagittal", "Coronal", "3D", "Browser", "Profile", …)

  • geometry (int vector) – Position on screen and size of the new window (x, y, w, h)

  • block (AWindowsBlock) – A block in which the new window must be added

  • no_decoration (bool) – Indicates if decorations (menus, buttons) can be painted around the view.

  • options (dict) – Internal advanced options.

Returns

window – The newly created window

Return type

AWindow

createWindowsBlock(nbCols=None, nbRows=None)[source]

Creates a window containing other windows.

Parameters
  • nbCols (int) – Number of columns of the windows block

  • nbRows (int) – Number of rows of the windows block (exclusive with nbCols)

Returns

block – A window which can contain several AWindow

Return type

AWindowsBlock

deleteElements(elements)[source]

Deletes objects, windows, referentials, anything that is referenced in anatomist application.

Parameters

elements (list of AItem) – Elements to delete

deleteObjects(objects)[source]

Deletes objects

Parameters

objects (list of AObject) – Objects to delete

disableListening(event)[source]

Set listening of this event off.

Parameters

event (str) – Name of the event to disable.

duplicateObject(source, shallowCopy=True)[source]

Creates a copy of source object.

Parameters

source (AObject) – The object to copy.

Returns

object – The copy

Return type

AObject

enableListening(event, notifier)[source]

Set listening of this event on. So when the event occurs, the notifier’s notify method is called. This method is automatically called when the first listener is added to a notifier. That is to say that notifiers are activated only if they have registered listeners.

Parameters
  • event (str) – Name of the event to listen

  • notifier (soma.notification.Notifier) – The notifier whose notify method must be called when this event occurs

execute(command, **kwargs)[source]

Executes a command in anatomist application. It should be a command that can be processed by Anatomist command processor. The list of available commands is in the commands system. Parameters are converted before sending the request to anatomist application.

Parameters
  • command (str) – Name of the command to execute.

  • kwargs (dict) – Parameters for the command

fusionObjects(objects, method=None, ask_order=False)[source]

Creates a fusionned multi object that contains all given objects.

Parameters
  • objects (list of AObject) – List of objects that must be fusionned

  • method (str) – Method to apply for the fusion ('Fusion2DMethod'…)

  • ask_order (bool) – If True, asks user in what order the fusion must be processed.

Returns

object – The newly created fusion object.

Return type

AObject

getAimsInfo()[source]
Returns

info – Information about AIMS library.

Return type

str

getCommandsList()[source]
Returns

commands – List of commands available in Anatomist with their parameters. dict command name -> dict parameter name -> dict attribute -> value (needed, type)

Return type

dict

getDefaultWindowsGroup()[source]

Normally returns 0

getFusionInfo(objects=None)[source]

Gets information about fusion methods. If objects is not specified, the global list of all fusion methods is returned. Otherwise the allowed fusions for those specific objects is returned.

Returns

info – Fusion methods

Return type

dict

getModulesInfo()[source]
Returns

modules – List of modules and their description. dict module name -> dict attribute -> value (description)

Return type

dict

getObject(filename)[source]

Get the object corresponding to this filename if it is currently loaded.

Parameters

filename (str) – Filename of the requested object

Returns

object – The object if it is loaded, else returns None.

Return type

AObject

getObjects()[source]

Gets all objects referenced in current context.

Returns

objects – List of existing objects

Return type

list of AObject

getPalette(name)[source]
Returns

palette – The named palette

Return type

APalette

getPalettes()[source]
Returns

palettes – List of palettes.

Return type

list of APalette

getReferentials()[source]

Gets all referentials in current context.

Returns

refs – List of referentials

Return type

list of Referential

getSelection(group=None)[source]
Parameters

group (AWindowsGroup) – Get the selection in this group. If None, returns the selection in the default group.

Returns

objects – The list of selected objects in the group of windows

Return type

list of AObject

getTransformations()[source]

Gets all transformations.

Returns

trans – List of transformations

Return type

list of Transformation

getVersion()[source]
Returns

version – Anatomist version

Return type

str

getWindows()[source]

Gets all windows referenced in current context.

Returns

windows – List of opened windows

Return type

list of AWindow

groupObjects(objects)[source]

Creates a multi object containing objects in parameters.

Parameters

objects (list of AObject) – Objects to put in a group

Returns

group – The newly created multi object

Return type

AObject

importObjects(top_level_only=False)[source]

Gets objects importing those that are not referenced in the current context.

Parameters

top_level_only (bool) – If True, imports only top-level objects (that have no parents), else all objects are imported.

Returns

objects – List of existing objects

Return type

list of AObject

importReferentials()[source]

Gets all referentials importing those that are not referenced in the current context.

Returns

refs – List of referentials

Return type

list of Referential

importTransformations()[source]

Gets all transformations importing those that are not referenced in the current context.

Returns

trans – List of transformations

Return type

list of Transformation

importWindows()[source]

Gets all windows importing those that are not referenced in the current context.

Returns

windows – List of opened windows

Return type

list of AWindow

linkCursorLastClickedPosition(ref=None)[source]

Gives the last clicked position of the cursor.

Parameters

ref (Referential) – If given, cursor position value will be in this referential. Else, anatomist central referential is used.

Returns

position – Last position of the cursor

Return type

float vector, size 3

linkWindows(windows, group=None)[source]

Links windows in a group. Moving cursor position in a window moves it in all linked windows. By default all windows are in the same group.

Parameters
  • windows (list of AWindow) – The windows to link

  • group (AWindowsGroup) – Put the windows in this group. If it is None, a new group is created.

loadCursor(filename)[source]

Loads a cursor for 3D windows from a file.

Parameters

filename (str) – The file containing object data

Returns

cursor – The loaded object

Return type

AObject

loadObject(filename, objectName=None, restrict_object_types=None, forceReload=True, duplicate=False, hidden=False)[source]

Loads an object from a file (volume, mesh, graph, texture…)

Parameters
  • filename (str) – The file containing object data

  • objectName (str) – Object name

  • restrict_object_types (dict) – object -> accpepted types list. Ex: {'Volume' : ['S16', 'FLOAT']}

  • forceReload (bool) – If True the object will be loaded even if it is already loaded in Anatomist. Otherwise, the already loaded one is returned.

  • duplicate (bool) – If the object already exists, duplicate it. The original and the copy will share the same data but not display parameters as palette. If the object is not loaded yet, load it hidden and duplicate it (unable to keep the original object with default display parameters).

  • hidden (bool) – a hidden object does not appear in Anatomist main control window.

Returns

object – The loaded object

Return type

AObject

loadReferentialFromHeader(objects)[source]

Extracts referentials / transformations from objects headers when they contain such information, and assign them.

Parameters

objects (list of AObject) – Objects which referential information must be loaded

loadTransformation(filename, origin, destination)[source]

Loads a transformation from a referential to another. The transformation informations are given in a file.

Parameters
  • filename (str) – File containing transformation information

  • origin (Referential) – Origin of the transformation

  • destination (Referential) – Referential after applying transformation

Returns

trans – Transformation to apply to convert coordinates from one referent

Return type

Transformation

log(message)[source]

Use this method to print a log message. This method prints on standard output. To be redefined for another type of log.

static makeList(thing)[source]

Transforms the argument into a list: a list with one element if it is not a sequence, or return the input sequence if it is already one

newItemRep()[source]

Creates a new item representation. This method depends on the mean of communication with anatomist. Must be redefined in implementation api.

reloadObjects(objects)[source]

Reload objects already in memory reading their files.

removeObjects(objects, windows, remove_children=False)[source]

Removes objects from windows.

Parameters
  • objects (list of AObject) – List of objects to remove

  • windows (list of AWindow) – List of windows from which the objects must be removed

send(command, **kwargs)[source]

Sends a command to anatomist application. Call this method if there is no answer to get. This method depends on the mean of communication with anatomist. Must be redefined in implementation api.

Parameters
  • command (str) – Name of the command to execute. Any command that can be processed by anatomist command processor. The complete commands list is in the commands system

  • kwargs (dict) – Parameters for the command

setGraphParams(display_mode=None, label_attribute=None, save_only_modified=None, saving_mode=None, selection_color=None, selection_color_inverse=None, set_base_directory=None, show_tooltips=None, use_nomenclature=None)[source]

Modifies graphs and selections options.

Parameters
  • display_mode (str) – Paint mode of objects in graph nodes : mesh, bucket, all, first

  • label_attribute (str) – Selects the attribute used as selection filter: label or name

  • save_only_modified (bool int (0/1)) – If enabled, graph save saves not all sub objects but only those that have been modified.

  • saving_mode (str) – Graph saving mode : unchanged (keep the reading format), global (1 file for all same category sub-objects), or local (1 file per sub- object)

  • selection_color (int vector) – Selected objects color : R G B [A [NA]] (A opacity, NA: 0/1 use object opacity parameter)

  • selection_color_inverse (bool int (0/1)) – Selection inverses color instead of using selection_color

  • set_base_directory (bool int (0/1)) – Save subobjects in a directory <graph name>.data

  • show_tooltips (bool int (0/1)) – Show graph nodes names in tooltips

  • use_nomenclature (bool int (0/1)) – Enable graph coloring with nomenclature

setMaterial(objects, material=None, refresh=True, ambient=None, diffuse=None, emission=None, specular=None, shininess=None, lighting=None, smooth_shading=None, polygon_filtering=None, depth_buffer=None, face_culling=None, polygon_mode=None, unlit_color=None, line_width=None, ghost=None, front_face=None, selectable_mode=None, use_shader=None, shader_color_normals=None, normal_is_direction=None)[source]

Changes objects material properties.

Parameters
  • objects (AObject or list) – objects to change material on.

  • material (Material) – Material characteristics, including render properties. The material may be specified as a Material object, or as its various properties (ambient, diffuse, etc.). If both a material parameter and other properties are specified, the material is used as a base, and properties are used to modify it

  • refresh (bool) – If True, force windows refreshing

  • ambient (list) – RGB[A] vector: float values between 0 and 1.

  • diffuse (list) – RGB[A] vector: float values between 0 and 1. This parameter corresponds to the “standard” notion of color

  • emission (list) – RGB[A] vector: float values between 0 and 1.

  • specular (list) – RGB[A] vector: float values between 0 and 1.

  • shininess (float) – 0-124

  • lighting (int) – enables (1) or disables (0) objects lighting/shading. Setting this value to -1 goes back to the default mode (globally set at the view/scene level).

  • smooth_shading (int) – (tristate: 0/1/-1) smooth or flat polygons mode

  • polygon_filtering (int) – (tristate: 0/1/-1) filtering (antialiasing) of lines/polygons

  • depth_buffer (int) – (tristate: 0/1/-1) enables/disables writing in the Z-buffer. You can disable it if you want to click “through” an object (but it may have strange effects on the rendering)

  • face_culling (int) – (tristate: 0/1/-1) don’t draw polygons seen from the back side. The best is to enable it for transparent objects, and to disable it for “open” (on which both sides may be seen) and opaque meshes. For objects both open and transparent, there is no perfoect setting…

  • polygon_mode (string) – polygons rendering mode: “normal”, “wireframe”, “outline” (normal + wireframe), “hiddenface_wireframe” (wireframe with hidden faces), “default” (use the global view settings), “ext_outlined” (thickened external boundaries + normal rendering).

  • unlit_color (RGB[A] vector: float values between 0 and 1.) – color used for lines when lighting is off. For now it only affects polygons boundaries in “outlined” or “ext_outlined” polygon modes.

  • line_width (float) – Lines thickness (meshes, segments, wireframe rendering modes). A null or negative value fallsback to default (1 in principle).

  • front_face (string) – Specifies if the mesh(es) polygons external face is the clockwise or counterclockwise side. Normally in Aims/Anatomist indirect referentials, polygons are in clockwise orientation. Values are “clockwise”, “counterclockwise”, or “neutral” (the default).

  • selectable_mode (string) –

    New in Anatomist 4.5. Replaces the ghost property.

    always_selectable:

    object is selecatble whatever its opacity.

    ghost:

    object is not selectable.

    selectable_when_opaque:

    object is selectable when totally opaque (this is the default in Anatomist).

    selectable_when_not_totally_transparent:

    object is selectable unless opacity is zero.

  • use_shader (int) – enable or disable the use of OpenGL shaders for this object.

  • shader_color_normals (int) – when shaders are enabled, normals can be represented as colors on the object.

  • normal_is_direction (int) – when shaders are enabled and shader_color_normals is set, normals may be pre-calculates as mesh direction, on a “line” mesh (polygons are lines, not triangles).

setObjectPalette(objects, palette=None, minVal=None, maxVal=None, palette2=None, minVal2=None, maxVal2=None, mixMethod=None, linMixFactor=None, palette1Dmapping=None, absoluteMode=False, zeroCentered1=None, zeroCentered2=None)[source]

Assign a palette to objects

Parameters
  • objects (list of AObject) – Assign palette parameters to these objects

  • palette (APalette or str (name)) – Principal palette to apply

  • minVal (float (0 - 1)) – Palette value to assign to objects texture min value (proportionally to palette’s limits)

  • maxVal (float (0 - 1)) – Palette value to assign to objects texture max value

  • palette2 (APalette or str (name)) – Second palette, for 2D textures

  • minVal2 (float (0 - 1)) – Second palette value to affect to object texture second component min value

  • maxVal2 (float (0 - 1)) – Second palette value to assign to object texture second component max value

  • mixMethod (string) – Method to mix two palettes in a 2D palette : linear or geometric

  • linMixFactor (float) – mix factor for the linear method

  • palette1Dmapping (string) – way of using 2D palette for 1D texture : FirstLine or Diagonal

  • absoluteMode (bool) – if True, min/max values are supposed to be absolute values (in regard to objects texture) rather than proportions

  • zeroCentered1 (bool) – min/max should be updated to keep absolute value 0 at the center of the palette (for palette 1).

  • zeroCentered2 (bool) – min/max should be updated to keep absolute value 0 at the center of the palette (for palette 2).

setPaintParams(brush_size=None, brush_type=None, follow_linked_cursor=None, line_mode=None, millimeter_mode=None, replace_mode=None, region_transparency=None)[source]

Setup Paint contol parameters. All parameters are optional.

Parameters
  • brush_size (float) – Radius of the paint brush, either in millimeters or in voxels, depending on the millimeter_mode.

  • brush_type (str) – “point”, “square”, “disk”, or “sphere”. “ball” is an alias for sphere.

  • follow_linked_cursor (bool) – Linked cursor moving with brush

  • line_mode (bool) – line interpolation mode between brush strokes

  • millimeter_mode (bool) – brush size can be either in mm or in voxels. In voxels mode, the brush may be anisotropic.

  • replace_mode (bool) – region replacing mode (when drawing on a different region)

  • region_transparency (float) – value of the region transparency

setWindowsControl(windows, control)[source]

Changes the selected button in windows menu.

Parameters
  • windows (list of AWindow) – Windows to set control on

  • control (str) – Control to set. Examples of controls: ‘PaintControl’, ‘NodeSelectionControl’, ‘Default 3D Control’, ‘Selection 3D’, ‘Flight Control’, ‘ObliqueControl’, ‘TransformationControl’, ‘CutControl’, ‘Browser Selection’, ‘RoiControl’…

showObject(object)[source]

Displays the given object in a new window

sync()[source]

Wait for anatomist finishing current processing.

waitEndProcessing()[source]

Deprecated. Use method sync instead.