diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataSequentialPlayer.cpp b/Modules/IGT/IGTFilters/mitkNavigationDataSequentialPlayer.cpp index b6066c4223..3cdb0f0da0 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataSequentialPlayer.cpp +++ b/Modules/IGT/IGTFilters/mitkNavigationDataSequentialPlayer.cpp @@ -1,228 +1,227 @@ /*=================================================================== 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" -//for the pause -#include +#include //for the pause #include #include #include //Exceptions #include "mitkIGTException.h" #include "mitkIGTIOException.h" mitk::NavigationDataSequentialPlayer::NavigationDataSequentialPlayer() : mitk::NavigationDataPlayerBase() , m_Doc(new TiXmlDocument) , m_DataElem(0) , m_CurrentElem(0) , m_Repeat(false) , m_NumberOfSnapshots(0) , m_LastGoTo(0) { } mitk::NavigationDataSequentialPlayer::~NavigationDataSequentialPlayer() { delete m_Doc; } void mitk::NavigationDataSequentialPlayer::ReinitXML() { m_DataElem = m_Doc->FirstChildElement("Data"); int toolcount; if(!m_DataElem) { - //throwing an exception - mitkThrowException(mitk::IGTException) << "Data element not found"; MITK_WARN << "Data element not found"; + mitkThrowException(mitk::IGTException) << "Data element not found"; } else { m_DataElem->QueryIntAttribute("ToolCount", &toolcount); this->SetNumberOfOutputs(toolcount); mitk::NavigationData::Pointer emptyNd = mitk::NavigationData::New(); mitk::NavigationData::PositionType position; mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0); position.Fill(0.0); emptyNd->SetPosition(position); emptyNd->SetOrientation(orientation); emptyNd->SetDataValid(false); mitk::NavigationData::Pointer tmp; for (unsigned int index = 0; index < this->GetNumberOfOutputs(); index++) { tmp = mitk::NavigationData::New(); tmp->Graft(emptyNd); this->SetNthOutput(index, tmp); } // find out _NumberOfSnapshots m_NumberOfSnapshots = 0; TiXmlElement* nextND = m_DataElem->FirstChildElement("NavigationData"); while(nextND) { ++m_NumberOfSnapshots; nextND = nextND->NextSiblingElement("NavigationData"); } // e.g. 12 nd found and 2 tools used => number of snapshots is 12:2=6 m_NumberOfSnapshots = m_NumberOfSnapshots/toolcount; } } void mitk::NavigationDataSequentialPlayer::GoToSnapshot(int i) { + if(!m_Repeat && (this->GetNumberOfSnapshots() numOfUpdateCalls = 4 if(m_LastGoTo <= i) numOfUpdateCalls = i - m_LastGoTo; // goto(4), m_LastGoTo=7 => numOfUpdateCalls = 7 else { if(!m_Repeat) { - //throwing an exception - mitkThrowException(mitk::IGTException)<<"cannot go back to snapshot " << i << " because the " + std::stringstream message; + message <<"cannot go back to snapshot " << i << " because the " << this->GetNameOfClass() << " is configured to not repeat the" << " navigation data"; - - MITK_WARN << "cannot go back to snapshot " << i << " because the " - << this->GetNameOfClass() << " is configured to not repeat the" - << " navigation data"; - + MITK_WARN << message; + mitkThrowException(mitk::IGTException) << message; } else { numOfUpdateCalls = (m_NumberOfSnapshots - m_LastGoTo) + i; } } for(int j=0; jUpdate(); m_LastGoTo = i; } void mitk::NavigationDataSequentialPlayer:: SetFileName(const std::string& _FileName) { m_FileName = _FileName; - // if Loading wasnt succesfull - // (!m_Doc->LoadFile(m_FileName)=false) wherase (m_Doc->LoadFile(m_FileName)=true) - + if(!m_Doc->LoadFile(m_FileName)) { this->SetNumberOfOutputs(0); std::ostringstream s; s << "File " << _FileName << " could not be loaded"; - //may be we need to change to mitk::exception mitkThrowException(mitk::IGTIOException)<ReinitXML(); + } this->Modified(); } -//NEW PART is ADDED void mitk::NavigationDataSequentialPlayer:: SetXMLString(const std::string& _XMLString) { m_XMLString = _XMLString; if((m_Doc->Parse( m_XMLString.c_str()))== NULL) { - this->ReinitXML(); - } else + this->ReinitXML(); + } + else { //if the string is not an XML string - std::ostringstream s; - s << "String" << _XMLString << " is not an XML string"; - mitkThrowException(mitk::IGTIOException)<Modified(); } void mitk::NavigationDataSequentialPlayer::GenerateData() { assert(m_DataElem); // very important: go through the tools (there could be more than one) mitk::NavigationData::Pointer tmp; - //MITK_INFO << "this->GetNumberOfOutputs()" << this->GetNumberOfOutputs(); + for (unsigned int index = 0; index < this->GetNumberOfOutputs(); index++) { - //MITK_INFO << "index" << index; // go to the first element if(!m_CurrentElem) m_CurrentElem = m_DataElem->FirstChildElement("NavigationData"); // go to the next element else + { m_CurrentElem = m_CurrentElem->NextSiblingElement(); + } // if repeat is on: go back to the first element (prior calls delivered NULL // elem) if(!m_CurrentElem && m_Repeat) m_CurrentElem = m_DataElem->FirstChildElement("NavigationData"); mitk::NavigationData* output = this->GetOutput(index); tmp = this->ReadVersion1(); if(tmp.IsNotNull()) { output->Graft(tmp); m_StreamValid = true; } else // no valid output { output->SetDataValid(false); m_StreamValid = false; - //throwing exception - mitkThrowException(mitk::IGTException)<<"Error: Cannot parse input file."; - //m_ErrorMessage = "Error: Cannot parse input file."; + + m_ErrorMessage = "Error: Cannot parse input file."; + mitkThrowException(mitk::IGTException)<ReadNavigationData(elem); } void mitk::NavigationDataSequentialPlayer::UpdateOutputInformation() { this->Modified(); // make sure that we need to be updated Superclass::UpdateOutputInformation(); } diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataSequentialPlayer.h b/Modules/IGT/IGTFilters/mitkNavigationDataSequentialPlayer.h index 5c0fbf50c6..d99e842e7f 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataSequentialPlayer.h +++ b/Modules/IGT/IGTFilters/mitkNavigationDataSequentialPlayer.h @@ -1,117 +1,122 @@ /*=================================================================== 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 #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 NavigationDataSequentialPlayer : public NavigationDataPlayerBase { public: mitkClassMacro(NavigationDataSequentialPlayer, NavigationDataPlayerBase); itkNewMacro(Self); /** - * \brief sets the file name and path (if XMLString is set, this is neglected) - * @throws Throws an exception if the given file cannot be loaded - */ + * \brief sets the file name and path (if XMLString is set, this is neglected) + * @throw mitk::IGTIOException Throws an exception if the given file cannot be loaded. + */ void SetFileName(const std::string& _FileName); /** * \brief returns the file name and path */ itkGetStringMacro(FileName); /** * \brief sets a xml string (by this, the xml string is not read from file) - * @throws Throws an mitk::IGT excepton if the string to set is not an XMLString + * @throw mitk::IGTExcepton Throws an mitk::IGTExcepton if the string to set is not an XMLString */ void SetXMLString(const std::string& _XMLString); /** * \brief returns the current xml string */ itkGetStringMacro(XMLString); - /// - /// set to true if the data player should repeat the outputs - /// + /** + * @brief Set to true if the data player should repeat the outputs. + */ itkSetMacro(Repeat, bool); - /// - /// set if the data player should repeat the outputs - /// + + /** + * @return Returns if the data player should repeat the outputs. + */ itkGetMacro(Repeat, bool); - /// - /// \return the number of navigation data snapshots available in the file - /// + + /** + * @return Returns the number of navigation data snapshots available in the file + */ itkGetMacro(NumberOfSnapshots, unsigned int); - /// - /// advance the output to the i-th snapshot - /// e.g. if you want to have the NavData of snapshot - /// 17 then you can call GoToSnapshot(17). index begins at 1! - /// you can then also go back to snapshot 1 with GoToSnapshot(1) - /// - //@throws Throws an exception if cannot go back to particular snapshot + /** + * advance the output to the i-th snapshot + * e.g. if you want to have the NavData of snapshot + * 17 then you can call GoToSnapshot(17). index begins at 1! + * you can then also go back to snapshot 1 with GoToSnapshot(1) + * + * @throw mitk::IGTException Throws an exception if cannot go back to particular snapshot. + */ void GoToSnapshot(int i); /** * \brief Used for pipeline update just to tell the pipeline * that we always have to update */ virtual void UpdateOutputInformation(); protected: NavigationDataSequentialPlayer(); virtual ~NavigationDataSequentialPlayer(); - //@throws Throws an exception if data element is not found + + /** + * @throw mitk::IGTException Throws an exception if data element is not found. + */ void ReinitXML(); + mitk::NavigationData::Pointer ReadVersion1(); - /// - /// do the work here - /// - /* - *@throws Throws an exception if cannot parse input file - */ + + /** + * @throw mitk::IGTException Throws an exception if cannot parse input file + */ virtual void GenerateData(); std::string m_FileName; std::string m_XMLString; TiXmlDocument* m_Doc; TiXmlElement* m_DataElem; TiXmlElement* m_CurrentElem; bool m_Repeat; unsigned int m_NumberOfSnapshots; int m_LastGoTo; }; } // namespace mitk #endif /* MITKNavigationDataSequentialPlayer_H_HEADER_INCLUDED_ */