MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNavigationDataSource.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
17//Microservices
18#include <usGetModuleContext.h>
19#include <usModule.h>
20#include <usServiceProperties.h>
21#include <usModuleContext.h>
22
23const std::string mitk::NavigationDataSource::US_INTERFACE_NAME = "org.mitk.services.NavigationDataSource";
24const std::string mitk::NavigationDataSource::US_PROPKEY_DEVICENAME = US_INTERFACE_NAME + ".devicename";
25const std::string mitk::NavigationDataSource::US_PROPKEY_ID = US_INTERFACE_NAME + ".id";
26const std::string mitk::NavigationDataSource::US_PROPKEY_ISACTIVE = US_INTERFACE_NAME + ".isActive";
27
29: itk::ProcessObject(), m_Name("NavigationDataSource (no defined type)"), m_IsFrozen(false), m_ToolMetaDataCollection(mitk::NavigationToolStorage::New())
30{
31}
32
36
38{
39 if (this->GetNumberOfIndexedOutputs() < 1)
40 return nullptr;
41
42 return static_cast<NavigationData*>(this->ProcessObject::GetPrimaryOutput());
43}
44
46{
47 NavigationData* out = dynamic_cast<NavigationData*>( this->ProcessObject::GetOutput(idx) );
48 if ( out == nullptr && this->ProcessObject::GetOutput(idx) != nullptr )
49 {
50 itkWarningMacro (<< "Unable to convert output number " << idx << " to type " << typeid( NavigationData ).name () );
51 }
52 return out;
53}
54
56{
57 DataObjectPointerArray outputs = this->GetOutputs();
58 for (DataObjectPointerArray::iterator it = outputs.begin(); it != outputs.end(); ++it)
59 if (navDataName == (static_cast<NavigationData*>(it->GetPointer()))->GetName())
60 return static_cast<NavigationData*>(it->GetPointer());
61 return nullptr;
62}
63
64itk::ProcessObject::DataObjectPointerArraySizeType mitk::NavigationDataSource::GetOutputIndex( std::string navDataName )
65{
66 DataObjectPointerArray outputs = this->GetOutputs();
67 for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i)
68 if (navDataName == (static_cast<NavigationData*>(outputs.at(i).GetPointer()))->GetName())
69 return i;
70 throw std::invalid_argument("output name does not exist");
71}
72
74 // Get Context
75 us::ModuleContext* context = us::GetModuleContext();
76
77 // Define ServiceProps
78 us::ServiceProperties props;
79 mitk::UIDGenerator uidGen = mitk::UIDGenerator ("org.mitk.services.NavigationDataSource.id_");
80 props[ US_PROPKEY_ID ] = uidGen.GetUID();
81 props[ US_PROPKEY_DEVICENAME ] = m_Name;
82 m_ServiceRegistration = context->RegisterService(this, props);
83}
84
86 if (m_ServiceRegistration != nullptr) m_ServiceRegistration.Unregister();
87 m_ServiceRegistration = 0;
88}
89
91 return this->m_ServiceRegistration.GetReference().GetProperty(US_PROPKEY_ID).ToString();
92}
93
94void mitk::NavigationDataSource::GraftOutput(itk::DataObject *graft)
95{
96 this->GraftNthOutput(0, graft);
97}
98
99void mitk::NavigationDataSource::GraftNthOutput(unsigned int idx, itk::DataObject *graft)
100{
101 if ( idx >= this->GetNumberOfIndexedOutputs() )
102 {
103 itkExceptionMacro(<<"Requested to graft output " << idx <<
104 " but this filter only has " << this->GetNumberOfIndexedOutputs() << " Outputs.");
105 }
106
107 if ( !graft )
108 {
109 itkExceptionMacro(<<"Requested to graft output with a nullptr pointer object" );
110 }
111
112 itk::DataObject* output = this->GetOutput(idx);
113 if ( !output )
114 {
115 itkExceptionMacro(<<"Requested to graft output that is a nullptr pointer" );
116 }
117 // Call Graft on NavigationData to copy member data
118 output->Graft( graft );
119}
120
121itk::DataObject::Pointer mitk::NavigationDataSource::MakeOutput ( DataObjectPointerArraySizeType /*idx*/ )
122{
123 return mitk::NavigationData::New().GetPointer();
124}
125
126itk::DataObject::Pointer mitk::NavigationDataSource::MakeOutput( const DataObjectIdentifierType & name )
127{
128 itkDebugMacro("MakeOutput(" << name << ")");
129 if( this->IsIndexedOutputName(name) )
130 {
131 return this->MakeOutput( this->MakeIndexFromOutputName(name) );
132 }
133 return static_cast<itk::DataObject *>(mitk::NavigationData::New().GetPointer());
134}
135
136mitk::PropertyList::ConstPointer mitk::NavigationDataSource::GetParameters() const
137{
138 mitk::PropertyList::Pointer p = mitk::PropertyList::New();
139 // add properties to p like this:
140 //p->SetProperty("MyFilter_MyParameter", mitk::PropertyDataType::New(m_MyParameter));
141 return mitk::PropertyList::ConstPointer(p);
142}
143
145{
146 m_IsFrozen = true;
147}
148
150{
151 m_IsFrozen = false;
152}
153
154mitk::NavigationTool::Pointer mitk::NavigationDataSource::GetToolMetaData(DataObjectPointerArraySizeType idx)
155{
156 if (idx >= this->GetNumberOfIndexedOutputs()) { return mitk::NavigationTool::New(); }
157 else { return GetToolMetaData(this->GetOutput(idx)->GetName()); }
158}
159
160mitk::NavigationTool::Pointer mitk::NavigationDataSource::GetToolMetaData(const std::string& navDataName)
161{
162 mitk::NavigationTool::Pointer returnValue = m_ToolMetaDataCollection->GetToolByName(navDataName);
163 if (returnValue == nullptr) { returnValue = mitk::NavigationTool::New(); }
164 return returnValue;
165}
virtual void GraftOutput(itk::DataObject *graft)
Graft the specified DataObject onto this ProcessObject's output.
itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
virtual void GraftNthOutput(unsigned int idx, itk::DataObject *graft)
Graft the specified DataObject onto this ProcessObject's output.
NavigationData * GetOutput(void)
return the output (output with id 0) of the filter
std::string GetMicroserviceID()
Returns the id that this device is registered with. The id will only be valid, if the NavigationDataS...
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 mitk::PropertyList::ConstPointer GetParameters() const
Get all filter parameters as a PropertyList.
DataObjectPointerArraySizeType GetOutputIndex(std::string navDataName)
return the index of the output with name navDataName, -1 if no output with that name was found
static const std::string US_PROPKEY_DEVICENAME
static const std::string US_PROPKEY_ISACTIVE
virtual void UnRegisterMicroservice()
Registers this object as a Microservice, making it available to every module and/or plugin.
static const std::string US_INTERFACE_NAME
These Constants are used in conjunction with Microservices.
NavigationTool::Pointer GetToolMetaData(DataObjectPointerArraySizeType idx)
An object of this class represents a collection of navigation tools. You may add/delete navigation to...
IGT Exceptions.