MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkIGTLMessageSource.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 "mitkUIDGenerator.h"
15
16//Microservices
17#include <usGetModuleContext.h>
18#include <usModule.h>
19#include <usServiceProperties.h>
20#include <usModuleContext.h>
21
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";
32
34 : itk::ProcessObject(), m_Name("IGTLMessageSource (no defined type)"),
35 m_Type("NONE"), m_StreamingFPS(0)
36{
37}
38
40{
41 //this->UnRegisterMicroservice();
42}
43
45{
46 if (this->GetNumberOfIndexedOutputs() < 1)
47 {
48 MITK_WARN << "IGTLMessageSource contained no outputs. Returning nullptr.";
49 return nullptr;
50 }
51
52 return static_cast<IGTLMessage*>(this->ProcessObject::GetPrimaryOutput());
53}
54
56 DataObjectPointerArraySizeType idx)
57{
58 IGTLMessage* out =
59 dynamic_cast<IGTLMessage*>( this->ProcessObject::GetOutput(idx) );
60 if ( out == nullptr && this->ProcessObject::GetOutput(idx) != nullptr )
61 {
62 itkWarningMacro (<< "Unable to convert output number " << idx << " to type "
63 << typeid( IGTLMessage ).name () );
64 }
65 return out;
66}
67
69 const std::string& messageName)
70{
71 DataObjectPointerArray outputs = this->GetOutputs();
72 for (DataObjectPointerArray::iterator it = outputs.begin();
73 it != outputs.end();
74 ++it)
75 {
76 if (messageName ==
77 (static_cast<IGTLMessage*>(it->GetPointer()))->GetName())
78 {
79 return static_cast<IGTLMessage*>(it->GetPointer());
80 }
81 }
82 return nullptr;
83}
84
85itk::ProcessObject::DataObjectPointerArraySizeType
87{
88 DataObjectPointerArray outputs = this->GetOutputs();
89 for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i)
90 {
91 if (messageName ==
92 (static_cast<IGTLMessage*>(outputs.at(i).GetPointer()))->GetName())
93 {
94 return i;
95 }
96 }
97 throw std::invalid_argument("output name does not exist");
98}
99
101{
102 // Get Context
103 us::ModuleContext* context = us::GetModuleContext();
104
105 // Define ServiceProps
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);
113}
114
116{
117 if (m_ServiceRegistration != nullptr)
118 {
119 m_ServiceRegistration.Unregister();
120 }
121 m_ServiceRegistration = 0;
122}
123
125{
126 us::Any referenceProperty =
127 this->m_ServiceRegistration.GetReference().GetProperty(US_PROPKEY_ID);
128 return referenceProperty.ToString();
129}
130
131void mitk::IGTLMessageSource::GraftOutput(itk::DataObject *graft)
132{
133 this->GraftNthOutput(0, graft);
134}
135
137 itk::DataObject *graft)
138{
139 if ( idx >= this->GetNumberOfIndexedOutputs() )
140 {
141 itkExceptionMacro(<<"Requested to graft output " << idx << " but this filter"
142 "only has " << this->GetNumberOfIndexedOutputs() << " Outputs.");
143 }
144
145 if ( !graft )
146 {
147 itkExceptionMacro(<<"Requested to graft output with a nullptr pointer object" );
148 }
149
150 itk::DataObject* output = this->GetOutput(idx);
151 if ( !output )
152 {
153 itkExceptionMacro(<<"Requested to graft output that is a nullptr pointer" );
154 }
155 // Call Graft on IGTLMessage to copy member data
156 output->Graft( graft );
157}
158
159itk::DataObject::Pointer mitk::IGTLMessageSource::MakeOutput ( DataObjectPointerArraySizeType /*idx*/ )
160{
161 return IGTLMessage::New().GetPointer();
162}
163
164itk::DataObject::Pointer mitk::IGTLMessageSource::MakeOutput( const DataObjectIdentifierType & name )
165{
166 itkDebugMacro("MakeOutput(" << name << ")");
167 if( this->IsIndexedOutputName(name) )
168 {
169 return this->MakeOutput( this->MakeIndexFromOutputName(name) );
170 }
171 return static_cast<itk::DataObject *>(IGTLMessage::New().GetPointer());
172}
173
174mitk::PropertyList::ConstPointer mitk::IGTLMessageSource::GetParameters() const
175{
176 mitk::PropertyList::Pointer p = mitk::PropertyList::New();
177 // add properties to p like this:
178 //p->SetProperty("MyFilter_MyParameter", mitk::PropertyDataType::New(m_MyParameter));
179 return mitk::PropertyList::ConstPointer(p);
180}
181
183{
184 this->m_StreamingFPSMutex.lock();
185 this->m_StreamingFPS = fps;
186 this->m_StreamingFPSMutex.unlock();
187}
188
189
191{
192 unsigned int fps = 0;
193 this->m_StreamingFPSMutex.lock();
194 fps = this->m_StreamingFPS;
195 this->m_StreamingFPSMutex.unlock();
196 return fps;
197}
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.
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.