PlusLib  2.9.0
Software library for tracked ultrasound image acquisition, calibration, and processing.
vtkPlusOpenIGTLinkClient.h
Go to the documentation of this file.
1 /*=Plus=header=begin======================================================
2  Program: Plus
3  Copyright (c) Laboratory for Percutaneous Surgery. All rights reserved.
4  See License.txt for details.
5 =========================================================Plus=header=end*/
6 
7 #ifndef __VTKPLUSOPENIGTLINKCLIENT_H
8 #define __VTKPLUSOPENIGTLINKCLIENT_H
9 
10 #include "vtkPlusServerExport.h"
11 
12 // Local includes
13 #include "vtkPlusCommand.h"
15 
16 // OpenIGTLink includes
17 #include <igtlClientSocket.h>
18 #include <igtlCommandMessage.h>
19 #include <igtlMessageHeader.h>
20 #include <igtlOSUtil.h>
21 
22 // VTK includes
23 #include <vtkObject.h>
24 
25 // STL includes
26 #include <deque>
27 #include <string>
28 
29 class vtkMultiThreader;
30 class vtkIGSIORecursiveCriticalSection;
31 
40 class vtkPlusServerExport vtkPlusOpenIGTLinkClient : public vtkObject
41 {
42 public:
43  static vtkPlusOpenIGTLinkClient* New();
44  vtkTypeMacro(vtkPlusOpenIGTLinkClient, vtkObject);
45  virtual void PrintSelf(ostream& os, vtkIndent indent);
46 
47  vtkSetMacro(ServerPort, int);
48  vtkGetMacroConst(ServerPort, int);
49 
50  vtkGetStdStringMacro(ServerHost);
51  vtkSetStdStringMacro(ServerHost);
52 
53  vtkSetMacro(ServerIGTLVersion, int);
54  vtkGetMacroConst(ServerIGTLVersion, int);
55 
57  PlusStatus Connect(double timeoutSec = -1);
58 
60  PlusStatus Disconnect();
61 
63  PlusStatus SendCommand(vtkPlusCommand* command);
64 
66  PlusStatus SendMessage(igtl::MessageBase::Pointer packedMessage);
67 
69  PlusStatus ReceiveReply(PlusStatus& result,
70  int32_t& outOriginalCommandId,
71  std::string& outErrorString,
72  std::string& outContent,
73  igtl::MessageBase::MetaDataMap& outParameters,
74  std::string& outCommandName,
75  double timeoutSec = 0);
76 
77  void Lock();
78  void Unlock();
79 
88  virtual bool OnMessageReceived(igtl::MessageHeader::Pointer messageHeader)
89  {
90  return false;
91  }
92 
93 protected:
95  virtual ~vtkPlusOpenIGTLinkClient();
96 
98  igtlUint64 SocketReceive(void* data, igtlUint64 length);
99 
101  static void* DataReceiverThread(vtkMultiThreader::ThreadInfo* data);
102 
103 protected:
105  vtkSmartPointer<vtkPlusIgtlMessageFactory> IgtlMessageFactory;
106 
107  std::pair<bool, bool> DataReceiverActive;
108 
110 
112  vtkSmartPointer<vtkMultiThreader> Threader;
113 
115  vtkSmartPointer<vtkIGSIORecursiveCriticalSection> Mutex;
116  vtkSmartPointer<vtkIGSIORecursiveCriticalSection> SocketMutex;
117 
118  igtl::ClientSocket::Pointer ClientSocket;
119 
121 
122  std::deque<igtl::MessageBase::Pointer> Replies;
123 
125  std::string ServerHost;
126 
127  // IGTL protocol version of the server
129 
130  static const float CLIENT_SOCKET_TIMEOUT_SEC;
131 
132 private:
134  void operator=(const vtkPlusOpenIGTLinkClient&);
135 };
136 
137 #endif
const uint32_t * data
Definition: phidget22.h:3971
This is an abstract superclass for commands in the OpenIGTLink network interface for Plus.
igsioStatus PlusStatus
Definition: PlusCommon.h:40
vtkSmartPointer< vtkIGSIORecursiveCriticalSection > Mutex
virtual bool OnMessageReceived(igtl::MessageHeader::Pointer messageHeader)
vtkSmartPointer< vtkPlusIgtlMessageFactory > IgtlMessageFactory
static const float CLIENT_SOCKET_TIMEOUT_SEC
This class provides a network interface to access Plus functions as an OpenIGTLink client.
vtkSmartPointer< vtkIGSIORecursiveCriticalSection > SocketMutex
std::deque< igtl::MessageBase::Pointer > Replies
igtl::ClientSocket::Pointer ClientSocket
vtkSmartPointer< vtkMultiThreader > Threader
std::pair< bool, bool > DataReceiverActive