33 #include "igtlBindMessage.h"
34 #include "igtlQuaternionTrackingDataMessage.h"
35 #include "igtlTrackingDataMessage.h"
44 this->
SetName(
"IGTLMessageProvider");
49 m_IsStreaming =
false;
53 m_StopStreamingCommand->SetCallbackFunction(
this,
57 m_StreamingCommand->SetCallbackFunction(
this,
71 this->InvokeEvent(StreamingStartRequiredEvent());
79 if (this->GetInput() !=
nullptr)
82 if (dynamic_cast<igtl::TrackingDataMessage*>(curMessage.GetPointer()) !=
nullptr)
84 igtl::TrackingDataMessage* tdMsg =
85 (igtl::TrackingDataMessage*)(curMessage.GetPointer());
87 tdMsg->GetTrackingDataElement(0, trackingData);
88 float x_pos, y_pos, z_pos;
89 trackingData->GetPosition(&x_pos, &y_pos, &z_pos);
96 if (this->m_IGTLDevice.IsNull())
99 for (
unsigned int index = 0; index < this->GetNumberOfIndexedInputs(); index++)
114 if ( igtlMsg.IsNotNull() )
117 this->m_IGTLDevice->SendMessage(igtlMsg);
125 if (this->GetNumberOfOutputs() > 0)
127 for (
int numOP = this->GetNumberOfOutputs() - 1; numOP >= 0; numOP--)
128 this->RemoveOutput(numOP);
133 if (m_IGTLDevice.IsNull())
136 this->SetNumberOfIndexedOutputs(1);
137 if (this->GetOutput(0) == NULL)
139 DataObjectPointer newOutput = this->MakeOutput(0);
140 this->SetNthOutput(0, newOutput);
162 MITK_DEBUG(
"IGTLMessageProvider") <<
"lost connection, stop streaming";
163 this->StopStreamingOfAllSources();
169 return requestType.substr(4);
177 const char * requestType = curCommand->GetDeviceType();
179 std::string reqType(requestType);
180 bool isGetMsg = !reqType.find(
"GET_");
181 bool isSTTMsg = !reqType.find(
"STT_");
182 bool isSTPMsg = !reqType.find(
"STP_");
183 bool isRTSMsg = !reqType.find(
"RTS_");
190 if ( source.IsNull() )
192 if ( !this->GetIGTLDevice()->SendRTSMessage(type.c_str()) )
196 MITK_WARN(
"IGTLMessageProvider") <<
"Tried to send a RTS message but did "
197 "not succeed. Check if this type ( "
198 << type <<
" ) was added to the message "
211 if (sourceOutput.IsNotNull() && sourceOutput->IsDataValid())
214 if ( source.IsNotNull() )
216 this->GetIGTLDevice()->SendMessage(sourceMsg);
226 igtl::MessageBase* curCommandPt = curCommand.GetPointer();
227 if ( std::strcmp( curCommand->GetDeviceType(),
"STT_BIND" ) == 0 )
229 fps = ((igtl::StartBindMessage*)curCommandPt)->GetResolution();
231 else if ( std::strcmp( curCommand->GetDeviceType(),
"STT_QTDATA" ) == 0 )
233 fps = ((igtl::StartQuaternionTrackingDataMessage*)curCommandPt)->GetResolution();
235 else if ( std::strcmp( curCommand->GetDeviceType(),
"STT_TDATA" ) == 0 )
237 fps = ((igtl::StartTrackingDataMessage*)curCommandPt)->GetResolution();
240 this->StartStreamingOfSource(source, fps);
244 this->StopStreamingOfSource(source);
255 return m_IsStreaming;
266 if ( !m_IsStreaming )
270 this->ConnectTo(src);
273 this->m_StreamingTimeMutex->Lock();
274 this->m_StreamingTime = 1.0 / (double) fps * 1000.0;
275 this->m_StreamingTimeMutex->Unlock();
285 this->m_StreamingCommand);
287 this->m_IsStreaming =
true;
291 MITK_WARN(
"IGTLMessageProvider") <<
"This provider just supports the "
292 "streaming of one source.";
298 this->InvokeEvent(StreamingStartRequiredEvent());
303 this->InvokeEvent(StreamingStopRequiredEvent());
310 this->DisconnectFrom(src);
317 this->m_StopStreamingCommand);
320 this->m_IsStreaming =
false;
328 this->m_StopStreamingCommand);
331 this->m_IsStreaming =
false;
342 "=" + requestedType +
")";
344 std::vector<us::ServiceReferenceU> serviceReferences =
345 context->GetServiceReferences(interface, filter);
349 if ( serviceReferences.size() )
354 if ( curSource.IsNotNull() )
364 this->m_IGTLDevice->SendMessage(msg);
370 for (DataObjectPointerArraySizeType i = 0;
371 i < UpstreamFilter->GetNumberOfOutputs(); i++)
373 this->SetInput(i, UpstreamFilter->
GetOutput(i));
380 for (DataObjectPointerArraySizeType i = 0;
381 i < UpstreamFilter->GetNumberOfOutputs(); i++)
383 this->RemoveInput(UpstreamFilter->
GetOutput(i));
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual igtl::MessageBase::Pointer GetMessage() const
returns the OpenIGTLink message
itk::SmartPointer< Self > Pointer
virtual void OnLostConnection() override
This method is called when the IGTL device lost the connection to the other side. ...
virtual void Update() override
void InvokeStopStreamingEvent()
Connects a mitk::IGTLDevice to a MITK-OpenIGTLink-Message-Filter-Pipeline.
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.
void StopStreamingOfSource(mitk::IGTLMessageSource *src)
Stops the streaming of the given message source.
void CreateOutputs()
Create the necessary outputs for the m_IGTLDevice.
bool IsStreaming()
Returns the streaming state.
void StopStreamingOfAllSources()
Stops the streaming of all message source.
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.
void Send(const IGTLMessage *msg)
sends the msg to the requesting client
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 void OnIncomingCommand() override
This method is called when the IGTL device hold by this class receives a new command.
virtual 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...
virtual 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)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.
virtual ~IGTLMessageProvider()