Medical Imaging Interaction Toolkit  2018.4.99-389bf124
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 (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 
16 
18  m_StatisticsCalculated(false)
19 {
22  //m_Statistics.Reset();
23 }
24 
26 {
27  m_PointSet1 = pSet1;
28  m_PointSet2 = pSet2;
29  m_StatisticsCalculated = false;
30  //m_Statistics.Reset();
31 }
32 
34 {
35 }
36 
38 {
39  if (pSet1.IsNotNull())
40  {
41  m_PointSet1 = pSet1;
42  }
43  if (pSet2.IsNotNull())
44  {
45  m_PointSet2 = pSet2;
46  }
47  m_StatisticsCalculated = false;
48  //m_Statistics.Reset();
49 }
50 
52 {
54  {
55  this->ComputeStatistics();
56  }
57  return m_DifferencesVector;
58 }
59 
61 {
63  {
64  this->ComputeStatistics();
65  }
67 }
68 
70 {
72  {
73  this->ComputeStatistics();
74  }
76 }
77 
79 {
81  {
82  this->ComputeStatistics();
83  }
85 }
86 
88 {
90  {
91  this->ComputeStatistics();
92  }
94 }
95 
97 {
99  {
100  this->ComputeStatistics();
101  }
103 }
104 
106 {
108  {
109  this->ComputeStatistics();
110  }
112 }
113 
115 {
117  {
118  this->ComputeStatistics();
119  }
121 }
122 
124 {
126  {
127  this->ComputeStatistics();
128  }
130 }
131 
133 {
135  {
136  this->ComputeStatistics();
137  }
139 }
140 
142 {
143  if ((m_PointSet1.IsNull())||(m_PointSet2.IsNull()))
144  {
145  itkExceptionMacro("Point sets specified are not valid. Please specify correct Point sets");
146  }
147  else if (m_PointSet1->GetSize()!=m_PointSet2->GetSize())
148  {
149  itkExceptionMacro("PointSets are not equal. Please make sure that your PointSets have the same size and hold corresponding points.");
150  }
151  else if (m_PointSet1->GetSize()==0)
152  {
153  itkExceptionMacro("There are no points in the PointSets. Please make sure that the PointSets contain points");
154  }
155  else
156  {
157  double mean = 0.0;
158  double sd = 0.0;
159  double rms= 0.0;
160 
161  std::vector<double> differencesVector;
162  mitk::Point3D point1;
163  mitk::Point3D point2;
164  auto numberOfPoints = static_cast<mitk::ImageStatisticsContainer::VoxelCountType>(m_PointSet1->GetSize());
165 
166  //Iterate over both pointsets in order to compare all points pair-wise
168  for( mitk::PointSet::PointsIterator pointSetIterator = m_PointSet1->Begin(), pointSetIterator2 = m_PointSet2->Begin();
169  pointSetIterator != end; ++pointSetIterator, ++pointSetIterator2) //iterate simultaneously over both sets
170  {
171  point1 = pointSetIterator.Value();
172  point2 = pointSetIterator2.Value();
173 
174  double squaredDistance = point1.SquaredEuclideanDistanceTo(point2);
175  mean+=sqrt(squaredDistance);
176  rms+=squaredDistance;
177  this->m_SquaredDifferencesVector.push_back(squaredDistance);
178  differencesVector.push_back(sqrt(squaredDistance));
179  }
180 
181  m_DifferencesVector = differencesVector;
182  mean = mean/static_cast<double>(numberOfPoints);
183  rms = sqrt(rms/ static_cast<double>(numberOfPoints));
184  for (std::vector<double>::size_type i=0; i<differencesVector.size(); i++)
185  {
186  sd+=(differencesVector.at(i)-mean)*(differencesVector.at(i)-mean);
187  }
188  double variance = sd/ static_cast<double>(numberOfPoints);
189  sd = sqrt(variance);
190  std::sort(differencesVector.begin(),differencesVector.end());
191  double median = 0.0;
192  if (numberOfPoints%2 == 0)
193  {
194  median = (differencesVector.at(numberOfPoints/2)+differencesVector.at(numberOfPoints/2-1))/2;
195  }
196  else
197  {
198  median = differencesVector.at((numberOfPoints-1)/2+1);
199  }
205  m_Statistics.AddStatistic(mitk::ImageStatisticsConstants::MAXIMUM(), differencesVector.at(numberOfPoints - 1));
208 
209  m_StatisticsCalculated = true;
210  }
211 }
DataType::PointsContainerIterator PointsIterator
Definition: mitkPointSet.h:135
double GetRMS()
returns the root mean squared distance of all corresponding points of the point sets ...
std::vector< double > m_SquaredDifferencesVector
vector holding the squared differences between the corresponding points
static Pointer New()
mitk::ImageStatisticsContainer::ImageStatisticsObject m_Statistics
struct holding the statistics
TType GetValueConverted(const std::string &name) const
Converts the requested value to the defined type.
void AddStatistic(const std::string &key, StatisticsVariantType value)
Adds a statistic to the statistics object.
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
bool m_StatisticsCalculated
flag indicating whether statistics are already calculated or not.
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 ...
std::vector< double > m_DifferencesVector
vector holding the differences between the corresponding points
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 ...
static const std::string STANDARDDEVIATION()
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...