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