Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkPointSetDifferenceStatisticsCalculator.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  m_StatisticsCalculated(false)
22 {
26  //m_Statistics.Reset();
27 }
28 
30 {
32  m_PointSet1 = pSet1;
33  m_PointSet2 = pSet2;
34  m_StatisticsCalculated = false;
35  //m_Statistics.Reset();
36 }
37 
39 {
40 }
41 
43 {
44  if (pSet1.IsNotNull())
45  {
46  m_PointSet1 = pSet1;
47  }
48  if (pSet2.IsNotNull())
49  {
50  m_PointSet2 = pSet2;
51  }
52  m_StatisticsCalculated = false;
53  //m_Statistics.Reset();
54 }
55 
57 {
58  if (!m_StatisticsCalculated)
59  {
60  this->ComputeStatistics();
61  }
62  return m_DifferencesVector;
63 }
64 
66 {
67  if (!m_StatisticsCalculated)
68  {
69  this->ComputeStatistics();
70  }
71  return m_SquaredDifferencesVector;
72 }
73 
75 {
76  if (!m_StatisticsCalculated)
77  {
78  this->ComputeStatistics();
79  }
80  return m_Statistics->GetMean();
81 }
82 
84 {
85  if (!m_StatisticsCalculated)
86  {
87  this->ComputeStatistics();
88  }
89  return m_Statistics->GetStd();
90 }
91 
93 {
94  if (!m_StatisticsCalculated)
95  {
96  this->ComputeStatistics();
97  }
98  return m_Statistics->GetVariance();
99 }
100 
102 {
103  if (!m_StatisticsCalculated)
104  {
105  this->ComputeStatistics();
106  }
107  return m_Statistics->GetRMS();
108 }
109 
111 {
112  if (!m_StatisticsCalculated)
113  {
114  this->ComputeStatistics();
115  }
116  return m_Statistics->GetMedian();
117 }
118 
120 {
121  if (!m_StatisticsCalculated)
122  {
123  this->ComputeStatistics();
124  }
125  return m_Statistics->GetMax();
126 }
127 
129 {
130  if (!m_StatisticsCalculated)
131  {
132  this->ComputeStatistics();
133  }
134  return m_Statistics->GetMin();
135 }
136 
138 {
139  if (!m_StatisticsCalculated)
140  {
141  this->ComputeStatistics();
142  }
143  return m_Statistics->GetN();
144 }
145 
147 {
148  if ((m_PointSet1.IsNull())||(m_PointSet2.IsNull()))
149  {
150  itkExceptionMacro("Point sets specified are not valid. Please specify correct Point sets");
151  }
152  else if (m_PointSet1->GetSize()!=m_PointSet2->GetSize())
153  {
154  itkExceptionMacro("PointSets are not equal. Please make sure that your PointSets have the same size and hold corresponding points.");
155  }
156  else if (m_PointSet1->GetSize()==0)
157  {
158  itkExceptionMacro("There are no points in the PointSets. Please make sure that the PointSets contain points");
159  }
160  else
161  {
162  double mean = 0.0;
163  double sd = 0.0;
164  double rms= 0.0;
165 
166  std::vector<double> differencesVector;
167  mitk::Point3D point1;
168  mitk::Point3D point2;
169  int numberOfPoints = m_PointSet1->GetSize();
170 
171  //Iterate over both pointsets in order to compare all points pair-wise
172  mitk::PointSet::PointsIterator end = m_PointSet1->End();
173  for( mitk::PointSet::PointsIterator pointSetIterator = m_PointSet1->Begin(), pointSetIterator2 = m_PointSet2->Begin();
174  pointSetIterator != end; ++pointSetIterator, ++pointSetIterator2) //iterate simultaneously over both sets
175  {
176  point1 = pointSetIterator.Value();
177  point2 = pointSetIterator2.Value();
178 
179  double squaredDistance = point1.SquaredEuclideanDistanceTo(point2);
180  mean+=sqrt(squaredDistance);
181  rms+=squaredDistance;
182  this->m_SquaredDifferencesVector.push_back(squaredDistance);
183  differencesVector.push_back(sqrt(squaredDistance));
184  }
185 
186  m_DifferencesVector = differencesVector;
187  mean = mean/numberOfPoints;
188  rms = sqrt(rms/numberOfPoints);
189  for (std::vector<double>::size_type i=0; i<differencesVector.size(); i++)
190  {
191  sd+=(differencesVector.at(i)-mean)*(differencesVector.at(i)-mean);
192  }
193  double variance = sd/numberOfPoints;
194  sd = sqrt(variance);
195  std::sort(differencesVector.begin(),differencesVector.end());
196  double median = 0.0;
197  if (numberOfPoints%2 == 0)
198  {
199  median = (differencesVector.at(numberOfPoints/2)+differencesVector.at(numberOfPoints/2-1))/2;
200  }
201  else
202  {
203  median = differencesVector.at((numberOfPoints-1)/2+1);
204  }
205  m_Statistics->SetMean(mean);
206  m_Statistics->SetStd(sd);
207  m_Statistics->SetVariance(variance);
208  m_Statistics->SetRMS(rms);
209  m_Statistics->SetMin(differencesVector.at(0));
210  m_Statistics->SetMax(differencesVector.at(numberOfPoints-1));
211  m_Statistics->SetMedian(median);
212  m_Statistics->SetN(numberOfPoints);
213 
214  m_StatisticsCalculated = true;
215  }
216 }
DataType::PointsContainerIterator PointsIterator
Definition: mitkPointSet.h:137
double GetRMS()
returns the root mean squared distance of all corresponding points of the point sets ...
static Pointer New()
double GetMax()
returns the maximal distance of all corresponding points of the point sets
mitk::PointSet::Pointer m_PointSet2
second point set used for comparison
std::vector< double > GetSquaredDifferences()
returns a vector holding the squared differences between the corresponding points of the point sets ...
double GetNumberOfPoints()
returns the total number of corresponding points of the point sets
std::vector< double > GetDifferences()
returns a vector holding the differences between the corresponding points of the point sets ...
void SetPointSets(mitk::PointSet::Pointer pSet1, mitk::PointSet::Pointer pSet2)
set point sets to be compared
double GetSD()
returns the standard deviation of the distances between all corresponding points of the point sets ...
mitk::ImageStatisticsCalculator::StatisticsContainer::Pointer m_Statistics
struct holding the statistics
double GetVariance()
returns the variance of the distances between all corresponding points of the point sets ...
double GetMin()
returns the minimal distance of all corresponding points of the point sets
mitk::PointSet::Pointer m_PointSet1
first point set used for comparison
double GetMean()
returns the mean distance of all corresponding points of the point sets
double GetMedian()
returns the median distance of all corresponding points of the point sets
void ComputeStatistics()
Method for computing the complete statistics of the differences between the given point sets...