Difference between revisions of "Documentation/4.2/Developers/OpenIGTLinkIF"

From Slicer Wiki
Jump to: navigation, search
m (Text replacement - "slicerWiki/index.php" to "wiki")
 
(19 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This page provides developer's information for 3D Slicer's OpenIGTLink IF module.
+
<noinclude>{{documentation/versioncheck}}</noinclude>
 +
This page provides developer's information for 3D Slicer 4.2's OpenIGTLink IF module.
  
=Create external OpenIGTLink server/client software=
+
=Creating external OpenIGTLink server/client software=
 
With the OpenIGTLink IF module, you can exchange various types of data (e.g. linear transforms and images) between 3D Slicer and external software over the local area network. We provide [http://www.na-mic.org/Wiki/index.php/OpenIGTLink/Library OpenIGTLink Library] to support OpenIGTLink-compatible software. Please refer the [http://www.na-mic.org/Wiki/index.php/OpenIGTLink/Library/Tutorial Tutorial].
 
With the OpenIGTLink IF module, you can exchange various types of data (e.g. linear transforms and images) between 3D Slicer and external software over the local area network. We provide [http://www.na-mic.org/Wiki/index.php/OpenIGTLink/Library OpenIGTLink Library] to support OpenIGTLink-compatible software. Please refer the [http://www.na-mic.org/Wiki/index.php/OpenIGTLink/Library/Tutorial Tutorial].
  
=Control OpenIGTLink IF from Python module=
+
=Controlling OpenIGTLink IF from Python module=
 
You can use the OpenIGTLink IF module's features from [[Slicer4:Python| 3D Slicer's Python interface]]. The features can be called from both Slicer Python Interactor (Python console) and Python module.
 
You can use the OpenIGTLink IF module's features from [[Slicer4:Python| 3D Slicer's Python interface]]. The features can be called from both Slicer Python Interactor (Python console) and Python module.
  
 
==Requirements==
 
==Requirements==
*3D Slicer 4.2 nightly build (11/10/2012 or later) available at [http://slicer.org http://slicer.org/] (4.2.0 release version has an issue in initialization of the OpenIGTLinkIF module. If you use this version, you need to open the OpenIGTLinkIF module, before using the Python interface)
+
*3D Slicer 4.2 nightly build (November 10, 2012 or later) available at [http://slicer.org http://slicer.org/] (4.2.0 release version has an issue in initialization of the OpenIGTLinkIF module. If you use this version, you need to open the OpenIGTLinkIF module, before using the Python interface)
*OpenIGTLink Simulators available in [http://wiki.slicer.org/slicerWiki/index.php/Modules:OpenIGTLinkIF-3.6-Simulators NA-MIC wiki] or the OpenIGTLink Library
+
*OpenIGTLink Simulators available in [http://wiki.slicer.org/wiki/Modules:OpenIGTLinkIF-3.6-Simulators NA-MIC wiki] or the OpenIGTLink Library
  
 
==Creating an OpenIGTLink connector node from Python Interactor==
 
==Creating an OpenIGTLink connector node from Python Interactor==
  
To establish an OpenIGTLink connection, first you need to create a OpenIGTLink connector node (vtkMRMLIGTLConnectorNode).
+
To establish an OpenIGTLink connection, first you need to create an OpenIGTLink connector node (vtkMRMLIGTLConnectorNode).
 
From Python Interactor:
 
From Python Interactor:
  
Line 24: Line 25:
  
 
If the connector node is properly added to the scene, you could see it in the Connector list in the OpenIGTLink IF module.
 
If the connector node is properly added to the scene, you could see it in the Connector list in the OpenIGTLink IF module.
 +
 +
==Importing a linear transform to external software (3D Slicer as a client)==
 +
 +
Suppose the downloaded simulator files are in <working directory>.
 +
 +
First, launch the "TrackerServer" simulator from a terminal (or a command prompt on Windows) and ask to wait for a connection from the 3D Slicer at port # 18944. The frame rate for sending linear transforms is set to 10 frames/sec
 +
 +
$ cd <working directory>
 +
$ ./TrackerServer 18944 10
 +
 +
Then open the Python Interactor and type in the following commands to configure the connector node as a client:
 +
 +
>>> cnode.SetTypeClient('localhost', 18944)
 +
1
 +
 +
Make sure that cnode.SetTypeClient() function returns 1. Then, start the client by:
 +
 +
>>> cnode.Start()
 +
1
 +
 +
If the connector node is successfully connected to the TrackerServer, you will start seeing 4x4 matrices printed on the terminal every 100 ms.
 +
You could also confirm in the Transform module that those matrices are imported to a linear transform node in the scene. Open "Transform" module
 +
and select "Tracker" from "Active Transform" menu.
  
 
==Exporting a linear transform to external software (3D Slicer as a client)==
 
==Exporting a linear transform to external software (3D Slicer as a client)==
Line 29: Line 53:
 
Suppose the simulator files are in <working directory>.  
 
Suppose the simulator files are in <working directory>.  
  
First, we launch the "ReceiveServer" simulator from a terminal (or a command prompt on Windows) and ask to wait for a connection from the 3D Slicer at port # 18944.
+
First, launch the "ReceiveServer" simulator from the terminal (or the command prompt on Windows) and ask to wait for a connection from the 3D Slicer at port # 18944.
  
 
  $ cd <working directory>
 
  $ cd <working directory>
 
  $ ./ReceiveServer 18944
 
  $ ./ReceiveServer 18944
  
Then open the Python Interactor and type in the following commands to configure the connector node as a client:
+
Then open the Python Interactor and type in the following command to configure the connector node as a client:
  
 
  >>> cnode.SetTypeClient('localhost', 18944)
 
  >>> cnode.SetTypeClient('localhost', 18944)
Line 44: Line 68:
 
  1
 
  1
  
Now the connector is connected to the ReceiveServer. You can check it from the Connector list in the OpenIGTLink IF module. If it is connected, the "Status" of the connector must be "ON".
+
Now the connector is connected to the ReceiveServer. You can confirm it from the Connector list in the OpenIGTLink IF module. If it is connected, the "Status" of the connector must be "ON".
 +
 
 +
The next step is to create a linear transform node to export. You can create it from "Transform" module, or from the Python Interactor:
 +
 
 +
>>> tnode = slicer.vtkMRMLLinearTransformNode()
 +
>>> slicer.mrmlScene.AddNode(tnode)
 +
(vtkMRMLLinearTransformNode)0x125e6cf70
 +
>>>
 +
 
 +
If you created the transform node from the Transform module, you need to get the node object in the Python Interactor. To do so, open "Data" module, click the "Display MRML ID's" under the "Nodes" interface, and check the node ID written on the right end of the "Nodes" interface. If the transform node is the first node you created after launching 3D Slicer, the node ID is usually "vtkMRMLLinearTransformNode4". You can obtain the node object in the Python Interactor by using GetNodeByID() function:
 +
 
 +
>>> tnode = slicer.mrmlScene.GetNodeByID('vtkMRMLLinearTransformNode4')
 +
 
 +
Now it's ready for the connector node to observe the transform node. Register the transform node to the connector as an outgoing data:
 +
 
 +
>>> cnode.RegisterOutgoingMRMLNode(tnode)
 +
1
 +
>>>
 +
 
 +
You may check from "I/O Configuration" in the OpenIGTLinkIF module if the linear transform node is registered as a OUTGOING node. (The linear transform node should be under "OUT" branch of the connector node.)
 +
 
 +
Let's try updating the transform node. Open the "Transform" module, choose the linear transform node from "Active Transform" and drag any of translation/rotation sliders. While you are dragging those sliders, you will see 4x4 matrices are shown on the terminal that runs "ReceiveServer."
 +
 
 +
To close the connection, you may call:
 +
 
 +
>>> cnode.Stop()

Latest revision as of 17:05, 21 November 2019

Home < Documentation < 4.2 < Developers < OpenIGTLinkIF


For the latest Slicer documentation, visit the read-the-docs.


This page provides developer's information for 3D Slicer 4.2's OpenIGTLink IF module.

Creating external OpenIGTLink server/client software

With the OpenIGTLink IF module, you can exchange various types of data (e.g. linear transforms and images) between 3D Slicer and external software over the local area network. We provide OpenIGTLink Library to support OpenIGTLink-compatible software. Please refer the Tutorial.

Controlling OpenIGTLink IF from Python module

You can use the OpenIGTLink IF module's features from 3D Slicer's Python interface. The features can be called from both Slicer Python Interactor (Python console) and Python module.

Requirements

  • 3D Slicer 4.2 nightly build (November 10, 2012 or later) available at http://slicer.org/ (4.2.0 release version has an issue in initialization of the OpenIGTLinkIF module. If you use this version, you need to open the OpenIGTLinkIF module, before using the Python interface)
  • OpenIGTLink Simulators available in NA-MIC wiki or the OpenIGTLink Library

Creating an OpenIGTLink connector node from Python Interactor

To establish an OpenIGTLink connection, first you need to create an OpenIGTLink connector node (vtkMRMLIGTLConnectorNode). From Python Interactor:

>>> cnode = slicer.vtkMRMLIGTLConnectorNode()
>>> slicer.mrmlScene.AddNode(cnode)
(vtkMRMLIGTLConnectorNode)0x125e6ce10

You may name the connector as follows:

>>> cnode.SetName('Connector1')

If the connector node is properly added to the scene, you could see it in the Connector list in the OpenIGTLink IF module.

Importing a linear transform to external software (3D Slicer as a client)

Suppose the downloaded simulator files are in <working directory>.

First, launch the "TrackerServer" simulator from a terminal (or a command prompt on Windows) and ask to wait for a connection from the 3D Slicer at port # 18944. The frame rate for sending linear transforms is set to 10 frames/sec

$ cd <working directory>
$ ./TrackerServer 18944 10

Then open the Python Interactor and type in the following commands to configure the connector node as a client:

>>> cnode.SetTypeClient('localhost', 18944)
1

Make sure that cnode.SetTypeClient() function returns 1. Then, start the client by:

>>> cnode.Start()
1

If the connector node is successfully connected to the TrackerServer, you will start seeing 4x4 matrices printed on the terminal every 100 ms. You could also confirm in the Transform module that those matrices are imported to a linear transform node in the scene. Open "Transform" module and select "Tracker" from "Active Transform" menu.

Exporting a linear transform to external software (3D Slicer as a client)

Suppose the simulator files are in <working directory>.

First, launch the "ReceiveServer" simulator from the terminal (or the command prompt on Windows) and ask to wait for a connection from the 3D Slicer at port # 18944.

$ cd <working directory>
$ ./ReceiveServer 18944

Then open the Python Interactor and type in the following command to configure the connector node as a client:

>>> cnode.SetTypeClient('localhost', 18944)
1

Make sure that cnode.SetTypeClient() function returns 1. Then, start the client by:

>>> cnode.Start()
1

Now the connector is connected to the ReceiveServer. You can confirm it from the Connector list in the OpenIGTLink IF module. If it is connected, the "Status" of the connector must be "ON".

The next step is to create a linear transform node to export. You can create it from "Transform" module, or from the Python Interactor:

>>> tnode = slicer.vtkMRMLLinearTransformNode()
>>> slicer.mrmlScene.AddNode(tnode)
(vtkMRMLLinearTransformNode)0x125e6cf70
>>> 

If you created the transform node from the Transform module, you need to get the node object in the Python Interactor. To do so, open "Data" module, click the "Display MRML ID's" under the "Nodes" interface, and check the node ID written on the right end of the "Nodes" interface. If the transform node is the first node you created after launching 3D Slicer, the node ID is usually "vtkMRMLLinearTransformNode4". You can obtain the node object in the Python Interactor by using GetNodeByID() function:

>>> tnode = slicer.mrmlScene.GetNodeByID('vtkMRMLLinearTransformNode4')

Now it's ready for the connector node to observe the transform node. Register the transform node to the connector as an outgoing data:

>>> cnode.RegisterOutgoingMRMLNode(tnode)
1
>>>

You may check from "I/O Configuration" in the OpenIGTLinkIF module if the linear transform node is registered as a OUTGOING node. (The linear transform node should be under "OUT" branch of the connector node.)

Let's try updating the transform node. Open the "Transform" module, choose the linear transform node from "Active Transform" and drag any of translation/rotation sliders. While you are dragging those sliders, you will see 4x4 matrices are shown on the terminal that runs "ReceiveServer."

To close the connection, you may call:

>>> cnode.Stop()