Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkIGTLDevice.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 #ifndef MITKIGTLDEVICE_H
18 #define MITKIGTLDEVICE_H
19 
20 #include "mitkCommon.h"
21 
22 //itk
23 #include "itkObject.h"
24 #include "itkFastMutexLock.h"
25 #include "itkMultiThreader.h"
26 
27 //igtl
28 #include "igtlSocket.h"
29 #include "igtlMessageBase.h"
30 #include "igtlTransformMessage.h"
31 
32 //mitkIGTL
33 #include "MitkOpenIGTLinkExports.h"
34 #include "mitkIGTLMessageFactory.h"
35 #include "mitkIGTLMessageQueue.h"
36 #include "mitkIGTLMessage.h"
37 
38 namespace mitk {
61  class MITKOPENIGTLINK_EXPORT IGTLDevice : public itk::Object
62  {
63  public:
65 
66  IGTLDevice(bool ReadFully);
67 
73  enum IGTLDeviceState { Setup, Ready, Running };
74 
82  virtual bool OpenConnection() = 0;
83 
90  virtual bool CloseConnection();
91 
97  virtual bool StopCommunication();
98 
104  bool StartCommunication();
105 
115  void RunCommunication(void (IGTLDevice::*ComFunction)(void), itk::FastMutexLock* mutex);
116 
125  void SendMessage(igtl::MessageBase::Pointer msg);
126 
133  void SendMessage(const IGTLMessage* msg);
134 
138  IGTLDeviceState GetState() const;
139 
144  igtl::MessageBase::Pointer GetNextCommand();
145 
150  igtl::ImageMessage::Pointer GetNextImage2dMessage();
151 
152  igtl::ImageMessage::Pointer GetNextImage3dMessage();
153 
154  igtl::TransformMessage::Pointer GetNextTransformMessage();
155 
156  igtl::TrackingDataMessage::Pointer GetNextTrackingDataMessage();
157 
158  igtl::StringMessage::Pointer GetNextStringMessage();
159 
160  igtl::MessageBase::Pointer GetNextMiscMessage();
161 
165  itkSetMacro(PortNumber, int);
166 
170  itkGetMacro(PortNumber, int);
171 
175  itkSetMacro(Hostname, std::string);
176 
180  itkGetMacro(Hostname, std::string);
181 
185  itkGetConstMacro(Name, std::string);
186 
190  itkSetMacro(Name, std::string);
191 
195  itkSetMacro(ReadFully, bool);
196 
200  itkGetConstMacro(MessageQueue, mitk::IGTLMessageQueue::Pointer);
201 
205  itkGetMacro(MessageFactory, mitk::IGTLMessageFactory::Pointer);
206 
211  static ITK_THREAD_RETURN_TYPE ThreadStartSending(void* data);
212 
217  static ITK_THREAD_RETURN_TYPE ThreadStartReceiving(void* data);
218 
223  static ITK_THREAD_RETURN_TYPE ThreadStartConnecting(void* data);
224 
239  virtual bool TestConnection();
240 
244  bool SendRTSMessage(const char* type);
245 
249  void EnableInfiniteBufferingMode(mitk::IGTLMessageQueue::Pointer queue,
250  bool enable = true);
251 
255  virtual unsigned int GetNumberOfConnections() = 0;
256 
257  protected:
272  unsigned int SendMessagePrivate(igtl::MessageBase::Pointer msg,
273  igtl::Socket::Pointer socket);
274 
280  virtual void Receive() = 0;
281 
296  unsigned int ReceivePrivate(igtl::Socket* device);
297 
302  virtual void Send() = 0;
303 
312  virtual void Connect();
313 
318  virtual void StopCommunicationWithSocket(igtl::Socket* socket) = 0;
319 
323  void SetState(IGTLDeviceState state);
324 
325  IGTLDevice();
326  virtual ~IGTLDevice();
327 
331  std::string m_Name;
332 
345 
347  std::string m_Hostname;
352 
355 
358 
359  private:
360 
363  itk::MultiThreader::Pointer m_MultiThreader;
365  int m_SendThreadID;
367  int m_ReceiveThreadID;
369  int m_ConnectThreadID;
371  bool m_ReadFully;
372  };
373 
380  itkEventMacro(MessageSentEvent, itk::AnyEvent);
381 
388  itkEventMacro(MessageReceivedEvent, itk::AnyEvent);
389 
396  itkEventMacro(CommandReceivedEvent, itk::AnyEvent);
397 
405  itkEventMacro(NewClientConnectionEvent, itk::AnyEvent);
406 
414  itkEventMacro(LostConnectionEvent, itk::AnyEvent);
415 } // namespace mitk
416 
417 #endif /* MITKIGTLDEVICE_H */
itk::FastMutexLock::Pointer m_ReceivingFinishedMutex
itk::FastMutexLock::Pointer m_StopCommunicationMutex
mitk::IGTLMessageFactory::Pointer m_MessageFactory
itk::SmartPointer< Self > Pointer
IGTLDeviceState m_State
std::string m_Name
itk::FastMutexLock::Pointer m_StateMutex
itk::FastMutexLock::Pointer m_ConnectingFinishedMutex
DataCollection - Class to facilitate loading/accessing structured data.
A wrapper for the OpenIGTLink message type.
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:53
std::string m_Hostname
IGTLDeviceState
Type for state variable. The IGTLDevice is always in one of these states.
mitk::IGTLMessageQueue::Pointer m_MessageQueue
itkEventMacro(ContourModelEvent, itk::AnyEvent)
itk::FastMutexLock::Pointer m_SendingFinishedMutex
Interface for all OpenIGTLink Devices.
igtl::Socket::Pointer m_Socket