OpenIGTLinkIF as server to receive tracking data

Hi all,

Still working on the PlusToolkit for my Xsens IMU. Because it is not that easy for me, I also try to work in parallel directly with the OpenIGTLink library (to get a functionnal prototype faster).

I am trying to receive data through the OpenIGTLinkIF module (using Slicer as a server). In parallel, I run an OpenIGTLink example (TrackerClient). I want to be able to use the module both as a front-end user and in a python script.

  • About the python script:
    I followed the first steps of the OpenIGTLinkIF developer tutorial (which is only for slicer as Client) and I am able to set Slicer as a server and to receive tracking data. But I couldn’t figure out how to access it. I think the RegisterIncomingMRMLNode() function from vtkMRMLIGTLConnectorNode.h is not formatted for Python yet (even the help function doe not recognize it).

  • About the OpenIGTLinkIF module:
    The small tutorial on the OpenIGTLinkIF is about an old version of OpenIGTLinkIF and I caanot figure out the last steps. Again, I can set Slicer as Server, and receive tracking data (STATUS = ON), but I cannot access it and make the stylus (or whatever else) turn relating to the random matrices sent by TrackerClient.

Again, thank you for your time,

If you have any problems, just commit your code and post your question and the link to the relevant code part here.

If you have the tracking data in Slicer then you just access it as a regular node. Slicer takes care of all communication, updating of the scene based on information that it collects on communications threads, etc. - in your Slicer scripts or modules you don’t need to deal with OpenIGTLink at all.

See this example how to observe transform changes and access the transformation matrix:

# Create a new transform
transformNode = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLTransformNode", "MyTransform")

# Callback function that will be called each time the transform is modified
def onMyTransformModified(caller, event):
  transformMatrix = vtk.vtkMatrix4x4()
  caller.GetMatrixTransformToWorld(transformMatrix)
  print("Transform modified. Translation X = {0}".format(transformMatrix.GetElement(0,3)))

# Add an observer that will make the callback function called each time the transform is modified
observationTag = transformNode.AddObserver(slicer.vtkMRMLTransformableNode.TransformModifiedEvent, onMyTransformModified)

At this point, go to transforms module and move the Translation LR slider to change X translation. Changed translation value will be printed on the Python console.

If you don’t need the observe transform changes anymore, you can remove the observer:

transformNode.RemoveObserver(observationTag)
1 Like

Complete SlicerIGT tutorials to learn this and many other very useful techniques.

@terajnol,
I cannot access it and make the stylus (or whatever else) turn relating to the random matrices sent by TrackerClient

Please try using “TrackingDataServer” in OpenIGTLink library instead, i think igtl::TransformMessage type is not converted in OpenIGTLinkIF module.
After you establish the connector with the TrackingDataServer. Input the following lines in the Slicer Python Interactor:
a = slicer.mrmlScene.GetNodeByID(“vtkMRMLIGTLConnectorNode1”) // Checke the Node ID in Slicer
b=slicer.vtkMRMLIGTLQueryNode()
b.SetQueryType(b.TYPE_START)
b.SetIGTLName(“TDATA”)
a.PushQuery(b)

Then open “Transforms” module in Slicer. you will see the received tranformation