MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkIGTTimeStamp.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
13#include "mitkIGTTimeStamp.h"
14#include <map>
15
16#include "mitkRealTimeClock.h"
17
18mitk::IGTTimeStamp::Pointer mitk::IGTTimeStamp::s_Instance = nullptr;
19
21, m_Time(-1.0), m_ReferenceTime(0.0)
22{
23}
24
28
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
46void 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 {
56 m_ReferenceTime = GetCurrentStamp();
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
70void 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 {
100 m_Time = GetCurrentStamp();
101 m_Time = m_Time - m_ReferenceTime;
102 }
103 return (double) m_Time;
104}
105
106
107double 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
130void mitk::IGTTimeStamp::SetRealTimeClock(mitk::RealTimeClock::Pointer Clock)
131{
132 m_RealTimeClock = Clock;
133}
134
135double 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() )
151 m_RealTimeClock = mitk::RealTimeClock::New();
152}
Time stamp in milliseconds.
static IGTTimeStamp * CreateInstance()
creates a new instance of mitkTimeStamp
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
static mitk::IGTTimeStamp::Pointer s_Instance
void Start(itk::Object::Pointer device)
starts the time-acquisition
void Stop(itk::Object::Pointer device)
stops the time-acqusition
void Initialize()
creates a new RealTimeClock
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()
double GetOffset(itk::Object::Pointer Device)
returns the offset of this device's starting-time to the reference-time in ms
static Pointer New(void)
instanciates a new, operating-system dependant, instance of mitk::RealTimeClock.