diff --git a/Modules/ImageStatistics/Testing/files.cmake b/Modules/ImageStatistics/Testing/files.cmake index 68b62b28ea..bca23c3b38 100644 --- a/Modules/ImageStatistics/Testing/files.cmake +++ b/Modules/ImageStatistics/Testing/files.cmake @@ -1,4 +1,5 @@ SET(MODULE_TESTS mitkImageStatisticsCalculatorTest.cpp mitkPointSetStatisticsCalculatorTest.cpp -) \ No newline at end of file + mitkPointSetDifferenceStatisticsCalculatorTest.cpp +) diff --git a/Modules/ImageStatistics/Testing/mitkPointSetDifferenceStatisticsCalculatorTest.cpp b/Modules/ImageStatistics/Testing/mitkPointSetDifferenceStatisticsCalculatorTest.cpp new file mode 100644 index 0000000000..50e1b213d1 --- /dev/null +++ b/Modules/ImageStatistics/Testing/mitkPointSetDifferenceStatisticsCalculatorTest.cpp @@ -0,0 +1,104 @@ +/*========================================================================= + +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 "mitkPointSetDifferenceStatisticsCalculator.h" + +//#include + +/** + * \brief Test class for mitkPointSetDifferenceStatisticsCalculator + */ +class mitkPointSetDifferenceStatisticsCalculatorTestClass +{ + +public: + + static void TestInstantiation() + { + // let's create an object of our class + mitk::PointSetDifferenceStatisticsCalculator::Pointer myPointSetDifferenceStatisticsCalculator = mitk::PointSetDifferenceStatisticsCalculator::New(); + MITK_TEST_CONDITION_REQUIRED(myPointSetDifferenceStatisticsCalculator.IsNotNull(),"Testing instantiation with constructor 1."); + + mitk::PointSet::Pointer myTestPointSet1 = mitk::PointSet::New(); + mitk::PointSet::Pointer myTestPointSet2 = mitk::PointSet::New(); + mitk::PointSetDifferenceStatisticsCalculator::Pointer myPointSetDifferenceStatisticsCalculator2 = mitk::PointSetDifferenceStatisticsCalculator::New(myTestPointSet1,myTestPointSet2); + MITK_TEST_CONDITION_REQUIRED(myPointSetDifferenceStatisticsCalculator2.IsNotNull(),"Testing instantiation with constructor 2."); + } + +static void TestSimpleCase() + { + + MITK_TEST_OUTPUT(<< "Starting simple test case..."); + + mitk::Point3D test; + mitk::PointSet::Pointer testPointSet1 = mitk::PointSet::New(); + + mitk::FillVector3D(test,0,0,0); + testPointSet1->InsertPoint(0,test); + + mitk::FillVector3D(test,1,1,1); + testPointSet1->InsertPoint(1,test); + + mitk::PointSet::Pointer testPointSet2 = mitk::PointSet::New(); + + mitk::FillVector3D(test,0.5,0.5,0.5); + testPointSet2->InsertPoint(0,test); + + mitk::FillVector3D(test,2,2,2); + testPointSet2->InsertPoint(1,test); + + double mean = (sqrt(0.75)+sqrt(3))/2; + double variance = ((sqrt(0.75)-mean)*(sqrt(0.75)-mean)+(sqrt(3)-mean)*(sqrt(3)-mean))/2; + double sd = sqrt(variance); + double rms = sqrt(3.75/2); + double min = sqrt(0.75); + double max = sqrt(3); + double median = (min + max)/2; + + mitk::PointSetDifferenceStatisticsCalculator::Pointer myPointSetDifferenceStatisticsCalculator = mitk::PointSetDifferenceStatisticsCalculator::New(testPointSet1,testPointSet2); + + MITK_TEST_CONDITION_REQUIRED((myPointSetDifferenceStatisticsCalculator->GetNumberOfPoints()==testPointSet1->GetSize()),".. Testing GetNumberOfPoints"); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(myPointSetDifferenceStatisticsCalculator->GetMean(),mean),".. Testing GetMean"); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(myPointSetDifferenceStatisticsCalculator->GetSD(),sd),".. Testing GetSD"); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(myPointSetDifferenceStatisticsCalculator->GetVariance(),variance),".. Testing GetVariance"); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(myPointSetDifferenceStatisticsCalculator->GetRMS(),rms),".. Testing GetRMS"); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(myPointSetDifferenceStatisticsCalculator->GetMin(),min),".. Testing GetMin"); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(myPointSetDifferenceStatisticsCalculator->GetMax(),max),".. Testing GetMax"); + MITK_TEST_CONDITION_REQUIRED(mitk::Equal(myPointSetDifferenceStatisticsCalculator->GetMedian(),median),".. Testing GetMedian"); + } +}; + +int mitkPointSetDifferenceStatisticsCalculatorTest(int argc, char* argv[]) +{ + // always start with this! + MITK_TEST_BEGIN("mitkPointSetDifferenceStatisticsCalculatorTest") + + // let's create an object of our class + mitk::PointSetDifferenceStatisticsCalculator::Pointer myPointSetDifferenceStatisticsCalculator = mitk::PointSetDifferenceStatisticsCalculator::New(); + MITK_TEST_CONDITION_REQUIRED(myPointSetDifferenceStatisticsCalculator.IsNotNull(),"Testing instantiation with constructor 1."); + + mitk::PointSet::Pointer myTestPointSet1 = mitk::PointSet::New(); + mitk::PointSet::Pointer myTestPointSet2 = mitk::PointSet::New(); + mitk::PointSetDifferenceStatisticsCalculator::Pointer myPointSetDifferenceStatisticsCalculator2 = mitk::PointSetDifferenceStatisticsCalculator::New(myTestPointSet1,myTestPointSet2); + MITK_TEST_CONDITION_REQUIRED(myPointSetDifferenceStatisticsCalculator2.IsNotNull(),"Testing instantiation with constructor 2."); + + mitkPointSetDifferenceStatisticsCalculatorTestClass::TestInstantiation(); + mitkPointSetDifferenceStatisticsCalculatorTestClass::TestSimpleCase(); + MITK_TEST_END() +} diff --git a/Modules/ImageStatistics/files.cmake b/Modules/ImageStatistics/files.cmake index 343ee8d404..c34c7179b3 100644 --- a/Modules/ImageStatistics/files.cmake +++ b/Modules/ImageStatistics/files.cmake @@ -1,12 +1,13 @@ SET(CPP_FILES mitkImageStatisticsCalculator.cpp mitkPointSetStatisticsCalculator.cpp + mitkPointSetDifferenceStatisticsCalculator.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 ) \ No newline at end of file +ENDIF ( ${VTK_MAJOR_VERSION}.${VTK_MINOR_VERSION} VERSION_LESS 5.8 ) diff --git a/Modules/ImageStatistics/mitkPointSetDifferenceStatisticsCalculator.cpp b/Modules/ImageStatistics/mitkPointSetDifferenceStatisticsCalculator.cpp new file mode 100644 index 0000000000..615e918274 --- /dev/null +++ b/Modules/ImageStatistics/mitkPointSetDifferenceStatisticsCalculator.cpp @@ -0,0 +1,190 @@ +/*========================================================================= + +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 "mitkPointSetDifferenceStatisticsCalculator.h" + +mitk::PointSetDifferenceStatisticsCalculator::PointSetDifferenceStatisticsCalculator() : + m_StatisticsCalculated(false) +{ + m_PointSet1 = mitk::PointSet::New(); + m_PointSet2 = mitk::PointSet::New(); +} + +mitk::PointSetDifferenceStatisticsCalculator::PointSetDifferenceStatisticsCalculator(mitk::PointSet::Pointer pSet1, mitk::PointSet::Pointer pSet2) +{ + m_PointSet1 = pSet1; + m_PointSet2 = pSet2; + m_StatisticsCalculated = false; +} + +mitk::PointSetDifferenceStatisticsCalculator::~PointSetDifferenceStatisticsCalculator() +{ +} + +void mitk::PointSetDifferenceStatisticsCalculator::SetPointSets(mitk::PointSet::Pointer pSet1, mitk::PointSet::Pointer pSet2) +{ + if (pSet1.IsNotNull()) + { + m_PointSet1 = pSet1; + } + if (pSet2.IsNotNull()) + { + m_PointSet2 = pSet2; + } + m_StatisticsCalculated = false; +} + +std::vector mitk::PointSetDifferenceStatisticsCalculator::GetDifferences() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_DifferencesVector; +} + +std::vector mitk::PointSetDifferenceStatisticsCalculator::GetSquaredDifferences() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_SquaredDifferencesVector; +} + +double mitk::PointSetDifferenceStatisticsCalculator::GetMean() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_Statistics.Mean; +} + +double mitk::PointSetDifferenceStatisticsCalculator::GetSD() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_Statistics.Sigma; +} + +double mitk::PointSetDifferenceStatisticsCalculator::GetVariance() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_Statistics.Variance; +} + +double mitk::PointSetDifferenceStatisticsCalculator::GetRMS() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_Statistics.RMS; +} + +double mitk::PointSetDifferenceStatisticsCalculator::GetMedian() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_Statistics.Median; +} + +double mitk::PointSetDifferenceStatisticsCalculator::GetMax() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_Statistics.Max; +} + +double mitk::PointSetDifferenceStatisticsCalculator::GetMin() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_Statistics.Min; +} + +double mitk::PointSetDifferenceStatisticsCalculator::GetNumberOfPoints() +{ + if (!m_StatisticsCalculated) + { + this->ComputeStatistics(); + } + return m_Statistics.N; +} + +void mitk::PointSetDifferenceStatisticsCalculator::ComputeStatistics() +{ + double mean, sd, rms= 0.0; + std::vector differencesVector; + mitk::Point3D point1; + mitk::Point3D point2; + int numberOfPoints = m_PointSet1->GetSize(); + for (int i=0; iGetPoint(i); + point2 = m_PointSet2->GetPoint(i); + double squaredDistance = point1.SquaredEuclideanDistanceTo(point2); + mean+=sqrt(squaredDistance); + rms+=squaredDistance; + this->m_SquaredDifferencesVector.push_back(squaredDistance); + differencesVector.push_back(sqrt(squaredDistance)); + } + m_DifferencesVector = differencesVector; + mean = mean/numberOfPoints; + rms = sqrt(rms/numberOfPoints); + for (int i=0; i +#include "ImageStatisticsExports.h" +#include "mitkImageStatisticsCalculator.h" +#include + +namespace mitk +{ + +/** + * \brief Class for calculating the difference between two corresponding point sets. + * The user can access the single distances between corresponding points as well as a complete statistic (mean, sd, rms, median, max, min) + * The point sets must be of equal size! + */ +class ImageStatistics_EXPORT PointSetDifferenceStatisticsCalculator : public itk::Object +{ +public: + + mitkClassMacro( PointSetDifferenceStatisticsCalculator, itk::Object ); + itkNewMacro( PointSetDifferenceStatisticsCalculator ); + + mitkNewMacro2Param(PointSetDifferenceStatisticsCalculator,mitk::PointSet::Pointer,mitk::PointSet::Pointer) + + /*! + \brief set point sets to be compared + */ + void SetPointSets(mitk::PointSet::Pointer pSet1, mitk::PointSet::Pointer pSet2); + /*! + \brief returns a vector holding the differences between the corresponding points of the point sets + */ + std::vector GetDifferences(); + /*! + \brief returns a vector holding the squared differences between the corresponding points of the point sets + */ + std::vector GetSquaredDifferences(); + /*! + \brief returns the mean distance of all corresponding points of the point sets + */ + double GetMean(); + /*! + \brief returns the standard deviation of the distances between all corresponding points of the point sets + */ + double GetSD(); + /*! + \brief returns the variance of the distances between all corresponding points of the point sets + */ + double GetVariance(); + /*! + \brief returns the root mean squared distance of all corresponding points of the point sets + */ + double GetRMS(); + /*! + \brief returns the median distance of all corresponding points of the point sets + */ + double GetMedian(); + /*! + \brief returns the maximal distance of all corresponding points of the point sets + */ + double GetMax(); + /*! + \brief returns the minimal distance of all corresponding points of the point sets + */ + double GetMin(); + /*! + \brief returns the total number of corresponding points of the point sets + */ + double GetNumberOfPoints(); + +protected: + + PointSetDifferenceStatisticsCalculator(); + PointSetDifferenceStatisticsCalculator(mitk::PointSet::Pointer,mitk::PointSet::Pointer); + virtual ~PointSetDifferenceStatisticsCalculator(); + + /*! + \brief Method for computing the complete statistics of the differences between the given point sets. + */ + void ComputeStatistics(); + + mitk::ImageStatisticsCalculator::Statistics m_Statistics; ///< struct holding the statistics + std::vector m_DifferencesVector; ///< vector holding the differences between the corresponding points + std::vector m_SquaredDifferencesVector; ///< vector holding the squared differences between the corresponding points + mitk::PointSet::Pointer m_PointSet1; ///< first point set used for comparison + mitk::PointSet::Pointer m_PointSet2; ///< second point set used for comparison + bool m_StatisticsCalculated; ///< flag indicating whether statistics are already calculated or not. +}; + +} + +#endif // #define _MITK_PointSetDifferenceStatisticsCalculator_H