14#include "mitkUIDGenerator.h"
17#include <usGetModuleContext.h>
19#include <usServiceProperties.h>
20#include <usModuleContext.h>
23 "org.mitk.services.IGTLMessageSource";
25 US_INTERFACE_NAME +
".devicename";
27 US_INTERFACE_NAME +
".devicetype";
29 US_INTERFACE_NAME +
".id";
31 US_INTERFACE_NAME +
".isActive";
34 :
itk::ProcessObject(), m_Name(
"IGTLMessageSource (no defined type)"),
35 m_Type(
"NONE"), m_StreamingFPS(0)
46 if (this->GetNumberOfIndexedOutputs() < 1)
48 MITK_WARN <<
"IGTLMessageSource contained no outputs. Returning nullptr.";
52 return static_cast<IGTLMessage*
>(this->ProcessObject::GetPrimaryOutput());
56 DataObjectPointerArraySizeType idx)
59 dynamic_cast<IGTLMessage*
>( this->ProcessObject::GetOutput(idx) );
60 if ( out ==
nullptr && this->ProcessObject::GetOutput(idx) !=
nullptr )
62 itkWarningMacro (<<
"Unable to convert output number " << idx <<
" to type "
69 const std::string& messageName)
71 DataObjectPointerArray outputs = this->GetOutputs();
72 for (DataObjectPointerArray::iterator it = outputs.begin();
77 (
static_cast<IGTLMessage*
>(it->GetPointer()))->GetName())
85itk::ProcessObject::DataObjectPointerArraySizeType
88 DataObjectPointerArray outputs = this->GetOutputs();
89 for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i)
92 (
static_cast<IGTLMessage*
>(outputs.at(i).GetPointer()))->GetName())
97 throw std::invalid_argument(
"output name does not exist");
103 us::ModuleContext* context = us::GetModuleContext();
106 us::ServiceProperties props;
107 mitk::UIDGenerator uidGen =
108 mitk::UIDGenerator (
"org.mitk.services.IGTLMessageSource.id_");
109 props[ US_PROPKEY_ID ] = uidGen.GetUID();
110 props[ US_PROPKEY_DEVICENAME ] = m_Name;
111 props[ US_PROPKEY_DEVICETYPE ] = m_Type;
112 m_ServiceRegistration = context->RegisterService(
this, props);
117 if (m_ServiceRegistration !=
nullptr)
119 m_ServiceRegistration.Unregister();
121 m_ServiceRegistration = 0;
126 us::Any referenceProperty =
127 this->m_ServiceRegistration.GetReference().GetProperty(US_PROPKEY_ID);
128 return referenceProperty.ToString();
133 this->GraftNthOutput(0, graft);
137 itk::DataObject *graft)
139 if ( idx >= this->GetNumberOfIndexedOutputs() )
141 itkExceptionMacro(<<
"Requested to graft output " << idx <<
" but this filter"
142 "only has " << this->GetNumberOfIndexedOutputs() <<
" Outputs.");
147 itkExceptionMacro(<<
"Requested to graft output with a nullptr pointer object" );
150 itk::DataObject* output = this->GetOutput(idx);
153 itkExceptionMacro(<<
"Requested to graft output that is a nullptr pointer" );
156 output->Graft( graft );
161 return IGTLMessage::New().GetPointer();
166 itkDebugMacro(
"MakeOutput(" << name <<
")");
167 if( this->IsIndexedOutputName(name) )
169 return this->MakeOutput( this->MakeIndexFromOutputName(name) );
171 return static_cast<itk::DataObject *
>(IGTLMessage::New().GetPointer());
176 mitk::PropertyList::Pointer p = mitk::PropertyList::New();
179 return mitk::PropertyList::ConstPointer(p);
184 this->m_StreamingFPSMutex.lock();
185 this->m_StreamingFPS = fps;
186 this->m_StreamingFPSMutex.unlock();
192 unsigned int fps = 0;
193 this->m_StreamingFPSMutex.lock();
194 fps = this->m_StreamingFPS;
195 this->m_StreamingFPSMutex.unlock();
void SetFPS(unsigned int fps)
Sets the fps used for streaming this source.
virtual void GraftNthOutput(unsigned int idx, itk::DataObject *graft)
Graft the specified DataObject onto this ProcessObject's output.
itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
DataObjectPointerArraySizeType GetOutputIndex(std::string messageName)
return the index of the output with name messageName, -1 if no output with that name was found
std::string GetMicroserviceID()
Returns the id that this device is registered with. The id will only be valid, if the IGTLMessageSour...
static const std::string US_INTERFACE_NAME
These Constants are used in conjunction with Microservices.
static const std::string US_PROPKEY_DEVICENAME
virtual void RegisterAsMicroservice()
Registers this object as a Microservice, making it available to every module and/or plugin....
static const std::string US_PROPKEY_ID
virtual void GraftOutput(itk::DataObject *graft)
Graft the specified DataObject onto this ProcessObject's output.
~IGTLMessageSource() override
static const std::string US_PROPKEY_ISACTIVE
virtual mitk::PropertyList::ConstPointer GetParameters() const
Get all filter parameters as a PropertyList.
unsigned int GetFPS()
Gets the fps used for streaming this source.
virtual void UnRegisterMicroservice()
Registers this object as a Microservice, making it available to every module and/or plugin.
static const std::string US_PROPKEY_DEVICETYPE
IGTLMessage * GetOutput(void)
return the output (output with id 0) of the filter
A wrapper for the OpenIGTLink message type.