Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkPointSetStatisticsCalculator.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 
13 
15 
17 {
19 }
20 
22 {
23  m_PointSet = pSet;
24 }
25 
27 {
28 }
29 
31 {
32  if (pSet.IsNull()) return;
33  m_PointSet = pSet;
34 }
35 
37 {
38  std::vector<mitk::Point3D> returnValue = std::vector<mitk::Point3D>();
39  for (int i=0; i<pSet->GetSize(); i++) returnValue.push_back(pSet->GetPoint(i));
40  return returnValue;
41 }
42 
43 double mitk::PointSetStatisticsCalculator::GetMax(std::vector<double> list)
44 {
45 if (list.empty()) return 0;
46 std::sort(list.begin(), list.end());
47 return list.at(list.size()-1);
48 }
49 
50 double mitk::PointSetStatisticsCalculator::GetMin(std::vector<double> list)
51 {
52 if (list.empty()) return 0;
53 std::sort(list.begin(), list.end());
54 return list.at(0);
55 }
56 
57 double mitk::PointSetStatisticsCalculator::GetStabw(std::vector<double> list)
58 {
59 if (list.empty()) return 0;
60 double returnValue = 0;
61 double mean = GetMean(list);
62 for(std::vector<double>::size_type i=0; i<list.size(); i++)
63  {
64  returnValue += pow((list.at(i)-mean),2);
65  }
66 
67 returnValue /= list.size();
68 returnValue = sqrt(returnValue);
69 return returnValue;
70 }
71 
73 {
74 if (list.empty()) return 0;
75 double returnValue = 0;
76 double mean = GetMean(list);
77 for(std::vector<double>::size_type i=0; i<list.size(); i++)
78  {
79  returnValue += pow((list.at(i)-mean),2);
80  }
81 
82 returnValue /= (list.size()-1);
83 returnValue = sqrt(returnValue);
84 return returnValue;
85 }
86 
87 double mitk::PointSetStatisticsCalculator::GetMean(std::vector<double> list)
88 {
89 if (list.empty()) return 0;
90 double mean = 0;
91 for(std::vector<double>::size_type i=0; i<list.size(); i++)
92  {
93  mean += list.at(i);
94  }
95 mean /= list.size();
96 return mean;
97 }
98 
99 double mitk::PointSetStatisticsCalculator::GetMedian(std::vector<double> list)
100 {
101 if (list.empty()) return 0;
102 std::sort(list.begin(), list.end());
103 if (list.size() % 2 == 0.) //even
104  {
105  double element1 = list.at(list.size()/2);
106  double element2 = list.at(list.size()/2);
107  return ((element1+element2)/2.0);
108  }
109 else //odd
110  {
111  return list.at((list.size())/2);
112  }
113 }
114 
116 {
117 if (list.empty())
118  {
119  mitk::Point3D emptyPoint;
120  emptyPoint.Fill(0);
121  return emptyPoint;
122  }
123 
124 //calculate mean
125 mitk::Point3D mean;
126 mean.Fill(0);
127 
128 for (std::vector<mitk::Point3D>::size_type i=0; i<list.size(); i++)
129  {
130  mean[0] += list.at(i)[0];
131  mean[1] += list.at(i)[1];
132  mean[2] += list.at(i)[2];
133  }
134 
135 mean[0] /= list.size();
136 mean[1] /= list.size();
137 mean[2] /= list.size();
138 
139 return mean;
140 }
141 
143 {
144 double returnValue = 0.0;
145 
146 if (CheckIfAllPositionsAreEqual()) return returnValue;
147 
148 std::vector<mitk::Point3D> pSet = PointSetToVector(m_PointSet);
149 
150 if (pSet.empty()) return 0;
151 
152 mitk::Point3D mean = GetMean(pSet);
153 
154 for(std::vector<mitk::Point3D>::size_type i=0; i<pSet.size(); i++)
155  {
156  returnValue += mean.EuclideanDistanceTo(pSet.at(i));
157  }
158 returnValue /= pSet.size();
159 
160 return returnValue;
161 }
162 
164 {
166 }
167 
169 {
171 }
172 
173 
175 {
176 double returnValue = 0.0;
177 
178 if (CheckIfAllPositionsAreEqual()) return returnValue;
179 
180 std::vector<mitk::Point3D> pSet = PointSetToVector(m_PointSet);
181 
182 if(pSet.empty()) return 0;
183 
184 mitk::Point3D mean = GetMean(pSet);
185 
186 for(std::vector<mitk::Point3D>::size_type i=0; i<pSet.size(); i++)
187  {
188  returnValue += pow(mean.EuclideanDistanceTo(pSet.at(i)),2);
189  }
190 returnValue /= pSet.size();
191 returnValue = sqrt(returnValue);
192 
193 return returnValue;
194 }
195 
197 {
199 }
200 
202 {
204 }
205 
207 {
209 }
210 
211 std::vector<double> mitk::PointSetStatisticsCalculator::GetErrorList(std::vector<mitk::Point3D> list)
212 {
213 std::vector<double> errorList = std::vector<double>();
214 mitk::Point3D mean = GetMean(list);
215 if (CheckIfAllPositionsAreEqual()) for(std::vector<mitk::Point3D>::size_type i=0; i<list.size(); i++) {errorList.push_back(0.0);}
216 else for(std::vector<mitk::Point3D>::size_type i=0; i<list.size(); i++) {errorList.push_back(mean.EuclideanDistanceTo(list.at(i)));}
217 return errorList;
218 }
219 
221 {
222 mitk::Vector3D returnValue;
223 
225  {
226  returnValue[0]=0;
227  returnValue[1]=0;
228  returnValue[2]=0;
229  return returnValue;
230  }
231 
232 std::vector<mitk::Point3D> pSet = PointSetToVector(m_PointSet);
233 std::vector<double> listX = std::vector<double>();
234 std::vector<double> listY = std::vector<double>();
235 std::vector<double> listZ = std::vector<double>();
236 for (std::vector<mitk::Point3D>::size_type i=0; i<pSet.size(); i++)
237  {
238  listX.push_back(pSet.at(i)[0]);
239  listY.push_back(pSet.at(i)[1]);
240  listZ.push_back(pSet.at(i)[2]);
241  }
242 returnValue[0] = GetStabw(listX);
243 returnValue[1] = GetStabw(listY);
244 returnValue[2] = GetStabw(listZ);
245 return returnValue;
246 }
247 
249 {
250 mitk::Vector3D returnValue;
251 
253  {
254  returnValue[0]=0;
255  returnValue[1]=0;
256  returnValue[2]=0;
257  return returnValue;
258  }
259 
260 std::vector<mitk::Point3D> pSet = PointSetToVector(m_PointSet);
261 std::vector<double> listX = std::vector<double>();
262 std::vector<double> listY = std::vector<double>();
263 std::vector<double> listZ = std::vector<double>();
264 for (std::vector<mitk::Point3D>::size_type i=0; i<pSet.size(); i++)
265  {
266  listX.push_back(pSet.at(i)[0]);
267  listY.push_back(pSet.at(i)[1]);
268  listZ.push_back(pSet.at(i)[2]);
269  }
270 returnValue[0] = GetSampleStabw(listX);
271 returnValue[1] = GetSampleStabw(listY);
272 returnValue[2] = GetSampleStabw(listZ);
273 return returnValue;
274 }
275 
277 {
279 }
280 
282 {
283 if (m_PointSet->GetSize()==0) return false;
284 if (m_PointSet->GetSize()==1) return true;
285 
286 mitk::Point3D lastPoint = m_PointSet->GetPoint(0);
287 for(int i=1; i<m_PointSet->GetSize(); i++)
288  {
289  if((m_PointSet->GetPoint(i)[0]!=lastPoint[0])||(m_PointSet->GetPoint(i)[1]!=lastPoint[1])||(m_PointSet->GetPoint(i)[2]!=lastPoint[2])) return false;
290  lastPoint = m_PointSet->GetPoint(i);
291  }
292 
293 return true;
294 }
static Pointer New()
std::vector< mitk::Point3D > PointSetToVector(mitk::PointSet::Pointer pSet)
Converts a point set to a vector of Point3D.
double GetMedian(std::vector< double > list)
mitk::Point3D GetMean(std::vector< mitk::Point3D > list)
std::vector< double > GetErrorList(std::vector< mitk::Point3D > list)
void SetPointSet(mitk::PointSet::Pointer pSet)
Sets the point set which will be analysed.
double GetSampleStabw(std::vector< double > list)