Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkNavigationDataSource.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found 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 
23 const std::string mitk::NavigationDataSource::US_INTERFACE_NAME = "org.mitk.services.NavigationDataSource";
24 const std::string mitk::NavigationDataSource::US_PROPKEY_DEVICENAME = US_INTERFACE_NAME + ".devicename";
25 const std::string mitk::NavigationDataSource::US_PROPKEY_ID = US_INTERFACE_NAME + ".id";
26 const 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 
34 {
35 }
36 
38 {
39  if (this->GetNumberOfIndexedOutputs() < 1)
40  return nullptr;
41 
42  return static_cast<NavigationData*>(this->ProcessObject::GetPrimaryOutput());
43 }
44 
45 mitk::NavigationData* mitk::NavigationDataSource::GetOutput(DataObjectPointerArraySizeType idx)
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 
64 itk::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
79  mitk::UIDGenerator uidGen = mitk::UIDGenerator ("org.mitk.services.NavigationDataSource.id_", 16);
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 
94 void mitk::NavigationDataSource::GraftOutput(itk::DataObject *graft)
95 {
96  this->GraftNthOutput(0, graft);
97 }
98 
99 void 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 
121 itk::DataObject::Pointer mitk::NavigationDataSource::MakeOutput ( DataObjectPointerArraySizeType /*idx*/ )
122 {
123  return mitk::NavigationData::New().GetPointer();
124 }
125 
126 itk::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 
137 {
139  // add properties to p like this:
140  //p->SetProperty("MyFilter_MyParameter", mitk::PropertyDataType::New(m_MyParameter));
142 }
143 
145 {
146  m_IsFrozen = true;
147 }
148 
150 {
151  m_IsFrozen = false;
152 }
153 
154 mitk::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 
160 mitk::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 }
ServiceReference< I1 > GetReference(InterfaceType< I1 >) const
static Pointer New()
static Pointer New()
NavigationData * GetOutput(void)
return the output (output with id 0) of the filter
Generated unique IDs.
Navigation Data.
DataCollection - Class to facilitate loading/accessing structured data.
NavigationTool::Pointer GetToolMetaData(DataObjectPointerArraySizeType idx)
NavigationToolStorage::Pointer m_ToolMetaDataCollection
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
An object of this class represents a collection of navigation tools. You may add/delete navigation to...
itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
static const std::string US_INTERFACE_NAME
These Constants are used in conjunction with Microservices.
virtual void GraftNthOutput(unsigned int idx, itk::DataObject *graft)
Graft the specified DataObject onto this ProcessObject&#39;s output.
virtual void GraftOutput(itk::DataObject *graft)
Graft the specified DataObject onto this ProcessObject&#39;s output.
virtual void UnRegisterMicroservice()
Registers this object as a Microservice, making it available to every module and/or plugin...
static const std::string US_PROPKEY_ISACTIVE
itk::SmartPointer< const Self > ConstPointer
virtual std::string GetName()
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
static Pointer New()
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
std::string GetMicroserviceID()
Returns the id that this device is registered with. The id will only be valid, if the NavigationDataS...
virtual mitk::PropertyList::ConstPointer GetParameters() const
Get all filter parameters as a PropertyList.
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.