Medical Imaging Interaction Toolkit  2018.4.99-4c24e3cb
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkNavigationDataSet.h"
14 #include "mitkPointSet.h"
15 #include "mitkBaseRenderer.h"
16 
17 mitk::NavigationDataSet::NavigationDataSet( unsigned int numberOfTools )
18  : m_NavigationDataVectors(std::vector<std::vector<mitk::NavigationData::Pointer> >()), m_NumberOfTools(numberOfTools)
19 {
20 }
21 
23 {
24 }
25 
26 bool mitk::NavigationDataSet::AddNavigationDatas( std::vector<mitk::NavigationData::Pointer> navigationDatas )
27 {
28  // test if tool with given index exist
29  if ( navigationDatas.size() != m_NumberOfTools )
30  {
31  MITK_WARN("NavigationDataSet") << "Tried to add too many or too few navigation Datas to NavigationDataSet. " << m_NumberOfTools << " required, tried to add " << navigationDatas.size() << ".";
32  return false;
33  }
34 
35  // test for consistent timestamp
36  if ( m_NavigationDataVectors.size() > 0)
37  {
38  for (std::vector<mitk::NavigationData::Pointer>::size_type i = 0; i < navigationDatas.size(); i++)
39  if (navigationDatas[i]->GetIGTTimeStamp() <= m_NavigationDataVectors.back()[i]->GetIGTTimeStamp())
40  {
41  MITK_WARN("NavigationDataSet") << "IGTTimeStamp of new NavigationData should be newer than timestamp of last NavigationData.";
42  return false;
43  }
44  }
45 
46  m_NavigationDataVectors.push_back(navigationDatas);
47  return true;
48 }
49 
50 mitk::NavigationData::Pointer mitk::NavigationDataSet::GetNavigationDataForIndex( unsigned int index, unsigned int toolIndex ) const
51 {
52  if ( index >= m_NavigationDataVectors.size() )
53  {
54  MITK_WARN("NavigationDataSet") << "There is no NavigationData available at index " << index << ".";
55  return nullptr;
56  }
57 
58  if ( toolIndex >= m_NavigationDataVectors.at(index).size() )
59  {
60  MITK_WARN("NavigationDataSet") << "There is NavigatitionData available at index " << index << " for tool " << toolIndex << ".";
61  return nullptr;
62  }
63 
64  return m_NavigationDataVectors.at(index).at(toolIndex);
65 }
66 
67 // Method not yet supported, code below compiles but delivers wrong results
68 //mitk::NavigationData::Pointer mitk::NavigationDataSet::GetNavigationDataBeforeTimestamp(
69 // mitk::NavigationData::TimeStampType timestamp, unsigned int toolIndex) const
70 //{
71 // if ( toolIndex >= m_NavigationDataVectors.size() )
72 // {
73 // MITK_WARN("NavigationDataSet") << "There is no tool with index " << toolIndex << ".";
74 // return nullptr;
75 // }
76 //
77 // std::vector<mitk::NavigationData::Pointer>::const_iterator it;
78 //
79 // // iterate through all NavigationData objects of the given tool index
80 // // till the timestamp of the NavigationData is greater then the given timestamp
81 // for (it = m_NavigationDataVectors.at(toolIndex).begin();
82 // it != m_NavigationDataVectors.at(toolIndex).end(); ++it)
83 // {
84 // if ( (*it)->GetIGTTimeStamp() > timestamp) { break; }
85 // }
86 //
87 // // first element was greater than timestamp -> return null
88 // if ( it == m_NavigationDataVectors.at(toolIndex).begin() )
89 // {
90 // MITK_WARN("NavigationDataSet") << "No NavigationData was recorded before given timestamp.";
91 // return nullptr;
92 // }
93 //
94 // // return last element smaller than the given timestamp
95 // return *(it-1);
96 //}
97 
98 std::vector< mitk::NavigationData::Pointer > mitk::NavigationDataSet::GetDataStreamForTool(unsigned int toolIndex)
99 {
100  if (toolIndex >= m_NumberOfTools )
101  {
102  MITK_WARN("NavigationDataSet") << "Invalid toolIndex: " << m_NumberOfTools << " Tools known, requested index " << toolIndex << "";
103  return std::vector<mitk::NavigationData::Pointer>();
104  }
105 
106  std::vector< mitk::NavigationData::Pointer > result;
107 
108  for(std::vector<std::vector<NavigationData::Pointer> >::size_type i = 0; i < m_NavigationDataVectors.size(); i++)
109  result.push_back(m_NavigationDataVectors[i][toolIndex]);
110 
111  return result;
112 }
113 
114 std::vector< mitk::NavigationData::Pointer > mitk::NavigationDataSet::GetTimeStep(unsigned int index) const
115 {
116  return m_NavigationDataVectors[index];
117 }
118 
120 {
121  return m_NumberOfTools;
122 }
123 
124 unsigned int mitk::NavigationDataSet::Size() const
125 {
126  return m_NavigationDataVectors.size();
127 }
128 
129 // ---> methods necessary for BaseData
131 {
132 }
133 
135 {
136  return false;
137 }
138 
140 {
141  return true;
142 }
143 
145 {
146 }
147 
149 {
150  return (Size() == 0);
151 }
152 
154 {
155  //iterate over all tools
156  for (unsigned int toolIndex = 0; toolIndex < this->GetNumberOfTools(); ++ toolIndex)
157  {
159  //iterate over all time steps
160  for (unsigned int time = 0; time < m_NavigationDataVectors.size(); time++)
161  {
162  _tempPointSet->InsertPoint(time,m_NavigationDataVectors[time][toolIndex]->GetPosition());
163  MITK_DEBUG << m_NavigationDataVectors[time][toolIndex]->GetPosition() << " --- " << _tempPointSet->GetPoint(time);
164  }
166  std::stringstream str;
167  str << "NavigationData Tool " << toolIndex;
168  dn->SetProperty("name", mitk::StringProperty::New(str.str()));
169  dn->SetData(_tempPointSet);
171  }
172 }
173 
174 // <--- methods necessary for BaseData
175 
176 // ---> methods for Iterators
177 
179 {
180  return m_NavigationDataVectors.cbegin();
181 }
182 
184 {
185  return m_NavigationDataVectors.cend();
186 }
unsigned int m_NumberOfTools
The Number of Tools that this class is going to support.
static BaseRenderer * GetInstance(vtkRenderWindow *renWin)
static vtkRenderWindow * GetRenderWindowByName(const std::string &name)
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...
virtual NavigationDataSetConstIterator Begin() const
Returns an iterator pointing to the first TimeStep.
virtual NavigationDataSetConstIterator End() const
Returns an iterator pointing behind to the last TimeStep.
unsigned int GetNumberOfTools() const
Returns the number of tools for which NavigationDatas are stored in this set.
Navigation Data.
static Pointer New()
#define MITK_DEBUG
Definition: mitkLogMacros.h:22
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
bool VerifyRequestedRegion() override
Verify that the RequestedRegion is within the LargestPossibleRegion.
#define MITK_WARN
Definition: mitkLogMacros.h:19
static Pointer New()
void SetRequestedRegionToLargestPossibleRegion() override
Set the RequestedRegion to the LargestPossibleRegion.
unsigned int Size() const
Returns the number of time steps stored in this NavigationDataSet.
NavigationData::Pointer GetNavigationDataForIndex(unsigned int index, unsigned int toolIndex) const
Get mitk::NavigationData from the given tool at given index.
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.
bool AddNavigationDatas(std::vector< mitk::NavigationData::Pointer > navigationDatas)
Add mitk::NavigationData of the given tool to the Set.
std::vector< std::vector< NavigationData::Pointer > > m_NavigationDataVectors
Holds all the mitk::NavigationData objects managed by this class.
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...
virtual DataStorage::Pointer GetDataStorage() const
std::vector< std::vector< mitk::NavigationData::Pointer > >::const_iterator NavigationDataSetConstIterator
This iterator iterates over the distinct time steps in this set. And is const.
static Pointer New()
NavigationDataSet(unsigned int numTools)
Constructs set with fixed number of tools.
bool RequestedRegionIsOutsideOfTheBufferedRegion() override
Determine whether the RequestedRegion is outside of the BufferedRegion.