Medical Imaging Interaction Toolkit  2016.11.0
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,
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 
19 
22 {
24 this->SetNumberOfRequiredOutputs(1);
25 this->SetNthOutput(0, output.GetPointer());
26 }
27 
28 
30 {
31 }
32 
33 
35 {
36  this->SetInput(0, nd);
37 }
38 
39 
41 {
42  if ( nd == NULL ) // if an input is set to NULL, remove it
43  this->RemoveInput(idx);
44  else
45  this->ProcessObject::SetNthInput(idx, const_cast<NavigationData*>(nd)); // ProcessObject is not const-correct so a const_cast is required here
46  this->CreateOutputsForAllInputs();
47 }
48 
49 
51 {
52  if (this->GetNumberOfInputs() < 1)
53  return NULL;
54 
55  return static_cast<const NavigationData*>(this->ProcessObject::GetInput(0));
56 }
57 
58 
60 {
61  if (this->GetNumberOfInputs() < 1)
62  return NULL;
63 
64  return static_cast<const NavigationData*>(this->ProcessObject::GetInput(idx));
65 }
66 
67 
69 {
70  const DataObjectPointerArray& inputs = const_cast<Self*>(this)->GetInputs();
71  for (DataObjectPointerArray::const_iterator it = inputs.begin(); it != inputs.end(); ++it)
72  if (std::string(navDataName) == (static_cast<NavigationData*>(it->GetPointer()))->GetName())
73  return static_cast<NavigationData*>(it->GetPointer());
74  return NULL;
75 }
76 
77 
78 itk::ProcessObject::DataObjectPointerArraySizeType mitk::NavigationDataToNavigationDataFilter::GetInputIndex( std::string navDataName )
79 {
80  DataObjectPointerArray outputs = this->GetInputs();
81  for (DataObjectPointerArray::size_type i = 0; i < outputs.size(); ++i)
82  if (navDataName == (static_cast<NavigationData*>(outputs.at(i).GetPointer()))->GetName())
83  return i;
84  throw std::invalid_argument("output name does not exist");
85 }
86 
88 {
89  for (DataObjectPointerArraySizeType i = 0; i < UpstreamFilter->GetNumberOfOutputs(); i++)
90  {
91  this->SetInput(i, UpstreamFilter->GetOutput(i));
92  }
93 }
94 
95 
97 {
98  this->SetNumberOfIndexedOutputs(this->GetNumberOfIndexedInputs()); // create outputs for all inputs
99  bool isModified = false;
100  for (unsigned int idx = 0; idx < this->GetNumberOfIndexedOutputs(); ++idx){
101  if (this->GetOutput(idx) == NULL)
102  {
104  this->SetNthOutput(idx, newOutput);
105  isModified = true;
106  }
107  }
108 
109  if(isModified)
110  this->Modified();
111 }
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()
itk::SmartPointer< Self > Pointer
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.
virtual void ConnectTo(mitk::NavigationDataSource *UpstreamFilter)
Connects the input of this filter to the outputs of the given NavigationDataSource.
const NavigationData * GetInput(void) const
Get the input of this filter.