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