Note
Click here to download the full example code
Using PyAnatomist in BrainVisaΒΆ
This example shows how to use Anatomist from a BrainVisa process, and get events from Anatomist even when it is run through a socket connection.
from __future__ import print_function
from __future__ import absolute_import
from neuroProcesses import *
from brainvisa.tools import aimsGlobals
import string
name = 'Test anatomist API socket implementation'
userLevel = 0
# by default, socket implementation is loaded in brainvisa
from brainvisa import anatomist as pyanatomist
import anatomist.api
signature = Signature(
'object_to_load', ReadDiskItem(
"3D Volume", aimsGlobals.anatomistVolumeFormats),
)
def initialization(self):
pass
def execution(self, context):
# with attribute create is False, the constructor returns the existing
# instance of anatomist or None if there isn't one.
a = pyanatomist.Anatomist(create=False)
print("anatomist instance:", a)
a = pyanatomist.Anatomist(create=True)
print("anatomist instance:", a)
# register a function to be called when an object is loaded in anatomist
a.onLoadNotifier.add(display)
# a.onLoadNotifier.remove(display)
# a.onCreateWindowNotifier.add(display)
# a.onDeleteNotifier.add(display)
# a.onFusionNotifier.add(display)
# a.onCloseWindowNotifier.add(display)
# a.onAddObjectNotifier.add(display)
# a.onRemoveObjectNotifier.add(display)
# a.onCursorNotifier.add(display)
obj = a.loadObject(self.object_to_load)
w = a.createWindow('Axial')
a.addObjects([obj], [w])
ref = obj.referential
context.write("referential of object :", ref.refUuid)
return [obj, w, ref]
def display(event, params):
print("** Event ** ", event, params)
Total running time of the script: ( 0 minutes 0.000 seconds)