diff --git a/Modules/IGT/IGTFilters/mitkNavigationData.h b/Modules/IGT/IGTFilters/mitkNavigationData.h index d7ceab42f9..25d67fa182 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationData.h +++ b/Modules/IGT/IGTFilters/mitkNavigationData.h @@ -1,205 +1,207 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ 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 MITKNAVIGATIONDATA_H_HEADER_INCLUDED_ #define MITKNAVIGATIONDATA_H_HEADER_INCLUDED_ #include #include #include #include namespace mitk { /**Documentation * \brief Navigation Data * * This class represents the data object that is passed through the MITK-IGT navigation filter * pipeline. It encapsulates position and orientation of a tracked tool/sensor. Additionally, * it contains a data structure that contains error/plausibility information * * \ingroup IGT */ class MitkIGT_EXPORT NavigationData : public itk::DataObject { public: mitkClassMacro(NavigationData, itk::DataObject); itkNewMacro(Self); /** * \brief Type that holds the position part of the tracking data */ typedef mitk::Point3D PositionType; /** * \brief Type that holds the orientation part of the tracking data */ typedef mitk::Quaternion OrientationType; /** * \brief type that holds the error characterization of the position and orientation measurements */ typedef itk::Matrix CovarianceMatrixType; /** * \brief type that holds the time at which the data was recorded */ typedef double TimeStampType; /** * \brief sets the position of the NavigationData object */ itkSetMacro(Position, PositionType); /** * \brief returns position of the NavigationData object */ itkGetConstMacro(Position, PositionType); /** * \brief sets the orientation of the NavigationData object */ itkSetMacro(Orientation, OrientationType); /** * \brief returns the orientation of the NavigationData object */ itkGetConstMacro(Orientation, OrientationType); /** * \brief returns true if the object contains valid data */ virtual bool IsDataValid() const; /** * \brief sets the dataValid flag of the NavigationData object indicating if the object contains valid data */ itkSetMacro(DataValid, bool); /** * \brief sets the timestamp of the NavigationData object */ itkSetMacro(TimeStamp, TimeStampType); /** * \brief gets the timestamp of the NavigationData object */ itkGetConstMacro(TimeStamp, TimeStampType); /** * \brief sets the HasPosition flag of the NavigationData object */ itkSetMacro(HasPosition, bool); /** * \brief gets the HasPosition flag of the NavigationData object */ itkGetConstMacro(HasPosition, bool); /** * \brief sets the HasOrientation flag of the NavigationData object */ itkSetMacro(HasOrientation, bool); /** * \brief gets the HasOrientation flag of the NavigationData object */ itkGetConstMacro(HasOrientation, bool); /** * \brief sets the 6x6 Error Covariance Matrix of the NavigationData object */ itkSetMacro(CovErrorMatrix, CovarianceMatrixType); /** * \brief gets the 6x6 Error Covariance Matrix of the NavigationData object */ itkGetConstMacro(CovErrorMatrix, CovarianceMatrixType); /** * \brief set the name of the NavigationData object */ itkSetStringMacro(Name); /** * \brief returns the name of the NavigationData object */ itkGetStringMacro(Name); /** * \brief Graft the data and information from one NavigationData to another. * * Copies the content of data into this object. * This is a convenience method to setup a second NavigationData object with all the meta * information of another NavigationData object. * Note that this method is different than just using two * SmartPointers to the same NavigationData object since separate DataObjects are * still maintained. */ virtual void Graft(const DataObject *data); /** * \brief copy meta data of a NavigationData object * * copies all meta data from NavigationData data to this object */ virtual void CopyInformation(const DataObject* data); /** - * \brief print object information + * \brief Prints the object information to the given stream os. + * \param os The stream which is used to print the output. + * \param indent Defines the indentation of the output. */ void PrintSelf(std::ostream& os, itk::Indent indent) const; /** * Set the position part of m_CovErrorMatrix to I*error^2 * This means that all position variables are assumed to be independent */ void SetPositionAccuracy(mitk::ScalarType error); /** * Set the orientation part of m_CovErrorMatrix to I*error^2 * This means that all orientation variables are assumed to be independent */ void SetOrientationAccuracy(mitk::ScalarType error); protected: NavigationData(); virtual ~NavigationData(); /** * \brief holds the position part of the tracking data */ PositionType m_Position; /** * \brief holds the orientation part of the tracking data */ OrientationType m_Orientation; /** * \brief A 6x6 covariance matrix parameterizing the Gaussian error * distribution of the measured position and orientation. * * The hasPosition/hasOrientation fields define which entries * are valid. */ CovarianceMatrixType m_CovErrorMatrix; ///< holds the error characterization of the position and orientation /** * \brief defines if position part of m_CovErrorMatrix is valid */ bool m_HasPosition; /** * \brief defines if orientation part of m_CovErrorMatrix is valid */ bool m_HasOrientation; /** * \brief defines if the object contains valid values */ bool m_DataValid; /** * \brief contains the time at which the tracking data was recorded */ TimeStampType m_TimeStamp; /** * \brief name of the navigation data */ std::string m_Name; }; } // namespace mitk #endif /* MITKNAVIGATIONDATA_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/Testing/mitkNavigationDataTest.cpp b/Modules/IGT/Testing/mitkNavigationDataTest.cpp index e42d388f33..b795d3fe21 100644 --- a/Modules/IGT/Testing/mitkNavigationDataTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataTest.cpp @@ -1,102 +1,202 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-10-18 21:46:13 +0200 (So, 18. Okt 2009) $ 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 "mitkTestingMacros.h" #include "mitkNavigationData.h" -//#include "mitkTrackingTypes.h" -// -//#include "mitkCommon.h" -// -//#include -//#include + +#include "itkIndent.h" + +class NavigationDataTestClass + { + public: + static mitk::NavigationData::Pointer GetTestData() + { + mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); + mitk::NavigationData::PositionType p; + mitk::FillVector3D(p, 44.4, 55.5, 66.66); + nd->SetPosition(p); + mitk::NavigationData::OrientationType o(1.0, 2.0, 3.0, 4.0); + nd->SetOrientation(o); + nd->SetDataValid(true); + nd->SetTimeStamp(100.111); + nd->SetHasPosition(false); + nd->SetHasOrientation(false); + mitk::NavigationData::CovarianceMatrixType m; + m.Fill(17.17); + m(2, 2) = 1000.01; + nd->SetCovErrorMatrix(m); + nd->SetName("my NavigationData"); + nd->SetPositionAccuracy(100.0); + nd->SetOrientationAccuracy(10.0); + return nd; + + } + + static void TestInstatiation() + { + // Test instantiation of NavigationData + mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); + MITK_TEST_CONDITION(nd.IsNotNull(),"Test instatiation"); + } + + static void TestGetterSetter() + { + mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); + + mitk::NavigationData::PositionType p; + mitk::FillVector3D(p, 44.4, 55.5, 66.66); + nd->SetPosition(p); + MITK_TEST_CONDITION(nd->GetPosition() == p, "Set-/GetPosition()"); + + mitk::NavigationData::OrientationType o(1.0, 2.0, 3.0, 4.0); + nd->SetOrientation(o); + MITK_TEST_CONDITION(nd->GetOrientation() == o, "Set-/GetOrientation()"); + + nd->SetDataValid(true); + MITK_TEST_CONDITION(nd->IsDataValid() == true, "Set-/IsDataValid()"); + + nd->SetTimeStamp(100.111); + MITK_TEST_CONDITION(mitk::Equal(nd->GetTimeStamp(), 100.111), "Set-/GetTimeStamp()"); + + nd->SetHasPosition(false); + MITK_TEST_CONDITION(nd->GetHasPosition() == false, "Set-/GetHasPosition()"); + + nd->SetHasOrientation(false); + MITK_TEST_CONDITION(nd->GetHasOrientation() == false, "Set-/GetHasOrientation()"); + + mitk::NavigationData::CovarianceMatrixType m; + m.Fill(17.17); + m(2, 2) = 1000.01; + nd->SetCovErrorMatrix(m); + MITK_TEST_CONDITION(nd->GetCovErrorMatrix() == m, "Set-/GetCovErrorMatrix()"); + + nd->SetName("my NavigationData"); + MITK_TEST_CONDITION(std::string(nd->GetName()) == "my NavigationData", "Set-/GetName()"); + + + nd->SetPositionAccuracy(100.0); + mitk::NavigationData::CovarianceMatrixType result = nd->GetCovErrorMatrix(); + MITK_TEST_CONDITION(mitk::Equal(result(0, 0), 10000.0) + && mitk::Equal(result(1, 1), 10000.0) + && mitk::Equal(result(2, 2), 10000.0), "SetPositionAccuracy()"); + + + nd->SetOrientationAccuracy(10.0); + mitk::NavigationData::CovarianceMatrixType result2 = nd->GetCovErrorMatrix(); + MITK_TEST_CONDITION(mitk::Equal(result2(3, 3), 100.0) + && mitk::Equal(result2(4, 4), 100.0) + && mitk::Equal(result2(5, 5), 100.0), "SetOrientationAccuracy()"); + + } + static void TestGraft() + { + //create test data + mitk::NavigationData::Pointer nd = GetTestData(); + + mitk::NavigationData::Pointer graftedCopy = mitk::NavigationData::New(); + graftedCopy->Graft(nd); + + bool graftIsEqual = (nd->GetPosition() == graftedCopy->GetPosition()) + && (nd->GetOrientation() == graftedCopy->GetOrientation()) + && (nd->IsDataValid() == graftedCopy->IsDataValid()) + && mitk::Equal(nd->GetTimeStamp(), graftedCopy->GetTimeStamp()) + && (nd->GetHasPosition() == graftedCopy->GetHasPosition()) + && (nd->GetHasOrientation() == graftedCopy->GetHasOrientation()) + && (nd->GetCovErrorMatrix() == graftedCopy->GetCovErrorMatrix()) + && (std::string(nd->GetName()) == graftedCopy->GetName()); + + + MITK_TEST_CONDITION(graftIsEqual, "Graft() produces equal NavigationData object"); + } + + static void TestPrintSelf() + { + mitk::NavigationData::Pointer nd = GetTestData(); + itk::Indent myIndent = itk::Indent(); + + MITK_TEST_OUTPUT(<<"Testing method PrintSelf(), method output will follow:"); + bool success = true; + try + { + nd->PrintSelf(std::cout,myIndent); + } + catch(...) + { + success = false; + } + MITK_TEST_CONDITION(success, "Testing method PrintSelf()."); + } + + static void TestWrongInputs() + { + + mitk::NavigationData::Pointer nd = GetTestData(); + + + // Test CopyInformation + bool success = false; + try + { + nd->CopyInformation(NULL); + } + catch(itk::ExceptionObject e) + { + success = true; + } + MITK_TEST_CONDITION(success, "Testing wrong input for method CopyInformation."); + + + // Test Graft + success = false; + try + { + nd->Graft(NULL); + } + catch(itk::ExceptionObject e) + { + success = true; + } + MITK_TEST_CONDITION(success, "Testing wrong input for method Graft."); + + + + } + }; /** * This function is testing the Class mitk::NavigationData. For most tests we would need the MicronTracker hardware, so only a few * simple tests, which can run without the hardware are implemented yet (2009, January, 23rd). As soon as there is a working * concept to test the tracking classes which are very close to the hardware on all systems more tests are needed here. */ int mitkNavigationDataTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("NavigationData"); - // Test instantiation of NavigationData - mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); - MITK_TEST_CONDITION(nd.IsNotNull(),"Test instatiation"); - - mitk::NavigationData::PositionType p; - mitk::FillVector3D(p, 44.4, 55.5, 66.66); - nd->SetPosition(p); - MITK_TEST_CONDITION(nd->GetPosition() == p, "Set-/GetPosition()"); - - mitk::NavigationData::OrientationType o(1.0, 2.0, 3.0, 4.0); - nd->SetOrientation(o); - MITK_TEST_CONDITION(nd->GetOrientation() == o, "Set-/GetOrientation()"); - - nd->SetDataValid(true); - MITK_TEST_CONDITION(nd->IsDataValid() == true, "Set-/IsDataValid()"); - - nd->SetTimeStamp(100.111); - MITK_TEST_CONDITION(mitk::Equal(nd->GetTimeStamp(), 100.111), "Set-/GetTimeStamp()"); - - nd->SetHasPosition(false); - MITK_TEST_CONDITION(nd->GetHasPosition() == false, "Set-/GetHasPosition()"); - - nd->SetHasOrientation(false); - MITK_TEST_CONDITION(nd->GetHasOrientation() == false, "Set-/GetHasOrientation()"); + NavigationDataTestClass::TestInstatiation(); + NavigationDataTestClass::TestGetterSetter(); + NavigationDataTestClass::TestGraft(); + NavigationDataTestClass::TestPrintSelf(); + NavigationDataTestClass::TestWrongInputs(); - mitk::NavigationData::CovarianceMatrixType m; - m.Fill(17.17); - m(2, 2) = 1000.01; - nd->SetCovErrorMatrix(m); - MITK_TEST_CONDITION(nd->GetCovErrorMatrix() == m, "Set-/GetCovErrorMatrix()"); + - nd->SetName("my NavigationData"); - MITK_TEST_CONDITION(std::string(nd->GetName()) == "my NavigationData", "Set-/GetName()"); - - nd->SetPositionAccuracy(100.0); - mitk::NavigationData::CovarianceMatrixType result = nd->GetCovErrorMatrix(); - MITK_TEST_CONDITION(mitk::Equal(result(0, 0), 10000.0) - && mitk::Equal(result(1, 1), 10000.0) - && mitk::Equal(result(2, 2), 10000.0), "SetPositionAccuracy()"); - - - nd->SetOrientationAccuracy(10.0); - mitk::NavigationData::CovarianceMatrixType result2 = nd->GetCovErrorMatrix(); - MITK_TEST_CONDITION(mitk::Equal(result2(3, 3), 100.0) - && mitk::Equal(result2(4, 4), 100.0) - && mitk::Equal(result2(5, 5), 100.0), "SetOrientationAccuracy()"); - - - mitk::NavigationData::Pointer graftedCopy = mitk::NavigationData::New(); - graftedCopy->Graft(nd); - - bool graftIsEqual = (nd->GetPosition() == graftedCopy->GetPosition()) - && (nd->GetOrientation() == graftedCopy->GetOrientation()) - && (nd->IsDataValid() == graftedCopy->IsDataValid()) - && mitk::Equal(nd->GetTimeStamp(), graftedCopy->GetTimeStamp()) - && (nd->GetHasPosition() == graftedCopy->GetHasPosition()) - && (nd->GetHasOrientation() == graftedCopy->GetHasOrientation()) - && (nd->GetCovErrorMatrix() == graftedCopy->GetCovErrorMatrix()) - && (std::string(nd->GetName()) == graftedCopy->GetName()); - MITK_TEST_CONDITION(graftIsEqual, "Graft() produces equal NavigationData object"); - MITK_TEST_END(); }