Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkIGTTimeStamp.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 "mitkIGTTimeStamp.h"
14 #include <map>
15 
16 #include "mitkRealTimeClock.h"
17 
18 mitk::IGTTimeStamp::Pointer mitk::IGTTimeStamp::s_Instance = nullptr;
19 
21 , m_Time(-1.0), m_ReferenceTime(0.0)
22 {
23 }
24 
26 {
27 }
28 
30 {
32 }
33 
35 {
36  if (IGTTimeStamp::s_Instance.IsNull())
37  {
38  mitk::IGTTimeStamp::Pointer ts = new mitk::IGTTimeStamp;
39  s_Instance = ts;
40  return s_Instance;
41  }
42  else
43  return s_Instance;
44 }
45 
46 void mitk::IGTTimeStamp::Start(itk::Object::Pointer device)
47 {
48  if (m_RealTimeClock.IsNull())
49  {
50  Initialize();
51  }
52  if ( s_Instance.IsNotNull() )
53  {
54  if (m_DeviceMap.empty())
55  {
57  m_Time = 0.0;
58  }
59  m_DeviceMap.insert( std::pair<itk::Object::Pointer, double>(device, this->GetElapsed()) );
60  }
61  else
62  {
63  itkGenericOutputMacro("Trying to use mitk::TimeStamp::Start() "
64  << "without an available singleton instance. Either no instance has "
65  << "been created (use TimeStamp::CreateInstance) or it has already "
66  << "been destroyed.");
67  }
68 }
69 
70 void mitk::IGTTimeStamp::Stop(itk::Object::Pointer device)
71 {
72  if ( s_Instance.IsNotNull() )
73  {
74  m_MapIterator = m_DeviceMap.find(device);
75  if ( m_MapIterator != m_DeviceMap.end() )
76  {
77  m_DeviceMap.erase( m_MapIterator );
78  }
79 
80  if (m_DeviceMap.empty())
81  {
82  m_ReferenceTime = 0;
83  m_Time = -1;
84  }
85  }
86  else
87  {
88  itkGenericOutputMacro("Trying to use mitk::TimeStamp::Stop() "
89  << "without an available singleton instance. Either no instance has "
90  << "been created (use TimeStamp::CreateInstance) or it has already "
91  << "been destroyed.");
92  }
93 }
94 
95 
97 {
98  if (m_Time > -1)
99  {
102  }
103  return (double) m_Time;
104 }
105 
106 
107 double mitk::IGTTimeStamp::GetElapsed(itk::Object::Pointer device)
108 {
109  double offset = this->GetOffset( device );
110  if ( offset > -1 )
111  {
112  double time = this->GetElapsed();
113  return (double) time - this->GetOffset(device);
114  }
115  else
116  {
117  return (double) -1;
118  }
119 }
120 
122 {
123  if (m_RealTimeClock.IsNotNull())
124  {
125  return m_RealTimeClock->GetCurrentStamp();
126  }
127  else return 0.0;
128 }
129 
130 void mitk::IGTTimeStamp::SetRealTimeClock(mitk::RealTimeClock::Pointer Clock)
131 {
132  m_RealTimeClock = Clock;
133 }
134 
135 double mitk::IGTTimeStamp::GetOffset(itk::Object::Pointer Device)
136 {
137  m_MapIterator = m_DeviceMap.find(Device);
138  if ( m_MapIterator != m_DeviceMap.end() )
139  {
140  return m_MapIterator->second;
141  }
142  else
143  {
144  return -1.0;
145  }
146 }
147 
149 {
150  if ( m_RealTimeClock.IsNull() )
152 }
double GetElapsed()
returns the time elapsed since calling Start() for the first time in milliseconds ...
void SetRealTimeClock(mitk::RealTimeClock::Pointer Clock)
setter for the internally used RealTimeClock()
mitk::RealTimeClock::Pointer m_RealTimeClock
Time stamp in milliseconds.
std::map< itk::Object::Pointer, double >::iterator m_MapIterator
static mitk::IGTTimeStamp::Pointer s_Instance
double GetOffset(itk::Object::Pointer Device)
returns the offset of this device&#39;s starting-time to the reference-time in ms
static Vector3D offset
static IGTTimeStamp * CreateInstance()
creates a new instance of mitkTimeStamp
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
void Start(itk::Object::Pointer device)
starts the time-acquisition
void Initialize()
creates a new RealTimeClock
std::map< itk::Object::Pointer, double > m_DeviceMap
void Stop(itk::Object::Pointer device)
stops the time-acqusition
static Pointer New(void)
instanciates a new, operating-system dependant, instance of mitk::RealTimeClock.