diff --git a/Modules/IGT/IO/mitkNavigationDataPlayerBase.cpp b/Modules/IGT/IO/mitkNavigationDataPlayerBase.cpp index b03e87c271..f62b6e171a 100644 --- a/Modules/IGT/IO/mitkNavigationDataPlayerBase.cpp +++ b/Modules/IGT/IO/mitkNavigationDataPlayerBase.cpp @@ -1,109 +1,110 @@ /*=================================================================== 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_Repeat(false) { - m_Name ="Navigation Data Player Source"; + this->SetName("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 (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 (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(); this->GenerateData(); } 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 d3a8af503d..8f526de99b 100644 --- a/Modules/IGT/IO/mitkNavigationDataPlayerBase.h +++ b/Modules/IGT/IO/mitkNavigationDataPlayerBase.h @@ -1,100 +1,118 @@ /*=================================================================== 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. * + * Each subclass has to check the state of m_Repeat and do or do not repeat + * the playing accordingly. + * * \ingroup IGT */ class MitkIGT_EXPORT NavigationDataPlayerBase : public NavigationDataSource { public: - mitkClassMacro(NavigationDataPlayerBase, NavigationDataSource); + mitkClassMacro(NavigationDataPlayerBase, NavigationDataSource) + + /** + * \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 Used for pipeline update just to tell the pipeline that we always have to update. */ virtual void UpdateOutputInformation(); - itkGetMacro(NavigationDataSet, NavigationDataSet::Pointer); + 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. */ 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. */ 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 */ bool IsAtEnd(); protected: NavigationDataPlayerBase(); virtual ~NavigationDataPlayerBase(); /** * \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. * Aftwer calling this method, the first Navigationdata from the loaded Navigationdataset is loaded into the outputs. */ 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(). */ void GraftEmptyOutput(); + /** + * \brief If the player should repeat outputs. Default is false. + */ + bool m_Repeat; + NavigationDataSet::Pointer m_NavigationDataSet; /** * \brief Iterator always points to the NavigationData object which is in the outputs at the moment. */ mitk::NavigationDataSet::NavigationDataSetIterator m_NavigationDataSetIterator; }; } // namespace mitk #endif /* MITKNavigationDataSequentialPlayer_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp index 5985d2b35f..4030687417 100644 --- a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp +++ b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.cpp @@ -1,98 +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 "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->GenerateData(); } bool mitk::NavigationDataSequentialPlayer::GoToNextSnapshot() { if (m_NavigationDataSetIterator == m_NavigationDataSet->End()) { MITK_WARN("NavigationDataSequentialPlayer") << "Cannot go to next snapshot, already at end of NavigationDataset. Ignoring..."; return false; } ++m_NavigationDataSetIterator; 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; } } this->GenerateData(); 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 < 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 +} diff --git a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.h b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.h index 42f0492942..fea196e200 100644 --- a/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.h +++ b/Modules/IGT/IO/mitkNavigationDataSequentialPlayer.h @@ -1,94 +1,79 @@ /*=================================================================== 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. * This method internally calls GenerateData, so outputs are refreshed automatically * * 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 Advance the output to the next snapshot of mitk::NavigationData. * Filter output is updated inside the function. * * \return false if no next snapshot is available (happens only if m_Repeat is set to false). * @throw mitk::IGTException Throws an exception if an output is null. */ bool GoToNextSnapshot(); /** * \brief Used for pipeline update just to tell the pipeline * that we always have to update */ virtual void UpdateOutputInformation(); protected: NavigationDataSequentialPlayer(); virtual ~NavigationDataSequentialPlayer(); /** * \brief Does nothing. * mitk::NavigationDataSequentialPlayer::GoToNextSnapshot() should be called * for generating next data. */ virtual void GenerateData(); - - /** - * \brief If the player should repeat outputs. Default is false. - */ - bool m_Repeat; }; } // namespace mitk #endif /* MITKNavigationDataSequentialPlayer_H_HEADER_INCLUDED_ */