Automate Slicer functions

Hi all,
I was developing as my final degree project a OpenIGTLink communication between a software called ORB-SLAM2 and 3DSlicer(to pass a series of transforms). I have made the communication successfully but I have to operate with the OpenIGTLink and tranforms modules and I want to automate all the process. What I want to automate is:

  1. Load a .stl file in the scene.
  2. Open a IGTLConnector in OpenIGTLink and set it as active client.
  3. Apply the transforms sent by the OpenIGTLink module to the 3d model loaded in step 1 in the transforms module.

My teacher told me that I can do this actions creating a python module with an apply button, and when you press the button you apply all the changes (making easier to the user to work with this information). I would like to know if this is possible and when I can find information about how can I develop that.

Thanks.

Look in Base/Python/slicer/util.py, there are utility functions for loading a variety of data.

Yes, it’s all scriptable. You might have to poke at the API a little bit in the prompt to find exactly what you need, but there’s plenty of python code to start from in SlicerIGT, e.g.:

https://github.com/SlicerIGT/SlicerIGT/blob/master/PlusRemote/PlusRemote.py

You would only need to do this once: set the parent transform of the model to the transform that is receiving the OpenIGTLink updates. The model node will have a SetAndObserveTransformNodeID method, see:

https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Add_a_texture_mapped_plane_to_the_scene_as_a_model

Ok, I would try to do as you say. Then it should be possible to do it this way with only an apply button?

Thanks

Yes.

Setting up a new connection using Python:

cn=slicer.vtkMRMLIGTLConnectorNode()
slicer.mrmlScene.AddNode(cn)
cn.Start()

However, you only need to create the connector node from a script if you write a script for setting up the scene. Most often you manually set up everything in a scene (OpenIGTLink connection, transform, models, views, tool calibrations, etc.) and then save that scene. Then at the beginning of the procedure you open the scene and Slicer automatically connects to your tracker/imaging system and everything just works. If the “persistence” flag of the OpenIGTLink connection is disabled then you need to activate the connection manually (this is useful when the IP address of a clinical navigation system on the hospital network is stored in the scene and you want to avoid accidental connection attempts).