Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "mitkUIDGenerator.h"
19 
20 
21 //Microservices
22 #include <usGetModuleContext.h>
23 #include <usModule.h>
24 #include <usServiceProperties.h>
25 #include <usModuleContext.h>
26 
27 const std::string mitk::NavigationDataSource::US_INTERFACE_NAME = "org.mitk.services.NavigationDataSource";
28 const std::string mitk::NavigationDataSource::US_PROPKEY_DEVICENAME = US_INTERFACE_NAME + ".devicename";
29 const std::string mitk::NavigationDataSource::US_PROPKEY_ID = US_INTERFACE_NAME + ".id";
30 const std::string mitk::NavigationDataSource::US_PROPKEY_ISACTIVE = US_INTERFACE_NAME + ".isActive";
31 
33 : itk::ProcessObject(), m_Name("NavigationDataSource (no defined type)"), m_IsFrozen(false)
34 {
35 }
36 
38 {
39 }
40 
42 {
43  if (this->GetNumberOfIndexedOutputs() < 1)
44  return NULL;
45 
46  return static_cast<NavigationData*>(this->ProcessObject::GetPrimaryOutput());
47 }
48 
49 mitk::NavigationData* mitk::NavigationDataSource::GetOutput(DataObjectPointerArraySizeType idx)
50 {
51  NavigationData* out = dynamic_cast<NavigationData*>( this->ProcessObject::GetOutput(idx) );
52  if ( out == NULL && this->ProcessObject::GetOutput(idx) != NULL )
53  {
54  itkWarningMacro (<< "Unable to convert output number " << idx << " to type " << typeid( NavigationData ).name () );
55  }
56  return out;
57 }
58 
60 {
61  DataObjectPointerArray outputs = this->GetOutputs();
62  for (DataObjectPointerArray::iterator it = outputs.begin(); it != outputs.end(); ++it)
63  if (navDataName == (static_cast<NavigationData*>(it->GetPointer()))->GetName())
64  return static_cast<NavigationData*>(it->GetPointer());
65  return NULL;
66 }
67 
68 itk::ProcessObject::DataObjectPointerArraySizeType mitk::NavigationDataSource::GetOutputIndex( std::string navDataName )
69 {
70  DataObjectPointerArray outputs = this->GetOutputs();
71  for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i)
72  if (navDataName == (static_cast<NavigationData*>(outputs.at(i).GetPointer()))->GetName())
73  return i;
74  throw std::invalid_argument("output name does not exist");
75 }
76 
78  // Get Context
79  us::ModuleContext* context = us::GetModuleContext();
80 
81  // Define ServiceProps
83  mitk::UIDGenerator uidGen = mitk::UIDGenerator ("org.mitk.services.NavigationDataSource.id_", 16);
84  props[ US_PROPKEY_ID ] = uidGen.GetUID();
85  props[ US_PROPKEY_DEVICENAME ] = m_Name;
86  m_ServiceRegistration = context->RegisterService(this, props);
87 }
88 
90  if (m_ServiceRegistration != NULL) m_ServiceRegistration.Unregister();
91  m_ServiceRegistration = 0;
92 }
93 
95  return this->m_ServiceRegistration.GetReference().GetProperty(US_PROPKEY_ID).ToString();
96 }
97 
98 void mitk::NavigationDataSource::GraftOutput(itk::DataObject *graft)
99 {
100  this->GraftNthOutput(0, graft);
101 }
102 
103 void mitk::NavigationDataSource::GraftNthOutput(unsigned int idx, itk::DataObject *graft)
104 {
105  if ( idx >= this->GetNumberOfIndexedOutputs() )
106  {
107  itkExceptionMacro(<<"Requested to graft output " << idx <<
108  " but this filter only has " << this->GetNumberOfIndexedOutputs() << " Outputs.");
109  }
110 
111  if ( !graft )
112  {
113  itkExceptionMacro(<<"Requested to graft output with a NULL pointer object" );
114  }
115 
116  itk::DataObject* output = this->GetOutput(idx);
117  if ( !output )
118  {
119  itkExceptionMacro(<<"Requested to graft output that is a NULL pointer" );
120  }
121  // Call Graft on NavigationData to copy member data
122  output->Graft( graft );
123 }
124 
125 itk::DataObject::Pointer mitk::NavigationDataSource::MakeOutput ( DataObjectPointerArraySizeType /*idx*/ )
126 {
127  return mitk::NavigationData::New().GetPointer();
128 }
129 
130 itk::DataObject::Pointer mitk::NavigationDataSource::MakeOutput( const DataObjectIdentifierType & name )
131 {
132  itkDebugMacro("MakeOutput(" << name << ")");
133  if( this->IsIndexedOutputName(name) )
134  {
135  return this->MakeOutput( this->MakeIndexFromOutputName(name) );
136  }
137  return static_cast<itk::DataObject *>(mitk::NavigationData::New().GetPointer());
138 }
139 
141 {
143  // add properties to p like this:
144  //p->SetProperty("MyFilter_MyParameter", mitk::PropertyDataType::New(m_MyParameter));
146 }
147 
149 {
150  m_IsFrozen = true;
151 }
152 
154 {
155  m_IsFrozen = false;
156 }
static Pointer New()
itk::SmartPointer< Self > Pointer
static Pointer New()
NavigationData * GetOutput(void)
return the output (output with id 0) of the filter
Generated unique IDs.
Navigation Data.
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 itk::DataObject::Pointer MakeOutput(DataObjectPointerArraySizeType idx) override
virtual mitk::PropertyList::ConstPointer GetParameters() const
Get all filter parameters as a PropertyList.
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's output.
virtual void GraftOutput(itk::DataObject *graft)
Graft the specified DataObject onto this ProcessObject'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
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
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...
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.