diff --git a/Modules/IGT/IO/mitkNavigationDataPlayer.h b/Modules/IGT/IO/mitkNavigationDataPlayer.h index 3b95e9409f..26e77bdf4e 100644 --- a/Modules/IGT/IO/mitkNavigationDataPlayer.h +++ b/Modules/IGT/IO/mitkNavigationDataPlayer.h @@ -1,110 +1,105 @@ /*=================================================================== 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 MITKNavigationDataPlayer_H_HEADER_INCLUDED_ #define MITKNavigationDataPlayer_H_HEADER_INCLUDED_ #include #include - namespace mitk { /**Documentation - * \brief This class is used to play recorded (see mitkNavigationDataRecorder class) files. + * \brief This class is used to play recorded (see mitkNavigationDataRecorder class) NavigationDataSets. * - * If you want to play a file you have to set an input stream. This can be an own one (use StartPlaying(std::istream*)) - * or a preset (use StartPlaying()). The presets are NormalFile and ZipFile and can be set with the method - * SetPlayerMode(PlayerMode). The presets need a FileName. Therefore the FileName must be set before the preset. - * For pausing the player call Pause(). A call of Resume() will continue the playing. + * TODO * * * \ingroup IGT */ class MitkIGT_EXPORT NavigationDataPlayer : public NavigationDataPlayerBase { public: mitkClassMacro(NavigationDataPlayer, NavigationDataPlayerBase); itkFactorylessNewMacro(Self) - itkCloneMacro(Self) + itkCloneMacro(Self) - enum PlayerState { PlayerStopped, PlayerRunning, PlayerPaused }; + enum PlayerState { PlayerStopped, PlayerRunning, PlayerPaused }; typedef mitk::NavigationData::TimeStampType TimeStampType; /** * \brief Used for pipeline update just to tell the pipeline that we always have to update */ virtual void UpdateOutputInformation(); /** - * \brief This method starts the player. - * - * The method mitk::NavigationDataPlayer::SetNavigationDataSet() has to be called before. - * - * @throw mitk::IGTException If m_NavigationDataSet is null. - */ + * \brief This method starts the player. + * + * The method mitk::NavigationDataPlayer::SetNavigationDataSet() has to be called before. + * + * @throw mitk::IGTException If m_NavigationDataSet is null. + */ void StartPlaying(); /** - * \brief Stops the player and closes the stream. After a call of StopPlaying() - * StartPlaying() must be called to get new output data - * - * \warning the output is generated in this method because we know first about the number of output after - * reading the first lines of the XML file. Therefore you should assign your output after the call of this method - */ + * \brief Stops the player and closes the stream. After a call of StopPlaying() + * StartPlaying() must be called to get new output data + * + * \warning the output is generated in this method because we know first about the number of output after + * reading the first lines of the XML file. Therefore you should assign your output after the call of this method + */ void StopPlaying(); /** - * \brief This method pauses the player. If you want to play again call Resume() - */ + * \brief This method pauses the player. If you want to play again call Resume() + */ void Pause(); /** - * \brief This method resumes the player when it was paused. - */ + * \brief This method resumes the player when it was paused. + */ void Resume(); PlayerState GetCurrentPlayerState(); TimeStampType GetTimeStampSinceStart(); protected: NavigationDataPlayer(); virtual ~NavigationDataPlayer(); /** - * \brief Set outputs to the navigation data object corresponding to current time. - */ + * \brief Set outputs to the navigation data object corresponding to current time. + */ virtual void GenerateData(); PlayerState m_CurPlayerState; /** - * \brief The start time of the playing. Set in the method mitk::NavigationDataPlayer::StartPlaying(). - */ + * \brief The start time of the playing. Set in the method mitk::NavigationDataPlayer::StartPlaying(). + */ TimeStampType m_StartPlayingTimeStamp; /** - * \brief Stores the time when a pause began. - */ + * \brief Stores the time when a pause began. + */ TimeStampType m_PauseTimeStamp; TimeStampType m_TimeStampSinceStart; }; } // namespace mitk #endif /* MITKNavigationDataPlayer_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/Testing/mitkNavigationDataSequentialPlayerTest.cpp b/Modules/IGT/Testing/mitkNavigationDataSequentialPlayerTest.cpp index 7ccbd9823f..d04b765833 100644 --- a/Modules/IGT/Testing/mitkNavigationDataSequentialPlayerTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataSequentialPlayerTest.cpp @@ -1,267 +1,268 @@ - /*=================================================================== 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 //foe exceptions #include "mitkIGTException.h" #include "mitkIGTIOException.h" - -vnl_vector tTool0Snapshot1(3); -vnl_vector tTool1Snapshot2(3); -mitk::Quaternion qTool0Snapshot0; -mitk::Quaternion qTool1Snapshot1; - -mitk::NavigationDataSequentialPlayer::Pointer player( - mitk::NavigationDataSequentialPlayer::New()); - -bool runLoop() +class mitkNavigationDataSequentialPlayerTestSuite : public mitk::TestFixture { + CPPUNIT_TEST_SUITE(mitkNavigationDataSequentialPlayerTestSuite); + MITK_TEST(TestStandardWorkflow); + MITK_TEST(TestRestartWithNewNavigationDataSet); + MITK_TEST(TestSetFileNameException); + MITK_TEST(TestGoToSnapshotException); + MITK_TEST(TestSetXMLStringException); + MITK_TEST(TestDoubleUpdate); + CPPUNIT_TEST_SUITE_END(); + +private: + /** Members used inside the different test methods. All members are initialized via setUp().*/ + vnl_vector tTool0Snapshot1; + vnl_vector tTool1Snapshot2; + mitk::Quaternion qTool0Snapshot0; + mitk::Quaternion qTool1Snapshot1; + + mitk::NavigationDataSequentialPlayer::Pointer player; + +public: + + void setUp(){ + tTool0Snapshot1 = vnl_vector(3); + tTool1Snapshot2 = vnl_vector(3); + mitk::Quaternion qTool0Snapshot0; + mitk::Quaternion qTool1Snapshot1; + + player = mitk::NavigationDataSequentialPlayer::New(); + } - - bool success = true; - mitk::NavigationData::Pointer nd0; - mitk::NavigationData::Pointer nd1; - for(unsigned int i=0; iGetNumberOfSnapshots();++i) + void tearDown() { - player->GoToNextSnapshot(); - player->Update(); - nd0 = player->GetOutput(); - nd1 = player->GetOutput(1); - - // test some values - if(nd0.IsNull() || nd1.IsNull()) return false; + } - if(i==0) - { - if (!(qTool0Snapshot0.as_vector() == nd0->GetOrientation().as_vector())) {success = false;} - } - else if(i==1) - { - if (!(tTool0Snapshot1 == nd0->GetPosition().GetVnlVector())) {success = false;} - else if (!(qTool1Snapshot1.as_vector() == nd1->GetOrientation().as_vector())) {success = false;} - } - else if(i==2) // should be repeated + bool runLoop() + { + bool success = true; + mitk::NavigationData::Pointer nd0; + mitk::NavigationData::Pointer nd1; + for(unsigned int i=0; iGetNumberOfSnapshots(); ++i) { - if (!(tTool1Snapshot2 == nd1->GetPosition().GetVnlVector())) {success = false;} + player->GoToNextSnapshot(); + player->Update(); + nd0 = player->GetOutput(); + nd1 = player->GetOutput(1); + + // test some values + if(nd0.IsNull() || nd1.IsNull()) return false; + + if(i==0) + { + if (!(qTool0Snapshot0.as_vector() == nd0->GetOrientation().as_vector())) {success = false;} + } + else if(i==1) + { + if (!(tTool0Snapshot1 == nd0->GetPosition().GetVnlVector())) {success = false;} + else if (!(qTool1Snapshot1.as_vector() == nd1->GetOrientation().as_vector())) {success = false;} + } + else if(i==2) // should be repeated + { + if (!(tTool1Snapshot2 == nd1->GetPosition().GetVnlVector())) {success = false;} + } } - + return success; } - return success; -} -void TestStandardWorkflow() -{ - // create test values valid for the xml data above - tTool0Snapshot1[0] = -336.65; - tTool0Snapshot1[1] = 138.5; - tTool0Snapshot1[2]= -2061.07; - tTool1Snapshot2[0] = -56.93; - tTool1Snapshot2[1] = 233.79; - tTool1Snapshot2[2]= -2042.6; - vnl_vector_fixed qVec; - qVec[0] = 0.0085; - qVec[1] = -0.0576; - qVec[2]= -0.0022; - qVec[3]= 0.9982; - qTool0Snapshot0 = mitk::Quaternion(qVec); - qVec[0] = 0.4683; - qVec[1] = 0.0188; - qVec[2]= -0.8805; - qVec[3]= 0.0696; - qTool1Snapshot1 = mitk::Quaternion(qVec); - - //test SetXMLString() - std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData_2ToolsDouble.xml", "Modules/IGT/Testing/Data"); - - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - player->SetNavigationDataSet(reader->Read(file)); - - MITK_TEST_CONDITION(player->GetNumberOfSnapshots() == 3,"Testing method SetXMLString with 3 navigation datas."); - 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_TEST_CONDITION(tTool1Snapshot2 == nd1->GetPosition().GetVnlVector(), - "Testing GoToSnapshot() [1]"); - - MITK_TEST_OUTPUT( << tTool1Snapshot2 << "\t" << nd1->GetPosition().GetVnlVector()); - - player->GoToSnapshot(0); - mitk::NavigationData::Pointer nd0 = player->GetOutput(); - MITK_TEST_CONDITION(qTool0Snapshot0.as_vector() == nd0->GetOrientation().as_vector(), - "Testing GoToSnapshot() [2]"); - - MITK_TEST_OUTPUT( << qTool0Snapshot0.as_vector() << "\t" <GetOrientation().as_vector() ); - - player->GoToSnapshot(2); - - // and a third time - MITK_TEST_CONDITION(runLoop(),"Tested if repeat works again."); - -} - -void TestRestartWithNewNavigationDataSet() -{ - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); + void TestStandardWorkflow() + { + // create test values valid for the xml data above + tTool0Snapshot1[0] = -336.65; + tTool0Snapshot1[1] = 138.5; + tTool0Snapshot1[2]= -2061.07; + tTool1Snapshot2[0] = -56.93; + tTool1Snapshot2[1] = 233.79; + tTool1Snapshot2[2]= -2042.6; + vnl_vector_fixed qVec; + qVec[0] = 0.0085; + qVec[1] = -0.0576; + qVec[2]= -0.0022; + qVec[3]= 0.9982; + qTool0Snapshot0 = mitk::Quaternion(qVec); + qVec[0] = 0.4683; + qVec[1] = 0.0188; + qVec[2]= -0.8805; + qVec[3]= 0.0696; + qTool1Snapshot1 = mitk::Quaternion(qVec); + + //test SetXMLString() + std::string file = GetTestDataFilePath("IGT-Data/NavigationDataTestData_2ToolsDouble.xml"); + mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); + player->SetNavigationDataSet(reader->Read(file)); - mitk::NavigationDataSequentialPlayer::Pointer player(mitk::NavigationDataSequentialPlayer::New()); + MITK_TEST_CONDITION(player->GetNumberOfSnapshots() == 3,"Testing method SetXMLString with 3 navigation datas."); + MITK_TEST_CONDITION(player->GetNumberOfIndexedOutputs() == 2,"Testing number of outputs"); - std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData_2ToolsDouble.xml", "Modules/IGT/Testing/Data"); + //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 - player->SetNavigationDataSet(reader->Read(file)); - mitk::NavigationData::PositionType nd1 = player->GetOutput(0)->GetPosition(); - player->SetNavigationDataSet(reader->Read(file)); - player->Update(); - mitk::NavigationData::PositionType nd2 = player->GetOutput(0)->GetPosition(); + // now test the go to snapshot function + player->GoToSnapshot(2); + mitk::NavigationData::Pointer nd1 = player->GetOutput(1); + MITK_TEST_CONDITION(tTool1Snapshot2 == nd1->GetPosition().GetVnlVector(), + "Testing GoToSnapshot() [1]"); - MITK_TEST_CONDITION(nd1 == nd2, "First output must be the same after setting same navigation data again."); + MITK_TEST_OUTPUT( << tTool1Snapshot2 << "\t" << nd1->GetPosition().GetVnlVector()); - // setting new NavigationDataSet with different tool count should result in an exception - file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData.xml", "Modules/IGT/Testing/Data"); - MITK_TEST_FOR_EXCEPTION(mitk::IGTException, player->SetNavigationDataSet(reader->Read(file))); -} + player->GoToSnapshot(0); + mitk::NavigationData::Pointer nd0 = player->GetOutput(); + MITK_TEST_CONDITION(qTool0Snapshot0.as_vector() == nd0->GetOrientation().as_vector(), + "Testing GoToSnapshot() [2]"); -void TestSetFileNameException() -{ //testing exception if file name hasnt been set - mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer = mitk::NavigationDataSequentialPlayer::New(); - bool exceptionThrown=false; - try - { - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - myTestPlayer->SetNavigationDataSet(reader->Read("")); - } - catch(mitk::IGTIOException) - { - exceptionThrown=true; - MITK_TEST_OUTPUT(<<"Tested exception for the case when file version is wrong in SetFileName. Application should not crash."); + MITK_TEST_OUTPUT( << qTool0Snapshot0.as_vector() << "\t" <GetOrientation().as_vector() ); + + player->GoToSnapshot(2); + + // and a third time + MITK_TEST_CONDITION(runLoop(),"Tested if repeat works again."); } - MITK_TEST_CONDITION(exceptionThrown, "Testing SetFileName method if exception (if file name hasnt been set) was thrown."); - //testing ReInItXML method if data element is not found - mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer1 = mitk::NavigationDataSequentialPlayer::New(); - std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestDataInvalidTags.xml", "Modules/IGT/Testing/Data"); - bool exceptionThrown1=false; - try + void TestRestartWithNewNavigationDataSet() { mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - myTestPlayer1->SetNavigationDataSet(reader->Read(file)); - } - catch(mitk::IGTException) - { - exceptionThrown1=true; - } - MITK_TEST_CONDITION(exceptionThrown1, "Testing SetFileName method if exception (if data element not found) was thrown."); -} + mitk::NavigationDataSequentialPlayer::Pointer player(mitk::NavigationDataSequentialPlayer::New()); -void TestGoToSnapshotException() -{ - //testing GoToSnapShot for exception - mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer2 = mitk::NavigationDataSequentialPlayer::New(); - std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData_2Tools.xml", "Modules/IGT/Testing/Data"); - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - myTestPlayer2->SetNavigationDataSet(reader->Read(file)); - - 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."); -} + std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData_2ToolsDouble.xml", "Modules/IGT/Testing/Data"); -void TestSetXMLStringException() -{ - mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer3 = mitk::NavigationDataSequentialPlayer::New(); + player->SetNavigationDataSet(reader->Read(file)); + mitk::NavigationData::PositionType nd1 = player->GetOutput(0)->GetPosition(); + player->SetNavigationDataSet(reader->Read(file)); + player->Update(); + mitk::NavigationData::PositionType nd2 = player->GetOutput(0)->GetPosition(); - bool exceptionThrown3=false; + MITK_TEST_CONDITION(nd1 == nd2, "First output must be the same after setting same navigation data again."); - //The string above XML_INVALID_TESTSTRING is a wrong string, some element were deleted in above - try - { - std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("InvalidVersionNavigationDataTestData.xml", "Modules/IGT/Testing/Data"); - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - myTestPlayer3->SetNavigationDataSet(reader->Read(file)); + // setting new NavigationDataSet with different tool count should result in an exception + file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData.xml", "Modules/IGT/Testing/Data"); + MITK_TEST_FOR_EXCEPTION(mitk::IGTException, player->SetNavigationDataSet(reader->Read(file))); } - catch(mitk::IGTIOException) - { - exceptionThrown3=true; - } - MITK_TEST_CONDITION(exceptionThrown3, "Testing SetXMLString method with an invalid XML string."); -} -void TestDoubleUpdate() -{ - std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData_2Tools.xml", "Modules/IGT/Testing/Data"); + void TestSetFileNameException() + { //testing exception if file name hasnt been set + mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer = mitk::NavigationDataSequentialPlayer::New(); + bool exceptionThrown=false; + try + { + mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); + myTestPlayer->SetNavigationDataSet(reader->Read("")); + } + catch(mitk::IGTIOException) + { + exceptionThrown=true; + MITK_TEST_OUTPUT(<<"Tested exception for the case when file version is wrong in SetFileName. Application should not crash."); + } + MITK_TEST_CONDITION(exceptionThrown, "Testing SetFileName method if exception (if file name hasnt been set) was thrown."); - mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); - player->SetNavigationDataSet(reader->Read(file)); + //testing ReInItXML method if data element is not found + mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer1 = mitk::NavigationDataSequentialPlayer::New(); + std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestDataInvalidTags.xml", "Modules/IGT/Testing/Data"); + bool exceptionThrown1=false; + try + { + mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); + myTestPlayer1->SetNavigationDataSet(reader->Read(file)); + } + catch(mitk::IGTException) + { + exceptionThrown1=true; + } + MITK_TEST_CONDITION(exceptionThrown1, "Testing SetFileName method if exception (if data element not found) was thrown."); + } - player->Update(); - mitk::Quaternion nd1Orientation = player->GetOutput()->GetOrientation(); + void TestGoToSnapshotException() + { + //testing GoToSnapShot for exception + mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer2 = mitk::NavigationDataSequentialPlayer::New(); + std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData_2Tools.xml", "Modules/IGT/Testing/Data"); + mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); + myTestPlayer2->SetNavigationDataSet(reader->Read(file)); - player->Update(); - mitk::Quaternion nd2Orientation = player->GetOutput()->GetOrientation(); + 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."); + } - MITK_TEST_CONDITION(nd1Orientation.as_vector() == nd2Orientation.as_vector(), "Output must be the same no matter if Update() was called between."); + void TestSetXMLStringException() + { + mitk::NavigationDataSequentialPlayer::Pointer myTestPlayer3 = mitk::NavigationDataSequentialPlayer::New(); - MITK_TEST_CONDITION(player->GoToNextSnapshot(), "There must be a next snapshot available."); - player->Update(); - mitk::Quaternion nd3Orientation = player->GetOutput()->GetOrientation(); + bool exceptionThrown3=false; - MITK_TEST_CONDITION(nd1Orientation.as_vector() != nd3Orientation.as_vector(), "Output must be different if GoToNextSnapshot() was called between."); -} + //The string above XML_INVALID_TESTSTRING is a wrong string, some element were deleted in above + try + { + std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("InvalidVersionNavigationDataTestData.xml", "Modules/IGT/Testing/Data"); + mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); + myTestPlayer3->SetNavigationDataSet(reader->Read(file)); + } + catch(mitk::IGTIOException) + { + exceptionThrown3=true; + } + MITK_TEST_CONDITION(exceptionThrown3, "Testing SetXMLString method with an invalid XML string."); + } + void TestDoubleUpdate() + { + std::string file = mitk::StandardFileLocations::GetInstance()->FindFile("NavigationDataTestData_2Tools.xml", "Modules/IGT/Testing/Data"); + mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); + player->SetNavigationDataSet(reader->Read(file)); + player->Update(); + mitk::Quaternion nd1Orientation = player->GetOutput()->GetOrientation(); -/**Documentation - * test for the class "NavigationDataRecorder". - */ -int mitkNavigationDataSequentialPlayerTest(int /* argc */, char* /*argv*/[]) -{ - MITK_TEST_BEGIN("NavigationDataSequentialPlayer"); + player->Update(); + mitk::Quaternion nd2Orientation = player->GetOutput()->GetOrientation(); - TestStandardWorkflow(); - TestRestartWithNewNavigationDataSet(); - TestSetFileNameException(); - TestSetXMLStringException(); - TestGoToSnapshotException(); - TestDoubleUpdate(); + 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_END(); -} + 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/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerView.cpp b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerView.cpp index 1ac416f5df..15d9ac454e 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerView.cpp +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerView.cpp @@ -1,185 +1,193 @@ /*=================================================================== 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. ===================================================================*/ // Blueberry #include #include // Qmitk #include "QmitkNavigationDataPlayerView.h" #include "QmitkStdMultiWidget.h" // QT #include //mitk #include #include #include #include // VTK #include const std::string QmitkNavigationDataPlayerView::VIEW_ID = "org.mitk.views.navigationdataplayer"; QmitkNavigationDataPlayerView::QmitkNavigationDataPlayerView() : QmitkFunctionality() , m_Controls( 0 ) , m_MultiWidget( NULL ) { } QmitkNavigationDataPlayerView::~QmitkNavigationDataPlayerView() { } void QmitkNavigationDataPlayerView::CreateQtPartControl( QWidget *parent ) { // build up qt view, unless already done if ( !m_Controls ) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkNavigationDataPlayerViewControls; m_Controls->setupUi( parent ); this->CreateBundleWidgets( parent ); this->CreateConnections(); // make deselected Player invisible m_Controls->m_TimedWidget->setVisible(false); } } void QmitkNavigationDataPlayerView::CreateBundleWidgets(QWidget* parent) { //m_PlayerWidget = new QmitkIGTPlayerWidget( parent ); // this bundle's ND player widget } void QmitkNavigationDataPlayerView::CreateConnections() { connect( m_Controls->m_RdbSequential, SIGNAL(released()), this, SLOT(OnSelectPlayer()) ); connect( m_Controls->m_RdbTimeBased, SIGNAL(released()), this, SLOT(OnSelectPlayer()) ); connect( m_Controls->m_BtnOpenFile, SIGNAL(released()), this, SLOT(OnOpenFile()) ); connect( m_Controls->m_ChkDisplay, SIGNAL(released()), this, SLOT(OnSetDisplay()) ); connect( m_Controls->m_chkRepeat, SIGNAL(released()), this, SLOT(OnSetRepeat()) ); connect( m_Controls->m_ChkMicroservice, SIGNAL(released()), this, SLOT(OnSetMicroservice()) ); connect( m_Controls->m_SequentialWidget, SIGNAL(SignalUpdate()), this, SLOT(OnUpdate()) ); connect( m_Controls->m_TimedWidget, SIGNAL(SignalUpdate()), this, SLOT(OnUpdate()) ); + + SetInteractionComponentsEnabledState(false); } void QmitkNavigationDataPlayerView::OnPlayingStarted() { } void QmitkNavigationDataPlayerView::OnOpenFile(){ mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); // FIXME Filter for correct Files and use correct Reader QString fileName = QFileDialog::getOpenFileName(NULL, "Open Navigation Data Set", "", ""); m_Data = reader->Read(fileName.toStdString()); // Update Labels m_Controls->m_LblFilePath->setText(fileName); m_Controls->m_LblFrames->setText(QString::number(m_Data->Size())); m_Controls->m_LblTools->setText(QString::number(m_Data->GetNumberOfTools())); // Initialize Widgets and create Player OnSelectPlayer(); + SetInteractionComponentsEnabledState(true); } void QmitkNavigationDataPlayerView::OnSelectPlayer(){ if (m_Controls->m_RdbSequential->isChecked()) { m_Controls->m_SequentialWidget->setVisible(true); m_Controls->m_TimedWidget->setVisible(false); mitk::NavigationDataSequentialPlayer::Pointer seqPlayer = mitk::NavigationDataSequentialPlayer::New(); seqPlayer->SetNavigationDataSet(m_Data); m_Controls->m_SequentialWidget->SetPlayer(seqPlayer); m_Player = seqPlayer; } else { m_Controls->m_SequentialWidget->setVisible(false); m_Controls->m_TimedWidget->setVisible(true); mitk::NavigationDataPlayer::Pointer timedPlayer = mitk::NavigationDataPlayer::New(); timedPlayer->SetNavigationDataSet(m_Data); m_Controls->m_TimedWidget->SetPlayer(timedPlayer); m_Player = timedPlayer; } // SetupRenderingPipeline OnSetDisplay(); } void ConfigurePlayer(){ // FIXME: Why is repeat not available in the base class? // TODO finish method } void QmitkNavigationDataPlayerView::OnSetRepeat(){ MITK_WARN << "Repeat not yet supported"; } void QmitkNavigationDataPlayerView::OnSetMicroservice(){ MITK_WARN << "Register as Microservice not yet supported"; } void QmitkNavigationDataPlayerView::OnUpdate(){ m_VisFilter->Update(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkNavigationDataPlayerView::OnSetDisplay(){ DestroyPipeline(); if ( (m_Controls->m_ChkDisplay->isChecked()) && ( m_Player.IsNotNull() )) { CreatePipeline(); } } void QmitkNavigationDataPlayerView::CreatePipeline(){ m_VisFilter = mitk::NavigationDataObjectVisualizationFilter::New(); m_VisFilter->ConnectTo(m_Player); for (unsigned int i = 0 ; i < m_Player->GetNumberOfIndexedOutputs(); i++ ) { mitk::DataNode::Pointer node = mitk::DataNode::New(); QString name = "Recorded Tool " + QString::number(i); node->SetName(name.toStdString()); //create small sphere and use it as surface mitk::Surface::Pointer mySphere = mitk::Surface::New(); vtkSphereSource *vtkData = vtkSphereSource::New(); vtkData->SetRadius(5.0f); vtkData->SetCenter(0.0, 0.0, 0.0); vtkData->Update(); mySphere->SetVtkPolyData(vtkData->GetOutput()); vtkData->Delete(); node->SetData(mySphere); m_VisFilter->SetRepresentationObject(i, mySphere); // Add Node to DataStorageand to local list of Nodes GetDataStorage()->Add(node); m_RenderingNodes.push_back(node); } } void QmitkNavigationDataPlayerView::DestroyPipeline(){ m_VisFilter = NULL; for (unsigned int i = 0; i < m_RenderingNodes.size(); i++){ this->GetDataStorage()->Remove(m_RenderingNodes[i]); } m_RenderingNodes.clear(); +} + +void QmitkNavigationDataPlayerView::SetInteractionComponentsEnabledState(bool isActive){ + m_Controls->m_grpbxSettings->setEnabled(isActive); + m_Controls->m_grpbxControls->setEnabled(isActive); } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerView.h b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerView.h index 961c3b7dcb..bbafa6e5dd 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerView.h +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerView.h @@ -1,129 +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. ===================================================================*/ #ifndef QmitkNavigationDataPlayerView_h #define QmitkNavigationDataPlayerView_h #include //Qmitk #include #include // ui #include "ui_QmitkNavigationDataPlayerViewControls.h" //mitk #include /*! \brief QmitkNavigationDataPlayerView \warning This application module is not yet documented. Use "svn blame/praise/annotate" and ask the author to provide basic documentation. \sa QmitkFunctionality \ingroup Functionalities */ class QmitkNavigationDataPlayerView : public QmitkFunctionality { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; QmitkNavigationDataPlayerView(); virtual ~QmitkNavigationDataPlayerView(); virtual void CreateQtPartControl(QWidget *parent); /** \brief This method creates this bundle's SIGNAL and SLOT connections */ virtual void CreateConnections(); protected slots: /*! \brief FIXME not currently used */ void OnPlayingStarted(); /*! \brief loads a file and triggers creation of players and the pipeline */ void OnOpenFile(); /*! \brief Creates the correct player and displays the according widget */ void OnSelectPlayer(); /*! \brief FIXME not currently used */ void OnSetRepeat(); /*! \brief FIXME not currently used */ void OnSetMicroservice(); /*! \brief Triggers the creation and destruction of the rendering pipeline */ void OnSetDisplay(); /*! \brief FIXME not currently used */ void OnUpdate(); protected: /** * \brief configures the player according to the checkboxes set in the GUI */ void ConfigurePlayer(); /** * \brief Creates the Rendering Pipeline necessary to Render the images */ void CreatePipeline(); /** * \brief Destroys the Rendering Pipeline (but not the player) */ void DestroyPipeline(); + /** + * \brief Makes player component active or inactive. + * + * Used to activate all components once data is loaded + */ + void SetInteractionComponentsEnabledState(bool isActive); + void CreateBundleWidgets(QWidget* parent); Ui::QmitkNavigationDataPlayerViewControls* m_Controls; mitk::NavigationDataObjectVisualizationFilter::Pointer m_VisFilter; std::vector m_RenderingNodes; mitk::NavigationDataPlayerBase::Pointer m_Player; mitk::NavigationDataSet::Pointer m_Data; QmitkStdMultiWidget* m_MultiWidget; QmitkIGTPlayerWidget* m_PlayerWidget; ///< this bundle's playback widget private: }; #endif // _QMITKNAVIGATIONDATAPLAYERVIEW_H_INCLUDED \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerViewControls.ui b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerViewControls.ui index e7320deee2..8ebdfef54e 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerViewControls.ui +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkNavigationDataPlayerViewControls.ui @@ -1,185 +1,188 @@ QmitkNavigationDataPlayerViewControls 0 0 415 762 0 0 QmitkTemplate - + File Management Open File No navigation data set loaded... Frames: Tools: N/A N/A - + + + true + Settings Sequential Player true Time-based Player Repeat true Register as Microservice true Display true - + Player Controls Qt::Vertical 20 40 QmitkNavigationDataSequentialPlayerControlWidget QWidget
QmitkNavigationDataSequentialPlayerControlWidget.h
1
QmitkNavigationDataPlayerControlWidget QWidget
QmitkNavigationDataPlayerControlWidget.h
1