diff --git a/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.cpp b/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.cpp index 5e5fb41ac1..4d8336812f 100644 --- a/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.cpp +++ b/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.cpp @@ -1,264 +1,299 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:56:03 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 17179 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkPointSetStatisticsCalculator.h" mitk::PointSetStatisticsCalculator::PointSetStatisticsCalculator() { m_PointSet = mitk::PointSet::New(); } mitk::PointSetStatisticsCalculator::PointSetStatisticsCalculator(mitk::PointSet::Pointer pSet) { m_PointSet = pSet; } mitk::PointSetStatisticsCalculator::~PointSetStatisticsCalculator() { } void mitk::PointSetStatisticsCalculator::SetPointSet(mitk::PointSet::Pointer pSet) { if (pSet.IsNull()) return; m_PointSet = pSet; } std::vector mitk::PointSetStatisticsCalculator::PointSetToVector(mitk::PointSet::Pointer pSet) { std::vector returnValue = std::vector(); for (int i=0; iGetSize(); i++) returnValue.push_back(pSet->GetPoint(i)); return returnValue; } double mitk::PointSetStatisticsCalculator::GetMax(std::vector list) { if (list.empty()) return 0; std::sort(list.begin(), list.end()); return list.at(list.size()-1); } double mitk::PointSetStatisticsCalculator::GetMin(std::vector list) { if (list.empty()) return 0; std::sort(list.begin(), list.end()); return list.at(0); } double mitk::PointSetStatisticsCalculator::GetStabw(std::vector list) { if (list.empty()) return 0; double returnValue = 0; double mean = GetMean(list); for(int i=0; i list) { if (list.empty()) return 0; double returnValue = 0; double mean = GetMean(list); for(int i=0; i list) { if (list.empty()) return 0; double mean = 0; for(int i=0; i list) { if (list.empty()) return 0; std::sort(list.begin(), list.end()); if (list.size() % 2 == 0.) //even { double element1 = list.at(list.size()/2); double element2 = list.at(list.size()/2); return ((element1+element2)/2.0); } else //odd { return list.at((list.size())/2); } } mitk::Point3D mitk::PointSetStatisticsCalculator::GetMean(std::vector list) { if (list.empty()) { mitk::Point3D emptyPoint; emptyPoint.Fill(0); - return 0; + return emptyPoint; } //calculate mean mitk::Point3D mean; mean.Fill(0); for (int i=0; i pSet = PointSetToVector(m_PointSet); if (pSet.empty()) return 0; mitk::Point3D mean = GetMean(pSet); for(int i=0; i pSet = PointSetToVector(m_PointSet); if(pSet.empty()) return 0; mitk::Point3D mean = GetMean(pSet); for(int i=0; i mitk::PointSetStatisticsCalculator::GetErrorList(std::vector list) { std::vector errorList = std::vector(); mitk::Point3D mean = GetMean(list); -for(int i=0; i pSet = PointSetToVector(m_PointSet); std::vector listX = std::vector(); std::vector listY = std::vector(); std::vector listZ = std::vector(); for (int i=0; i pSet = PointSetToVector(m_PointSet); std::vector listX = std::vector(); std::vector listY = std::vector(); std::vector listZ = std::vector(); for (int i=0; iGetSize()==0) return false; +if (m_PointSet->GetSize()==1) return true; + +mitk::Point3D lastPoint = m_PointSet->GetPoint(0); +for(int i=1; iGetSize(); i++) + { + if((m_PointSet->GetPoint(i)[0]!=lastPoint[0])||(m_PointSet->GetPoint(i)[1]!=lastPoint[1])||(m_PointSet->GetPoint(i)[2]!=lastPoint[2])) return false; + lastPoint = m_PointSet->GetPoint(i); + } + +return true; +} diff --git a/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.h b/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.h index e846625c10..e04287f69c 100644 --- a/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.h +++ b/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.h @@ -1,119 +1,122 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:56:03 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 17179 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _MITK_PointSetSTATISTICSCALCULATOR_H #define _MITK_PointSetSTATISTICSCALCULATOR_H #include #include "ImageStatisticsExports.h" #include namespace mitk { /** * \brief Class for calculating statistics (like standard derivation, RMS, mean, etc.) for a PointSet. */ class ImageStatistics_EXPORT PointSetStatisticsCalculator : public itk::Object { public: mitkClassMacro( PointSetStatisticsCalculator, itk::Object ); itkNewMacro( PointSetStatisticsCalculator ); mitkNewMacro1Param(PointSetStatisticsCalculator,mitk::PointSet::Pointer) /** @brief Sets the point set which will be analysed. */ void SetPointSet(mitk::PointSet::Pointer pSet); /** @return Returns the mean position of the analysed point set (only valid navigation data). Returns [0;0;0] if there is no valid navigation data.*/ mitk::Point3D GetPositionMean(); /** @return Returns the standard derivation of each component (x, y and z) of the analysed point set (only valid navigation data). Returns [0;0;0] if there is no valid navigation data.*/ mitk::Vector3D GetPositionStandardDeviation(); /** @return Returns the sample standard derivation of each component (x, y and z) of the analysed point set (only valid navigation data). Returns [0;0;0] if there is no valid navigation data.*/ mitk::Vector3D GetPositionSampleStandardDeviation(); /** @return Returns the mean distance to the mean postion (=mean error) of the analysed point set (only valid navigation data). Returns 0 if there is no valid navigation data. */ double GetPositionErrorMean(); /** @return Returns the standard derivation of the errors of all positions of the analysed point set (only valid navigation data). Returns 0 if there is no valid navigation data. */ double GetPositionErrorStandardDeviation(); /** @return Returns the sample standard derivation of the errors of all positions of the analysed point set (only valid navigation data). Returns 0 if there is no valid navigation data. */ double GetPositionErrorSampleStandardDeviation(); /** @return Returns the RMS of the errors of all positions of the analysed point set (only valid navigation data). Returns 0 if there is no valid navigation data. */ double GetPositionErrorRMS(); /** @return Returns the median of the errors of all positions of the analysed point set (only valid navigation data). Returns 0 if there is no valid navigation data. */ double GetPositionErrorMedian(); /** @return Returns the maximum of the errors of all positions of the analysed point set (only valid navigation data). Returns 0 if there is no valid navigation data. */ double GetPositionErrorMax(); /** @return Returns the minimum of the errors of all positions of the analysed point set (only valid navigation data). Returns 0 if there is no valid navigation data. */ double GetPositionErrorMin(); //##################################################################################################### //this both methods are used by another class an so they are public... perhaps we want to move them //out of this class because they have nothing to do with point sets. /** @return returns the standard derivation of the given list (NOT of the point set).*/ double GetStabw(std::vector list); /** @return returns the sample standard derivation of the given list (NOT of the point set).*/ double GetSampleStabw(std::vector list); //##################################################################################################### protected: PointSetStatisticsCalculator(); PointSetStatisticsCalculator(mitk::PointSet::Pointer); virtual ~PointSetStatisticsCalculator(); // TODO: Remove the std::vector data structure and use mitk::PointSet everywhere /** @return Returns a list with the distances to the mean of the list */ std::vector GetErrorList(std::vector list); /** @return Returns the mean of the point list. Returns [0;0;0] if the list is empty. */ mitk::Point3D GetMean(std::vector list); /** @brief Converts a point set to a vector of Point3D. */ std::vector PointSetToVector(mitk::PointSet::Pointer pSet); + /** @return Returns true if all positions in the evaluated points set are equal. False if not. */ + bool CheckIfAllPositionsAreEqual(); + mitk::PointSet::Pointer m_PointSet; double GetMean(std::vector list); double GetMedian(std::vector list); double GetMax(std::vector list); double GetMin(std::vector list); }; } #endif // #define _MITK_PointSetSTATISTICSCALCULATOR_H \ No newline at end of file