diff --git a/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp b/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp index fbf6b98ade..75c8eb23e7 100644 --- a/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp @@ -1,97 +1,123 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include #include #include #include #include #include #include #include //for exceptions #include "mitkIGTException.h" #include "mitkIGTIOException.h" class mitkNavigationDataRecorderTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkNavigationDataRecorderTestSuite); MITK_TEST(PlayAndRecord); CPPUNIT_TEST_SUITE_END(); private: mitk::NavigationDataSet::Pointer m_NavigationDataSet; mitk::NavigationDataSequentialPlayer::Pointer m_Player; public: void setUp() { mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); std::string path = GetTestDataFilePath("IGT-Data/RecordedNavigationData.xml"); m_NavigationDataSet = reader->Read(path); m_Player = mitk::NavigationDataSequentialPlayer::New(); m_Player->SetNavigationDataSet(m_NavigationDataSet); } void tearDown() { } void PlayAndRecord() { // Aim is to read an xml into a pointset, play that set with a sequentialplayer, record it // again, write the result to xml , and compare the output mitk::NavigationDataRecorder::Pointer recorder = mitk::NavigationDataRecorder::New(); recorder->SetStandardizeTime(false); // connect player to recorder recorder->ConnectTo(m_Player); recorder->StartRecording(); while (!m_Player->IsAtEnd()) { recorder->Update(); m_Player->GoToNextSnapshot(); } + mitk::NavigationDataSet::Pointer recordedData = recorder->GetNavigationDataSet(); + + MITK_TEST_CONDITION_REQUIRED(recordedData->Size() == m_NavigationDataSet->Size(), "Test if recorded Dataset is of equal size as original"); + MITK_TEST_CONDITION_REQUIRED(compareDataSet(recordedData), "Test recorded dataset for equality with reference"); + recorder->StopRecording(); MITK_TEST_CONDITION_REQUIRED(! recorder->GetRecording(), "Test if StopRecording is working"); recorder->ResetRecording(); MITK_TEST_CONDITION_REQUIRED(recorder->GetNavigationDataSet()->Size() == 0, "Test correct reset of recorder"); //Reset Player //player = mitk::NavigationDataSequentialPlayer::New(); m_Player->SetNavigationDataSet(m_NavigationDataSet); // Check if Limiting recording works recorder->SetRecordCountLimit(100); recorder->StartRecording(); while (!m_Player->IsAtEnd()) { recorder->Update(); m_Player->GoToNextSnapshot(); } MITK_TEST_CONDITION_REQUIRED(recorder->GetNavigationDataSet()->Size() == 100, "Test if SetRecordCountLimit works as intended."); } + +private: + + /* + * private hepler method that compares the recorded Dataset against the member variable. + * This is a reasonable test only under the assumption that the Data should be equal from coyping - It does not consider + * homonymus Quaternions and NO FLOAT ROUNDING ISSUES + */ + bool compareDataSet(mitk::NavigationDataSet::Pointer recorded) + { + for (unsigned int tool = 0; tool < recorded->GetNumberOfTools(); tool++){ + for (unsigned int i = 0; i < recorded->Size(); i++) + { + mitk::NavigationData::Pointer ref = m_NavigationDataSet->GetNavigationDataForIndex(i,tool); + mitk::NavigationData::Pointer rec = recorded->GetNavigationDataForIndex(i,tool); + if (!(ref->GetOrientation().as_vector() == rec->GetOrientation().as_vector())) {return false;} + if (!(ref->GetPosition().GetVnlVector() == rec->GetPosition().GetVnlVector())) {return false;} + } + } + return true; + } }; MITK_TEST_SUITE_REGISTRATION(mitkNavigationDataRecorder) \ No newline at end of file