Medical Imaging Interaction Toolkit  2016.11.0
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,
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 
17 #include "mitkIGTTimeStamp.h"
18 #include <map>
19 
20 #include "mitkRealTimeClock.h"
21 
23 
25 , m_Time(-1.0), m_ReferenceTime(0.0)
26 {
27 }
28 
30 {
31 }
32 
34 {
36 }
37 
39 {
40  if (IGTTimeStamp::s_Instance.IsNull())
41  {
43  s_Instance = ts;
44  return s_Instance;
45  }
46  else
47  return s_Instance;
48 }
49 
51 {
52  if (m_RealTimeClock.IsNull())
53  {
54  Initialize();
55  }
56  if ( s_Instance.IsNotNull() )
57  {
58  if (m_DeviceMap.empty())
59  {
60  m_ReferenceTime = GetCurrentStamp();
61  m_Time = 0.0;
62  }
63  m_DeviceMap.insert( std::pair<itk::Object::Pointer, double>(device, this->GetElapsed()) );
64  }
65  else
66  {
67  itkGenericOutputMacro("Trying to use mitk::TimeStamp::Start() "
68  << "without an available singleton instance. Either no instance has "
69  << "been created (use TimeStamp::CreateInstance) or it has already "
70  << "been destroyed.");
71  }
72 }
73 
75 {
76  if ( s_Instance.IsNotNull() )
77  {
78  m_MapIterator = m_DeviceMap.find(device);
79  if ( m_MapIterator != m_DeviceMap.end() )
80  {
81  m_DeviceMap.erase( m_MapIterator );
82  }
83 
84  if (m_DeviceMap.empty())
85  {
86  m_ReferenceTime = 0;
87  m_Time = -1;
88  }
89  }
90  else
91  {
92  itkGenericOutputMacro("Trying to use mitk::TimeStamp::Stop() "
93  << "without an available singleton instance. Either no instance has "
94  << "been created (use TimeStamp::CreateInstance) or it has already "
95  << "been destroyed.");
96  }
97 }
98 
99 
101 {
102  if (m_Time > -1)
103  {
104  m_Time = GetCurrentStamp();
105  m_Time = m_Time - m_ReferenceTime;
106  }
107  return (double) m_Time;
108 }
109 
110 
112 {
113  double offset = this->GetOffset( device );
114  if ( offset > -1 )
115  {
116  double time = this->GetElapsed();
117  return (double) time - this->GetOffset(device);
118  }
119  else
120  {
121  return (double) -1;
122  }
123 }
124 
126 {
127  if (m_RealTimeClock.IsNotNull())
128  {
129  return m_RealTimeClock->GetCurrentStamp();
130  }
131  else return 0.0;
132 }
133 
135 {
136  m_RealTimeClock = Clock;
137 }
138 
140 {
141  m_MapIterator = m_DeviceMap.find(Device);
142  if ( m_MapIterator != m_DeviceMap.end() )
143  {
144  return m_MapIterator->second;
145  }
146  else
147  {
148  return -1.0;
149  }
150 }
151 
153 {
154  if ( m_RealTimeClock.IsNull() )
155  m_RealTimeClock = mitk::RealTimeClock::New();
156 }
itk::SmartPointer< Self > Pointer
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()
Time stamp in milliseconds.
static mitk::IGTTimeStamp::Pointer s_Instance
double GetOffset(itk::Object::Pointer Device)
returns the offset of this device'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
void Stop(itk::Object::Pointer device)
stops the time-acqusition
static Pointer New(void)
instanciates a new, operating-system dependant, instance of mitk::RealTimeClock.