29 #include "igtlBindMessage.h" 30 #include "igtlQuaternionTrackingDataMessage.h" 31 #include "igtlTrackingDataMessage.h" 40 this->
SetName(
"IGTLMessageProvider");
42 m_StreamingTimeMutex = itk::FastMutexLock::New();
45 m_IsStreaming =
false;
48 this->m_StopStreamingCommand = ProviderCommand::New();
49 m_StopStreamingCommand->SetCallbackFunction(
this,
52 this->m_StreamingCommand = ProviderCommand::New();
53 m_StreamingCommand->SetCallbackFunction(
this,
67 this->InvokeEvent(StreamingStartRequiredEvent());
78 if (dynamic_cast<igtl::TrackingDataMessage*>(curMessage.GetPointer()) !=
nullptr)
80 igtl::TrackingDataMessage* tdMsg =
81 (igtl::TrackingDataMessage*)(curMessage.GetPointer());
82 igtl::TrackingDataElement::Pointer trackingData = igtl::TrackingDataElement::New();
83 tdMsg->GetTrackingDataElement(0, trackingData);
84 float x_pos, y_pos, z_pos;
85 trackingData->GetPosition(&x_pos, &y_pos, &z_pos);
95 for (
unsigned int index = 0; index < this->GetNumberOfIndexedInputs(); index++)
103 if ( !msg->IsDataValid() )
115 if (this->GetNumberOfOutputs() > 0)
117 for (
int numOP = this->GetNumberOfOutputs() - 1; numOP >= 0; numOP--)
118 this->RemoveOutput(numOP);
126 this->SetNumberOfIndexedOutputs(1);
129 DataObjectPointer newOutput = this->
MakeOutput(0);
130 this->SetNthOutput(0, newOutput);
152 MITK_DEBUG(
"IGTLMessageProvider") <<
"lost connection, stop streaming";
159 return requestType.substr(4);
165 igtl::MessageBase::Pointer curCommand = this->
m_IGTLDevice->GetNextCommand();
167 const char * requestType = curCommand->GetDeviceType();
169 std::string reqType(requestType);
170 bool isGetMsg = !reqType.find(
"GET_");
171 bool isSTTMsg = !reqType.find(
"STT_");
172 bool isSTPMsg = !reqType.find(
"STP_");
177 mitk::IGTLMessageSource::Pointer source = this->
GetFittingSource(type.c_str());
180 if ( source.IsNull() )
186 MITK_WARN(
"IGTLMessageProvider") <<
"Tried to send a RTS message but did " 187 "not succeed. Check if this type ( " 188 << type <<
" ) was added to the message " 200 mitk::IGTLMessage::Pointer sourceOutput = source->GetOutput();
201 if (sourceOutput.IsNotNull() && sourceOutput->IsDataValid())
203 if ( source.IsNotNull() )
215 igtl::MessageBase* curCommandPt = curCommand.GetPointer();
216 if ( std::strcmp( curCommand->GetDeviceType(),
"STT_BIND" ) == 0 )
218 fps = ((igtl::StartBindMessage*)curCommandPt)->GetResolution();
220 else if ( std::strcmp( curCommand->GetDeviceType(),
"STT_QTDATA" ) == 0 )
222 fps = ((igtl::StartQuaternionTrackingDataMessage*)curCommandPt)->GetResolution();
224 else if ( std::strcmp( curCommand->GetDeviceType(),
"STT_TDATA" ) == 0 )
226 fps = ((igtl::StartTrackingDataMessage*)curCommandPt)->GetResolution();
244 return m_IsStreaming;
250 if ( src ==
nullptr )
255 if ( !m_IsStreaming )
262 this->m_StreamingTimeMutex->Lock();
263 this->m_StreamingTime = 1.0 / (double) fps * 1000.0;
264 this->m_StreamingTimeMutex->Unlock();
274 this->m_StreamingCommand);
276 this->m_IsStreaming =
true;
280 MITK_WARN(
"IGTLMessageProvider") <<
"This provider just supports the " 281 "streaming of one source.";
287 this->InvokeEvent(StreamingStartRequiredEvent());
292 this->InvokeEvent(StreamingStopRequiredEvent());
306 this->m_StopStreamingCommand);
309 this->m_IsStreaming =
false;
317 this->m_StopStreamingCommand);
320 this->m_IsStreaming =
false;
331 "=" + requestedType +
")";
333 std::vector<us::ServiceReferenceU> serviceReferences =
334 context->GetServiceReferences(interface, filter);
338 if ( serviceReferences.size() )
340 mitk::IGTLMessageSource::Pointer curSource =
343 if ( curSource.IsNotNull() )
354 MITK_INFO <<
"Sending OpenIGTLink Message: " << msg->ToString();
362 for (DataObjectPointerArraySizeType i = 0;
363 i < UpstreamFilter->GetNumberOfOutputs(); i++)
372 if (UpstreamFilter ==
nullptr)
375 for (DataObjectPointerArraySizeType i = 0; i < UpstreamFilter->GetNumberOfOutputs(); ++i)
377 auto input = UpstreamFilter->
GetOutput(i);
379 if (input ==
nullptr)
382 auto nb = this->GetNumberOfIndexedInputs();
384 for (DataObjectPointerArraySizeType i = 0; i < nb; ++i)
388 this->RemoveInput(i);
~IGTLMessageProvider() override
void OnLostConnection() override
This method is called when the IGTL device lost the connection to the other side. ...
void InvokeStopStreamingEvent()
Connects a mitk::IGTLDevice to a MITK-OpenIGTLink-Message-Filter-Pipeline.
itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
const IGTLMessage * GetInput(void) const
Get the input of this filter.
static void Update(vtkPolyData *)
DataCollection - Class to facilitate loading/accessing structured data.
mitk::IGTLMessageSource::Pointer GetFittingSource(const char *requestedType)
Looks for microservices that provide messages with the requested type.
mitk::IGTLDevice::Pointer m_IGTLDevice
virtual mitk::IGTLDevice * GetIGTLDevice()
returns the OpenIGTLink device that is used by this filter
void StopStreamingOfSource(mitk::IGTLMessageSource *src)
Stops the streaming of the given message source.
void CreateOutputs()
Create the necessary outputs for the m_IGTLDevice.
void Send(mitk::IGTLMessage::Pointer msg)
sends the msg to the requesting client
bool IsStreaming()
Returns the streaming state.
void StopStreamingOfAllSources()
Stops the streaming of all message source.
bool SendRTSMessage(const char *type)
Send RTS message of given type.
void InvokeStartStreamingEvent()
void StartStreamingOfSource(mitk::IGTLMessageSource *src, unsigned int fps)
Starts the streaming of the given message source with the given fps.
IGTLMessage * GetOutput(void)
return the output (output with id 0) of the filter
A wrapper for the OpenIGTLink message type.
static const std::string US_PROPKEY_DEVICETYPE
void CallThisFromGUIThread(itk::Command *, itk::EventObject *e=nullptr)
Change the current application cursor.
void DisconnectFrom(mitk::IGTLMessageSource *UpstreamFilter)
Disconnects this filter from the outputs of the given IGTLMessageSource.
static CallbackFromGUIThread * GetInstance()
This class is a singleton.
OpenIGTLink message source.
virtual igtl::MessageBase::Pointer GetMessage() const
returns the OpenIGTLink message
virtual void SetInput(unsigned int idx, const IGTLMessage *msg)
Set input with id idx of this filter.
void OnIncomingCommand() override
This method is called when the IGTL device hold by this class receives a new command.
void OnIncomingMessage() override
This method is called when the IGTL device hold by this class receives a new message.
virtual void SetName(std::string _arg)
Sets the human readable name of this source. There is also a default name, but you can use this metho...
void SendMessage(mitk::IGTLMessage::Pointer msg)
Adds the given message to the sending queue.
void GenerateData() override
filter execute method
static const std::string US_INTERFACE_NAME
These Constants are used in conjunction with Microservices.
void ConnectTo(mitk::IGTLMessageSource *UpstreamFilter)
Connects the input of this filter to the outputs of the given IGTLMessageSource.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
std::string RemoveRequestPrefixes(std::string requestType)