Medical Imaging Interaction Toolkit  2018.4.99-08619e4f
Medical Imaging Interaction Toolkit
mitkNavigationDataToNavigationDataFilter.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 
15 
18 {
19 mitk::NavigationData::Pointer output = mitk::NavigationData::New();
20 this->SetNumberOfRequiredOutputs(1);
21 this->SetNthOutput(0, output.GetPointer());
22 }
23 
24 
26 {
27 }
28 
29 
31 {
32  this->SetInput(0, nd);
33 }
34 
35 
37 {
38  if ( nd == nullptr ) // if an input is set to nullptr, remove it
39  this->RemoveInput(idx);
40  else
41  this->ProcessObject::SetNthInput(idx, const_cast<NavigationData*>(nd)); // ProcessObject is not const-correct so a const_cast is required here
43 }
44 
45 
47 {
48  if (this->GetNumberOfInputs() < 1)
49  return nullptr;
50 
51  return static_cast<const NavigationData*>(this->ProcessObject::GetInput(0));
52 }
53 
54 
56 {
57  if (this->GetNumberOfInputs() < 1)
58  return nullptr;
59 
60  return static_cast<const NavigationData*>(this->ProcessObject::GetInput(idx));
61 }
62 
63 
65 {
66  const DataObjectPointerArray& inputs = const_cast<Self*>(this)->GetInputs();
67  for (DataObjectPointerArray::const_iterator it = inputs.begin(); it != inputs.end(); ++it)
68  if (std::string(navDataName) == (static_cast<NavigationData*>(it->GetPointer()))->GetName())
69  return static_cast<NavigationData*>(it->GetPointer());
70  return nullptr;
71 }
72 
73 
74 itk::ProcessObject::DataObjectPointerArraySizeType mitk::NavigationDataToNavigationDataFilter::GetInputIndex( std::string navDataName )
75 {
76  DataObjectPointerArray outputs = this->GetInputs();
77  for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i)
78  if (navDataName == (static_cast<NavigationData*>(outputs.at(i).GetPointer()))->GetName())
79  return i;
80  throw std::invalid_argument("output name does not exist");
81 }
82 
84 {
85  for (DataObjectPointerArraySizeType i = 0; i < UpstreamFilter->GetNumberOfOutputs(); i++)
86  {
87  this->SetInput(i, UpstreamFilter->GetOutput(i));
88  }
89 }
90 
91 
93 {
94  this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs()); // create outputs for all inputs
95  bool isModified = false;
96  for (unsigned int idx = 0; idx < this->GetNumberOfIndexedOutputs(); ++idx){
97  if (this->GetOutput(idx) == nullptr)
98  {
99  mitk::NavigationData::Pointer newOutput = mitk::NavigationData::New();
100  this->SetNthOutput(idx, newOutput);
101  isModified = true;
102  }
103  }
104 
105  if(isModified)
106  this->Modified();
107 }
DataObjectPointerArraySizeType GetInputIndex(std::string navDataName)
return the index of the input with name navDataName, throw std::invalid_argument exception if that na...
static Pointer New()
NavigationData * GetOutput(void)
return the output (output with id 0) of the filter
Navigation Data.
DataCollection - Class to facilitate loading/accessing structured data.
virtual void SetInput(const NavigationData *nd)
Set the input of this filter.
const NavigationData * GetInput(void) const
Get the input of this filter.
virtual void ConnectTo(mitk::NavigationDataSource *UpstreamFilter)
Connects the input of this filter to the outputs of the given NavigationDataSource.