MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNavigationDataDelayFilter.cpp
Go to the documentation of this file.
1/*============================================================================
2
3The Medical Imaging Interaction Toolkit (MITK)
4
5Copyright (c) German Cancer Research Center (DKFZ)
6All rights reserved.
7
8Use of this source code is governed by a 3-clause BSD license that can be
9found in the LICENSE file.
10
11============================================================================*/
12
14
16{
17 m_Tolerance = 0;
18}
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}
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