MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkIGTLMessageQueue.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14#include <string>
15#include "igtlMessageBase.h"
16
17void mitk::IGTLMessageQueue::PushSendMessage(mitk::IGTLMessage::Pointer message)
18{
19 this->m_Mutex.lock();
21 m_SendQueue.clear();
22
23 m_SendQueue.push_back(message);
24 this->m_Mutex.unlock();
25}
26
27void mitk::IGTLMessageQueue::PushCommandMessage(igtl::MessageBase::Pointer message)
28{
29 this->m_Mutex.lock();
30 if (this->m_BufferingType == IGTLMessageQueue::NoBuffering)
31 m_CommandQueue.clear();
32
33 m_CommandQueue.push_back(message);
34 this->m_Mutex.unlock();
35}
36
37void mitk::IGTLMessageQueue::PushMessage(igtl::MessageBase::Pointer msg)
38{
39 this->m_Mutex.lock();
40
41 std::stringstream infolog;
42
43 infolog << "Received message of type ";
44
45 if (dynamic_cast<igtl::TrackingDataMessage*>(msg.GetPointer()) != nullptr)
46 {
47 if (this->m_BufferingType == IGTLMessageQueue::NoBuffering)
48 m_TrackingDataQueue.clear();
49
50 this->m_TrackingDataQueue.push_back(dynamic_cast<igtl::TrackingDataMessage*>(msg.GetPointer()));
51
52 infolog << "TDATA";
53 }
54 else if (dynamic_cast<igtl::TransformMessage*>(msg.GetPointer()) != nullptr)
55 {
56 if (this->m_BufferingType == IGTLMessageQueue::NoBuffering)
57 m_TransformQueue.clear();
58
59 this->m_TransformQueue.push_back(dynamic_cast<igtl::TransformMessage*>(msg.GetPointer()));
60
61 infolog << "TRANSFORM";
62 }
63 else if (dynamic_cast<igtl::StringMessage*>(msg.GetPointer()) != nullptr)
64 {
65 if (this->m_BufferingType == IGTLMessageQueue::NoBuffering)
66 m_StringQueue.clear();
67
68 this->m_StringQueue.push_back(dynamic_cast<igtl::StringMessage*>(msg.GetPointer()));
69
70 infolog << "STRING";
71 }
72 else if (dynamic_cast<igtl::ImageMessage*>(msg.GetPointer()) != nullptr)
73 {
74 igtl::ImageMessage::Pointer imageMsg = dynamic_cast<igtl::ImageMessage*>(msg.GetPointer());
75 int* dim = new int[3];
76 imageMsg->GetDimensions(dim);
77 if (dim[2] > 1)
78 {
79 if (this->m_BufferingType == IGTLMessageQueue::NoBuffering)
80 m_Image3dQueue.clear();
81
82 this->m_Image3dQueue.push_back(dynamic_cast<igtl::ImageMessage*>(msg.GetPointer()));
83
84 infolog << "IMAGE3D";
85 }
86 else
87 {
88 if (this->m_BufferingType == IGTLMessageQueue::NoBuffering)
89 m_Image2dQueue.clear();
90
91 this->m_Image2dQueue.push_back(dynamic_cast<igtl::ImageMessage*>(msg.GetPointer()));
92
93 infolog << "IMAGE2D";
94 }
95 }
96 else
97 {
98 if (this->m_BufferingType == IGTLMessageQueue::NoBuffering)
99 m_MiscQueue.clear();
100
101 this->m_MiscQueue.push_back(msg);
102
103 infolog << "OTHER";
104 }
105
106 m_Latest_Message = msg;
107
108 //MITK_INFO << infolog.str();
109
110 this->m_Mutex.unlock();
111}
112
113mitk::IGTLMessage::Pointer mitk::IGTLMessageQueue::PullSendMessage()
114{
115 mitk::IGTLMessage::Pointer ret = nullptr;
116 this->m_Mutex.lock();
117 if (this->m_SendQueue.size() > 0)
118 {
119 ret = this->m_SendQueue.front();
120 this->m_SendQueue.pop_front();
121 }
122 this->m_Mutex.unlock();
123 return ret;
124}
125
126igtl::MessageBase::Pointer mitk::IGTLMessageQueue::PullMiscMessage()
127{
128 igtl::MessageBase::Pointer ret = nullptr;
129 this->m_Mutex.lock();
130 if (this->m_MiscQueue.size() > 0)
131 {
132 ret = this->m_MiscQueue.front();
133 this->m_MiscQueue.pop_front();
134 }
135 this->m_Mutex.unlock();
136 return ret;
137}
138
140{
141 igtl::ImageMessage::Pointer ret = nullptr;
142 this->m_Mutex.lock();
143 if (this->m_Image2dQueue.size() > 0)
144 {
145 ret = this->m_Image2dQueue.front();
146 this->m_Image2dQueue.pop_front();
147 }
148 this->m_Mutex.unlock();
149 return ret;
150}
151
153{
154 igtl::ImageMessage::Pointer ret = nullptr;
155 this->m_Mutex.lock();
156 if (this->m_Image3dQueue.size() > 0)
157 {
158 ret = this->m_Image3dQueue.front();
159 this->m_Image3dQueue.pop_front();
160 }
161 this->m_Mutex.unlock();
162 return ret;
163}
164
165igtl::TrackingDataMessage::Pointer mitk::IGTLMessageQueue::PullTrackingMessage()
166{
167 igtl::TrackingDataMessage::Pointer ret = nullptr;
168 this->m_Mutex.lock();
169 if (this->m_TrackingDataQueue.size() > 0)
170 {
171 ret = this->m_TrackingDataQueue.front();
172 this->m_TrackingDataQueue.pop_front();
173 }
174 this->m_Mutex.unlock();
175 return ret;
176}
177
179{
180 igtl::MessageBase::Pointer ret = nullptr;
181 this->m_Mutex.lock();
182 if (this->m_CommandQueue.size() > 0)
183 {
184 ret = this->m_CommandQueue.front();
185 this->m_CommandQueue.pop_front();
186 }
187 this->m_Mutex.unlock();
188 return ret;
189}
190
191igtl::StringMessage::Pointer mitk::IGTLMessageQueue::PullStringMessage()
192{
193 igtl::StringMessage::Pointer ret = nullptr;
194 this->m_Mutex.lock();
195 if (this->m_StringQueue.size() > 0)
196 {
197 ret = this->m_StringQueue.front();
198 this->m_StringQueue.pop_front();
199 }
200 this->m_Mutex.unlock();
201 return ret;
202}
203
204igtl::TransformMessage::Pointer mitk::IGTLMessageQueue::PullTransformMessage()
205{
206 igtl::TransformMessage::Pointer ret = nullptr;
207 this->m_Mutex.lock();
208 if (this->m_TransformQueue.size() > 0)
209 {
210 ret = this->m_TransformQueue.front();
211 this->m_TransformQueue.pop_front();
212 }
213 this->m_Mutex.unlock();
214 return ret;
215}
216
218{
219 this->m_Mutex.lock();
220 std::stringstream s;
221 if (this->m_Latest_Message != nullptr)
222 {
223 s << "Device Type: " << this->m_Latest_Message->GetDeviceType() << std::endl;
224 s << "Device Name: " << this->m_Latest_Message->GetDeviceName() << std::endl;
225 }
226 else
227 {
228 s << "No Msg";
229 }
230 this->m_Mutex.unlock();
231 return s.str();
232}
233
235{
236 this->m_Mutex.lock();
237 std::stringstream s;
238 if (m_Latest_Message != nullptr)
239 {
240 s << this->m_Latest_Message->GetDeviceType();
241 }
242 else
243 {
244 s << "";
245 }
246 this->m_Mutex.unlock();
247 return s.str();
248}
249
251{
252 this->m_Mutex.lock();
253 std::stringstream s;
254 if (m_Latest_Message != nullptr)
255 {
256 s << "Device Type: " << this->m_Latest_Message->GetDeviceType() << std::endl;
257 s << "Device Name: " << this->m_Latest_Message->GetDeviceName() << std::endl;
258 }
259 else
260 {
261 s << "No Msg";
262 }
263 this->m_Mutex.unlock();
264 return s.str();
265}
266
268{
269 this->m_Mutex.lock();
270 std::stringstream s;
271 if (m_Latest_Message != nullptr)
272 {
273 s << this->m_Latest_Message->GetDeviceType();
274 }
275 else
276 {
277 s << "";
278 }
279 this->m_Mutex.unlock();
280 return s.str();
281}
282
284{
285 return (this->m_CommandQueue.size() + this->m_Image2dQueue.size() + this->m_Image3dQueue.size() + this->m_MiscQueue.size()
286 + this->m_StringQueue.size() + this->m_TrackingDataQueue.size() + this->m_TransformQueue.size());
287}
288
290{
291 this->m_Mutex.lock();
292 if (enable)
293 this->m_BufferingType = IGTLMessageQueue::BufferingType::NoBuffering;
294 else
295 this->m_BufferingType = IGTLMessageQueue::BufferingType::Infinit;
296 this->m_Mutex.unlock();
297}
298
303
305{
306 this->m_Mutex.unlock();
307}
igtl::ImageMessage::Pointer PullImage3dMessage()
std::deque< mitk::IGTLMessage::Pointer > m_SendQueue
std::string GetNextMsgInformationString()
Returns a string with information about the oldest message in the queue.
std::string GetLatestMsgInformationString()
Returns a string with information about the oldest message in the queue.
igtl::StringMessage::Pointer PullStringMessage()
void PushCommandMessage(igtl::MessageBase::Pointer message)
Adds the message to the queue.
void EnableNoBufferingMode(bool enable)
BufferingType m_BufferingType
defines the kind of buffering
std::mutex m_Mutex
Mutex to take car of the queue.
igtl::TransformMessage::Pointer PullTransformMessage()
std::string GetLatestMsgDeviceType()
Returns the device type of the oldest message in the queue.
void PushSendMessage(mitk::IGTLMessage::Pointer message)
void PushMessage(igtl::MessageBase::Pointer message)
Adds the message to the queue.
mitk::IGTLMessage::Pointer PullSendMessage()
igtl::ImageMessage::Pointer PullImage2dMessage()
igtl::MessageBase::Pointer PullMiscMessage()
Returns and removes the oldest message from the queue.
int GetSize()
Get the number of messages in the queue.
std::string GetNextMsgDeviceType()
Returns the device type of the oldest message in the queue.
igtl::TrackingDataMessage::Pointer PullTrackingMessage()
igtl::MessageBase::Pointer PullCommandMessage()