Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 
18 #ifndef MITKNDITRACKINGDEVICE_H_HEADER_INCLUDED_C1C2FCD2
19 #define MITKNDITRACKINGDEVICE_H_HEADER_INCLUDED_C1C2FCD2
20 
21 #include "mitkTrackingDevice.h"
22 
23 #include <MitkIGTExports.h>
24 #include <itkMultiThreader.h>
25 #include "itkFastMutexLock.h"
26 #include <vector>
27 
28 #include "mitkNDIProtocol.h"
29 #include "mitkNDIPassiveTool.h"
31 
32 
33 namespace mitk
34 {
35  class NDIProtocol;
36 
44  class MITKIGT_EXPORT NDITrackingDevice : public TrackingDevice
45  {
46  friend class NDIProtocol;
47 
48  public:
49  typedef std::vector<NDIPassiveTool::Pointer> Tool6DContainerType;
50 
59 
61  itkFactorylessNewMacro(Self)
62  itkCloneMacro(Self)
63 
67  //itkSetMacro(Type, TrackingDeviceType);
68 
69 
82  virtual bool OpenConnection() override;
83 
89  virtual bool CloseConnection() override;
90 
92  bool InitializeWiredTools();
93 
97  virtual void SetRotationMode(RotationMode r) override;
98 
106  virtual mitk::TrackingDeviceType TestConnection();
107 
117  bool DiscoverWiredTools();
118 
127  virtual bool StartTracking() override;
128 
132  virtual TrackingTool* GetTool(unsigned int toolNumber) const override;
133 
134  virtual mitk::TrackingTool* GetToolByName(std::string name) const override;
138  virtual unsigned int GetToolCount() const override;
139 
152  mitk::TrackingTool* AddTool(const char* toolName, const char* fileName, TrackingPriority p = NDIPassiveTool::Dynamic);
153 
159  virtual bool RemoveTool(TrackingTool* tool);
160 
164  virtual bool UpdateTool(mitk::TrackingTool* tool);
165 
166  virtual void SetPortNumber(const PortNumber _arg);
167  itkGetConstMacro(PortNumber, PortNumber);
168  virtual void SetDeviceName(std::string _arg);
169  itkGetStringMacro(DeviceName);
170  virtual void SetBaudRate(const BaudRate _arg);
171  itkGetConstMacro(BaudRate, BaudRate);
172  virtual void SetDataBits(const DataBits _arg);
173  itkGetConstMacro(DataBits, DataBits);
174  virtual void SetParity(const Parity _arg);
175  itkGetConstMacro(Parity, Parity);
176  virtual void SetStopBits(const StopBits _arg);
177  itkGetConstMacro(StopBits, StopBits);
178  virtual void SetHardwareHandshake(const HardwareHandshake _arg);
179  itkGetConstMacro(HardwareHandshake, HardwareHandshake);
180  virtual void SetIlluminationActivationRate(const IlluminationActivationRate _arg);
181  itkGetConstMacro(IlluminationActivationRate, IlluminationActivationRate);
182  virtual void SetDataTransferMode(const DataTransferMode _arg);
183  itkGetConstMacro(DataTransferMode, DataTransferMode);
184  virtual bool Beep(unsigned char count);
185 
186  NDIErrorCode GetErrorCode(const std::string* input);
187 
188  virtual bool SetOperationMode(OperationMode mode);
189  virtual OperationMode GetOperationMode();
190 
194  virtual bool GetMarkerPositions(MarkerPointContainerType* markerpositions);
195 
200  virtual int GetMajorFirmwareRevisionNumber();
201 
206  virtual const char* GetFirmwareRevisionNumber();
207 
208 
209 
210 
211 
212  protected:
213 
214  typedef std::vector<std::string> NDITrackingVolumeContainerType;
215  typedef std::vector<int> TrackingVolumeDimensionType;
216 
222  virtual bool GetSupportedVolumes(unsigned int* numberOfVolumes, NDITrackingVolumeContainerType* volumes, TrackingVolumeDimensionType* volumesDimensions);
223 
228  virtual bool SetVolume(mitk::TrackingDeviceData volume);
229 
235  virtual bool InternalAddTool(NDIPassiveTool* tool);
236 
237  /* Methods for NDIProtocol friend class */
238  virtual void InvalidateAll();
239  NDIPassiveTool* GetInternalTool(std::string portHandle);
240 
251  NDIErrorCode FreePortHandles();
252 
253  NDIErrorCode Send(const std::string* message, bool addCRC = true);
254  NDIErrorCode Receive(std::string* answer, unsigned int numberOfBytes);
255  NDIErrorCode ReceiveByte(char* answer);
256  NDIErrorCode ReceiveLine(std::string* answer);
257  void ClearSendBuffer();
258  void ClearReceiveBuffer();
259  const std::string CalcCRC(const std::string* input);
260 
261 public:
262 
271  virtual void TrackTools();
272 
280  virtual void TrackMarkerPositions();
281 
289  virtual void TrackToolsAndMarkers();
290 
294  static ITK_THREAD_RETURN_TYPE ThreadStartTracking(void* data);
295 
296  protected:
298  virtual ~NDITrackingDevice();
299 
300  std::string m_DeviceName;
301  PortNumber m_PortNumber;
302  BaudRate m_BaudRate;
303  DataBits m_DataBits;
304  Parity m_Parity;
305  StopBits m_StopBits;
306  HardwareHandshake m_HardwareHandshake;
307  IlluminationActivationRate m_IlluminationActivationRate;
309  DataTransferMode m_DataTransferMode;
310  Tool6DContainerType m_6DTools;
311 
312  itk::FastMutexLock::Pointer m_ToolsMutex;
313  mitk::SerialCommunication::Pointer m_SerialCommunication;
314  itk::FastMutexLock::Pointer m_SerialCommunicationMutex;
315  NDIProtocol::Pointer m_DeviceProtocol;
316 
317  itk::MultiThreader::Pointer m_MultiThreader;
318  int m_ThreadID;
319  OperationMode m_OperationMode;
320  itk::FastMutexLock::Pointer m_MarkerPointsMutex;
321  MarkerPointContainerType m_MarkerPoints;
322  };
323 } // namespace mitk
324 #endif /* MITKNDITRACKINGDEVICE_H_HEADER_INCLUDED_C1C2FCD2 */
mitk::SerialCommunication::DataBits DataBits
Number of data bits used in the serial connection.
Interface for all Tracking Tools.
std::vector< std::string > NDITrackingVolumeContainerType
vector of tracking volumes
mitk::SerialCommunication::StopBits StopBits
Number of stop bits used in the serial connection.
OperationMode
Error codes of NDI tracking devices.
IlluminationActivationRate
activation rate of IR illuminator for NDI Polaris tracking device
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
mitk::SerialCommunication::BaudRate BaudRate
Baud rate of the serial connection.
std::vector< NDIPassiveTool::Pointer > Tool6DContainerType
List of 6D tools of the correct type for this tracking device.
mitk::SerialCommunication::HardwareHandshake HardwareHandshake
Hardware handshake mode of the serial connection.
std::vector< int > TrackingVolumeDimensionType
List of the supported tracking volume dimensions.
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Interface for all Tracking Devices.
mitk::SerialCommunication::Parity Parity
Parity mode used in the serial connection.
std::vector< MarkerPointType > MarkerPointContainerType
mitk::SerialCommunication::PortNumber PortNumber
Port number of the serial connection.
serial communication interface
Implementation of a passive NDI optical tool.
std::string TrackingDeviceType
superclass for specific NDI tracking Devices that use serial communication.
mitk::NDIPassiveTool::TrackingPriority TrackingPriority
Tracking priority used for tracking a tool.
TrackingPriority
tracking priority for NDI tracking devices
NDIErrorCode
Error codes of NDI tracking devices.
DataTransferMode
Data transfer mode for NDI tracking devices.
The NDI Protocol class provides building and parsing of command strings and answers to and from a NDI...
mitk::TrackingDeviceType NDITrackingDeviceType
This enumeration includes the two types of NDI tracking devices (Polaris, Aurora).