diff --git a/Modules/IGT/IO/mitkNavigationDataPlayer.h b/Modules/IGT/IO/mitkNavigationDataPlayer.h index 526544a59d..0b8ce97ec6 100644 --- a/Modules/IGT/IO/mitkNavigationDataPlayer.h +++ b/Modules/IGT/IO/mitkNavigationDataPlayer.h @@ -1,109 +1,109 @@ /*=================================================================== 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. * * 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. * * * \ingroup IGT */ class MitkIGT_EXPORT NavigationDataPlayer : public NavigationDataPlayerBase { public: mitkClassMacro(NavigationDataPlayer, NavigationDataPlayerBase); itkNewMacro(Self); /** * \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. */ 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 */ void StopPlaying(); /** * \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. */ void Resume(); /** * \brief This method checks if player arrived at end of file. * */ - bool IsAtEnd(); + virtual bool IsAtEnd(); protected: NavigationDataPlayer(); virtual ~NavigationDataPlayer(); /** * \brief Set outputs to the navigation data object corresponding to current time. */ virtual void GenerateData(); enum PlayerState { PlayerStopped, PlayerRunning, PlayerPaused }; PlayerState m_CurPlayerState; typedef mitk::NavigationData::TimeStampType TimeStampType; /** * \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. */ TimeStampType m_PauseTimeStamp; }; } // namespace mitk #endif /* MITKNavigationDataPlayer_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/IO/mitkNavigationDataPlayerBase.h b/Modules/IGT/IO/mitkNavigationDataPlayerBase.h index df24137d67..edff7742b8 100644 --- a/Modules/IGT/IO/mitkNavigationDataPlayerBase.h +++ b/Modules/IGT/IO/mitkNavigationDataPlayerBase.h @@ -1,83 +1,89 @@ /*=================================================================== 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 #include "mitkNavigationDataReaderInterface.h" #include "tinyxml.h" namespace mitk{ /**Documentation * \brief This class is a slightly changed reimplementation of the * NavigationDataPlayer which does not care about timestamps and just * outputs the navigationdatas in their sequential order * * \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 */ virtual void UpdateOutputInformation(); itkGetMacro(NavigationDataSet, NavigationDataSet::Pointer); void SetNavigationDataSet(NavigationDataSet::Pointer navigationDataSet); /** * @return Returns the number of navigation data snapshots available in the player */ unsigned int GetNumberOfSnapshots(); + /** + * \brief This method checks if player arrived at end of file. + * + */ + virtual bool IsAtEnd() = 0; + protected: NavigationDataPlayerBase(); virtual ~NavigationDataPlayerBase(); virtual void GenerateData() = 0; /** * \brief Initializes the outputs of this NavigationDataSource. */ void InitPlayer(); /** * */ void GraftEmptyOutput(); NavigationDataSet::Pointer m_NavigationDataSet; mitk::NavigationDataSet::NavigationDataSetIterator m_NavigationDataSetIterator; unsigned int m_NumberOfOutputs; ///< stores the number of outputs known from NavigationDataSet /** * \brief Creates NavigationData from XML element and returns it * @throw mitk::Exception Throws an exception if elem is NULL. */ mitk::NavigationData::Pointer ReadNavigationData(TiXmlElement* elem); }; } // namespace mitk #endif /* MITKNavigationDataSequentialPlayer_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp index 918a3b5a46..df72011dc1 100644 --- a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp +++ b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp @@ -1,84 +1,89 @@ /*=================================================================== 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->Update(); } void mitk::NavigationDataSequentialPlayer::GenerateData() { if ( m_NavigationDataSetIterator == m_NavigationDataSet->End() ) { if ( m_Repeat ) { // set data back to start if repeat is enabled m_NavigationDataSetIterator = m_NavigationDataSet->Begin(); } else { // no more data available this->GraftEmptyOutput(); return; } } for (unsigned int index = 0; index < m_NumberOfOutputs; index++) { mitk::NavigationData* output = this->GetOutput(index); if( !output ) { mitkThrowException(mitk::IGTException) << "Output of index "<Graft(m_NavigationDataSetIterator->at(index)); } ++m_NavigationDataSetIterator; } void mitk::NavigationDataSequentialPlayer::UpdateOutputInformation() { this->Modified(); // make sure that we need to be updated Superclass::UpdateOutputInformation(); } + +bool mitk::NavigationDataSequentialPlayer::IsAtEnd() +{ + return m_NavigationDataSetIterator == m_NavigationDataSet->End(); +} diff --git a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.h b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.h index 20df2d8776..f9360e83ec 100644 --- a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.h +++ b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.h @@ -1,82 +1,88 @@ /*=================================================================== 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 MITKNavigationDataSequentialPlayer_H_HEADER_INCLUDED_ #define MITKNavigationDataSequentialPlayer_H_HEADER_INCLUDED_ #include namespace mitk { /**Documentation * \brief This class is a slightly changed reimplementation of the * NavigationDataPlayer which does not care about timestamps and just * outputs the navigationdatas in their sequential order * * \ingroup IGT */ class MitkIGT_EXPORT NavigationDataSequentialPlayer : public NavigationDataPlayerBase { public: mitkClassMacro(NavigationDataSequentialPlayer, NavigationDataPlayerBase); itkNewMacro(Self); /** * \brief Set to true if the data player should repeat the outputs. */ itkSetMacro(Repeat, bool); /** * \return Returns if the data player should repeat the outputs. */ itkGetMacro(Repeat, bool); /** * \brief Advance the output to the i-th snapshot of mitk::NavigationData. * E.g. if you want to have the NavData of snapshot * 18 then you can call GoToSnapshot(17). Index begins at 0. * You can only go back if m_Repeat is set true. * * Filter output is updated inside the function. * * @throw mitk::IGTException Throws an exception if cannot go back to particular snapshot. */ void GoToSnapshot(unsigned int i); /** * \brief Used for pipeline update just to tell the pipeline * that we always have to update */ virtual void UpdateOutputInformation(); + /** + * \brief This method checks if player arrived at end of file. + * + */ + virtual bool IsAtEnd(); + protected: NavigationDataSequentialPlayer(); virtual ~NavigationDataSequentialPlayer(); /** * * @throw mitk::IGTException Throws an exception if an output is null. */ virtual void GenerateData(); bool m_Repeat; }; } // namespace mitk #endif /* MITKNavigationDataSequentialPlayer_H_HEADER_INCLUDED_ */