Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
mitkNavigationDataDelayFilter.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 
14 
16 {
17  m_Tolerance = 0;
18 }
20 {
21 }
22 
24 {
25  // Check if number of outputs has changed since the previous call. If yes, reset buffer.
26  // This actually compares the number of Navigation Datas in each step and compares it to the current number of inputs.
27  // If these values differ, the number of inputrs have changed.
28  if ((!m_Buffer.empty()) && (this->GetNumberOfInputs() != m_Buffer.front().second.size()))
29  {
30  decltype(m_Buffer) tmp;
31  m_Buffer.swap(tmp); // Clear queue with copy-and-swap idiom
32  }
33 
34  // Put current navigationdatas from input into buffer
35  itk::TimeStamp now;
36  now.Modified();
37 
38  std::vector<mitk::NavigationData::Pointer> ndList;
39  for (unsigned int i = 0; i < this->GetNumberOfInputs() ; ++i)
40  {
41  mitk::NavigationData::Pointer nd = mitk::NavigationData::New();
42  nd->Graft(this->GetInput(i));
43  ndList.push_back(nd);
44  }
45 
46  m_Buffer.push( std::make_pair(now.GetMTime(), ndList) );
47 
48  // Find most recent member from buffer that is old enough to output, considering the Delay
49  // remove all sets that are too old already in the process
50  BufferType current;
51  bool foundCurrent = false;
52 
53  while ( (m_Buffer.size() > 0) && (m_Buffer.front().first + m_Delay <= now.GetMTime() + m_Tolerance ) )
54  {
55  foundCurrent = true;
56  current = m_Buffer.front();
57  m_Buffer.pop();
58  }
59 
60  // update outputs with tracking data from previous step, or none if empty
61  if ( !foundCurrent) return;
62 
63  for (unsigned int i = 0; i < this->GetNumberOfOutputs() ; ++i)
64  {
65  mitk::NavigationData* output = this->GetOutput(i);
66  assert(output);
67  const mitk::NavigationData* input = current.second[i];
68  assert(input);
69 
70  if (input->IsDataValid() == false)
71  {
72  output->SetDataValid(false);
73  continue;
74  }
75  output->Graft(input); // First, copy all information from input to output
76  output->SetDataValid(true); // operation was successful, therefore data of output is valid.
77  }
78 }
static Pointer New()
NavigationData * GetOutput(void)
return the output (output with id 0) of the filter
Navigation Data.
virtual void SetDataValid(bool _arg)
sets the dataValid flag of the NavigationData object indicating if the object contains valid data ...
unsigned int m_Delay
The amount of time by which the Navigationdatas are delayed in milliseconds.
const NavigationData * GetInput(void) const
Get the input of this filter.
std::queue< BufferType > m_Buffer
This field containes the buffered navigation datas. It is a queue of (pair of (time and vector of (se...
void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.
virtual bool IsDataValid() const
returns true if the object contains valid data