Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkNavigationDataSmoothingFilter.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 
21  m_NumerOfValues(5)
22 {
23 }
24 
26 {
27 }
28 
30 {
31  DataObjectPointerArraySizeType numberOfInputs = this->GetNumberOfInputs();
32 
33  if ( numberOfInputs == 0 ) return;
34 
35  this->CreateOutputsForAllInputs();
36 
37  //initialize list if nessesary
38  if ( m_LastValuesList.size() != numberOfInputs )
39  {
40  this->InitializeLastValuesList();
41  }
42 
43  //add current value to list
44  for ( unsigned int i = 0; i < numberOfInputs; ++i )
45  {
46  this->AddValue(i,this->GetInput(i)->GetPosition());
47  }
48 
49  //generate output
50  for (unsigned int i = 0; i < numberOfInputs; ++i)
51  {
52  const mitk::NavigationData* nd = this->GetInput(i);
53  assert(nd);
54 
55  mitk::NavigationData* output = this->GetOutput(i);
56  assert(output);
57 
58  output->Graft(nd); // copy all information from input to output
59 
60  output->SetPosition(GetMean(i));
61 
62  output->SetDataValid(nd->IsDataValid());
63  }
64 }
65 
67 {
68  m_LastValuesList = std::map< int, std::map< int , mitk::Point3D> >();
69 
70  for ( unsigned int i = 0; i < this->GetNumberOfOutputs(); ++i )
71  {
72  std::map<int,mitk::Point3D> currentList;
73  for ( int j = 0; j < m_NumerOfValues; ++j )
74  {
75  mitk::Point3D emptyPoint;
76  emptyPoint.Fill(0);
77  currentList.insert(std::pair<int, mitk::Point3D>(j, emptyPoint));
78  }
79  m_LastValuesList.insert(std::pair<int, std::map<int,mitk::Point3D> > (i,currentList));
80  }
81 }
82 
84 {
85  for (int i = 1; i < m_NumerOfValues; ++i)
86  {
87  m_LastValuesList[outputID][i-1] = m_LastValuesList[outputID][i];
88  }
89 
90  m_LastValuesList[outputID][m_NumerOfValues-1] = value;
91 }
92 
94 {
95  mitk::Point3D mean;
96  mean.Fill(0);
97  for (int i=0; i<m_NumerOfValues; i++)
98  {
99  mean[0] += m_LastValuesList[outputID][i][0];
100  mean[1] += m_LastValuesList[outputID][i][1];
101  mean[2] += m_LastValuesList[outputID][i][2];
102  }
103  mean[0] /= m_NumerOfValues;
104  mean[1] /= m_NumerOfValues;
105  mean[2] /= m_NumerOfValues;
106  return mean;
107 }
void AddValue(int outputID, mitk::Point3D value)
NavigationDataToNavigationDataFilter is the base class of all filters that receive NavigationDatas as...
Navigation Data.
DataCollection - Class to facilitate loading/accessing structured data.
virtual void SetDataValid(bool _arg)
sets the dataValid flag of the NavigationData object indicating if the object contains valid data ...
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual void SetPosition(PositionType _arg)
sets the position of the NavigationData object
virtual void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.