diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.cpp b/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.cpp index db4f51e3df..c08364b68c 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.cpp +++ b/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.cpp @@ -1,298 +1,315 @@ /*========================================================================= 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 #define _USE_MATH_DEFINES #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) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); return myCalculator->GetPositionMean(); } mitk::Vector3D mitk::NavigationDataEvaluationFilter::GetPositionStandardDeviation(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); return myCalculator->GetPositionStandardDeviation(); } mitk::Vector3D mitk::NavigationDataEvaluationFilter::GetPositionSampleStandardDeviation(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); return myCalculator->GetPositionSampleStandardDeviation(); } 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; } mitk::Vector3D mitk::NavigationDataEvaluationFilter::GetEulerAnglesMean(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(QuaternionsToEulerAngles(m_LoggedQuaternions[input]))); mitk::Vector3D returnValue; returnValue[0] = myCalculator->GetPositionMean()[0]; returnValue[1] = myCalculator->GetPositionMean()[1]; returnValue[2] = myCalculator->GetPositionMean()[2]; return returnValue; } double mitk::NavigationDataEvaluationFilter::GetEulerAnglesRMS(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(QuaternionsToEulerAngles(m_LoggedQuaternions[input]))); return myCalculator->GetPositionErrorRMS(); } double mitk::NavigationDataEvaluationFilter::GetEulerAnglesRMSDegree(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(QuaternionsToEulerAnglesGrad(m_LoggedQuaternions[input]))); return myCalculator->GetPositionErrorRMS(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorMean(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); return myCalculator->GetPositionErrorMean(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorStandardDeviation(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); return myCalculator->GetPositionErrorStandardDeviation(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorSampleStandardDeviation(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); return myCalculator->GetPositionErrorSampleStandardDeviation(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorRMS(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); return myCalculator->GetPositionErrorRMS(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorMedian(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); return myCalculator->GetPositionErrorMedian(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorMax(int input) { mitk::PointSetStatisticsCalculator::Pointer myCalculator = mitk::PointSetStatisticsCalculator::New(VectorToPointSet(m_LoggedPositions[input])); return myCalculator->GetPositionErrorMax(); } double mitk::NavigationDataEvaluationFilter::GetPositionErrorMin(int 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; } mitk::Quaternion mitk::NavigationDataEvaluationFilter::GetMean(std::vector 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; } mitk::PointSet::Pointer mitk::NavigationDataEvaluationFilter::VectorToPointSet(std::vector pSet) { mitk::PointSet::Pointer returnValue = mitk::PointSet::New(); for (int i=0; iInsertPoint(i,thisPoint); } return returnValue; } std::vector mitk::NavigationDataEvaluationFilter::QuaternionsToEulerAngles(std::vector quaterions) { std::vector returnValue = std::vector(); for (int i=0; i mitk::NavigationDataEvaluationFilter::QuaternionsToEulerAnglesGrad(std::vector quaterions) { double PI = M_PI; std::vector returnValue = std::vector(); std::vector eulerAnglesRadians = QuaternionsToEulerAngles(quaterions); for (int i=0; i=i)||(i<0)) returnValue.Fill(0); + else returnValue = m_LoggedPositions[input].at(i); + return returnValue; +} + + +mitk::Quaternion mitk::NavigationDataEvaluationFilter::GetLoggedOrientation(int i, int input) +{ + mitk::Quaternion returnValue; + if ((m_LoggedQuaternions[input].size()>=i)||(i<0)) returnValue.fill(0); + else returnValue = m_LoggedQuaternions[input].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 942e09a125..197be2b0ae 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.h +++ b/Modules/IGT/IGTFilters/mitkNavigationDataEvaluationFilter.h @@ -1,119 +1,125 @@ /*========================================================================= 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 euler angles (theta_x, theta_y, theta_z) of the specified input since the start of the statistic (last call of ResetStatistic()) */ mitk::Vector3D GetEulerAnglesMean(int input); /** @return Returns the RMS of the error of the euler angles (theta_x, theta_y, theta_z) in radians of the specified input since the start of the statistic (last call of ResetStatistic()) */ double GetEulerAnglesRMS(int input); /** @return Returns the RMS of the error of the euler angles (theta_x, theta_y, theta_z) in degree of the specified input since the start of the statistic (last call of ResetStatistic()) */ double GetEulerAnglesRMSDegree(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); + + /** @return Returns a logged point on position i of the specified input. If there is no point on position i the method returns [0,0,0] */ + mitk::Point3D GetLoggedPosition(int i, int input); + + /** @return Returns a logged orientation on position i of the specified input. If there is no orientation on position i the method returns [0,0,0,0] */ + mitk::Quaternion GetLoggedOrientation(int i, 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; mitk::Quaternion GetMean(std::vector list); mitk::PointSet::Pointer VectorToPointSet(std::vector pSet); mitk::PointSet::Pointer VectorToPointSet(std::vector pSet); /** @brief Converts a list of quaterions to a list of euler angles (theta_x, theta_y, theta_z) */ std::vector QuaternionsToEulerAngles(std::vector quaterions); //in radians std::vector QuaternionsToEulerAnglesGrad(std::vector quaterions); //in degree }; } // namespace mitk #endif /* MITKNavigationDataEvaluationFilter_H_HEADER_INCLUDED_ */ \ No newline at end of file