diff --git a/Modules/IGT/DataManagement/mitkNavigationDataSet.cpp b/Modules/IGT/DataManagement/mitkNavigationDataSet.cpp index d37cd3b69b..ea695108e4 100644 --- a/Modules/IGT/DataManagement/mitkNavigationDataSet.cpp +++ b/Modules/IGT/DataManagement/mitkNavigationDataSet.cpp @@ -1,160 +1,161 @@ /*=================================================================== 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 "mitkNavigationDataSet.h" mitk::NavigationDataSet::NavigationDataSet( unsigned int numberOfTools ) : m_NavigationDataVectors(std::vector >()), m_NumberOfTools(numberOfTools) { } mitk::NavigationDataSet::~NavigationDataSet( ) { } bool mitk::NavigationDataSet::AddNavigationDatas( std::vector navigationDatas ) { // test if tool with given index exist if ( navigationDatas.size() != m_NumberOfTools ) { MITK_WARN("NavigationDataSet") << "Tried to add to many or too few navigation Datas to NavigationDataSet. " << m_NavigationDataVectors.size() << " required, tried to add " << navigationDatas.size() << "."; return false; } // test for consistent timestamp if ( m_NavigationDataVectors.size() > 0) { for (int i = 0; i < navigationDatas.size(); i++) - if (navigationDatas[i]->GetIGTTimeStamp() <= (*(m_NavigationDataVectors[i].end()-1))->GetIGTTimeStamp()) + if (navigationDatas[i]->GetIGTTimeStamp() <= m_NavigationDataVectors.back()[i]->GetIGTTimeStamp()) { MITK_WARN("NavigationDataSet") << "IGTTimeStamp of new NavigationData should be newer then timestamp of last NavigationData."; return false; } } m_NavigationDataVectors.push_back(navigationDatas); return true; } mitk::NavigationData::Pointer mitk::NavigationDataSet::GetNavigationDataForIndex( unsigned int index, unsigned int toolIndex ) const { if ( index >= m_NavigationDataVectors.size() ) { MITK_WARN("NavigationDataSet") << "There is no NavigationData available at index " << index << "."; return NULL; } if ( toolIndex >= m_NavigationDataVectors.at(index).size() ) { MITK_WARN("NavigationDataSet") << "There is NavigatitionData available at index " << index << " for tool " << toolIndex << "."; return NULL; } return m_NavigationDataVectors.at(toolIndex).at(index); } -mitk::NavigationData::Pointer mitk::NavigationDataSet::GetNavigationDataBeforeTimestamp( - mitk::NavigationData::TimeStampType timestamp, unsigned int toolIndex) const -{ - if ( toolIndex >= m_NavigationDataVectors.size() ) - { - MITK_WARN("NavigationDataSet") << "There is no tool with index " << toolIndex << "."; - return NULL; - } - - std::vector::const_iterator it; - - // iterate through all NavigationData objects of the given tool index - // till the timestamp of the NavigationData is greater then the given timestamp - for (it = m_NavigationDataVectors.at(toolIndex).begin(); - it != m_NavigationDataVectors.at(toolIndex).end(); ++it) - { - if ( (*it)->GetIGTTimeStamp() > timestamp) { break; } - } - - // first element was greater than timestamp -> return null - if ( it == m_NavigationDataVectors.at(toolIndex).begin() ) - { - MITK_WARN("NavigationDataSet") << "No NavigationData was recorded before given timestamp."; - return NULL; - } - - // return last element smaller than the given timestamp - return *(it-1); -} +// Method not yet supported, code below compiles but delivers wrong results +//mitk::NavigationData::Pointer mitk::NavigationDataSet::GetNavigationDataBeforeTimestamp( +// mitk::NavigationData::TimeStampType timestamp, unsigned int toolIndex) const +//{ +// if ( toolIndex >= m_NavigationDataVectors.size() ) +// { +// MITK_WARN("NavigationDataSet") << "There is no tool with index " << toolIndex << "."; +// return NULL; +// } +// +// std::vector::const_iterator it; +// +// // iterate through all NavigationData objects of the given tool index +// // till the timestamp of the NavigationData is greater then the given timestamp +// for (it = m_NavigationDataVectors.at(toolIndex).begin(); +// it != m_NavigationDataVectors.at(toolIndex).end(); ++it) +// { +// if ( (*it)->GetIGTTimeStamp() > timestamp) { break; } +// } +// +// // first element was greater than timestamp -> return null +// if ( it == m_NavigationDataVectors.at(toolIndex).begin() ) +// { +// MITK_WARN("NavigationDataSet") << "No NavigationData was recorded before given timestamp."; +// return NULL; +// } +// +// // return last element smaller than the given timestamp +// return *(it-1); +//} unsigned int mitk::NavigationDataSet::GetNumberOfTools() { return m_NavigationDataVectors.size(); } unsigned int mitk::NavigationDataSet::GetNumberOfNavigationDatas(bool check) { if (this->GetNumberOfTools() == 0) { return 0; }; unsigned int number = m_NavigationDataVectors.at(0).size();; if (check) { for (std::vector >::iterator it = m_NavigationDataVectors.begin()+1; it != m_NavigationDataVectors.end(); ++it) { if (it->size() != number) { MITK_WARN << "Number of NavigationData objects differs for different tools."; return -1; } } } return number; } // ---> methods necessary for BaseData void mitk::NavigationDataSet::SetRequestedRegionToLargestPossibleRegion() { } bool mitk::NavigationDataSet::RequestedRegionIsOutsideOfTheBufferedRegion() { return false; } bool mitk::NavigationDataSet::VerifyRequestedRegion() { return true; } void mitk::NavigationDataSet::SetRequestedRegion(const DataObject * ) { } // <--- methods necessary for BaseData // ---> methods for Iterators mitk::NavigationDataSet::NavigationDataSetIterator mitk::NavigationDataSet::Begin() { //TODO default implementation mitk::NavigationDataSet::NavigationDataSetIterator result; return result; } mitk::NavigationDataSet::NavigationDataSetIterator mitk::NavigationDataSet::End() { //TODO default implementation mitk::NavigationDataSet::NavigationDataSetIterator result; return result; } diff --git a/Modules/IGT/DataManagement/mitkNavigationDataSet.h b/Modules/IGT/DataManagement/mitkNavigationDataSet.h index aae188be49..21c9e6287c 100644 --- a/Modules/IGT/DataManagement/mitkNavigationDataSet.h +++ b/Modules/IGT/DataManagement/mitkNavigationDataSet.h @@ -1,102 +1,103 @@ /*=================================================================== 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 MITKNAVIGATIONDATASET_H_HEADER_INCLUDED_ #define MITKNAVIGATIONDATASET_H_HEADER_INCLUDED_ #include #include "mitkBaseData.h" #include "mitkNavigationData.h" namespace mitk { /** * \brief Data structure which stores sets of mitk::NavigationData for * multiple tools. * * */ class MitkIGT_EXPORT NavigationDataSet : public BaseData { public: typedef std::vector< std::vector >::iterator NavigationDataSetIterator; mitkClassMacro(NavigationDataSet, BaseData); mitkNewMacro1Param(Self, unsigned int); /** * \brief Add mitk::NavigationData of the given tool to the Set. * * @param toolIndex Index of the tool for which mitk::NavigationData should be added. * @param navigationData mitk::NavigationData object to be added. * @return true if object could be added to the set, false otherwise (e.g. tool with given index not existing) */ bool AddNavigationDatas( std::vector navigationDatas ); /** * \brief Get mitk::NavigationData from the given tool at given index. * * @param toolIndex Index of the tool from which mitk::NavigationData should be returned. * @param index Index of the mitk::NavigationData object that should be returned. * @return mitk::NavigationData at the specified indices, 0 if there is no object at the indices. */ NavigationData::Pointer GetNavigationDataForIndex( unsigned int index, unsigned int toolIndex ) const; /** * \brief Get last mitk::Navigation object for given tool whose timestamp is less than the given timestamp. * @param toolIndex Index of the tool from which mitk::NavigationData should be returned. * @param timestamp Timestamp for selecting last object before. * @return Last mitk::NavigationData with timestamp less than given timestamp, 0 if there is no adequate object. */ - NavigationData::Pointer GetNavigationDataBeforeTimestamp( mitk::NavigationData::TimeStampType timestamp , unsigned int toolIndex ) const; + // Method not yet supported + //NavigationData::Pointer GetNavigationDataBeforeTimestamp( mitk::NavigationData::TimeStampType timestamp , unsigned int toolIndex ) const; unsigned int GetNumberOfTools(); unsigned int GetNumberOfNavigationDatas(bool check = true); virtual NavigationDataSetIterator Begin(); virtual NavigationDataSetIterator End(); // virtual methods, that need to be implemented, but aren't reasonable for NavigationData virtual void SetRequestedRegionToLargestPossibleRegion( ); virtual bool RequestedRegionIsOutsideOfTheBufferedRegion( ); virtual bool VerifyRequestedRegion( ); virtual void SetRequestedRegion( const itk::DataObject *data ); protected: /** * \brief Constructs set with fixed number of tools. * @param numTools How many tools are used with this mitk::NavigationDataSet. */ NavigationDataSet( unsigned int numTools ); virtual ~NavigationDataSet( ); /** * \brief Holds all the mitk::NavigationData objects managed by this class. * * The first dimension is the index of the navigation data, the second is the * tool to which this data belongs. i.e. the first dimension is usually the longer one. */ std::vector > m_NavigationDataVectors; /** * \brief The Number of Tools that this class is going to support. */ int m_NumberOfTools; }; } #endif // MITKNAVIGATIONDATASET_H_HEADER_INCLUDED_ diff --git a/Modules/IGT/Testing/mitkNavigationDataSetTest.cpp b/Modules/IGT/Testing/mitkNavigationDataSetTest.cpp index 316947afd6..7ff178e5ec 100644 --- a/Modules/IGT/Testing/mitkNavigationDataSetTest.cpp +++ b/Modules/IGT/Testing/mitkNavigationDataSetTest.cpp @@ -1,92 +1,87 @@ /*=================================================================== 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 "mitkTestingMacros.h" #include "mitkNavigationData.h" #include "mitkNavigationDataSet.h" static void TestEmptySet() { mitk::NavigationDataSet::Pointer navigationDataSet = mitk::NavigationDataSet::New(1); MITK_TEST_CONDITION_REQUIRED(! navigationDataSet->GetNavigationDataForIndex(0,0) , "Trying to get non-existant NavigationData by index should return false."); - MITK_TEST_CONDITION_REQUIRED(! navigationDataSet->GetNavigationDataBeforeTimestamp(0, 100), "Trying to get non-existant NavigationData by timestamp should return false.") + //MITK_TEST_CONDITION_REQUIRED(! navigationDataSet->GetNavigationDataBeforeTimestamp(0, 100), "Trying to get non-existant NavigationData by timestamp should return false.") } static void TestSetAndGet() { mitk::NavigationDataSet::Pointer navigationDataSet = mitk::NavigationDataSet::New(2); mitk::NavigationData::Pointer nd11 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd12 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd13 = mitk::NavigationData::New(); nd12->SetIGTTimeStamp(1); nd12->SetIGTTimeStamp(2); mitk::NavigationData::Pointer nd21 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd22 = mitk::NavigationData::New(); mitk::NavigationData::Pointer nd23 = mitk::NavigationData::New(); nd22->SetIGTTimeStamp(1); // First set, Timestamp = 0 std::vector step1; step1.push_back(nd11); step1.push_back(nd21); // Second set, Timestamp = 1 std::vector step2; step2.push_back(nd12); step2.push_back(nd22); //Third set, Timestamp invalid () std::vector step3; step3.push_back(nd13); step3.push_back(nd23); MITK_TEST_CONDITION_REQUIRED(navigationDataSet->AddNavigationDatas(step1), "Adding a valid first set, should be successful."); MITK_TEST_CONDITION_REQUIRED(navigationDataSet->AddNavigationDatas(step2), "Adding a valid second set, should be successful."); MITK_TEST_CONDITION_REQUIRED(!(navigationDataSet->AddNavigationDatas(step3)), "Adding an invalid third set, should be unsusuccessful."); MITK_TEST_CONDITION_REQUIRED(navigationDataSet->GetNavigationDataForIndex(0, 0) == nd11, "First NavigationData object for tool 0 should be the same as added previously."); MITK_TEST_CONDITION_REQUIRED(navigationDataSet->GetNavigationDataForIndex(0, 1) == nd12, "Second NavigationData object for tool 0 should be the same as added previously."); MITK_TEST_CONDITION_REQUIRED(navigationDataSet->GetNavigationDataForIndex(1, 0) == nd21, "First NavigationData object for tool 0 should be the same as added previously."); MITK_TEST_CONDITION_REQUIRED(navigationDataSet->GetNavigationDataForIndex(1, 1) == nd22, "Second NavigationData object for tool 0 should be the same as added previously."); - - MITK_TEST_CONDITION_REQUIRED(navigationDataSet->GetNavigationDataBeforeTimestamp(0, 1.5) == nd11, - "First navigation data object should be returned when timestamp '2' is given."); - MITK_TEST_CONDITION_REQUIRED(navigationDataSet->GetNavigationDataBeforeTimestamp(0, 2.5) == nd12, - "Second navigation data object should be returned when timestamp '3.5' is given."); } /** * */ int mitkNavigationDataSetTest(int /* argc */, char* /*argv*/[]) { MITK_TEST_BEGIN("NavigationDataSet"); TestEmptySet(); TestSetAndGet(); MITK_TEST_END(); }