Medical Imaging Interaction Toolkit  2023.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkNDITrackingDevice.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 
14 #ifndef mitkNDITrackingDevice_h
15 #define mitkNDITrackingDevice_h
16 
17 #include "mitkTrackingDevice.h"
18 
19 #include <MitkIGTExports.h>
20 #include <thread>
21 #include <mutex>
22 #include <vector>
23 
24 #include "mitkNDIProtocol.h"
25 #include "mitkNDIPassiveTool.h"
27 
28 
29 namespace mitk
30 {
31  class NDIProtocol;
32 
40  class MITKIGT_EXPORT NDITrackingDevice : public TrackingDevice
41  {
42  friend class NDIProtocol;
43 
44  public:
45  typedef std::vector<NDIPassiveTool::Pointer> Tool6DContainerType;
46 
55 
57  itkFactorylessNewMacro(Self);
58  itkCloneMacro(Self);
59 
63  //itkSetMacro(Type, TrackingDeviceType);
64 
65 
78  bool OpenConnection() override;
79 
85  bool CloseConnection() override;
86 
88  bool InitializeWiredTools();
89 
93  void SetRotationMode(RotationMode r) override;
94 
102  virtual mitk::TrackingDeviceType TestConnection();
103 
113  bool DiscoverWiredTools();
114 
123  bool StartTracking() override;
124 
128  TrackingTool* GetTool(unsigned int toolNumber) const override;
129 
130  mitk::TrackingTool* GetToolByName(std::string name) const override;
134  unsigned int GetToolCount() const override;
135 
148  mitk::TrackingTool* AddTool(const char* toolName, const char* fileName, TrackingPriority p = NDIPassiveTool::Dynamic);
149 
155  virtual bool RemoveTool(TrackingTool* tool);
156 
160  virtual bool UpdateTool(mitk::TrackingTool* tool);
161 
162  virtual void SetPortNumber(const PortNumber _arg);
163  itkGetConstMacro(PortNumber, PortNumber);
164  virtual void SetDeviceName(std::string _arg);
165  itkGetStringMacro(DeviceName);
166  virtual void SetBaudRate(const BaudRate _arg);
167  itkGetConstMacro(BaudRate, BaudRate);
168  virtual void SetDataBits(const DataBits _arg);
169  itkGetConstMacro(DataBits, DataBits);
170  virtual void SetParity(const Parity _arg);
171  itkGetConstMacro(Parity, Parity);
172  virtual void SetStopBits(const StopBits _arg);
173  itkGetConstMacro(StopBits, StopBits);
174  virtual void SetHardwareHandshake(const HardwareHandshake _arg);
175  itkGetConstMacro(HardwareHandshake, HardwareHandshake);
176  virtual void SetIlluminationActivationRate(const IlluminationActivationRate _arg);
178  virtual void SetDataTransferMode(const DataTransferMode _arg);
179  itkGetConstMacro(DataTransferMode, DataTransferMode);
180  virtual bool Beep(unsigned char count);
181 
182  NDIErrorCode GetErrorCode(const std::string* input);
183 
184  virtual bool SetOperationMode(OperationMode mode);
185  virtual OperationMode GetOperationMode();
186 
190  virtual bool GetMarkerPositions(MarkerPointContainerType* markerpositions);
191 
196  virtual int GetMajorFirmwareRevisionNumber();
197 
202  virtual const char* GetFirmwareRevisionNumber();
203 
205  bool AutoDetectToolsAvailable() override;
206 
208  bool AddSingleToolIsAvailable() override;
209 
214  mitk::NavigationToolStorage::Pointer AutoDetectTools() override;
215 
216 
217 
218  protected:
219 
220  typedef std::vector<std::string> NDITrackingVolumeContainerType;
221  typedef std::vector<int> TrackingVolumeDimensionType;
222 
228  virtual bool GetSupportedVolumes(unsigned int* numberOfVolumes, NDITrackingVolumeContainerType* volumes, TrackingVolumeDimensionType* volumesDimensions);
229 
234  virtual bool SetVolume(mitk::TrackingDeviceData volume);
235 
241  virtual bool InternalAddTool(NDIPassiveTool* tool);
242 
243  /* Methods for NDIProtocol friend class */
244  virtual void InvalidateAll();
245  NDIPassiveTool* GetInternalTool(std::string portHandle);
246 
257  NDIErrorCode FreePortHandles();
258 
259  NDIErrorCode Send(const std::string* message, bool addCRC = true);
260  NDIErrorCode Receive(std::string* answer, unsigned int numberOfBytes);
261  NDIErrorCode ReceiveByte(char* answer);
262  NDIErrorCode ReceiveLine(std::string* answer);
263  void ClearSendBuffer();
264  void ClearReceiveBuffer();
265  const std::string CalcCRC(const std::string* input);
266 
267 public:
268 
277  virtual void TrackTools();
278 
286  virtual void TrackMarkerPositions();
287 
295  virtual void TrackToolsAndMarkers();
296 
300  void ThreadStartTracking();
301 
302  protected:
304  ~NDITrackingDevice() override;
305 
306  std::string m_DeviceName;
313  IlluminationActivationRate m_IlluminationActivationRate;
317 
318  mutable std::mutex m_ToolsMutex;
319  mitk::SerialCommunication::Pointer m_SerialCommunication;
321  NDIProtocol::Pointer m_DeviceProtocol;
322 
323  std::thread m_Thread;
325  std::mutex m_MarkerPointsMutex;
327  };
328 } // namespace mitk
329 #endif
mitk::NDITrackingDevice::TrackingVolumeDimensionType
std::vector< int > TrackingVolumeDimensionType
List of the supported tracking volume dimensions.
Definition: mitkNDITrackingDevice.h:221
mitk::NDITrackingDevice::StopBits
mitk::SerialCommunication::StopBits StopBits
Number of stop bits used in the serial connection.
Definition: mitkNDITrackingDevice.h:52
mitk::SerialCommunication::HardwareHandshake
HardwareHandshake
Definition: mitkSerialCommunication.h:110
mitk::NDITrackingDevice::m_DeviceName
std::string m_DeviceName
Device Name.
Definition: mitkNDITrackingDevice.h:306
mitk::NDIPassiveTool
Implementation of a passive NDI optical tool.
Definition: mitkNDIPassiveTool.h:31
mitk::NDITrackingDevice::m_SerialCommunication
mitk::SerialCommunication::Pointer m_SerialCommunication
serial communication interface
Definition: mitkNDITrackingDevice.h:319
mitk::SerialCommunication::Parity
Parity
Definition: mitkSerialCommunication.h:97
mitk::TrackingDevice::RotationMode
RotationMode
Definition: mitkTrackingDevice.h:52
mitk::NDITrackingDevice::m_BaudRate
BaudRate m_BaudRate
COM Port Baud Rate.
Definition: mitkNDITrackingDevice.h:308
mitk::NDIPassiveTool::Dynamic
@ Dynamic
Definition: mitkNDIPassiveTool.h:41
mitk::SerialCommunication::BaudRate
BaudRate
Definition: mitkSerialCommunication.h:67
mitk::NDITrackingDevice::TrackingPriority
mitk::NDIPassiveTool::TrackingPriority TrackingPriority
Tracking priority used for tracking a tool.
Definition: mitkNDITrackingDevice.h:54
mitk::NDIPassiveTool::TrackingPriority
TrackingPriority
tracking priority for NDI tracking devices
Definition: mitkNDIPassiveTool.h:38
mitk::NDIErrorCode
NDIErrorCode
Error codes of NDI tracking devices.
Definition: mitkNDIProtocol.h:31
mitk::NDITrackingDevice::m_OperationMode
OperationMode m_OperationMode
tracking mode (6D tool tracking, 3D marker tracking,...)
Definition: mitkNDITrackingDevice.h:324
mitk::NDITrackingDevice::Tool6DContainerType
std::vector< NDIPassiveTool::Pointer > Tool6DContainerType
List of 6D tools of the correct type for this tracking device.
Definition: mitkNDITrackingDevice.h:45
mitk::DataTransferMode
DataTransferMode
Data transfer mode for NDI tracking devices.
Definition: mitkTrackingTypes.h:65
mitk::TrackingDeviceData
Definition: mitkTrackingTypes.h:34
mitkNDIProtocol.h
mitk::MarkerPointContainerType
std::vector< MarkerPointType > MarkerPointContainerType
Definition: mitkTrackingTypes.h:84
mitk
Find image slices visible on a given plane.
Definition: RenderingTests.dox:1
mitk::NDITrackingDevice::m_DeviceProtocol
NDIProtocol::Pointer m_DeviceProtocol
create and parse NDI protocol strings
Definition: mitkNDITrackingDevice.h:321
mitk::NDITrackingDevice::Parity
mitk::SerialCommunication::Parity Parity
Parity mode used in the serial connection.
Definition: mitkNDITrackingDevice.h:51
mitk::NDIProtocol
The NDI Protocol class provides building and parsing of command strings and answers to and from a NDI...
Definition: mitkNDIProtocol.h:86
mitk::NDITrackingDevice::m_HardwareHandshake
HardwareHandshake m_HardwareHandshake
which tracking volume is currently used (if device supports multiple volumes) (
Definition: mitkNDITrackingDevice.h:312
mitk::NDITrackingDevice::NDITrackingVolumeContainerType
std::vector< std::string > NDITrackingVolumeContainerType
vector of tracking volumes
Definition: mitkNDITrackingDevice.h:220
mitk::NDITrackingDevice::m_DataBits
DataBits m_DataBits
Number of Data Bits per token.
Definition: mitkNDITrackingDevice.h:309
mitk::TrackingDevice
Interface for all Tracking Devices.
Definition: mitkTrackingDevice.h:34
mitk::NDITrackingDevice::m_StopBits
StopBits m_StopBits
number of stop bits per token
Definition: mitkNDITrackingDevice.h:311
mitk::NDITrackingDevice::NDITrackingDeviceType
mitk::TrackingDeviceType NDITrackingDeviceType
This enumeration includes the two types of NDI tracking devices (Polaris, Aurora).
Definition: mitkNDITrackingDevice.h:47
mitk::SerialCommunication::PortNumber
PortNumber
Definition: mitkSerialCommunication.h:50
mitk::IlluminationActivationRate
IlluminationActivationRate
activation rate of IR illuminator for NDI Polaris tracking device
Definition: mitkTrackingTypes.h:55
mitkSerialCommunication.h
mitk::SerialCommunication::DataBits
DataBits
Definition: mitkSerialCommunication.h:91
mitk::NDITrackingDevice::HardwareHandshake
mitk::SerialCommunication::HardwareHandshake HardwareHandshake
Hardware handshake mode of the serial connection.
Definition: mitkNDITrackingDevice.h:53
mitk::NDITrackingDevice::PortNumber
mitk::SerialCommunication::PortNumber PortNumber
Port number of the serial connection.
Definition: mitkNDITrackingDevice.h:48
mitk::NDITrackingDevice::m_SerialCommunicationMutex
std::mutex m_SerialCommunicationMutex
mutex for coordinated access of serial communication interface
Definition: mitkNDITrackingDevice.h:320
mitk::NDITrackingDevice::m_DataTransferMode
DataTransferMode m_DataTransferMode
use TX (text) or BX (binary) (
Definition: mitkNDITrackingDevice.h:315
mitk::NDITrackingDevice::DataBits
mitk::SerialCommunication::DataBits DataBits
Number of data bits used in the serial connection.
Definition: mitkNDITrackingDevice.h:50
mitk::NDITrackingDevice::m_MarkerPoints
MarkerPointContainerType m_MarkerPoints
container for markers (3D point tracking mode)
Definition: mitkNDITrackingDevice.h:326
mitk::NDITrackingDevice::m_6DTools
Tool6DContainerType m_6DTools
list of 6D tools
Definition: mitkNDITrackingDevice.h:316
mitk::NDITrackingDevice::m_PortNumber
PortNumber m_PortNumber
COM Port Number.
Definition: mitkNDITrackingDevice.h:307
mitk::NDITrackingDevice
superclass for specific NDI tracking Devices that use serial communication.
Definition: mitkNDITrackingDevice.h:40
mitk::SerialCommunication::StopBits
StopBits
Definition: mitkSerialCommunication.h:104
mitk::TrackingTool
Interface for all Tracking Tools.
Definition: mitkTrackingTool.h:42
mitk::NDITrackingDevice::m_MarkerPointsMutex
std::mutex m_MarkerPointsMutex
mutex for marker point data container
Definition: mitkNDITrackingDevice.h:325
mitkNDIPassiveTool.h
mitkClassMacro
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:36
mitk::NDITrackingDevice::m_ToolsMutex
std::mutex m_ToolsMutex
mutex for coordinated access of tool container
Definition: mitkNDITrackingDevice.h:318
mitk::OperationMode
OperationMode
Error codes of NDI tracking devices.
Definition: mitkTrackingTypes.h:44
mitkTrackingDevice.h
mitk::TrackingDeviceType
std::string TrackingDeviceType
Definition: mitkTrackingTypes.h:22
mitk::NDITrackingDevice::m_Parity
Parity m_Parity
Parity mode for communication.
Definition: mitkNDITrackingDevice.h:310
mitk::NDITrackingDevice::m_Thread
std::thread m_Thread
ID of tracking thread.
Definition: mitkNDITrackingDevice.h:323
mitk::NDITrackingDevice::BaudRate
mitk::SerialCommunication::BaudRate BaudRate
Baud rate of the serial connection.
Definition: mitkNDITrackingDevice.h:49