Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkNavigationDataSet.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #include "mitkNavigationDataSet.h"
18 
19 mitk::NavigationDataSet::NavigationDataSet( unsigned int numberOfTools )
20  : m_NavigationDataVectors(std::vector<std::vector<mitk::NavigationData::Pointer> >()), m_NumberOfTools(numberOfTools)
21 {
22 }
23 
25 {
26 }
27 
28 bool mitk::NavigationDataSet::AddNavigationDatas( std::vector<mitk::NavigationData::Pointer> navigationDatas )
29 {
30  // test if tool with given index exist
31  if ( navigationDatas.size() != m_NumberOfTools )
32  {
33  MITK_WARN("NavigationDataSet") << "Tried to add too many or too few navigation Datas to NavigationDataSet. " << m_NumberOfTools << " required, tried to add " << navigationDatas.size() << ".";
34  return false;
35  }
36 
37  // test for consistent timestamp
38  if ( m_NavigationDataVectors.size() > 0)
39  {
40  for (std::vector<mitk::NavigationData::Pointer>::size_type i = 0; i < navigationDatas.size(); i++)
41  if (navigationDatas[i]->GetIGTTimeStamp() <= m_NavigationDataVectors.back()[i]->GetIGTTimeStamp())
42  {
43  MITK_WARN("NavigationDataSet") << "IGTTimeStamp of new NavigationData should be newer than timestamp of last NavigationData.";
44  return false;
45  }
46  }
47 
48  m_NavigationDataVectors.push_back(navigationDatas);
49  return true;
50 }
51 
52 mitk::NavigationData::Pointer mitk::NavigationDataSet::GetNavigationDataForIndex( unsigned int index, unsigned int toolIndex ) const
53 {
54  if ( index >= m_NavigationDataVectors.size() )
55  {
56  MITK_WARN("NavigationDataSet") << "There is no NavigationData available at index " << index << ".";
57  return nullptr;
58  }
59 
60  if ( toolIndex >= m_NavigationDataVectors.at(index).size() )
61  {
62  MITK_WARN("NavigationDataSet") << "There is NavigatitionData available at index " << index << " for tool " << toolIndex << ".";
63  return nullptr;
64  }
65 
66  return m_NavigationDataVectors.at(index).at(toolIndex);
67 }
68 
69 // Method not yet supported, code below compiles but delivers wrong results
70 //mitk::NavigationData::Pointer mitk::NavigationDataSet::GetNavigationDataBeforeTimestamp(
71 // mitk::NavigationData::TimeStampType timestamp, unsigned int toolIndex) const
72 //{
73 // if ( toolIndex >= m_NavigationDataVectors.size() )
74 // {
75 // MITK_WARN("NavigationDataSet") << "There is no tool with index " << toolIndex << ".";
76 // return NULL;
77 // }
78 //
79 // std::vector<mitk::NavigationData::Pointer>::const_iterator it;
80 //
81 // // iterate through all NavigationData objects of the given tool index
82 // // till the timestamp of the NavigationData is greater then the given timestamp
83 // for (it = m_NavigationDataVectors.at(toolIndex).begin();
84 // it != m_NavigationDataVectors.at(toolIndex).end(); ++it)
85 // {
86 // if ( (*it)->GetIGTTimeStamp() > timestamp) { break; }
87 // }
88 //
89 // // first element was greater than timestamp -> return null
90 // if ( it == m_NavigationDataVectors.at(toolIndex).begin() )
91 // {
92 // MITK_WARN("NavigationDataSet") << "No NavigationData was recorded before given timestamp.";
93 // return NULL;
94 // }
95 //
96 // // return last element smaller than the given timestamp
97 // return *(it-1);
98 //}
99 
100 std::vector< mitk::NavigationData::Pointer > mitk::NavigationDataSet::GetDataStreamForTool(unsigned int toolIndex)
101 {
102  if (toolIndex >= m_NumberOfTools )
103  {
104  MITK_WARN("NavigationDataSet") << "Invalid toolIndex: " << m_NumberOfTools << " Tools known, requested index " << toolIndex << "";
105  return std::vector<mitk::NavigationData::Pointer>();
106  }
107 
108  std::vector< mitk::NavigationData::Pointer > result;
109 
110  for(std::vector<std::vector<NavigationData::Pointer> >::size_type i = 0; i < m_NavigationDataVectors.size(); i++)
111  result.push_back(m_NavigationDataVectors[i][toolIndex]);
112 
113  return result;
114 }
115 
116 std::vector< mitk::NavigationData::Pointer > mitk::NavigationDataSet::GetTimeStep(unsigned int index) const
117 {
118  return m_NavigationDataVectors[index];
119 }
120 
122 {
123  return m_NumberOfTools;
124 }
125 
126 unsigned int mitk::NavigationDataSet::Size() const
127 {
128  return m_NavigationDataVectors.size();
129 }
130 
131 // ---> methods necessary for BaseData
133 {
134 }
135 
137 {
138  return false;
139 }
140 
142 {
143  return true;
144 }
145 
147 {
148 }
149 
151 {
152  return (Size() == 0);
153 }
154 
155 // <--- methods necessary for BaseData
156 
157 // ---> methods for Iterators
158 
160 {
161  return m_NavigationDataVectors.cbegin();
162 }
163 
165 {
166  return m_NavigationDataVectors.cend();
167 }
itk::SmartPointer< Self > Pointer
NavigationData::Pointer GetNavigationDataForIndex(unsigned int index, unsigned int toolIndex) const
Get mitk::NavigationData from the given tool at given index.
virtual void SetRequestedRegion(const itk::DataObject *data) override
Set the requested region from this data object to match the requested region of the data object passe...
Navigation Data.
unsigned int Size() const
Returns the number of time steps stored in this NavigationDataSet.
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
virtual bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
virtual NavigationDataSetConstIterator Begin() const
Returns an iterator pointing to the first TimeStep.
#define MITK_WARN
Definition: mitkLogMacros.h:23
virtual void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
virtual NavigationDataSetConstIterator End() const
Returns an iterator pointing behind to the last TimeStep.
virtual bool IsEmpty() const override
This overrid is probably a little hacky. See Bug 19086.
virtual std::vector< mitk::NavigationData::Pointer > GetTimeStep(unsigned int index) const
Returns a vector that contains NavigationDatas for each tool for a given timestep.
unsigned int GetNumberOfTools() const
Returns the number of tools for which NavigationDatas are stored in this set.
bool AddNavigationDatas(std::vector< mitk::NavigationData::Pointer > navigationDatas)
Add mitk::NavigationData of the given tool to the Set.
virtual std::vector< mitk::NavigationData::Pointer > GetDataStreamForTool(unsigned int toolIndex)
Get last mitk::Navigation object for given tool whose timestamp is less than the given timestamp...
std::vector< std::vector< mitk::NavigationData::Pointer > >::const_iterator NavigationDataSetConstIterator
This iterator iterates over the distinct time steps in this set. And is const.
NavigationDataSet(unsigned int numTools)
Constructs set with fixed number of tools.
virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.