OpenIGTLink/Library/Tutorial
Contents
Two approaches to use the Open IGT Link
Using the low-level C library
The library has been built on the low-level C-library called igtlutil, which is a collection of several data structures with supporting functions for data serialization, endian conversion and cyclic redundancy check, written in ANSI C. The developers can directly use this low-level C-library from their programs. The library is particularly useful to develop embedded or old systems that do not have any modern C++ compiler. The usage of igtlutil can be found in the igtlutil tutorial page.
Using the C++ message classes
The library provides much more simple, portable and safer ways to generate standard Open IGT Link messages using C++ classes. The developers can easily add classes to serialize/deserialize their own data types, by inheriting the base message class. It also provides the multi-platform TCP socket / threading classes; the developers can write multi-platform IGT applications, which communicate with other IGT devices and software, with the Open IGT Link library. Those classes are implemented based on Win32 socket / thread API for Windows and BSD socket / POSIX Thread API for Linux and Mac OS X, and have been tested on those environments.
Please refer OpenIGTLink/Approaches to choose your approach.
Setting up the library
Please refer the Open IGT Link library building instruction.
Using the low-level C library (igtlutil)
The code snippet can be found in igtlutil tutorial page.
Using the Open IGT Link Library C++ interface
Get the example code
The example code is available in the Examples/ directory of Open IGT Link library. The instruction is available in the Open IGT Link Library page.
Example Name | Directory | Description |
TrackerClient.cxx | Example/Tracker | Example to send dummy tracking; works as a TCP client. |
TrackerServer.cxx | Example/Tracker | Example to send dummy tracking; works as a TCP server. |
ReceiveServer.cxx | Example/Receiver | Example to receive tracking data; works as a TCP server. |
ImagerClient.cxx (to be added) | Example/Imager | Example to send image data; works as a TCP client |
ImagerServer.cxx (to be added) | Example/Imager | Example to send image data; works as a TCP client |
Code snippet from Tracker Client program
The code "Tracker/TrackerClient.cxx" demonstrates how to create open igt link message, establish connection with the Open IGT Link server, then repeat sending coordinate data to the server, using Open IGT Link Library.
First, establish connection with server (ip: 192.168.0.1, port number: 18944) using igtl::ClientSocket class:
igtl::ClientSocket::Pointer socket; socket = igtl::ClientSocket::New(); int r = socket->ConnectToServer("192.168.0.1", 18944); if (r != 0) { // // do error handling // }
Prepare a class instance for the Open IGT Link message:
igtl::TransformMessage::Pointer transMsg; transMsg = igtl::TransformMessage::New();
Set Open IGT Link device name:
transMsg->SetDeviceName("Tracker");
Substitute matrix into the Matrix4x4 class:
igtl::Matrix4x4 matrix; GetRandomTestMatrix(matrix);
Set the matrix to the message class:
transMsg->SetMatrix(matrix);
Pack the data. This member function generates byte stream formatted in Open IGT Link format.
transMsg->Pack();
Send data through TCP/IP socket connection:
socket->Send(transMsg->GetPackPointer(), transMsg->GetPackSize());