Medical Imaging Interaction Toolkit  2018.4.99-f51274ea
Medical Imaging Interaction Toolkit
mitkNavigationDataRecorder.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 #include <mitkIGTTimeStamp.h>
15 
17  : m_NumberOfInputs(0),
18  m_NavigationDataSet(nullptr),
19  m_Recording(false),
20  m_StandardizeTime(false),
21  m_StandardizedTimeInitialized(false),
22  m_RecordCountLimit(-1),
23  m_RecordOnlyValidData(false)
24 {
25 
26 }
27 
29 {
30  //mitk::IGTTimeStamp::GetInstance()->Stop(this); //commented out because of bug 18952
31 }
32 
34 {
35  // get each input, lookup the associated BaseData and transfer the data
36  DataObjectPointerArray inputs = this->GetIndexedInputs(); //get all inputs
37 
38  //This vector will hold the NavigationDatas that are copied from the inputs
39  std::vector< mitk::NavigationData::Pointer > clonedDatas;
40 
41  bool atLeastOneInputIsInvalid = false;
42 
43  // For each input
44  for (unsigned int index=0; index < inputs.size(); index++)
45  {
46  // First copy input to output
47  this->GetOutput(index)->Graft(this->GetInput(index));
48 
49  // if we are not recording, that's all there is to do
50  if (! m_Recording) continue;
51 
52  if (atLeastOneInputIsInvalid || !this->GetInput(index)->IsDataValid())
53  {
54  atLeastOneInputIsInvalid = true;
55  }
56 
57  // Clone a Navigation Data
58  mitk::NavigationData::Pointer clone = mitk::NavigationData::New();
59  clone->Graft(this->GetInput(index));
60  clonedDatas.push_back(clone);
61 
63  {
65  clonedDatas[index]->SetIGTTimeStamp(igtTimestamp);
66  }
67  }
68 
69  // if limitation is set and has been reached, stop recording
70  if ((m_RecordCountLimit > 0) && (m_NavigationDataSet->Size() >= static_cast<unsigned int>(m_RecordCountLimit)))
71  m_Recording = false;
72  // We can skip the rest of the method, if recording is deactivated
73  if (!m_Recording) return;
74  // We can skip the rest of the method, if we read only valid data
75  if (m_RecordOnlyValidData && atLeastOneInputIsInvalid) return;
76 
77  // Add data to set
78  m_NavigationDataSet->AddNavigationDatas(clonedDatas);
79 }
80 
82 {
83  if (m_Recording)
84  {
85  MITK_WARN << "Already recording please stop before start new recording session";
86  return;
87  }
88  m_Recording = true;
89 
90  // The first time this StartRecording is called, we initialize the standardized time.
91  // Afterwards, it can be reset via ResetNavigationDataSet();
94 
95  if (m_NavigationDataSet.IsNull())
96  m_NavigationDataSet = mitk::NavigationDataSet::New(GetNumberOfIndexedInputs());
97 }
98 
100 {
101  if (!m_Recording)
102  {
103  std::cout << "You have to start a recording first" << std::endl;
104  return;
105  }
106  m_Recording = false;
107 }
108 
110 {
111  m_NavigationDataSet = mitk::NavigationDataSet::New(GetNumberOfIndexedInputs());
112 
113  if (m_Recording)
114  {
117  }
118 }
119 
121 {
122  return m_NavigationDataSet->Size();
123 }
virtual void StartRecording()
Starts recording NavigationData into the NavigationDataSet.
virtual void ResetRecording()
Resets the Datasets and the timestamp, so a new recording can happen.
static Pointer New()
NavigationData * GetOutput(void)
return the output (output with id 0) of the filter
bool m_Recording
indicates whether the recording is started or not
double GetElapsed()
returns the time elapsed since calling Start() for the first time in milliseconds ...
int m_RecordCountLimit
limits the number of frames, recording will be stopped if the limit is reached. -1 disables the limit...
bool m_StandardizedTimeInitialized
set to true the first time start recording is called.
virtual void StopRecording()
Stops StopsRecording to the NavigationDataSet.
virtual int GetNumberOfRecordedSteps()
Returns the number of time steps that were recorded in the current set. Warning: This Method does NOT...
const NavigationData * GetInput(void) const
Get the input of this filter.
double TimeStampType
type that holds the time at which the data was recorded in milliseconds
bool m_StandardizeTime
indicates whether one should use the timestamps in NavigationData or create new timestamps upon recor...
#define MITK_WARN
Definition: mitkLogMacros.h:19
static void clone(T *&dst, S *src, int n)
Definition: svm.cpp:59
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
void Start(itk::Object::Pointer device)
starts the time-acquisition
bool m_RecordOnlyValidData
indicates whether only valid data is recorded
void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.
void Stop(itk::Object::Pointer device)
stops the time-acqusition
mitk::NavigationDataSet::Pointer m_NavigationDataSet