Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkNavigationDataEvaluationFilter.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 
19 
20 #define _USE_MATH_DEFINES
21 #include <math.h>
22 
25 {
26 
27 }
28 
29 
31 {
32 
33 }
34 
36 {
37 
38  this->CreateOutputsForAllInputs(); // make sure that we have the same number of outputs as inputs
39  this->CreateMembersForAllInputs();
40 
41  /* update outputs with tracking data from tools */
42  for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i)
43  {
44  //first copy outputs to inputs
45  mitk::NavigationData* output = this->GetOutput(i);
46  assert(output);
47  const mitk::NavigationData* input = this->GetInput(i);
48  assert(input);
49  if (input->IsDataValid() == false) {output->SetDataValid(false);}
50  else {output->Graft(input);}
51 
52  //then save statistics
53  if(input->IsDataValid())
54  {
55  m_LoggedPositions[i].push_back(input->GetPosition());
56  m_LoggedQuaternions[i].push_back(input->GetOrientation());
57  }
58  else
59  {
60  m_InvalidSamples[i]++;
61  }
62  }
63 
64 }
66 {
67  while(this->m_LoggedPositions.size() < this->GetNumberOfInputs())
68  {
69  std::pair<std::size_t,std::vector<mitk::Point3D> > newElement(m_LoggedPositions.size(),std::vector<mitk::Point3D>());
70  m_LoggedPositions.insert(newElement);
71  }
72  while(this->m_LoggedQuaternions.size() < this->GetNumberOfInputs())
73  {
74  std::pair<std::size_t,std::vector<mitk::Quaternion> > newElement(m_LoggedQuaternions.size(),std::vector<mitk::Quaternion>());
75  m_LoggedQuaternions.insert(newElement);
76  }
77  while(this->m_InvalidSamples.size() < this->GetNumberOfInputs())
78  {
79  std::pair<std::size_t,int> newElement(m_InvalidSamples.size(),0);
80  m_InvalidSamples.insert(newElement);
81  }
82 
83 
84 }
85 
87 {
88 for (unsigned int i = 0; i < m_LoggedPositions.size(); i++) m_LoggedPositions[i] = std::vector<mitk::Point3D>();
89 for (unsigned int i = 0; i < m_LoggedQuaternions.size(); i++) m_LoggedQuaternions[i] = std::vector<mitk::Quaternion>();
90 for (unsigned int i = 0; i < m_InvalidSamples.size(); i++) m_InvalidSamples[i] = 0;
91 }
92 
94 {
95 return this->m_LoggedPositions[input].size();
96 }
97 
98 
100 {
101 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
102 return myCalculator->GetPositionMean();
103 }
104 
106 {
107 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
108 return myCalculator->GetPositionStandardDeviation();
109 }
110 
112 {
113 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
114 return myCalculator->GetPositionSampleStandardDeviation();
115 }
116 
118 {
119 return GetMean(m_LoggedQuaternions[input]);
120 }
121 
123 {
124 mitk::Quaternion returnValue;
125 std::vector<double> list1 = std::vector<double>();
126 std::vector<double> list2 = std::vector<double>();
127 std::vector<double> list3 = std::vector<double>();
128 std::vector<double> list4 = std::vector<double>();
129 for (unsigned int i=0; i<m_LoggedQuaternions[input].size(); i++)
130  {
131  list1.push_back(m_LoggedQuaternions[input].at(i)[0]);
132  list2.push_back(m_LoggedQuaternions[input].at(i)[1]);
133  list3.push_back(m_LoggedQuaternions[input].at(i)[2]);
134  list4.push_back(m_LoggedQuaternions[input].at(i)[3]);
135  }
137 returnValue[0] = myCalculator->GetStabw(list1);
138 returnValue[1] = myCalculator->GetStabw(list2);
139 returnValue[2] = myCalculator->GetStabw(list3);
140 returnValue[3] = myCalculator->GetStabw(list4);
141 return returnValue;
142 }
143 
145 {
146 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(QuaternionsToEulerAngles(m_LoggedQuaternions[input])));
147 mitk::Vector3D returnValue;
148 returnValue[0] = myCalculator->GetPositionMean()[0];
149 returnValue[1] = myCalculator->GetPositionMean()[1];
150 returnValue[2] = myCalculator->GetPositionMean()[2];
151 return returnValue;
152 }
153 
155 {
156 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(QuaternionsToEulerAngles(m_LoggedQuaternions[input])));
157 return myCalculator->GetPositionErrorRMS();
158 }
159 
161 {
162 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(QuaternionsToEulerAnglesGrad(m_LoggedQuaternions[input])));
163 return myCalculator->GetPositionErrorRMS();
164 }
165 
166 
167 
169 {
170 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
171 return myCalculator->GetPositionErrorMean();
172 }
173 
175 {
176 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
177 return myCalculator->GetPositionErrorStandardDeviation();
178 }
179 
181 {
182 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
183 return myCalculator->GetPositionErrorSampleStandardDeviation();
184 }
185 
186 
188 {
189 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
190 return myCalculator->GetPositionErrorRMS();
191 }
192 
194 {
195 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
196 return myCalculator->GetPositionErrorMedian();
197 }
198 
200 {
201 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
202 return myCalculator->GetPositionErrorMax();
203 }
204 
206 {
207 mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input]));
208 return myCalculator->GetPositionErrorMin();
209 }
210 
212 {
213 return m_InvalidSamples[input];
214 }
215 
217 {
218 return (m_InvalidSamples[input]/(m_InvalidSamples[input]+((double)m_LoggedPositions[input].size())))*100.0;
219 }
220 
222 {
223 //calculate mean
224 mitk::Quaternion mean;
225 mean[0] = 0;
226 mean[1] = 0;
227 mean[2] = 0;
228 mean[3] = 0;
229 
230 for (unsigned int i=0; i<list.size(); i++)
231  {
232  mean[0] += list.at(i)[0];
233  mean[1] += list.at(i)[1];
234  mean[2] += list.at(i)[2];
235  mean[3] += list.at(i)[3];
236  }
237 
238 mean[0] /= list.size();
239 mean[1] /= list.size();
240 mean[2] /= list.size();
241 mean[3] /= list.size();
242 
243 return mean;
244 }
245 
247 {
249  for (unsigned int i=0; i<pSet.size(); i++) returnValue->InsertPoint(i,pSet.at(i));
250  return returnValue;
251 }
252 
254 {
256  for (unsigned int i=0; i<pSet.size(); i++)
257  {
258  mitk::Point3D thisPoint;
259  thisPoint[0] = pSet.at(i)[0];
260  thisPoint[1] = pSet.at(i)[1];
261  thisPoint[2] = pSet.at(i)[2];
262  returnValue->InsertPoint(i,thisPoint);
263  }
264  return returnValue;
265 }
266 
267 std::vector<mitk::Vector3D> mitk::NavigationDataEvaluationFilter::QuaternionsToEulerAngles(std::vector<mitk::Quaternion> quaterions)
268 {
269  std::vector<mitk::Vector3D> returnValue = std::vector<mitk::Vector3D>();
270  for (unsigned int i=0; i<quaterions.size(); i++)
271  {
272  mitk::Vector3D eulerAngles;
273  mitk::Quaternion currentQuaternion = quaterions.at(i);
274  currentQuaternion.normalize(); //must be normalized due to the documentation of the vnl method rotation_euler_angles()
275  eulerAngles[0] = currentQuaternion.rotation_euler_angles()[0];
276  eulerAngles[1] = currentQuaternion.rotation_euler_angles()[1];
277  eulerAngles[2] = currentQuaternion.rotation_euler_angles()[2];
278  returnValue.push_back(eulerAngles);
279  }
280  return returnValue;
281 }
282 
283 std::vector<mitk::Vector3D> mitk::NavigationDataEvaluationFilter::QuaternionsToEulerAnglesGrad(std::vector<mitk::Quaternion> quaterions)
284 {
285  double PI = M_PI;
286  std::vector<mitk::Vector3D> returnValue = std::vector<mitk::Vector3D>();
287  std::vector<mitk::Vector3D> eulerAnglesRadians = QuaternionsToEulerAngles(quaterions);
288  for (unsigned int i=0; i<eulerAnglesRadians.size(); i++)
289  {
290  mitk::Vector3D currentAngles;
291  currentAngles[0] = (eulerAnglesRadians.at(i)[0]/PI)*180;
292  currentAngles[1] = (eulerAnglesRadians.at(i)[1]/PI)*180;
293  currentAngles[2] = (eulerAnglesRadians.at(i)[2]/PI)*180;
294  returnValue.push_back(currentAngles);
295  }
296  return returnValue;
297 }
298 
300 {
301  mitk::Point3D returnValue;
302  if (m_LoggedPositions[input].size()<=i) returnValue.Fill(0);
303  else returnValue = m_LoggedPositions[input].at(i);
304  return returnValue;
305 }
306 
307 
309 {
310  mitk::Quaternion returnValue;
311  if (m_LoggedQuaternions[input].size()<=i) returnValue.fill(0);
312  else returnValue = m_LoggedQuaternions[input].at(i);
313  return returnValue;
314 }
itk::SmartPointer< Self > Pointer
NavigationDataToNavigationDataFilter is the base class of all filters that receive NavigationDatas as...
mitk::Quaternion GetMean(std::vector< mitk::Quaternion > list)
Navigation Data.
static Pointer New()
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 OrientationType GetOrientation() const
returns the orientation of the NavigationData object
void CreateMembersForAllInputs()
Creates the member variables which store all the statistical data for every input.
const mitk::ScalarType PI
mitk::Point3D GetLoggedPosition(unsigned int i, int input)
virtual void GenerateData() override
filter execute method
std::vector< mitk::Vector3D > QuaternionsToEulerAnglesGrad(std::vector< mitk::Quaternion > quaterions)
void ResetStatistic()
Resets all statistics and starts again.
std::vector< mitk::Vector3D > QuaternionsToEulerAngles(std::vector< mitk::Quaternion > quaterions)
Converts a list of quaterions to a list of euler angles (theta_x, theta_y, theta_z) ...
mitk::Quaternion GetLoggedOrientation(unsigned int i, int input)
vnl_quaternion< ScalarType > Quaternion
virtual bool IsDataValid() const
returns true if the object contains valid data
virtual PositionType GetPosition() const
returns position of the NavigationData object
mitk::PointSet::Pointer VectorToPointSet(std::vector< mitk::Point3D > pSet)
virtual void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.