diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.cpp b/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.cpp index 62dcdd2b9f..e2385cc939 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.cpp +++ b/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.cpp @@ -1,353 +1,226 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: 16011 $ 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 "mitkNavigationDataEvaluationFilter.h" -#include - +#include mitk::NavigationDataEvaluationFilter::NavigationDataEvaluationFilter() : mitk::NavigationDataToNavigationDataFilter() { } mitk::NavigationDataEvaluationFilter::~NavigationDataEvaluationFilter() { } void mitk::NavigationDataEvaluationFilter::GenerateData() { this->CreateOutputsForAllInputs(); // make sure that we have the same number of outputs as inputs this->CreateMembersForAllInputs(); /* update outputs with tracking data from tools */ for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i) { //first copy outputs to inputs mitk::NavigationData* output = this->GetOutput(i); assert(output); const mitk::NavigationData* input = this->GetInput(i); assert(input); if (input->IsDataValid() == false) {output->SetDataValid(false);} else {output->Graft(input);} //then save statistics if(input->IsDataValid()) { m_LoggedPositions[i].push_back(input->GetPosition()); m_LoggedQuaternions[i].push_back(input->GetOrientation()); } else { m_InavildSamples[i]++; } } } void mitk::NavigationDataEvaluationFilter::CreateMembersForAllInputs() { while(this->m_LoggedPositions.size() < this->GetNumberOfInputs()) { std::pair > newElement(m_LoggedPositions.size(),std::vector()); m_LoggedPositions.insert(newElement); } while(this->m_LoggedQuaternions.size() < this->GetNumberOfInputs()) { std::pair > newElement(m_LoggedQuaternions.size(),std::vector()); m_LoggedQuaternions.insert(newElement); } while(this->m_InavildSamples.size() < this->GetNumberOfInputs()) { std::pair newElement(m_LoggedQuaternions.size(),0); m_InavildSamples.insert(newElement); } } void mitk::NavigationDataEvaluationFilter::ResetStatistic() { for (int i = 0; i < m_LoggedPositions.size(); i++) m_LoggedPositions[i] = std::vector(); for (int i = 0; i < m_LoggedQuaternions.size(); i++) m_LoggedQuaternions[i] = std::vector(); for (int i = 0; i < m_InavildSamples.size(); i++) m_InavildSamples[i] = 0; } int mitk::NavigationDataEvaluationFilter::GetNumberOfAnalysedNavigationData(int input) { return this->m_LoggedPositions[input].size(); } mitk::Point3D mitk::NavigationDataEvaluationFilter::GetPositionMean(int input) { -return GetMean(m_LoggedPositions[input]); +mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); +return myCalculator->GetPositionMean(); } mitk::Vector3D mitk::NavigationDataEvaluationFilter::GetPositionStandardDeviation(int input) { -mitk::Vector3D returnValue; -std::vector listX = std::vector(); -std::vector listY = std::vector(); -std::vector listZ = std::vector(); -for (int i=0; iGetPositionStandardDeviation(); } mitk::Vector3D mitk::NavigationDataEvaluationFilter::GetPositionSampleStandardDeviation(int input) { -mitk::Vector3D returnValue; -std::vector listX = std::vector(); -std::vector listY = std::vector(); -std::vector listZ = std::vector(); -for (int i=0; iGetPositionSampleStandardDeviation(); } mitk::Quaternion mitk::NavigationDataEvaluationFilter::GetQuaternionMean(int input) { return GetMean(m_LoggedQuaternions[input]); } mitk::Quaternion mitk::NavigationDataEvaluationFilter::GetQuaternionStandardDeviation(int input) { mitk::Quaternion returnValue; std::vector list1 = std::vector(); std::vector list2 = std::vector(); std::vector list3 = std::vector(); std::vector list4 = std::vector(); for (int i=0; iGetStabw(list1); +returnValue[1] = myCalculator->GetStabw(list2); +returnValue[2] = myCalculator->GetStabw(list3); +returnValue[3] = myCalculator->GetStabw(list4); return returnValue; } double mitk::NavigationDataEvaluationFilter::GetPositionErrorMean(int input) { -double returnValue = 0.0; -mitk::Point3D mean = GetMean(m_LoggedPositions[input]); - -for(int i=0; iGetPositionErrorMean(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorStandardDeviation(int input) { -return GetStabw(GetErrorList(m_LoggedPositions[input])); +mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); +return myCalculator->GetPositionErrorStandardDeviation(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorSampleStandardDeviation(int input) { -return GetSampleStabw(GetErrorList(m_LoggedPositions[input])); +mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); +return myCalculator->GetPositionErrorSampleStandardDeviation(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorRMS(int input) { -double returnValue = 0.0; - -mitk::Point3D mean = GetMean(m_LoggedPositions[input]); - -for(int i=0; iGetPositionErrorRMS(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorMedian(int input) { -return GetMedian(GetErrorList(m_LoggedPositions[input])); +mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); +return myCalculator->GetPositionErrorMedian(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorMax(int input) { -return GetMax(GetErrorList(m_LoggedPositions[input])); +mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); +return myCalculator->GetPositionErrorMax(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorMin(int input) { -return GetMin(GetErrorList(m_LoggedPositions[input])); +mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); +return myCalculator->GetPositionErrorMin(); } int mitk::NavigationDataEvaluationFilter::GetNumberOfInvalidSamples(int input) { return m_InavildSamples[input]; } double mitk::NavigationDataEvaluationFilter::GetPercentageOfInvalidSamples(int input) { return (m_InavildSamples[input]/(m_InavildSamples[input]+((double)m_LoggedPositions[input].size())))*100.0; } -double mitk::NavigationDataEvaluationFilter::GetMedian(std::vector list) -{ -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); - } -} - -std::vector mitk::NavigationDataEvaluationFilter::GetErrorList(std::vector list) -{ -std::vector errorList = std::vector(); -mitk::Point3D mean = GetMean(list); -for(int i=0; i list) -{ -//calculate mean -mitk::Point3D mean; -mean.Fill(0); - -for (int i=0; i list) -{ -std::sort(list.begin(), list.end()); -return list.at(list.size()-1); -} - -double mitk::NavigationDataEvaluationFilter::GetMin(std::vector list) -{ -std::sort(list.begin(), list.end()); -return list.at(0); -} - -double mitk::NavigationDataEvaluationFilter::GetStabw(std::vector list) -{ -double returnValue = 0; -double mean = GetMean(list); -for(int i=0; i list) -{ -double returnValue = 0; -double mean = GetMean(list); -for(int i=0; i list) -{ -double mean = 0; -for(int i=0; i list) { //calculate mean mitk::Quaternion mean; mean[0] = 0; mean[1] = 0; mean[2] = 0; mean[3] = 0; for (int i=0; i pSet) +{ + mitk::PointSet::Pointer returnValue = mitk::PointSet::New(); + for (int i=0; iInsertPoint(i,pSet.at(i)); + return returnValue; } \ No newline at end of file diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.h b/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.h index a09623301f..fd1b4dfa35 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.h +++ b/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.h @@ -1,126 +1,108 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision: 16011 $ 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 MITKNavigationDataEvaluationFilter_H_HEADER_INCLUDED_ #define MITKNavigationDataEvaluationFilter_H_HEADER_INCLUDED_ #include - +#include #include #include namespace mitk { /**Documentation * \brief NavigationDataEvaluationFilter calculates statistical data (mean value, mean error, etc.) on the input navigation data. * Input navigation data are set 1:1 on output navigation data. * * \ingroup IGT */ class MitkIGT_EXPORT NavigationDataEvaluationFilter : public NavigationDataToNavigationDataFilter { public: mitkClassMacro(NavigationDataEvaluationFilter, NavigationDataToNavigationDataFilter); itkNewMacro(Self); /** @brief Resets all statistics and starts again. */ void ResetStatistic(); /** @return Returns the number of analysed navigation datas for the specified input (without invalid samples). */ int GetNumberOfAnalysedNavigationData(int input); /** @return Returns the number of invalid samples for the specified input. Invalid samples are ignored for the statistical calculation.*/ int GetNumberOfInvalidSamples(int input); /** @return Returns the percentage of invalid samples in relation to all samples for the specified input.*/ double GetPercentageOfInvalidSamples(int input); /** @return Returns the mean position of the specified input since the start of the statistic (last call of ResetStatistic()) */ mitk::Point3D GetPositionMean(int input); /** @return Returns the standard derivation of each component (x, y and z) of the specified input since the start of the statistic (last call of ResetStatistic()) */ mitk::Vector3D GetPositionStandardDeviation(int input); /** @return Returns the sample standard derivation of each component (x, y and z) of the specified input since the start of the statistic (last call of ResetStatistic()) */ mitk::Vector3D GetPositionSampleStandardDeviation(int input); /** @return Returns the mean quaternion of the specified input since the start of the statistic (last call of ResetStatistic()) */ mitk::Quaternion GetQuaternionMean(int input); /** @return Returns the standard derivation of each component of the specified input since the start of the statistic (last call of ResetStatistic()) */ mitk::Quaternion GetQuaternionStandardDeviation(int input); /** @return Returns the mean distance to the mean postion (=mean error) to the specified input. */ double GetPositionErrorMean(int input); /** @return Returns the standard derivation of the errors of all positions to the specified input. */ double GetPositionErrorStandardDeviation(int input); /** @return Returns the sample standard derivation of the errors of all positions to the specified input. */ double GetPositionErrorSampleStandardDeviation(int input); /** @return Returns the RMS of the errors of all positions to the specified input. */ double GetPositionErrorRMS(int input); /** @return Returns the median of the errors of all positions to the specified input. */ double GetPositionErrorMedian(int input); /** @return Returns the maximum of the errors of all positions to the specified input. */ double GetPositionErrorMax(int input); /** @return Returns the minimum of the errors of all positions to the specified input. */ double GetPositionErrorMin(int input); protected: NavigationDataEvaluationFilter(); virtual ~NavigationDataEvaluationFilter(); /**Documentation * \brief filter execute method * * transforms navigation data */ virtual void GenerateData(); /** @brief Creates the member variables which store all the statistical data for every input. */ void CreateMembersForAllInputs(); std::map > m_LoggedPositions; //a map here, to have one list for every navigation data std::map > m_LoggedQuaternions; std::map m_InavildSamples; - - /** @return returns a list with the distances to the mean of the list */ - std::vector GetErrorList(std::vector list); - - mitk::Point3D GetMean(std::vector list); - mitk::Quaternion GetMean(std::vector list); - - double GetMean(std::vector list); - - double GetMedian(std::vector list); - - double GetMax(std::vector list); - - double GetMin(std::vector list); - - /** @return returns the standard derivation of the list */ - double GetStabw(std::vector list); - - /** @return returns the sample standard derivation of the list */ - double GetSampleStabw(std::vector list); + mitk::PointSet::Pointer VectorToPointSet(std::vector pSet); + }; } // namespace mitk #endif /* MITKNavigationDataEvaluationFilter_H_HEADER_INCLUDED_ */ \ No newline at end of file diff --git a/Modules/ImageStatistics/Testing/files.cmake b/Modules/ImageStatistics/Testing/files.cmake index cfd9adbaca..68b62b28ea 100644 --- a/Modules/ImageStatistics/Testing/files.cmake +++ b/Modules/ImageStatistics/Testing/files.cmake @@ -1,3 +1,4 @@ -SET(MODULE_TESTS +SET(MODULE_TESTS mitkImageStatisticsCalculatorTest.cpp -) + mitkPointSetStatisticsCalculatorTest.cpp +) \ No newline at end of file diff --git a/Modules/ImageStatistics/Testing/mitkPointSetStatisticsCalculatorTest.cpp b/Modules/ImageStatistics/Testing/mitkPointSetStatisticsCalculatorTest.cpp new file mode 100644 index 0000000000..a28c3915e1 --- /dev/null +++ b/Modules/ImageStatistics/Testing/mitkPointSetStatisticsCalculatorTest.cpp @@ -0,0 +1,165 @@ +/*========================================================================= + +Program: Medical Imaging & Interaction Toolkit +Language: C++ +Date: $Date: 2008-02-25 17:27:17 +0100 (Mo, 25 Feb 2008) $ +Version: $Revision: 7837 $ + +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 "mitkStandardFileLocations.h" +#include "mitkTestingMacros.h" +#include "mitkPointSetStatisticsCalculator.h" + +//#include + +/** + * \brief Test class for mitkPointSetStatisticsCalculator + */ +class mitkPointSetStatisticsCalculatorTestClass +{ + /**************************** a few private help funktions ***********************************/ + private: + /** @brief Rounds a double. + * @param precision number of tested decimal places */ + static double round(double number, int precision) + { + double t = std::pow(10.,precision); + double returnValue = (int)(number*t+0.5)/t; + return returnValue; + } + /** @brief Tests two double values for equality. + * @param precision number of tested decimal places */ + static bool equals(double a, double b, int precision = 5) + { + if (round(a,precision)==round(b,precision)) return true; + else + { + std::cout << a << " is not " << b << std::endl; + return false; + } + } + /**********************************************************************************************/ + +public: + + static void TestInstantiation() + { + // let's create an object of our class + mitk::PointSetStatisticsCalculator::Pointer myPointSetStatisticsCalculator = mitk::PointSetStatisticsCalculator::New(); + MITK_TEST_CONDITION_REQUIRED(myPointSetStatisticsCalculator.IsNotNull(),"Testing instantiation with constructor 1."); + + mitk::PointSet::Pointer myTestPointSet = mitk::PointSet::New(); + mitk::PointSetStatisticsCalculator::Pointer myPointSetStatisticsCalculator2 = mitk::PointSetStatisticsCalculator::New(myTestPointSet); + MITK_TEST_CONDITION_REQUIRED(myPointSetStatisticsCalculator2.IsNotNull(),"Testing instantiation with constructor 2."); + } + +static void TestSimpleCase() + { + + MITK_TEST_OUTPUT(<< "Starting simple test case..."); + + mitk::Point3D test; + mitk::PointSet::Pointer testPointSet = mitk::PointSet::New(); + + mitk::FillVector3D(test,0,0,0); + testPointSet->InsertPoint(0,test); + + mitk::FillVector3D(test,1,1,1); + testPointSet->InsertPoint(1,test); + + mitk::PointSetStatisticsCalculator::Pointer myPointSetStatisticsCalculator = mitk::PointSetStatisticsCalculator::New(testPointSet); + + MITK_TEST_CONDITION_REQUIRED((myPointSetStatisticsCalculator->GetPositionMean()[0]==0.5),".. Testing GetPositionMean"); + MITK_TEST_CONDITION_REQUIRED((myPointSetStatisticsCalculator->GetPositionStandardDeviation()[0]==0.5),".. Testing GetPositionStandardDeviation"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionSampleStandardDeviation()[0],0.70710672),".. Testing GetPositionStandardDeviation"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorMean(),0.8660254),".. Testing GetPositionErrorMean"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorRMS(),0.8660254),".. Testing GetPositionErrorRMS"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorMax(),0.8660254),".. Testing GetPositionErrorMax"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorMedian(),0.8660254),".. Testing GetPositionErrorMedian"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorMin(),0.8660254),".. Testing GetPositionErrorMin"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorSampleStandardDeviation(),0),".. Testing GetPositionErrorSampleStandardDeviation"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorStandardDeviation(),0),".. Testing GetPositionErrorStandardDeviation"); + } + +static void TestComplexCase() + { + + MITK_TEST_OUTPUT(<< "Starting complex test case..."); + mitk::Point3D testPoint; + mitk::PointSet::Pointer testPointSet = mitk::PointSet::New(); + + //1st point + mitk::FillVector3D(testPoint,0,1,0); + testPointSet->InsertPoint(0,testPoint); + + //2nd point + mitk::FillVector3D(testPoint,0,1,0.34); + testPointSet->InsertPoint(1,testPoint); + + //3rd point + mitk::FillVector3D(testPoint,1,0.5,1); + testPointSet->InsertPoint(2,testPoint); + + //4th point + mitk::FillVector3D(testPoint,15,3,2); + testPointSet->InsertPoint(3,testPoint); + + //5th point + mitk::FillVector3D(testPoint,2,22.5,1.2655); + testPointSet->InsertPoint(4,testPoint); + + //6th point + mitk::FillVector3D(testPoint,4,1.3,2); + testPointSet->InsertPoint(5,testPoint); + + //7th point + mitk::FillVector3D(testPoint,0.001,0,1); + testPointSet->InsertPoint(6,testPoint); + + //8th point + mitk::FillVector3D(testPoint,1.2525,2.22,3); + testPointSet->InsertPoint(7,testPoint); + + //9th point + mitk::FillVector3D(testPoint,3.1,3,1); + testPointSet->InsertPoint(8,testPoint); + + mitk::PointSetStatisticsCalculator::Pointer myPointSetStatisticsCalculator = mitk::PointSetStatisticsCalculator::New(); + myPointSetStatisticsCalculator->SetPointSet(testPointSet); + + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionMean()[2],1.2895),".. Testing GetPositionMean"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionStandardDeviation()[2],0.86614074),".. Testing GetPositionStandardDeviation"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionSampleStandardDeviation()[2],0.91868098),".. Testing GetPositionStandardDeviation"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorMean(),6.06656587),".. Testing GetPositionErrorMean"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorRMS(),8.0793161),".. Testing GetPositionErrorRMS"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorMax(),18.6875241),".. Testing GetPositionErrorMax"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorMedian(),4.18522229),".. Testing GetPositionErrorMedian"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorMin(),0.90082741),".. Testing GetPositionErrorMin"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorSampleStandardDeviation(),5.65960626),".. Testing GetPositionErrorSampleStandardDeviation"); + MITK_TEST_CONDITION_REQUIRED(equals(myPointSetStatisticsCalculator->GetPositionErrorStandardDeviation(),5.33592795),".. Testing GetPositionErrorStandardDeviation"); + + } + + +}; + +int mitkPointSetStatisticsCalculatorTest(int argc, char* argv[]) +{ + // always start with this! + MITK_TEST_BEGIN("mitkPointSetStatisticsCalculatorTest") + + mitkPointSetStatisticsCalculatorTestClass::TestInstantiation(); + mitkPointSetStatisticsCalculatorTestClass::TestSimpleCase(); + mitkPointSetStatisticsCalculatorTestClass::TestComplexCase(); + + MITK_TEST_END() +} diff --git a/Modules/ImageStatistics/files.cmake b/Modules/ImageStatistics/files.cmake index 74cde7da0d..343ee8d404 100644 --- a/Modules/ImageStatistics/files.cmake +++ b/Modules/ImageStatistics/files.cmake @@ -1,11 +1,12 @@ SET(CPP_FILES mitkImageStatisticsCalculator.cpp + mitkPointSetStatisticsCalculator.cpp ) IF ( ${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION} VERSION_LESS 5.8 ) MESSAGE(STATUS "Using VTK 5.8 classes from MITK respository") SET(CPP_FILES ${CPP_FILES} vtkImageStencilRaster.cxx vtkLassoStencilSource.cxx ) -ENDIF ( ${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION} VERSION_LESS 5.8 ) +ENDIF ( ${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION} VERSION_LESS 5.8 ) \ No newline at end of file diff --git a/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.cpp b/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.cpp new file mode 100644 index 0000000000..9756a6977a --- /dev/null +++ b/Modules/ImageStatistics/mitkPointSetStatisticsCalculator.cpp @@ -0,0 +1,247 @@ +/*========================================================================= + +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) +{ +std::sort(list.begin(), list.end()); +return list.at(list.size()-1); +} + +double mitk::PointSetStatisticsCalculator::GetMin(std::vector list) +{ +std::sort(list.begin(), list.end()); +return list.at(0); +} + +double mitk::PointSetStatisticsCalculator::GetStabw(std::vector list) +{ +double returnValue = 0; +double mean = GetMean(list); +for(int i=0; i list) +{ +double returnValue = 0; +double mean = GetMean(list); +for(int i=0; i list) +{ +double mean = 0; +for(int i=0; i list) +{ +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) +{ +//calculate mean +mitk::Point3D mean; +mean.Fill(0); + +for (int i=0; i pSet = PointSetToVector(m_PointSet); + +mitk::Point3D mean = GetMean(pSet); + +for(int i=0; i pSet = PointSetToVector(m_PointSet); + +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; i +#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.*/ + mitk::Point3D GetPositionMean(); + + /** @return Returns the standard derivation of each component (x, y and z) of the analysed point set.*/ + mitk::Vector3D GetPositionStandardDeviation(); + + /** @return Returns the sample standard derivation of each component (x, y and z) of the analysed point set.*/ + mitk::Vector3D GetPositionSampleStandardDeviation(); + + /** @return Returns the mean distance to the mean postion (=mean error) of the analysed point set. */ + double GetPositionErrorMean(); + + /** @return Returns the standard derivation of the errors of all positions of the analysed point set. */ + double GetPositionErrorStandardDeviation(); + + /** @return Returns the sample standard derivation of the errors of all positions of the analysed point set. */ + double GetPositionErrorSampleStandardDeviation(); + + /** @return Returns the RMS of the errors of all positions of the analysed point set. */ + double GetPositionErrorRMS(); + + /** @return Returns the median of the errors of all positions of the analysed point set. */ + double GetPositionErrorMedian(); + + /** @return Returns the maximum of the errors of all positions of the analysed point set. */ + double GetPositionErrorMax(); + + /** @return Returns the minimum of the errors of all positions of the analysed point set. */ + 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); + + mitk::Point3D GetMean(std::vector list); + + /** @brief Converts a point set to a vector of Point3D. */ + std::vector PointSetToVector(mitk::PointSet::Pointer pSet); + + 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