diff --git a/Modules/IGT/IO/mitkNavigationDataPlayer.cpp b/Modules/IGT/IO/mitkNavigationDataPlayer.cpp index ff08aaad03..7bdd597660 100644 --- a/Modules/IGT/IO/mitkNavigationDataPlayer.cpp +++ b/Modules/IGT/IO/mitkNavigationDataPlayer.cpp @@ -1,161 +1,160 @@ /*=================================================================== 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 "mitkNavigationDataPlayer.h" #include #include #include -#include "mitkNavigationDataReaderXML.h" #include "mitkIGTException.h" mitk::NavigationDataPlayer::NavigationDataPlayer() : m_CurPlayerState(PlayerStopped), m_StartPlayingTimeStamp(0.0), m_PauseTimeStamp(0.0) { // to get a start time mitk::IGTTimeStamp::GetInstance()->Start(this); } mitk::NavigationDataPlayer::~NavigationDataPlayer() { StopPlaying(); } void mitk::NavigationDataPlayer::GenerateData() { if ( m_NavigationDataSet->Size() == 0 ) { MITK_WARN << "Cannot do anything with empty set of navigation datas."; return; } //Only produce new output if the player is started if (m_CurPlayerState != PlayerRunning) { //The output is not valid anymore this->GraftEmptyOutput(); return; } // get elapsed time since start of playing m_TimeStampSinceStart = mitk::IGTTimeStamp::GetInstance()->GetElapsed() - m_StartPlayingTimeStamp; // add offset of the first navigation data to the timestamp to start playing // imediatly with the first navigation data (not to wait till the first time // stamp is reached) TimeStampType timeStampSinceStartWithOffset = m_TimeStampSinceStart + m_NavigationDataSet->Begin()->at(0)->GetIGTTimeStamp(); // iterate through all NavigationData objects of the given tool index // till the timestamp of the NavigationData is greater then the given timestamp for (; m_NavigationDataSetIterator != m_NavigationDataSet->End(); ++m_NavigationDataSetIterator) { // test if the timestamp of the successor is greater than the time stamp if ( m_NavigationDataSetIterator+1 == m_NavigationDataSet->End() || (m_NavigationDataSetIterator+1)->at(0)->GetIGTTimeStamp() > timeStampSinceStartWithOffset ) { break; } } for (unsigned int index = 0; index < GetNumberOfOutputs(); index++) { mitk::NavigationData* output = this->GetOutput(index); if( !output ) { mitkThrowException(mitk::IGTException) << "Output of index "<Graft(m_NavigationDataSetIterator->at(index)); } // stop playing if the last NavigationData objects were grafted if (m_NavigationDataSetIterator+1 == m_NavigationDataSet->End()) { this->StopPlaying(); // start playing again if repeat is enabled if ( m_Repeat ) { this->StartPlaying(); } } } void mitk::NavigationDataPlayer::UpdateOutputInformation() { this->Modified(); // make sure that we need to be updated Superclass::UpdateOutputInformation(); } void mitk::NavigationDataPlayer::StartPlaying() { // make sure that player is initialized before playing starts this->InitPlayer(); // set state and iterator for playing from start m_CurPlayerState = PlayerRunning; m_NavigationDataSetIterator = m_NavigationDataSet->Begin(); // reset playing timestamps m_PauseTimeStamp = 0; m_TimeStampSinceStart = 0; // timestamp for indicating playing start set to current elapsed time m_StartPlayingTimeStamp = mitk::IGTTimeStamp::GetInstance()->GetElapsed(); } void mitk::NavigationDataPlayer::StopPlaying() { m_CurPlayerState = PlayerStopped; } void mitk::NavigationDataPlayer::Pause() { //player runs and pause was called -> pause the player if(m_CurPlayerState == PlayerRunning) { m_CurPlayerState = PlayerPaused; m_PauseTimeStamp = mitk::IGTTimeStamp::GetInstance()->GetElapsed(); } else { MITK_ERROR << "Player is either not started or already is paused" << std::endl; } } void mitk::NavigationDataPlayer::Resume() { // player is in pause mode -> play at the last position if(m_CurPlayerState == PlayerPaused) { m_CurPlayerState = PlayerRunning; // in this case m_StartPlayingTimeStamp is set to the total elapsed time with NO playback m_StartPlayingTimeStamp = mitk::IGTTimeStamp::GetInstance()->GetElapsed() - (m_PauseTimeStamp - m_StartPlayingTimeStamp); } else { MITK_ERROR << "Player is not paused!" << std::endl; } } mitk::NavigationDataPlayer::PlayerState mitk::NavigationDataPlayer::GetCurrentPlayerState() { return m_CurPlayerState; } mitk::NavigationDataPlayer::TimeStampType mitk::NavigationDataPlayer::GetTimeStampSinceStart() { return m_TimeStampSinceStart; } diff --git a/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp b/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp index 6154174623..64cd8ce361 100644 --- a/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataRecorderTest.cpp @@ -1,142 +1,141 @@ /*=================================================================== 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(TestRecording); MITK_TEST(TestStopRecording); MITK_TEST(TestLimiting); CPPUNIT_TEST_SUITE_END(); private: mitk::NavigationDataSet::Pointer m_NavigationDataSet; mitk::NavigationDataSequentialPlayer::Pointer m_Player; mitk::NavigationDataRecorder::Pointer m_Recorder; public: void setUp() override { - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); std::string path = GetTestDataFilePath("IGT-Data/RecordedNavigationData.xml"); - m_NavigationDataSet = reader->Read(path); + m_NavigationDataSet = dynamic_cast (mitk::IOUtil::LoadBaseData(path).GetPointer()); + m_Player = mitk::NavigationDataSequentialPlayer::New(); m_Player->SetNavigationDataSet(m_NavigationDataSet); m_Recorder = mitk::NavigationDataRecorder::New(); m_Recorder->SetStandardizeTime(false); // connect player to recorder m_Recorder->ConnectTo(m_Player); } void tearDown() override { } void TestRecording() { m_Recorder->StartRecording(); while (!m_Player->IsAtEnd()) { m_Recorder->Update(); m_Player->GoToNextSnapshot(); } mitk::NavigationDataSet::Pointer recordedData = m_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"); } void TestStopRecording() { // 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 m_Recorder->StartRecording(); int i = 0; while (i < 5) { m_Recorder->Update(); m_Player->GoToNextSnapshot(); i++; } m_Recorder->StopRecording(); MITK_TEST_CONDITION_REQUIRED(! m_Recorder->GetRecording(), "Test if StopRecording is working, part 1"); while (i < 5) { m_Recorder->Update(); m_Player->GoToNextSnapshot(); i++; } MITK_TEST_CONDITION_REQUIRED(m_Recorder->GetNavigationDataSet()->Size() == 5, "Test if StopRecording is working, part 2"); } void TestLimiting() { // Check if Limiting recording works m_Recorder->SetRecordCountLimit(30); m_Recorder->StartRecording(); while (!m_Player->IsAtEnd()) { m_Recorder->Update(); m_Player->GoToNextSnapshot(); } MITK_TEST_CONDITION_REQUIRED(m_Recorder->GetNavigationDataSet()->Size() == 30, "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 diff --git a/Modules/IGT/Testing/mitkNavigationDataSequentialPlayerTest.cpp b/Modules/IGT/Testing/mitkNavigationDataSequentialPlayerTest.cpp index b8bb7db227..95d007e89d 100644 --- a/Modules/IGT/Testing/mitkNavigationDataSequentialPlayerTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataSequentialPlayerTest.cpp @@ -1,175 +1,175 @@ /*=================================================================== 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 "mitkTestingMacros.h" #include -#include "mitkNavigationDataReaderXML.h" +#include #include #include //foe exceptions #include "mitkIGTException.h" #include "mitkIGTIOException.h" class mitkNavigationDataSequentialPlayerTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkNavigationDataSequentialPlayerTestSuite); MITK_TEST(TestStandardWorkflow); MITK_TEST(TestRestartWithNewNavigationDataSet); MITK_TEST(TestGoToSnapshotException); MITK_TEST(TestDoubleUpdate); CPPUNIT_TEST_SUITE_END(); private: /** Members used inside the different test methods. All members are initialized via setUp().*/ mitk::NavigationDataSet::Pointer NavigationDataSet; mitk::NavigationDataSequentialPlayer::Pointer player; public: void setUp() override{ player = mitk::NavigationDataSequentialPlayer::New(); std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2ToolsDouble.xml"); - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - NavigationDataSet =reader->Read(file); + + NavigationDataSet = dynamic_cast (mitk::IOUtil::LoadBaseData(file).GetPointer()); } void tearDown() override { } bool runLoop() { player->Update(); mitk::NavigationData::Pointer nd0; mitk::NavigationData::Pointer nd1; for(unsigned int i=0; iGetNumberOfSnapshots(); ++i) { nd0 = player->GetOutput(0); nd1 = player->GetOutput(1); // test some values if(nd0.IsNull() || nd1.IsNull()) return false; //Compare data mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(i,0); mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(i,1); if (!(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector())) {return false;} if (!(ref1->GetOrientation().as_vector() == nd1->GetOrientation().as_vector())) {return false;} if (!(ref0->GetPosition().GetVnlVector() == nd0->GetPosition().GetVnlVector())) {return false;} if (!(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector())) {return false;} // Goto next Snapshot player->GoToNextSnapshot(); } return true; } void TestStandardWorkflow() { // Set NavigationDatas for player player->SetNavigationDataSet(NavigationDataSet); MITK_TEST_CONDITION(player->GetNumberOfSnapshots() == 3,"Testing if player reports correct number of Snapshots"); MITK_TEST_CONDITION(player->GetNumberOfIndexedOutputs() == 2,"Testing number of outputs"); //rest repeat player->SetRepeat(true); MITK_TEST_CONDITION(runLoop(),"Testing first run."); MITK_TEST_CONDITION(runLoop(),"Testing second run."); //repeat is on should work a second time // now test the go to snapshot function player->GoToSnapshot(2); mitk::NavigationData::Pointer nd1 = player->GetOutput(1); mitk::NavigationData::Pointer ref1 = NavigationDataSet->GetNavigationDataForIndex(2,1); MITK_TEST_CONDITION(ref1->GetPosition().GetVnlVector() == nd1->GetPosition().GetVnlVector(), "Testing GoToSnapshot() [1]"); //MITK_TEST_OUTPUT( << "Reference:" << ref1->GetPosition().GetVnlVector() << "\tObserved: " << nd1->GetPosition().GetVnlVector()); player->GoToSnapshot(0); mitk::NavigationData::Pointer nd0 = player->GetOutput(); mitk::NavigationData::Pointer ref0 = NavigationDataSet->GetNavigationDataForIndex(0,0); MITK_TEST_CONDITION(ref0->GetOrientation().as_vector() == nd0->GetOrientation().as_vector(), "Testing GoToSnapshot() [2]"); //MITK_TEST_OUTPUT( << "Reference" << ref0->GetPosition().GetVnlVector() << "\tObserved:" <GetOrientation().as_vector() ); } void TestRestartWithNewNavigationDataSet() { player->SetNavigationDataSet(NavigationDataSet); mitk::NavigationData::PositionType nd1 = player->GetOutput(0)->GetPosition(); player->SetNavigationDataSet(NavigationDataSet); mitk::NavigationData::PositionType nd2 = player->GetOutput(0)->GetPosition(); MITK_TEST_CONDITION(nd1 == nd2, "First output must be the same after setting same navigation data again."); // setting new NavigationDataSet with different tool count should result in an exception std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData.xml"); - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - MITK_TEST_FOR_EXCEPTION(mitk::IGTException, player->SetNavigationDataSet(reader->Read(file))); + mitk::NavigationDataSet::Pointer dataset = dynamic_cast (mitk::IOUtil::LoadBaseData(file).GetPointer()); + MITK_TEST_FOR_EXCEPTION(mitk::IGTException, player->SetNavigationDataSet(dataset)); } void TestGoToSnapshotException() { //testing GoToSnapShot for exception mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer2 = mitk::NavigationDataSequentialPlayer::New(); std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2Tools.xml"); - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - myTestPlayer2->SetNavigationDataSet(reader->Read(file)); + mitk::NavigationDataSet::Pointer dataset = dynamic_cast (mitk::IOUtil::LoadBaseData(file).GetPointer()); + myTestPlayer2->SetNavigationDataSet(dataset); bool exceptionThrown2=false; try { unsigned int invalidSnapshot = 1000; myTestPlayer2->GoToSnapshot(invalidSnapshot); } catch(mitk::IGTException) { exceptionThrown2=true; } MITK_TEST_CONDITION(exceptionThrown2, "Testing if exception is thrown when GoToSnapShot method is called with an index that doesn't exist."); } void TestDoubleUpdate() { //std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2Tools.xml"); //mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); //player->SetNavigationDataSet(reader->Read(file)); player->SetNavigationDataSet(NavigationDataSet); player->Update(); mitk::Quaternion nd1Orientation = player->GetOutput()->GetOrientation(); player->Update(); mitk::Quaternion nd2Orientation = player->GetOutput()->GetOrientation(); MITK_TEST_CONDITION(nd1Orientation.as_vector() == nd2Orientation.as_vector(), "Output must be the same no matter if Update() was called between."); MITK_TEST_CONDITION(player->GoToNextSnapshot(), "There must be a next snapshot available."); player->Update(); mitk::Quaternion nd3Orientation = player->GetOutput()->GetOrientation(); MITK_TEST_CONDITION(nd1Orientation.as_vector() != nd3Orientation.as_vector(), "Output must be different if GoToNextSnapshot() was called between."); } }; MITK_TEST_SUITE_REGISTRATION(mitkNavigationDataSequentialPlayer) \ No newline at end of file diff --git a/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterCSVTest.cpp b/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterCSVTest.cpp index fb86994dd8..bfb6c2c5fe 100644 --- a/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterCSVTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterCSVTest.cpp @@ -1,141 +1,133 @@ /*=================================================================== 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. ===================================================================*/ //testing headers //#include #include #include #include #include #include #include -#include #include -#include - #include #include #include #include #include //for exceptions #include "mitkIGTException.h" #include "mitkIGTIOException.h" class mitkNavigationDataSetReaderWriterCSVTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkNavigationDataSetReaderWriterCSVTestSuite); // MITK_TEST(TestCompareFunction); MITK_TEST(TestReadWrite); CPPUNIT_TEST_SUITE_END(); private: std::string pathRead; std::string pathWrite; std::string pathWrong; - mitk::NavigationDataReaderCSV::Pointer reader; - - mitk::NavigationDataReaderXML::Pointer xmlReader; mitk::NavigationDataSet::Pointer set; public: void setUp() override { pathRead = GetTestDataFilePath("IGT-Data/RecordedNavigationData.xml"); pathWrong = GetTestDataFilePath("IGT-Data/NavigationDataTestData.CSV"); pathWrite="C:\\test.csv"; - - reader = mitk::NavigationDataReaderCSV::New(); - xmlReader= mitk::NavigationDataReaderXML::New(); } void tearDown() override { } void TestReadWrite() { // Aim is to read an CSV into a pointset, write that CSV again, and compare the output - set = xmlReader->Read(pathRead); + set = dynamic_cast(mitk::IOUtil::LoadBaseData(pathRead).GetPointer() ); + CPPUNIT_ASSERT_MESSAGE("Testing whether something was read at all", set != nullptr); mitk::IOUtil::SaveBaseData(set, pathWrite); //FIXME: Commented out, because test fails under linux. binary comparison of files is probably not the wa to go // See Bug 17775 //CPPUNIT_ASSERT_MESSAGE( "Testing if read/write cycle creates identical files", CompareFiles(pathRead, pathWrite)); //remove(pathWrite.c_str()); } bool CompareFiles(std::string file) { - set = reader->Read(file); + set = dynamic_cast(mitk::IOUtil::LoadBaseData(file).GetPointer()); double sample[2][30] ={ {5134019.44, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5134019.44, 0, 1, 101.2300034, -62.63999939, -203.2400055, -0.3059000075, 0.5752000213, 0, 0.7585999966, 5134019.44, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {5134082.84, 5134073.64, 1, -172.6100006, 12.60999966, -299.4500122, -0.1588999927, 0.4370000064, 0, 0.8852000237, 5134082.84, 5134073.64, 1, 101.2300034, -62.63999939, -203.2400055, -0.3059000075, 0.5752000213, 0, 0.7585999966, 5134082.84, 5134073.64, 0, 0, 0, 0, 0, 0, 0, 0} }; bool returnValue = true; for(int line = 0 ; line < 2; line++) { for (int tool =0; tool < 3; tool ++) { mitk::NavigationData::Pointer testline = set->GetNavigationDataForIndex(line,tool) ; returnValue = returnValue && mitk::Equal( testline->GetIGTTimeStamp() , sample [line] [(tool*10)] ); returnValue = returnValue && mitk::Equal( testline->IsDataValid() , sample [line] [(tool*10)+1] ); mitk::NavigationData::PositionType pos = testline->GetPosition(); returnValue = returnValue && mitk::Equal( pos[0] , sample [line] [(tool*10)+2] ); returnValue = returnValue && mitk::Equal( pos[1] , sample [line] [(tool*10)+3] ); returnValue = returnValue && mitk::Equal( pos[2] , sample [line] [(tool*10)+4] ); mitk::NavigationData::OrientationType ori = testline->GetOrientation(); returnValue = returnValue && mitk::Equal( ori[0] , sample [line] [(tool*10)+5] ); returnValue = returnValue && mitk::Equal( ori[1] , sample [line] [(tool*10)+6] ); returnValue = returnValue && mitk::Equal( ori[2] , sample [line] [(tool*10)+7] ); returnValue = returnValue && mitk::Equal( ori[3] , sample [line] [(tool*10)+8] ); } return returnValue; } } void TestCompareFunction() { CPPUNIT_ASSERT_MESSAGE("Checking if csv-file reader is working properly", CompareFiles(pathRead)); //CPPUNIT_ASSERT_MESSAGE("Asserting that compare function for files works correctly - Negative Test", ! CompareFiles(pathWrong) ); } }; MITK_TEST_SUITE_REGISTRATION(mitkNavigationDataSetReaderWriterCSV) \ No newline at end of file diff --git a/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterXMLTest.cpp b/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterXMLTest.cpp index 093615c0be..0edae64b52 100644 --- a/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterXMLTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataSetReaderWriterXMLTest.cpp @@ -1,141 +1,136 @@ /*=================================================================== 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. ===================================================================*/ //testing headers //#include #include #include #include #include #include #include -#include #include #include #include #include #include #include //for exceptions #include "mitkIGTException.h" #include "mitkIGTIOException.h" class mitkNavigationDataSetReaderWriterXMLTestSuite : public mitk::TestFixture { CPPUNIT_TEST_SUITE(mitkNavigationDataSetReaderWriterXMLTestSuite); MITK_TEST(TestCompareFunction); MITK_TEST(TestReadWrite); MITK_TEST(TestSetXMLStringException); CPPUNIT_TEST_SUITE_END(); private: std::string pathRead; std::string pathWrite; std::string pathWrong; - mitk::NavigationDataReaderXML::Pointer reader; mitk::NavigationDataSet::Pointer set; public: void setUp() override { pathRead = GetTestDataFilePath("IGT-Data/RecordedNavigationData.xml"); pathWrite = pathRead; pathWrite.insert(pathWrite.end()-4,'2');;//Insert 2: IGT-Data/NavigationDataSet2.xml std::ifstream FileTest(pathWrite.c_str()); if(FileTest){ //remove file if it already exists. TODO: Löschen funktioniert nicht!!!! xxxxxxxxxxxxxxxx FileTest.close(); std::remove(pathWrite.c_str()); } pathWrong = GetTestDataFilePath("IGT-Data/NavigationDataTestData.xml"); - - reader = mitk::NavigationDataReaderXML::New(); } void tearDown() override { } void TestReadWrite() { // Aim is to read an xml into a pointset, write that xml again, and compare the output - set = reader->Read(pathRead); + set = dynamic_cast (mitk::IOUtil::LoadBaseData(pathRead).GetPointer()); mitk::IOUtil::SaveBaseData(set, pathWrite); //FIXME: Commented out, because test fails under linux. binary comparison of files is probably not the wa to go // See Bug 17775 //CPPUNIT_ASSERT_MESSAGE( "Testing if read/write cycle creates identical files", CompareFiles(pathRead, pathWrite)); remove(pathWrite.c_str()); } bool CompareFiles(std::string file1, std::string file2) { FILE* f1 = fopen (file1.c_str() , "r"); FILE* f2 = fopen (file2.c_str() , "r"); char buf1[10000]; char buf2[10000]; do { size_t r1 = fread(buf1, 1, 10000, f1); size_t r2 = fread(buf2, 1, 10000, f2); if (r1 != r2 || memcmp(buf1, buf2, r1)) { fclose(f1); fclose(f2); return false; // Files are not equal } } while (!feof(f1) && !feof(f2)); bool returnValue = feof(f1) && feof(f2); fclose(f1); fclose(f2); return returnValue; } void TestSetXMLStringException() { bool exceptionThrown3=false; try { std::string file = GetTestDataFilePath("IGT-Data/InvalidVersionNavigationDataTestData.xml"); - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - reader->Read(file); + mitk::NavigationDataSet::Pointer dataset = dynamic_cast (mitk::IOUtil::LoadBaseData(file).GetPointer()); } catch(mitk::IGTIOException) { exceptionThrown3=true; } MITK_TEST_CONDITION(exceptionThrown3, "Reading an invalid XML string and expecting a exception"); } void TestCompareFunction() { CPPUNIT_ASSERT_MESSAGE("Asserting that compare function for files works correctly - Positive Test", CompareFiles(pathRead, pathRead)); CPPUNIT_ASSERT_MESSAGE("Asserting that compare function for files works correctly - Negative Test", ! CompareFiles(pathRead, pathWrong) ); } }; MITK_TEST_SUITE_REGISTRATION(mitkNavigationDataSetReaderWriterXML) \ No newline at end of file diff --git a/Modules/IGT/Testing/mitkNavigationDataToIGTLMessageFilterTest.cpp b/Modules/IGT/Testing/mitkNavigationDataToIGTLMessageFilterTest.cpp index cb37e65683..e87b3ce1e8 100644 --- a/Modules/IGT/Testing/mitkNavigationDataToIGTLMessageFilterTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataToIGTLMessageFilterTest.cpp @@ -1,261 +1,260 @@ /*=================================================================== 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 "mitkNavigationDataToIGTLMessageFilter.h" #include "mitkNavigationDataSequentialPlayer.h" -#include "mitkNavigationDataReaderXML.h" #include #include #include #include #include #include #include /** * Simple test for the class "NavigationDataToIGTLMessageFilter". * * argc and argv are the command line parameters which were passed to * the ADD_TEST command in the CMakeLists.txt file. For the automatic * tests, argv is either empty for the simple tests or contains the filename * of a test image for the image tests (see CMakeLists.txt). */ mitk::NavigationDataToIGTLMessageFilter::Pointer m_NavigationDataToIGTLMessageFilter; static void Setup() { m_NavigationDataToIGTLMessageFilter = mitk::NavigationDataToIGTLMessageFilter::New(); } static void SetInputs() { //Build up test data mitk::NavigationData::Pointer nd0 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd3 = mitk::NavigationData::New(); mitk::NavigationData::PositionType point0; point0[0] = 1.0; point0[1] = 2.0; point0[2] = 3.0; mitk::NavigationData::OrientationType orientation0; orientation0.put(0, 1.0); orientation0.put(1, 0.0); orientation0.put(2, 0.0); orientation0.put(3, 0.0); nd0->SetPosition(point0); nd0->SetOrientation(orientation0); nd0->SetDataValid(true); mitk::NavigationData::PositionType point1; point1[0] = 4.0; point1[1] = 5.0; point1[2] = 6.0; mitk::NavigationData::OrientationType orientation1; orientation1.put(0, 21.0); orientation1.put(1, 22.0); orientation1.put(2, 23.0); orientation1.put(3, 24.0); nd1->SetPosition(point1); nd1->SetOrientation(orientation1); nd1->SetDataValid(true); mitk::NavigationData::PositionType point2; point2[0] = 7.0; point2[1] = 8.0; point2[2] = 9.0; mitk::NavigationData::OrientationType orientation2; orientation2.put(0, 31.0); orientation2.put(1, 32.0); orientation2.put(2, 33.0); orientation2.put(3, 34.0); nd2->SetPosition(point2); nd2->SetOrientation(orientation2); nd2->SetDataValid(true); mitk::NavigationData::PositionType point3; point3[0] = 10.0; point3[1] = 11.0; point3[2] = 12.0; mitk::NavigationData::OrientationType orientation3; orientation3.put(0, 0.0); orientation3.put(1, 0.0); orientation3.put(2, 0.0); orientation3.put(3, 1.0); nd3->SetPosition(point3); nd3->SetOrientation(orientation3); nd3->SetDataValid(true); m_NavigationDataToIGTLMessageFilter->SetInput(0, nd0); m_NavigationDataToIGTLMessageFilter->SetInput(1, nd1); m_NavigationDataToIGTLMessageFilter->SetInput(2, nd2); m_NavigationDataToIGTLMessageFilter->SetInput(3, nd3); } static void TestModeQTransMsg() { Setup(); SetInputs(); m_NavigationDataToIGTLMessageFilter->SetOperationMode( mitk::NavigationDataToIGTLMessageFilter::ModeSendQTransMsg); //Process mitk::IGTLMessage::Pointer msg0 = m_NavigationDataToIGTLMessageFilter->GetOutput(); mitk::IGTLMessage::Pointer msg1 = m_NavigationDataToIGTLMessageFilter->GetOutput(1); mitk::IGTLMessage::Pointer msg2 = m_NavigationDataToIGTLMessageFilter->GetOutput(2); mitk::IGTLMessage::Pointer msg3 = m_NavigationDataToIGTLMessageFilter->GetOutput(3); msg0->Update(); igtl::PositionMessage::Pointer igtlMsg0 = dynamic_cast(msg0->GetMessage().GetPointer()); igtl::PositionMessage::Pointer igtlMsg3 = dynamic_cast(msg3->GetMessage().GetPointer()); MITK_TEST_OUTPUT(<< "Testing the converted OpenIGTLink messages:"); MITK_TEST_CONDITION(igtlMsg0.IsNotNull(), "Message0 is not null?"); MITK_TEST_CONDITION(igtlMsg3.IsNotNull(), "Message3 is not null?"); //Convert the data from the igtl message back to mitk types float pos0_[3]; float orientation0_[4]; igtlMsg0->GetPosition(pos0_); igtlMsg0->GetQuaternion(orientation0_); mitk::NavigationData::PositionType pos0; pos0[0] = pos0_[0]; pos0[1] = pos0_[1]; pos0[2] = pos0_[2]; mitk::NavigationData::OrientationType orientation0; orientation0[0] = orientation0_[0]; orientation0[1] = orientation0_[1]; orientation0[2] = orientation0_[2]; orientation0[3] = orientation0_[3]; float pos3_[3]; float orientation3_[4]; igtlMsg3->GetPosition(pos3_); igtlMsg3->GetQuaternion(orientation3_); mitk::NavigationData::PositionType pos3; pos3[0] = pos3_[0]; pos3[1] = pos3_[1]; pos3[2] = pos3_[2]; mitk::NavigationData::OrientationType orientation3; orientation3[0] = orientation3_[0]; orientation3[1] = orientation3_[1]; orientation3[2] = orientation3_[2]; orientation3[3] = orientation3_[3]; MITK_TEST_OUTPUT(<< "Testing the conversion of navigation data object to QTrans OpenIGTLink messages:"); MITK_TEST_CONDITION(mitk::Equal(pos0, m_NavigationDataToIGTLMessageFilter->GetInput(0)->GetPosition()), "Position0 correct?"); MITK_TEST_CONDITION(mitk::Equal(pos3, m_NavigationDataToIGTLMessageFilter->GetInput(3)->GetPosition()), "Position3 correct?"); MITK_TEST_CONDITION(mitk::Equal(orientation0, m_NavigationDataToIGTLMessageFilter->GetInput(0)->GetOrientation()), "Orientation0 correct?"); MITK_TEST_CONDITION(mitk::Equal(orientation3, m_NavigationDataToIGTLMessageFilter->GetInput(3)->GetOrientation()), "Orientation3 correct?"); } static void TestModeTransMsg() { Setup(); SetInputs(); m_NavigationDataToIGTLMessageFilter->SetOperationMode( mitk::NavigationDataToIGTLMessageFilter::ModeSendTransMsg); //Process mitk::IGTLMessage::Pointer msg0 = m_NavigationDataToIGTLMessageFilter->GetOutput(); mitk::IGTLMessage::Pointer msg1 = m_NavigationDataToIGTLMessageFilter->GetOutput(1); mitk::IGTLMessage::Pointer msg2 = m_NavigationDataToIGTLMessageFilter->GetOutput(2); mitk::IGTLMessage::Pointer msg3 = m_NavigationDataToIGTLMessageFilter->GetOutput(3); msg0->Update(); igtl::TransformMessage::Pointer igtlMsg0 = dynamic_cast(msg0->GetMessage().GetPointer()); igtl::TransformMessage::Pointer igtlMsg3 = dynamic_cast(msg3->GetMessage().GetPointer()); MITK_TEST_OUTPUT(<< "Testing the converted OpenIGTLink messages:"); MITK_TEST_CONDITION(igtlMsg0.IsNotNull(), "Message0 is not null?"); MITK_TEST_CONDITION(igtlMsg3.IsNotNull(), "Message3 is not null?"); //Convert the data from the igtl message back to mitk types mitk::AffineTransform3D::Pointer affineTransformation0 = mitk::AffineTransform3D::New(); igtl::Matrix4x4 transformation0_; mitk::Matrix3D transformation0; mitk::Vector3D offset0; igtlMsg0->GetMatrix(transformation0_); for ( unsigned int r = 0; r < 3; r++ ) { for ( unsigned int c = 0; c < 3; c++ ) { transformation0.GetVnlMatrix().set( r , c , transformation0_[r][c] ); } offset0.SetElement(r, transformation0_[r][3]); } //convert the igtl matrix here and set it in the affine transformation affineTransformation0->SetMatrix(transformation0); affineTransformation0->SetOffset(offset0); //the easiest way to convert the affine transform to position and quaternion mitk::NavigationData::Pointer nd0 = mitk::NavigationData::New(affineTransformation0, true); mitk::AffineTransform3D::Pointer affineTransformation3 = mitk::AffineTransform3D::New(); igtl::Matrix4x4 transformation3_; mitk::Matrix3D transformation3; mitk::Vector3D offset3; igtlMsg3->GetMatrix(transformation3_); for ( unsigned int r = 0; r < 3; r++ ) { for ( unsigned int c = 0; c < 3; c++ ) { transformation3.GetVnlMatrix().set( r , c , transformation3_[r][c] ); } offset3.SetElement(r, transformation3_[r][3]); } //convert the igtl matrix here and set it in the affine transformation affineTransformation3->SetMatrix(transformation3); affineTransformation3->SetOffset(offset3); //the easiest way to convert the affine transform to position and quaternion mitk::NavigationData::Pointer nd3 = mitk::NavigationData::New(affineTransformation3, true); MITK_TEST_OUTPUT(<< "Testing the conversion of navigation data object to Trans OpenIGTLink messages:"); MITK_TEST_CONDITION(mitk::Equal(nd0->GetPosition(), m_NavigationDataToIGTLMessageFilter->GetInput(0)->GetPosition()), "Position0 correct?"); MITK_TEST_CONDITION(mitk::Equal(nd3->GetPosition(), m_NavigationDataToIGTLMessageFilter->GetInput(3)->GetPosition()), "Position3 correct?"); MITK_TEST_CONDITION(mitk::Equal(nd0->GetOrientation(), m_NavigationDataToIGTLMessageFilter->GetInput(0)->GetOrientation()), "Orientation0 correct?"); MITK_TEST_CONDITION(mitk::Equal(nd3->GetOrientation(), m_NavigationDataToIGTLMessageFilter->GetInput(3)->GetOrientation()), "Orientation3 correct?"); } static void NavigationDataToIGTLMessageFilterContructor_DefaultCall_IsNotEmpty() { Setup(); MITK_TEST_CONDITION_REQUIRED(m_NavigationDataToIGTLMessageFilter.IsNotNull(),"Testing instantiation"); //I think this test is meaningless, because it will never ever fail. I keep it for know just to be save. } int mitkNavigationDataToIGTLMessageFilterTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("NavigationDataToIGTLMessageFilter"); NavigationDataToIGTLMessageFilterContructor_DefaultCall_IsNotEmpty(); TestModeQTransMsg(); TestModeTransMsg(); MITK_TEST_END(); } diff --git a/Modules/IGT/Testing/mitkNavigationDataToPointSetFilterTest.cpp b/Modules/IGT/Testing/mitkNavigationDataToPointSetFilterTest.cpp index 8bb4d8d7a8..3985dcf531 100644 --- a/Modules/IGT/Testing/mitkNavigationDataToPointSetFilterTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataToPointSetFilterTest.cpp @@ -1,240 +1,239 @@ /*=================================================================== 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 "mitkNavigationDataToPointSetFilter.h" #include "mitkNavigationDataSequentialPlayer.h" -#include "mitkNavigationDataReaderXML.h" #include #include +#include #include /** * Simple example for a test for the (non-existent) class "NavigationDataToPointSetFilter". * * argc and argv are the command line parameters which were passed to * the ADD_TEST command in the CMakeLists.txt file. For the automatic * tests, argv is either empty for the simple tests or contains the filename * of a test image for the image tests (see CMakeLists.txt). */ mitk::NavigationDataToPointSetFilter::Pointer m_NavigationDataToPointSetFilter; static void Setup() { m_NavigationDataToPointSetFilter = mitk::NavigationDataToPointSetFilter::New(); } static void TestMode3D() { Setup(); m_NavigationDataToPointSetFilter->SetOperationMode(mitk::NavigationDataToPointSetFilter::Mode3D); //Build up test data mitk::NavigationData::Pointer nd0 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd1 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd3 = mitk::NavigationData::New(); mitk::NavigationData::PositionType point0; point0[0] = 1.0; point0[1] = 2.0; point0[2] = 3.0; nd0->SetPosition(point0); nd0->SetDataValid(true); mitk::NavigationData::PositionType point1; point1[0] = 4.0; point1[1] = 5.0; point1[2] = 6.0; nd1->SetPosition(point1); nd1->SetDataValid(true); mitk::NavigationData::PositionType point2; point2[0] = 7.0; point2[1] = 8.0; point2[2] = 9.0; nd2->SetPosition(point2); nd2->SetDataValid(true); mitk::NavigationData::PositionType point3; point3[0] = 10.0; point3[1] = 11.0; point3[2] = 12.0; nd3->SetPosition(point3); nd3->SetDataValid(true); m_NavigationDataToPointSetFilter->SetInput(0, nd0); m_NavigationDataToPointSetFilter->SetInput(1, nd1); m_NavigationDataToPointSetFilter->SetInput(2, nd2); m_NavigationDataToPointSetFilter->SetInput(3, nd3); //Process mitk::PointSet::Pointer pointSet0 = m_NavigationDataToPointSetFilter->GetOutput(); mitk::PointSet::Pointer pointSet1 = m_NavigationDataToPointSetFilter->GetOutput(1); mitk::PointSet::Pointer pointSet2 = m_NavigationDataToPointSetFilter->GetOutput(2); mitk::PointSet::Pointer pointSet3 = m_NavigationDataToPointSetFilter->GetOutput(3); pointSet0->Update(); MITK_TEST_OUTPUT(<< "Testing the conversion of navigation data object to PointSets in Mode 3D:"); MITK_TEST_CONDITION(mitk::Equal(pointSet0->GetPoint(0), point0), "Pointset 0 correct?"); MITK_TEST_CONDITION(mitk::Equal(pointSet1->GetPoint(0), point1), "Pointset 1 correct?"); MITK_TEST_CONDITION(mitk::Equal(pointSet2->GetPoint(0), point2), "Pointset 2 correct?"); MITK_TEST_CONDITION(mitk::Equal(pointSet3->GetPoint(0), point3), "Pointset 3 correct?"); } static void TestMode4D() { Setup(); m_NavigationDataToPointSetFilter->SetOperationMode(mitk::NavigationDataToPointSetFilter::Mode4D); m_NavigationDataToPointSetFilter->SetRingBufferSize(2); //Build up test data mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd2 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd3 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd4 = mitk::NavigationData::New(); mitk::NavigationData::PositionType point; point[0] = 1.0; point[1] = 2.0; point[2] = 3.0; nd->SetPosition(point); point[0] = 4.0; point[1] = 5.0; point[2] = 6.0; nd2->SetPosition(point); point[0] = 7.0; point[1] = 8.0; point[2] = 9.0; nd3->SetPosition(point); point[0] = 10.0; point[1] = 11.0; point[2] = 12.0; nd4->SetPosition(point); m_NavigationDataToPointSetFilter->SetInput(0, nd); m_NavigationDataToPointSetFilter->SetInput(1, nd2); mitk::PointSet::Pointer pointSet = m_NavigationDataToPointSetFilter->GetOutput(); pointSet->Update(); MITK_TEST_CONDITION( pointSet->GetPoint(0,0)[0] == 1.0 && pointSet->GetPoint(0,0)[1] == 2.0 && pointSet->GetPoint(0,0)[2] == 3.0 && pointSet->GetPoint(1,0)[0] == 4.0 && pointSet->GetPoint(1,0)[1] == 5.0 && pointSet->GetPoint(1,0)[2] == 6.0 , "Testing the conversion of navigation data object to one point set in Mode 4D in first timestep" ); m_NavigationDataToPointSetFilter->SetInput(0, nd3); m_NavigationDataToPointSetFilter->SetInput(1, nd4); m_NavigationDataToPointSetFilter->Update(); pointSet = m_NavigationDataToPointSetFilter->GetOutput(); MITK_TEST_CONDITION( pointSet->GetPoint(0,0)[0] == 1.0 && pointSet->GetPoint(0,0)[1] == 2.0 && pointSet->GetPoint(0,0)[2] == 3.0 && pointSet->GetPoint(1,0)[0] == 4.0 && pointSet->GetPoint(1,0)[1] == 5.0 && pointSet->GetPoint(1,0)[2] == 6.0 && pointSet->GetPoint(0,1)[0] == 7.0 && pointSet->GetPoint(0,1)[1] == 8.0 && pointSet->GetPoint(0,1)[2] == 9.0 && pointSet->GetPoint(1,1)[0] == 10.0 && pointSet->GetPoint(1,1)[1] == 11.0 && pointSet->GetPoint(1,1)[2] == 12.0 , "Testing the conversion of navigation data object to one point set in Mode 4D in second timestep" ); m_NavigationDataToPointSetFilter->SetInput(0, nd3); m_NavigationDataToPointSetFilter->SetInput(1, nd4); pointSet = m_NavigationDataToPointSetFilter->GetOutput(); pointSet->Update(); MITK_TEST_CONDITION( pointSet->GetPoint(0,0)[0] == 7.0 && pointSet->GetPoint(0,0)[1] == 8.0 && pointSet->GetPoint(0,0)[2] == 9.0 && pointSet->GetPoint(1,0)[0] == 10.0 && pointSet->GetPoint(1,0)[1] == 11.0 && pointSet->GetPoint(1,0)[2] == 12.0 && pointSet->GetPoint(0,1)[0] == 7.0 && pointSet->GetPoint(0,1)[1] == 8.0 && pointSet->GetPoint(0,1)[2] == 9.0 && pointSet->GetPoint(1,1)[0] == 10.0 && pointSet->GetPoint(1,1)[1] == 11.0 && pointSet->GetPoint(1,1)[2] == 12.0 , "Testing the correct ring buffer behavior" ); } static void TestMode3DMean() { Setup(); m_NavigationDataToPointSetFilter->SetOperationMode(mitk::NavigationDataToPointSetFilter::Mode3DMean); int numberForMean = 5; m_NavigationDataToPointSetFilter->SetNumberForMean(numberForMean); MITK_TEST_CONDITION(mitk::Equal(m_NavigationDataToPointSetFilter->GetNumberForMean(), numberForMean), "Testing get/set for numberForMean"); mitk::NavigationDataSequentialPlayer::Pointer player = mitk::NavigationDataSequentialPlayer::New(); std::string file(MITK_IGT_DATA_DIR); file.append("/NavigationDataTestData_2Tools.xml"); - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - - player->SetNavigationDataSet( reader->Read(file) ); + mitk::NavigationDataSet::Pointer dataset = dynamic_cast (mitk::IOUtil::LoadBaseData(file).GetPointer()); + player->SetNavigationDataSet(dataset); for (unsigned int i = 0; i< player->GetNumberOfOutputs(); i++) { m_NavigationDataToPointSetFilter->SetInput(i, player->GetOutput(i)); } mitk::PointSet::Pointer pointSet0 = m_NavigationDataToPointSetFilter->GetOutput(); mitk::PointSet::Pointer pointSet1 = m_NavigationDataToPointSetFilter->GetOutput(1); m_NavigationDataToPointSetFilter->Update(); MITK_TEST_CONDITION(pointSet0->GetPoint(0)[0]==3.0 && pointSet0->GetPoint(0)[1]==2.0 && pointSet0->GetPoint(0)[2]==5.0, "Testing the average of first input"); MITK_TEST_CONDITION(pointSet1->GetPoint(0)[0]==30.0 && pointSet1->GetPoint(0)[1]==20.0 && pointSet1->GetPoint(0)[2]==50.0, "Testing the average of second input"); } static void NavigationDataToPointSetFilterContructor_DefaultCall_IsNotEmpty() { Setup(); MITK_TEST_CONDITION_REQUIRED(m_NavigationDataToPointSetFilter.IsNotNull(),"Testing instantiation"); //I think this test is meaningless, because it will never ever fail. I keep it for know just to be save. } static void NavigationDataToPointSetFilterSetInput_SimplePoint_EqualsGroundTruth() { Setup(); mitk::NavigationData::Pointer nd_in = mitk::NavigationData::New(); const mitk::NavigationData* nd_out = mitk::NavigationData::New(); mitk::NavigationData::PositionType point; point[0] = 1.0; point[1] = 2.0; point[2] = 3.0; nd_in->SetPosition(point); m_NavigationDataToPointSetFilter->SetInput(nd_in); nd_out = m_NavigationDataToPointSetFilter->GetInput(); MITK_TEST_CONDITION( nd_out->GetPosition() == nd_in->GetPosition(), "Testing get/set input" ); } int mitkNavigationDataToPointSetFilterTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("NavigationDataToPointSetFilter"); NavigationDataToPointSetFilterContructor_DefaultCall_IsNotEmpty(); NavigationDataToPointSetFilterSetInput_SimplePoint_EqualsGroundTruth(); TestMode3D(); TestMode4D(); // TestMode3DMean(); //infinite loop in debug mode, see bug 17763 MITK_TEST_END(); } diff --git a/Modules/IGTBase/autoload/IO/mitkIGTBaseActivator.cpp b/Modules/IGTBase/autoload/IO/mitkIGTBaseActivator.cpp index 62bc4ec788..282880795b 100644 --- a/Modules/IGTBase/autoload/IO/mitkIGTBaseActivator.cpp +++ b/Modules/IGTBase/autoload/IO/mitkIGTBaseActivator.cpp @@ -1,37 +1,41 @@ /*=================================================================== 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 "mitkIGTBaseActivator.h" -#include "mitkNavigationDataSetWriterXML.h" -#include "mitkNavigationDataSetWriterCSV.h" - +#include +#include +#include +#include namespace mitk { void IOExtActivator::Load(us::ModuleContext*) { m_NavigationDataSetWriterXML.reset(new NavigationDataSetWriterXML()); m_NavigationDataSetWriterCSV.reset(new NavigationDataSetWriterCSV()); + m_NavigationDataReaderCSV.reset(new NavigationDataReaderCSV()); + m_NavigationDataReaderXML.reset(new NavigationDataReaderXML()); + } void IOExtActivator::Unload(us::ModuleContext*) { } } US_EXPORT_MODULE_ACTIVATOR(mitk::IOExtActivator) diff --git a/Modules/IGTBase/autoload/IO/mitkIGTBaseActivator.h b/Modules/IGTBase/autoload/IO/mitkIGTBaseActivator.h index 9a34b3b751..23dce5863e 100644 --- a/Modules/IGTBase/autoload/IO/mitkIGTBaseActivator.h +++ b/Modules/IGTBase/autoload/IO/mitkIGTBaseActivator.h @@ -1,45 +1,46 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKIGTBASEACTIVATOR_H #define MITKIGTBASEACTIVATOR_H #include #include namespace mitk { struct IFileReader; struct IFileWriter; class IOExtActivator : public us::ModuleActivator { public: void Load(us::ModuleContext*context) override; void Unload(us::ModuleContext* context) override; private: std::unique_ptr m_NavigationDataSetWriterXML; std::unique_ptr m_NavigationDataSetWriterCSV; - + std::unique_ptr m_NavigationDataReaderXML; + std::unique_ptr m_NavigationDataReaderCSV; }; } #endif // MITKIGTBASEACTIVATOR_H diff --git a/Modules/IGT/IO/mitkNavigationDataReaderCSV.cpp b/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderCSV.cpp similarity index 82% rename from Modules/IGT/IO/mitkNavigationDataReaderCSV.cpp rename to Modules/IGTBase/autoload/IO/mitkNavigationDataReaderCSV.cpp index afd0c8e67c..7f7caba6a3 100644 --- a/Modules/IGT/IO/mitkNavigationDataReaderCSV.cpp +++ b/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderCSV.cpp @@ -1,164 +1,180 @@ /*=================================================================== 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. ===================================================================*/ +// MITK #include "mitkNavigationDataReaderCSV.h" +#include + +// STL #include -mitk::NavigationDataReaderCSV::NavigationDataReaderCSV() + +mitk::NavigationDataReaderCSV::NavigationDataReaderCSV() : AbstractFileReader( + mitk::IGTMimeTypes::NAVIGATIONDATASETCSV_MIMETYPE(), + "MITK NavigationData Reader (CSV)") { + RegisterService(); +} +mitk::NavigationDataReaderCSV::NavigationDataReaderCSV(const mitk::NavigationDataReaderCSV& other) : AbstractFileReader(other) +{ } mitk::NavigationDataReaderCSV::~NavigationDataReaderCSV() { +} + +mitk::NavigationDataReaderCSV* mitk::NavigationDataReaderCSV::Clone() const +{ + return new NavigationDataReaderCSV(*this); +} + +std::vector> mitk::NavigationDataReaderCSV::Read() +{ + std::vector fileContent = GetFileContentLineByLine(GetInputLocation()); + int NumOfTools = getNumberOfToolsInLine(fileContent[0]); + + mitk::NavigationDataSet::Pointer returnValue = mitk::NavigationDataSet::New(NumOfTools); + std::vector result; + result.push_back(returnValue.GetPointer()); + + // start from line 1 to leave out header + for (int i = 1; iAddNavigationDatas(parseLine(fileContent[i], NumOfTools)); + } + return result; } + int mitk::NavigationDataReaderCSV::getNumberOfToolsInLine(std::string line) { std::vector tokens=splitLine(line); int size = tokens.size(); int NumOfTools = (size-1)/8; if ( (size-1)%8 != 0 ) { MITK_ERROR("mitkNavigationDataReader") << "Illegal csv-file! Unexpected number of columns found! Assuming " << NumOfTools << " tools!"; } return NumOfTools ; } std::vector mitk::NavigationDataReaderCSV::splitLine(std::string line) { std::vector elems; std::stringstream ss(line); std::string item; while (std::getline(ss, item, ';')) { elems.push_back(item); } return elems; } mitk::NavigationData::Pointer mitk::NavigationDataReaderCSV::CreateNd(std::string timestamp, std::string valid, std::string X, std::string Y, std::string Z, std::string QX, std::string QY, std::string QZ, std::string QR) { mitk::NavigationData::Pointer result= mitk::NavigationData::New(); mitk::Point3D position; mitk::Quaternion orientation; bool isValid = false; double time; time = StringToDouble(timestamp); if (valid == "1") isValid = true; else isValid = false; position[0] = StringToDouble(X); position[1] = StringToDouble(Y); position[2] = StringToDouble(Z); orientation[0] = StringToDouble(QX); orientation[1] = StringToDouble(QY); orientation[2] = StringToDouble(QZ); orientation[3] = StringToDouble(QR); result->SetIGTTimeStamp(time); result->SetDataValid(isValid); result->SetPosition(position); result->SetOrientation(orientation); return result; } double mitk::NavigationDataReaderCSV::StringToDouble( const std::string& s ) { std::istringstream i(s); double x; if (!(i >> x)) return 0; return x; } std::vector mitk::NavigationDataReaderCSV::parseLine(std::string line, int NumOfTools) { std::vector parts = splitLine(line); std::vector result; for (int n = 0; n < NumOfTools; n++) { mitk::NavigationData::Pointer nd; int offset = n * 8; nd = CreateNd(parts[0], parts[offset + 1], parts[offset + 2], parts[offset + 3], parts[offset + 4], parts[offset + 5], parts[offset + 6], parts[offset + 7], parts[offset + 8]); result.push_back(nd); } return result; } -mitk::NavigationDataSet::Pointer mitk::NavigationDataReaderCSV::Read(std::string fileName) -{ - std::vector fileContent = GetFileContentLineByLine(fileName); - int NumOfTools = getNumberOfToolsInLine(fileContent[0]); - - mitk::NavigationDataSet::Pointer returnValue = mitk::NavigationDataSet::New(NumOfTools); - - // start from line 1 to leave out header - for (int i = 1; iAddNavigationDatas( parseLine( fileContent[i], NumOfTools) ); - } - - - return returnValue; -} - - std::vector mitk::NavigationDataReaderCSV::GetFileContentLineByLine(std::string filename) { std::vector readData = std::vector(); //save old locale char * oldLocale; oldLocale = setlocale( LC_ALL, nullptr ); //define own locale std::locale C("C"); setlocale( LC_ALL, "C" ); //read file std::ifstream file; file.open(filename.c_str(), std::ios::in); if (file.good()) { //read out file file.seekg(0L, std::ios::beg); // move to begin of file while (! file.eof()) { std::string buffer; std::getline(file,buffer); // read out file line by line if (buffer.size() > 0) readData.push_back(buffer); } } file.close(); //switch back to old locale setlocale( LC_ALL, oldLocale ); return readData; } diff --git a/Modules/IGT/IO/mitkNavigationDataReaderCSV.h b/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderCSV.h similarity index 85% rename from Modules/IGT/IO/mitkNavigationDataReaderCSV.h rename to Modules/IGTBase/autoload/IO/mitkNavigationDataReaderCSV.h index f709981bf5..06e02b54b1 100644 --- a/Modules/IGT/IO/mitkNavigationDataReaderCSV.h +++ b/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderCSV.h @@ -1,78 +1,82 @@ /*=================================================================== 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. ===================================================================*/ - #ifndef MITKNavigationDataReaderCSV_H_HEADER_INCLUDED_ #define MITKNavigationDataReaderCSV_H_HEADER_INCLUDED_ -#include "mitkNavigationDataReaderInterface.h" +#include +#include namespace mitk { /** This class reads csv logged navigation datas from the hard disc and returns * the navigation data set. * * Caution: at the moment only one navigation data is supported which means that only * the data of the first navigation tool in the file is read! */ - class MITKIGT_EXPORT NavigationDataReaderCSV : public NavigationDataReaderInterface + class NavigationDataReaderCSV : public AbstractFileReader { public: - mitkClassMacro(NavigationDataReaderCSV, NavigationDataReaderInterface); - itkNewMacro(Self); + NavigationDataReaderCSV(); + virtual ~NavigationDataReaderCSV(); /** @return Returns the NavigationDataSet of the first tool in the given file. * Returns an empty NavigationDataSet if the file could not be read. */ - virtual mitk::NavigationDataSet::Pointer Read(std::string fileName) override; + using AbstractFileReader::Read; + virtual std::vector> Read() override; protected: - NavigationDataReaderCSV(); - virtual ~NavigationDataReaderCSV(); /** * /brief Creates a NavigationData Pointer based on the given Input. */ mitk::NavigationData::Pointer CreateNd(std::string timestamp, std::string valid, std::string X, std::string Y, std::string Z, std::string QX, std::string QY, std::string QZ, std::string QR); /** * /brief Presents File Content line by line */ std::vector GetFileContentLineByLine(std::string filename); /** * /brief Calculates the Number of Tools based on the number of colums per line. */ int getNumberOfToolsInLine(std::string line); /** * /brief Converts string to double returns zero if failing */ std::vector parseLine(std::string line, int NumOfTools); /** * /brief Converts string to double returns zero if failing */ double StringToDouble( const std::string& s ); /** * /brief Split line in elemens based on a given delim */ std::vector splitLine(std::string line); + + NavigationDataReaderCSV(const NavigationDataReaderCSV& other); + + virtual mitk::NavigationDataReaderCSV* Clone() const override; + }; } #endif // MITKNavigationDataReaderCSV_H_HEADER_INCLUDED_ diff --git a/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderXML.cpp b/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderXML.cpp index 9b5d44534b..53022071f1 100644 --- a/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderXML.cpp +++ b/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderXML.cpp @@ -1,373 +1,383 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkNavigationDataReaderXML.h" #include // Third Party #include #include #include mitk::NavigationDataReaderXML::NavigationDataReaderXML() : AbstractFileReader( mitk::IGTMimeTypes::NAVIGATIONDATASETXML_MIMETYPE(), "MITK NavigationData Reader (XML)") { RegisterService(); } mitk::NavigationDataReaderXML::~NavigationDataReaderXML() { } +mitk::NavigationDataReaderXML::NavigationDataReaderXML(const mitk::NavigationDataReaderXML& other) : AbstractFileReader(other) +{ +} + +mitk::NavigationDataReaderXML* mitk::NavigationDataReaderXML::Clone() const +{ + return new NavigationDataReaderXML(*this); +} + + std::vector> mitk::NavigationDataReaderXML::Read() { mitk::NavigationDataSet::Pointer dataset; std::istream* in = GetInputStream(); if (in == nullptr) { dataset = Read(GetInputLocation()); } else { dataset = Read(in); } std::vector result; mitk::BaseData::Pointer base = dataset.GetPointer(); result.push_back(base); return result; } mitk::NavigationDataSet::Pointer mitk::NavigationDataReaderXML::Read(std::string fileName) { //save old locale char * oldLocale; oldLocale = setlocale( LC_ALL, nullptr ); //define own locale std::locale C("C"); setlocale( LC_ALL, "C" ); m_FileName = fileName; TiXmlDocument document; if ( !document.LoadFile(fileName)) { mitkThrowException(mitk::IGTIOException) << "File '"<QueryIntAttribute("Ver", &m_FileVersion) != TIXML_SUCCESS) { if (m_DataElem->QueryIntAttribute("version", &m_FileVersion) != TIXML_SUCCESS) { mitkThrowException(mitk::IGTIOException) << "Version not specified in XML file."; } } if (m_FileVersion != 1) { mitkThrowException(mitk::IGTIOException) << "File format version "<QueryIntAttribute("ToolCount", &m_NumberOfOutputs); mitk::NavigationDataSet::Pointer navigationDataSet = this->ReadNavigationDataSet(); //switch back to old locale setlocale( LC_ALL, oldLocale ); return navigationDataSet; } mitk::NavigationDataSet::Pointer mitk::NavigationDataReaderXML::Read(std::istream* stream) { //save old locale char * oldLocale; oldLocale = setlocale( LC_ALL, nullptr ); //define own locale std::locale C("C"); setlocale( LC_ALL, "C" ); // first get the file version m_FileVersion = this->GetFileVersion(stream); // check if we have a valid version: m_FileVersion has to be always bigger than 1 for playing if (m_FileVersion < 1) { StreamInvalid("Playing not possible. Invalid file version!"); return nullptr; } m_NumberOfOutputs = this->GetNumberOfNavigationDatas(stream); if (m_NumberOfOutputs == 0) { return nullptr; } mitk::NavigationDataSet::Pointer dataSet = this->ReadNavigationDataSet(); //switch back to old locale setlocale( LC_ALL, oldLocale ); return dataSet; } mitk::NavigationDataSet::Pointer mitk::NavigationDataReaderXML::ReadNavigationDataSet() { mitk::NavigationDataSet::Pointer navigationDataSet = mitk::NavigationDataSet::New(m_NumberOfOutputs); mitk::NavigationData::Pointer curNavigationData; do { std::vector navDatas(m_NumberOfOutputs); for (unsigned int n = 0; n < m_NumberOfOutputs; ++n) { curNavigationData = this->ReadVersion1(); if (curNavigationData.IsNull()) { if (n != 0) { MITK_WARN("mitkNavigationDataReaderXML") << "Different number of NavigationData objects for different tools. Ignoring last ones."; } break; } navDatas.at(n) = curNavigationData; } if (curNavigationData.IsNotNull()) { navigationDataSet->AddNavigationDatas(navDatas); } } while (curNavigationData.IsNotNull()); return navigationDataSet; } mitk::NavigationData::Pointer mitk::NavigationDataReaderXML::ReadVersion1() { if ( !m_parentElement ) { mitkThrowException(mitk::IGTIOException) << "Reading XML is not possible. Parent element is not set."; } TiXmlElement* elem; m_currentNode = m_parentElement->IterateChildren(m_currentNode); bool delElem; if(m_currentNode) { elem = m_currentNode->ToElement(); if(elem==nullptr) { mitkThrowException(mitk::IGTException) << "Cannot find element: Is this file damaged?"; } delElem = false; } else { elem = new TiXmlElement(""); delElem = true; } mitk::NavigationData::Pointer nd = this->ReadNavigationData(elem); if(delElem) { delete elem; } return nd; } mitk::NavigationData::Pointer mitk::NavigationDataReaderXML::ReadNavigationData(TiXmlElement* elem) { if (elem == nullptr) {mitkThrow() << "Error: Element is NULL!";} mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); mitk::NavigationData::PositionType position; mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0); mitk::NavigationData::TimeStampType timestamp = -1; mitk::NavigationData::CovarianceMatrixType matrix; bool hasPosition = true; bool hasOrientation = true; bool dataValid = false; position.Fill(0.0); matrix.SetIdentity(); elem->QueryDoubleAttribute("Time",×tamp); if (timestamp == -1) { return nullptr; //the calling method should check the return value if it is valid/not NULL } elem->QueryDoubleAttribute("X", &position[0]); elem->QueryDoubleAttribute("Y", &position[1]); elem->QueryDoubleAttribute("Z", &position[2]); elem->QueryDoubleAttribute("QX", &orientation[0]); elem->QueryDoubleAttribute("QY", &orientation[1]); elem->QueryDoubleAttribute("QZ", &orientation[2]); elem->QueryDoubleAttribute("QR", &orientation[3]); elem->QueryDoubleAttribute("C00", &matrix[0][0]); elem->QueryDoubleAttribute("C01", &matrix[0][1]); elem->QueryDoubleAttribute("C02", &matrix[0][2]); elem->QueryDoubleAttribute("C03", &matrix[0][3]); elem->QueryDoubleAttribute("C04", &matrix[0][4]); elem->QueryDoubleAttribute("C05", &matrix[0][5]); elem->QueryDoubleAttribute("C10", &matrix[1][0]); elem->QueryDoubleAttribute("C11", &matrix[1][1]); elem->QueryDoubleAttribute("C12", &matrix[1][2]); elem->QueryDoubleAttribute("C13", &matrix[1][3]); elem->QueryDoubleAttribute("C14", &matrix[1][4]); elem->QueryDoubleAttribute("C15", &matrix[1][5]); int tmpval = 0; elem->QueryIntAttribute("Valid", &tmpval); if (tmpval == 0) dataValid = false; else dataValid = true; tmpval = 0; elem->QueryIntAttribute("hO", &tmpval); if (tmpval == 0) hasOrientation = false; else hasOrientation = true; tmpval = 0; elem->QueryIntAttribute("hP", &tmpval); if (tmpval == 0) hasPosition = false; else hasPosition = true; nd->SetIGTTimeStamp(timestamp); nd->SetPosition(position); nd->SetOrientation(orientation); nd->SetCovErrorMatrix(matrix); nd->SetDataValid(dataValid); nd->SetHasOrientation(hasOrientation); nd->SetHasPosition(hasPosition); return nd; } // -- deprecated | begin unsigned int mitk::NavigationDataReaderXML::GetFileVersion(std::istream* stream) { if (stream==nullptr) { MITK_ERROR << "No input stream set!"; mitkThrowException(mitk::IGTIOException)<<"No input stream set!"; } if (!stream->good()) { MITK_ERROR << "Stream is not good!"; mitkThrowException(mitk::IGTIOException)<<"Stream is not good!"; } int version = 1; auto dec = new TiXmlDeclaration(); *stream >> *dec; if(strcmp(dec->Version(),"") == 0) { MITK_ERROR << "The input stream seems to have XML incompatible format"; mitkThrowException(mitk::IGTIOException) << "The input stream seems to have XML incompatible format"; } m_parentElement = new TiXmlElement(""); *stream >> *m_parentElement; //2nd line this is the file version std::string tempValue = m_parentElement->Value(); if(tempValue != "Version") { if(tempValue == "Data"){ m_parentElement->QueryIntAttribute("version",&version); } } else { m_parentElement->QueryIntAttribute("Ver",&version); } if (version > 0) { return version; } else { return 0; } } unsigned int mitk::NavigationDataReaderXML::GetNumberOfNavigationDatas(std::istream* stream) { if (stream == nullptr) { MITK_ERROR << "No input stream set!"; mitkThrowException(mitk::IGTException)<<"No input stream set!"; } if (!stream->good()) { MITK_ERROR << "Stream not good!"; mitkThrowException(mitk::IGTException)<<"Stream not good!"; } //If something has changed in a future version of the XML definition e.g. navigationcount or addional parameters //catch this here with a select case block (see GenerateData() method) int numberOfTools = 0; std::string tempValue = m_parentElement->Value(); if(tempValue == "Version"){ *stream >> *m_parentElement; } m_parentElement->QueryIntAttribute("ToolCount",&numberOfTools); if (numberOfTools > 0) { return numberOfTools; } return 0; } void mitk::NavigationDataReaderXML::StreamInvalid(std::string message) { m_StreamEnd = true; m_ErrorMessage = message; m_StreamValid = false; mitkThrowException(mitk::IGTIOException) << "Invalid stream!"; } // -- deprecated | end diff --git a/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderXML.h b/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderXML.h index 6755c4942c..3d34a5150b 100644 --- a/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderXML.h +++ b/Modules/IGTBase/autoload/IO/mitkNavigationDataReaderXML.h @@ -1,105 +1,108 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKNavigationDataReaderXML_H_HEADER_INCLUDED_ #define MITKNavigationDataReaderXML_H_HEADER_INCLUDED_ #include #include // includes for exceptions #include #include class TiXmlElement; class TiXmlNode; namespace mitk { class NavigationDataReaderXML : public AbstractFileReader { public: NavigationDataReaderXML(); virtual ~NavigationDataReaderXML(); using AbstractFileReader::Read; virtual std::vector> Read() override; protected: + NavigationDataReaderXML(const NavigationDataReaderXML& other); + virtual mitk::NavigationDataReaderXML* Clone() const override; + NavigationDataSet::Pointer ReadNavigationDataSet(); /** * \brief This method reads one line of the XML document and returns the data as a NavigationData object * If there is a new file version another method must be added which reads this data. * @throw mitk::IGTException Throws an exceptions if file is damaged. */ mitk::NavigationData::Pointer ReadVersion1(); mitk::NavigationData::Pointer ReadNavigationData(TiXmlElement* elem); std::string m_FileName; TiXmlElement* m_parentElement; TiXmlNode* m_currentNode; int m_FileVersion; ///< indicates which XML encoding is used int m_NumberOfOutputs; ///< stores the number of outputs known from the XML document // -- deprecated | begin //std::istream* m_Stream; ///< stores a pointer to the input stream bool m_StreamEnd; ///< stores if the input stream arrived at end bool m_StreamValid; ///< stores if the input stream is valid or not std::string m_ErrorMessage; ///< stores the error message if the stream is invalid /** * \brief Creates a stream out of the filename given by the variable m_FileName. * The stream is then set to m_Stream. * * @throw mitk::IGTIOException Throws an exception if file does not exist * @throw mitk::IGTException Throws an exception if the stream is NULL */ //void CreateStreamFromFilename(); /** * \brief Returns the file version out of the XML document. * @throw mitk::IGTException Throws an mitk::IGTException an exception if stream is NULL or not good. * @throw mitk::IGTIOException Throws an mitk::IGTIOException if the stream has an incompatible XML format. */ unsigned int GetFileVersion(std::istream* stream); /** * \brief Returns the number of tracked tools out of the XML document. * @throw Throws an exception if stream is NULL. * @throw Throws an exception if the input stream has an XML incompatible format. */ unsigned int GetNumberOfNavigationDatas(std::istream* stream); /** * @brief This is a helping method which gives an error message and throws an exception with the given message. * It can be used if a stream is found to be invalid. * * @throw mitk::IGTIOException Always throws an exception. */ void StreamInvalid(std::string message); ///< help method which sets the stream invalid and displays an error // -- deprecated | end private: NavigationDataSet::Pointer Read(std::istream* stream); NavigationDataSet::Pointer Read(std::string fileName); }; } // namespace mitk #endif // MITKNavigationDataReaderXML_H_HEADER_INCLUDED_ diff --git a/Modules/IGTBase/autoload/IO/mitkNavigationDataSetWriterCSV.cpp b/Modules/IGTBase/autoload/IO/mitkNavigationDataSetWriterCSV.cpp index 92c3ba6648..60429db6ea 100644 --- a/Modules/IGTBase/autoload/IO/mitkNavigationDataSetWriterCSV.cpp +++ b/Modules/IGTBase/autoload/IO/mitkNavigationDataSetWriterCSV.cpp @@ -1,107 +1,97 @@ /*=================================================================== 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 "mitkNavigationDataSetWriterCSV.h" #include -#include +#include mitk::NavigationDataSetWriterCSV::NavigationDataSetWriterCSV() : AbstractFileWriter(NavigationDataSet::GetStaticNameOfClass(), - CustomMimeType(NAVIGATIONDATASETCSV_MIMETYPE()), + mitk::IGTMimeTypes::NAVIGATIONDATASETCSV_MIMETYPE(), "MITK NavigationDataSet Reader (CSV)") { RegisterService(); } mitk::NavigationDataSetWriterCSV::~NavigationDataSetWriterCSV() {} mitk::NavigationDataSetWriterCSV::NavigationDataSetWriterCSV(const mitk::NavigationDataSetWriterCSV& other) : AbstractFileWriter(other) { } mitk::NavigationDataSetWriterCSV* mitk::NavigationDataSetWriterCSV::Clone() const { return new NavigationDataSetWriterCSV(*this); } void mitk::NavigationDataSetWriterCSV::Write() { std::ostream* out = GetOutputStream(); if (out == nullptr) { out = new std::ofstream(GetOutputLocation().c_str()); } mitk::NavigationDataSet::ConstPointer data = dynamic_cast (this->GetInput()); //save old locale char * oldLocale; oldLocale = setlocale( LC_ALL, nullptr ); //define own locale std::locale C("C"); setlocale( LC_ALL, "C" ); //write header unsigned int numberOfTools = data->GetNumberOfTools(); for (unsigned int index = 0; index < numberOfTools; index++){ *out << "TimeStamp_Tool" << index << ";Valid_Tool" << index << ";X_Tool" << index << ";Y_Tool" << index << ";Z_Tool" << index << ";QX_Tool" << index << ";QY_Tool" << index << ";QZ_Tool" << index << ";QR_Tool" << index << ";";} *out << "\n"; out->precision(15); // rounding precision because we don't want to loose data. //write data MITK_INFO << "Number of timesteps: " << data->Size(); for (unsigned int i=0; iSize(); i++) { std::vector< mitk::NavigationData::Pointer > NavigationDatasOfCurrentStep = data->GetTimeStep(i); for (unsigned int toolIndex = 0; toolIndex < numberOfTools; toolIndex++) { mitk::NavigationData::Pointer nd = NavigationDatasOfCurrentStep.at(toolIndex); *out << nd->GetTimeStamp() << ";" << nd->IsDataValid() << ";" << nd->GetPosition()[0] << ";" << nd->GetPosition()[1] << ";" << nd->GetPosition()[2] << ";" << nd->GetOrientation()[0] << ";" << nd->GetOrientation()[1] << ";" << nd->GetOrientation()[2] << ";" << nd->GetOrientation()[3] << ";"; } *out << "\n"; } out->flush(); delete out; //switch back to old locale setlocale( LC_ALL, oldLocale ); } - -mitk::CustomMimeType mitk::NavigationDataSetWriterCSV::NAVIGATIONDATASETCSV_MIMETYPE() -{ - mitk::CustomMimeType mimeType(IOMimeTypes::DEFAULT_BASE_NAME() + ".NavigationDataSet.csv"); - std::string category = "NavigationDataSet"; - mimeType.SetComment("NavigationDataSet (csv)"); - mimeType.SetCategory(category); - mimeType.AddExtension("csv"); - return mimeType; -} \ No newline at end of file diff --git a/Modules/IGTBase/autoload/IO/mitkNavigationDataSetWriterCSV.h b/Modules/IGTBase/autoload/IO/mitkNavigationDataSetWriterCSV.h index 3ccd0c9dbc..c3c4092c87 100644 --- a/Modules/IGTBase/autoload/IO/mitkNavigationDataSetWriterCSV.h +++ b/Modules/IGTBase/autoload/IO/mitkNavigationDataSetWriterCSV.h @@ -1,43 +1,41 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKNavigationDataSetWriterCSV_H_HEADER_INCLUDED_ #define MITKNavigationDataSetWriterCSV_H_HEADER_INCLUDED_ #include #include namespace mitk { class NavigationDataSetWriterCSV : public AbstractFileWriter { public: NavigationDataSetWriterCSV(); virtual~NavigationDataSetWriterCSV(); using AbstractFileWriter::Write; virtual void Write() override; protected: NavigationDataSetWriterCSV(const NavigationDataSetWriterCSV& other); virtual mitk::NavigationDataSetWriterCSV* Clone() const override; - - CustomMimeType NAVIGATIONDATASETCSV_MIMETYPE(); }; } #endif // MITKNavigationDataSetWriterCSV_H_HEADER_INCLUDED_ diff --git a/Modules/IGTBase/include/mitkIGTMimeTypes.h b/Modules/IGTBase/include/mitkIGTMimeTypes.h index d96e0f1d26..cef22a1141 100644 --- a/Modules/IGTBase/include/mitkIGTMimeTypes.h +++ b/Modules/IGTBase/include/mitkIGTMimeTypes.h @@ -1,33 +1,34 @@ /*=================================================================== 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. ===================================================================*/ #ifndef MITKIOMIMETYPE_H_HEADER_INCLUDED_ #define MITKIOMIMETYPE_H_HEADER_INCLUDED_ #include #include #include namespace mitk { class MITKIGTBASE_EXPORT IGTMimeTypes { public: static CustomMimeType NAVIGATIONDATASETXML_MIMETYPE(); + static CustomMimeType NAVIGATIONDATASETCSV_MIMETYPE(); }; } #endif // MITKIOMIMETYPE_H_HEADER_INCLUDED_ \ No newline at end of file diff --git a/Modules/IGTBase/src/mitkIGTMimeTypes.cpp b/Modules/IGTBase/src/mitkIGTMimeTypes.cpp index 02b30419a6..f342ad8bea 100644 --- a/Modules/IGTBase/src/mitkIGTMimeTypes.cpp +++ b/Modules/IGTBase/src/mitkIGTMimeTypes.cpp @@ -1,28 +1,38 @@ /*=================================================================== 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. ===================================================================*/ // MITK #include "mitkIGTMimeTypes.h" mitk::CustomMimeType mitk::IGTMimeTypes::NAVIGATIONDATASETXML_MIMETYPE() { mitk::CustomMimeType mimeType(IOMimeTypes::DEFAULT_BASE_NAME() + ".NavigationDataSet.xml"); std::string category = "NavigationDataSet"; mimeType.SetComment("NavigationDataSet (XML)"); mimeType.SetCategory(category); mimeType.AddExtension("xml"); return mimeType; +} + +mitk::CustomMimeType mitk::IGTMimeTypes::NAVIGATIONDATASETCSV_MIMETYPE() +{ + mitk::CustomMimeType mimeType(IOMimeTypes::DEFAULT_BASE_NAME() + ".NavigationDataSet.csv"); + std::string category = "NavigationDataSet"; + mimeType.SetComment("NavigationDataSet (csv)"); + mimeType.SetCategory(category); + mimeType.AddExtension("csv"); + return mimeType; } \ No newline at end of file