diff --git a/Modules/IGT/IO/mitkNavigationDataPlayer.cpp b/Modules/IGT/IO/mitkNavigationDataPlayer.cpp index 9a06ad2dfb..0c7192674b 100644 --- a/Modules/IGT/IO/mitkNavigationDataPlayer.cpp +++ b/Modules/IGT/IO/mitkNavigationDataPlayer.cpp @@ -1,161 +1,157 @@ /*=================================================================== 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) + 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() { //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; - // 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) { if ( m_NavigationDataSetIterator->at(0)->GetIGTTimeStamp() > m_TimeStampSinceStart) { break; } } // first element was greater than timestamp -> return null if ( m_NavigationDataSetIterator == m_NavigationDataSet->Begin() ) { MITK_WARN("NavigationDataSet") << "No NavigationData was recorded before given timestamp."; //The output is not at this time this->GraftEmptyOutput(); return; } - for (unsigned int index = 0; index < m_NumberOfOutputs; index++) + for (unsigned int index = 0; index < GetNumberOfOutputs(); index++) { mitk::NavigationData* output = this->GetOutput(index); if( !output ) { mitkThrowException(mitk::IGTException) << "Output of index "<Graft(curIterator->at(index)); } // stop playing if the last NavigationData objects were grafted if (m_NavigationDataSetIterator == m_NavigationDataSet->End()) { this->StopPlaying(); } } - 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(); // timestamp for indicating playing start is set to the past // so that the first navigation data object will be shown NOW m_StartPlayingTimeStamp = mitk::IGTTimeStamp::GetInstance()->GetElapsed() - - m_NavigationDataSet->Begin()->at(0)->GetIGTTimeStamp(); + - m_NavigationDataSet->Begin()->at(0)->GetIGTTimeStamp(); } void mitk::NavigationDataPlayer::StopPlaying() { m_CurPlayerState = PlayerStopped; // reset playing timestamps m_StartPlayingTimeStamp = 0; m_PauseTimeStamp = 0; } 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); + - (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; -} +} \ No newline at end of file diff --git a/Modules/IGT/IO/mitkNavigationDataPlayerBase.cpp b/Modules/IGT/IO/mitkNavigationDataPlayerBase.cpp index 3452bc0ce5..6bea38ce09 100644 --- a/Modules/IGT/IO/mitkNavigationDataPlayerBase.cpp +++ b/Modules/IGT/IO/mitkNavigationDataPlayerBase.cpp @@ -1,109 +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. ===================================================================*/ #include "mitkNavigationDataPlayerBase.h" // include for exceptions #include "mitkIGTException.h" mitk::NavigationDataPlayerBase::NavigationDataPlayerBase() - : m_NumberOfOutputs(0) { m_Name ="Navigation Data Player Source"; } mitk::NavigationDataPlayerBase::~NavigationDataPlayerBase() { } void mitk::NavigationDataPlayerBase::UpdateOutputInformation() { this->Modified(); // make sure that we need to be updated Superclass::UpdateOutputInformation(); } bool mitk::NavigationDataPlayerBase::IsAtEnd() { return m_NavigationDataSetIterator == m_NavigationDataSet->End(); } void mitk::NavigationDataPlayerBase::SetNavigationDataSet(NavigationDataSet::Pointer navigationDataSet) { m_NavigationDataSet = navigationDataSet; m_NavigationDataSetIterator = navigationDataSet->Begin(); this->InitPlayer(); } unsigned int mitk::NavigationDataPlayerBase::GetNumberOfSnapshots() { return m_NavigationDataSet.IsNull() ? 0 : m_NavigationDataSet->Size(); } unsigned int mitk::NavigationDataPlayerBase::GetCurrentSnapshotNumber() { return m_NavigationDataSet.IsNull() ? 0 : m_NavigationDataSetIterator - m_NavigationDataSet->Begin(); } void mitk::NavigationDataPlayerBase::InitPlayer() { if ( m_NavigationDataSet.IsNull() ) { mitkThrowException(mitk::IGTException) << "NavigationDataSet has to be set before initializing player."; } - if (m_NumberOfOutputs == 0) + if (GetNumberOfOutputs() == 0) { int requiredOutputs = m_NavigationDataSet->GetNumberOfTools(); this->SetNumberOfRequiredOutputs(requiredOutputs); for (unsigned int n = this->GetNumberOfOutputs(); n < requiredOutputs; ++n) { DataObjectPointer newOutput = this->MakeOutput(n); this->SetNthOutput(n, newOutput); this->Modified(); } } - else if (m_NumberOfOutputs != m_NavigationDataSet->GetNumberOfTools()) + else if (GetNumberOfOutputs() != m_NavigationDataSet->GetNumberOfTools()) { mitkThrowException(mitk::IGTException) << "Number of tools cannot be changed in existing player. Please create " << "a new player, if the NavigationDataSet has another number of tools now."; } this->Modified(); } void mitk::NavigationDataPlayerBase::GraftEmptyOutput() { for (unsigned int index = 0; index < m_NavigationDataSet->GetNumberOfTools(); index++) { mitk::NavigationData* output = this->GetOutput(index); assert(output); mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); mitk::NavigationData::PositionType position; mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0); position.Fill(0.0); nd->SetPosition(position); nd->SetOrientation(orientation); nd->SetDataValid(false); output->Graft(nd); } } \ No newline at end of file diff --git a/Modules/IGT/IO/mitkNavigationDataPlayerBase.h b/Modules/IGT/IO/mitkNavigationDataPlayerBase.h index 82b38abef6..afd127965e 100644 --- a/Modules/IGT/IO/mitkNavigationDataPlayerBase.h +++ b/Modules/IGT/IO/mitkNavigationDataPlayerBase.h @@ -1,106 +1,99 @@ /*=================================================================== 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 MITKNavigationDataPlayerBase_H_HEADER_INCLUDED_ #define MITKNavigationDataPlayerBase_H_HEADER_INCLUDED_ #include "mitkNavigationDataSource.h" #include "mitkNavigationDataSet.h" namespace mitk{ - /**Documentation - * \brief Base class for using mitk::NavigationData as a filter source. - * Subclasses can play objects of mitk::NavigationDataSet. - * - * \ingroup IGT - */ + * \brief Base class for using mitk::NavigationData as a filter source. + * Subclasses can play objects of mitk::NavigationDataSet. + * + * \ingroup IGT + */ class MitkIGT_EXPORT NavigationDataPlayerBase : public NavigationDataSource { public: mitkClassMacro(NavigationDataPlayerBase, NavigationDataSource); /** - * \brief Used for pipeline update just to tell the pipeline that we always have to update. - */ + * \brief Used for pipeline update just to tell the pipeline that we always have to update. + */ virtual void UpdateOutputInformation(); itkGetMacro(NavigationDataSet, NavigationDataSet::Pointer); /** - * \brief Set mitk::NavigationDataSet for playing. - * Player is initialized by call to mitk::NavigationDataPlayerBase::InitPlayer() - * inside this method. Method must be called before this object can be used as - * a filter source. - * - * @param navigationDataSet mitk::NavigationDataSet which will be played by this player. - */ + * \brief Set mitk::NavigationDataSet for playing. + * Player is initialized by call to mitk::NavigationDataPlayerBase::InitPlayer() + * inside this method. Method must be called before this object can be used as + * a filter source. + * + * @param navigationDataSet mitk::NavigationDataSet which will be played by this player. + */ void SetNavigationDataSet(NavigationDataSet::Pointer navigationDataSet); /** - * \brief Getter for the size of the mitk::NavigationDataSet used in this object. - * - * @return Returns the number of navigation data snapshots available in the player. - */ + * \brief Getter for the size of the mitk::NavigationDataSet used in this object. + * + * @return Returns the number of navigation data snapshots available in the player. + */ unsigned int GetNumberOfSnapshots(); unsigned int GetCurrentSnapshotNumber(); /** - * \brief This method checks if player arrived at end of file. - * - * @return true if last mitk::NavigationData object is in the outputs, false otherwise - */ + * \brief This method checks if player arrived at end of file. + * + * @return true if last mitk::NavigationData object is in the outputs, false otherwise + */ bool IsAtEnd(); protected: NavigationDataPlayerBase(); virtual ~NavigationDataPlayerBase(); /** - * \brief Every subclass hast to implement this method. See ITK filter documentation for details. - */ + * \brief Every subclass hast to implement this method. See ITK filter documentation for details. + */ virtual void GenerateData() = 0; /** - * \brief Initializes the outputs of this NavigationDataSource. - */ + * \brief Initializes the outputs of this NavigationDataSource. + */ void InitPlayer(); /** - * \brief Convenience method for subclasses. - * When there are no further mitk::NavigationData objects available, this - * method can be called in the implementation of mitk::NavigationDataPlayerBase::GenerateData(). - */ + * \brief Convenience method for subclasses. + * When there are no further mitk::NavigationData objects available, this + * method can be called in the implementation of mitk::NavigationDataPlayerBase::GenerateData(). + */ void GraftEmptyOutput(); NavigationDataSet::Pointer m_NavigationDataSet; /** - * \brief Iterator always points to the NavigationData object which is in the outputs at the moment. - */ + * \brief Iterator always points to the NavigationData object which is in the outputs at the moment. + */ mitk::NavigationDataSet::NavigationDataSetIterator m_NavigationDataSetIterator; - - /** - * \brief Stores the number of outputs known from NavigationDataSet. - */ - unsigned int m_NumberOfOutputs; }; } // namespace mitk #endif /* MITKNavigationDataSequentialPlayer_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp index 9a43dffa84..ee84291442 100644 --- a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp +++ b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp @@ -1,94 +1,94 @@ /*=================================================================== 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 "mitkNavigationDataSequentialPlayer.h" #include //for the pause #include #include //Exceptions #include "mitkIGTException.h" #include "mitkIGTIOException.h" mitk::NavigationDataSequentialPlayer::NavigationDataSequentialPlayer() : m_Repeat(false) { } mitk::NavigationDataSequentialPlayer::~NavigationDataSequentialPlayer() { } void mitk::NavigationDataSequentialPlayer::GoToSnapshot(unsigned int i) { if( !m_Repeat && (this->GetNumberOfSnapshots() <= i) ) { MITK_ERROR << "Snaphot " << i << " does not exist and repat is off: can't go to that snapshot!"; mitkThrowException(mitk::IGTException) << "Snapshot " << i << " does not exist and repat is off: can't go to that snapshot!"; } // set iterator to given position (modulo for allowing repeat) m_NavigationDataSetIterator = m_NavigationDataSet->Begin() + ( i % this->GetNumberOfSnapshots() ); // set outputs to selected snapshot this->GoToNextSnapshot(); } bool mitk::NavigationDataSequentialPlayer::GoToNextSnapshot() { if ( m_NavigationDataSetIterator == m_NavigationDataSet->End() ) { if ( m_Repeat ) { // set data back to start if repeat is enabled m_NavigationDataSetIterator = m_NavigationDataSet->Begin(); } else { return false; } } ++m_NavigationDataSetIterator; return true; } void mitk::NavigationDataSequentialPlayer::GenerateData() { if ( m_NavigationDataSetIterator == m_NavigationDataSet->End() ) { // no more data available this->GraftEmptyOutput(); } else { - for (unsigned int index = 0; index < m_NumberOfOutputs; index++) + 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)); } } } void mitk::NavigationDataSequentialPlayer::UpdateOutputInformation() { this->Modified(); // make sure that we need to be updated Superclass::UpdateOutputInformation(); } \ No newline at end of file