Time stamp in milliseconds. More...
#include <mitkTimeStamp.h>
Public Types | |
typedef TimeStamp | Self |
typedef itk::Object | Superclass |
typedef itk::SmartPointer< Self > | Pointer |
typedef itk::SmartPointer < const Self > | ConstPointer |
Public Member Functions | |
virtual const char * | GetClassName () const |
void | Start (itk::Object::Pointer device) |
starts the time-acquisition | |
void | Stop (itk::Object::Pointer device) |
stops the time-acqusition | |
double | GetElapsed () |
returns the time elapsed since calling Start() for the first time in milliseconds | |
double | GetElapsed (itk::Object::Pointer device) |
returns the time elapsed since 'device' called Start() in milliseconds | |
double | GetOffset (itk::Object::Pointer Device) |
returns the offset of this device's starting-time to the reference-time in ms | |
void | SetRealTimeClock (mitk::RealTimeClock::Pointer Clock) |
setter for the internally used RealTimeClock() | |
void | Initialize () |
creates a new RealTimeClock | |
Static Public Member Functions | |
static TimeStamp * | CreateInstance () |
creates and returns a new instance of mitkTimeStamp if necessary | |
static TimeStamp * | GetInstance () |
returns the current instance of mitkTimeStamp if one exists. | |
Protected Member Functions | |
TimeStamp () | |
virtual | ~TimeStamp () |
double | GetCurrentStamp () |
returns the current time acquired from the defined RealTimeClock | |
Protected Attributes | |
double | m_Time |
double | m_ReferenceTime |
mitk::RealTimeClock::Pointer | m_RealTimeClock |
std::map< itk::Object::Pointer, double > | m_DeviceMap |
std::map< itk::Object::Pointer, double >::iterator | m_MapIterator |
Static Protected Attributes | |
static mitk::TimeStamp::Pointer | s_Instance = NULL |
Time stamp in milliseconds.
This class provides a timestamp in milliseconds. It is a Singleton class, that internally uses a mitkRealTimeClock() for time-acquisition.
First you have to call Start() in order to set the reference-time to the current time. If the user has not created and set his own "RealTimeClock", initialize() will be called and a default mitkRealTimeClock() is created. In addition the TimeStamp() saves a pointer to the device calling and the respective offset-time. The first device will have an offset of 0, the following's offset will be the time elapsed since the starting of the first device. This offset can be prompted by calling GetOffset();
You can always get the time elapsed since calling Start() with GetElapsed(). It returns the time spent in milliseconds as a double.
When the TimeStamp is no longer used, you can call Stop(). This erases the pointer to the device and the offset. When all devices have "stopped tracking" the reference-time and the current-time are reset to 0.
Definition at line 53 of file mitkTimeStamp.h.
typedef itk::SmartPointer<const Self> mitk::TimeStamp::ConstPointer |
Definition at line 57 of file mitkTimeStamp.h.
typedef itk::SmartPointer<Self> mitk::TimeStamp::Pointer |
Definition at line 57 of file mitkTimeStamp.h.
typedef TimeStamp mitk::TimeStamp::Self |
Definition at line 57 of file mitkTimeStamp.h.
typedef itk::Object mitk::TimeStamp::Superclass |
Definition at line 57 of file mitkTimeStamp.h.
mitk::TimeStamp::TimeStamp | ( | ) | [protected] |
Definition at line 25 of file mitkTimeStamp.cpp.
: itk::Object() , m_Time(-1.0), m_ReferenceTime(0.0) { }
mitk::TimeStamp::~TimeStamp | ( | ) | [protected, virtual] |
Definition at line 30 of file mitkTimeStamp.cpp.
{ }
mitk::TimeStamp * mitk::TimeStamp::CreateInstance | ( | ) | [static] |
creates and returns a new instance of mitkTimeStamp if necessary
creates a new instance of mitkTimeStamp
if no instance if mitkTimeStamp exisits, a new one is created and returned, else simply the existing one is returned If a new instance could not be created, 1 is thrown and NULL is returned.
Definition at line 42 of file mitkTimeStamp.cpp.
{ if ( s_Instance.IsNotNull() ) { return s_Instance; } else { try { mitk::TimeStamp::Pointer ts = new mitk::TimeStamp; s_Instance = ts; } catch(...) { s_Instance = NULL; throw 1; } return s_Instance; } }
virtual const char* mitk::TimeStamp::GetClassName | ( | ) | const [virtual] |
double mitk::TimeStamp::GetCurrentStamp | ( | ) | [protected] |
returns the current time acquired from the defined RealTimeClock
only used internally
Definition at line 181 of file mitkTimeStamp.cpp.
{ if (m_RealTimeClock.IsNotNull()) { return m_RealTimeClock->GetCurrentStamp(); } else return 0.0; }
double mitk::TimeStamp::GetElapsed | ( | ) |
returns the time elapsed since calling Start() for the first time in milliseconds
GetElapsed() returns the time elapsed since Start() has been called first, no matter which itk::Object did the call. This method-call can be used if you want to need to have several processes you want to monitor and need timestamps in the same space of time, e.g. when using two tracking-devices on the same experiment.
Definition at line 150 of file mitkTimeStamp.cpp.
Referenced by mitk::NavigationDataPlayer::GenerateData(), mitk::NavigationDataPlayer::Pause(), mitk::NavigationDataPlayer::Resume(), mitk::NavigationDataPlayer::StartPlaying(), and mitk::NavigationDataRecorder::Update().
{ if (m_Time > -1) { m_Time = GetCurrentStamp(); m_Time = m_Time - m_ReferenceTime; } return (double) m_Time; }
double mitk::TimeStamp::GetElapsed | ( | itk::Object::Pointer | device ) |
returns the time elapsed since 'device' called Start() in milliseconds
GetElapsed(itk::Object device) returns the time elapsed since the given itk::Object called Start(). This overloaded method should be used when you only have one independent process to keep track of, e.g. when you want to measure how long it takes to execute a piece of code.
Definition at line 161 of file mitkTimeStamp.cpp.
{ double offset = this->GetOffset( device ); if ( offset > -1 ) { double time = this->GetElapsed(); return (double) time - this->GetOffset(device); } else { return (double) -1; } }
mitk::TimeStamp * mitk::TimeStamp::GetInstance | ( | ) | [static] |
returns the current instance of mitkTimeStamp if one exists.
returns a pointer to the current instance of mitkTimeStamp
If no instance exists, a new one is created.
This method returns a pointer to the currently existing TimeStamp. If there is no exisiting instance, a new one is created and returned automatically
Definition at line 71 of file mitkTimeStamp.cpp.
References s_Instance.
Referenced by mitk::TrackingDeviceSource::GenerateData(), mitk::NavigationDataPlayer::GenerateData(), mitkNavigationDataPlayerTest(), mitkTimeStampTest(), mitk::NavigationDataPlayer::NavigationDataPlayer(), mitk::NavigationDataRecorder::NavigationDataRecorder(), mitk::NavigationDataPlayer::Pause(), mitk::NavigationDataPlayer::Resume(), mitk::NavigationDataPlayer::StartPlaying(), mitk::VirtualTrackingDevice::StartTracking(), mitk::NDITrackingDevice::StartTracking(), mitk::MicroBirdTrackingDevice::StartTracking(), mitk::ClaronTrackingDevice::StartTracking(), mitk::VirtualTrackingDevice::StopTracking(), mitk::TrackingDevice::StopTracking(), and mitk::NavigationDataRecorder::Update().
{ if (TimeStamp::s_Instance.IsNull()) { mitk::TimeStamp::Pointer ts = new mitk::TimeStamp; s_Instance = ts; return s_Instance; } else return s_Instance; }
double mitk::TimeStamp::GetOffset | ( | itk::Object::Pointer | Device ) |
returns the offset of this device's starting-time to the reference-time in ms
Device 'A' is the first device to call Start(). Device 'B' calls Start() some time later. This time-difference is the offset, that each device has realtive to the device that started the time-acquisition. Each device's offset is stored in a map with a pointer to the device.
If this device has not been or is no longer saved in the map of devices, -1 will be returned.
only used internally
This method returns the time acquired when Start was called. This is the offset, that each device will have in relation to the device that started the time acqusition, that means, called Start first. Thus absolute time-values can be calculated for each device by subtracting the offset of all timeStamps.
If this device has not been or is no longer saved in the map of devices, -1 will be returned.
Definition at line 219 of file mitkTimeStamp.cpp.
{ m_MapIterator = m_DeviceMap.find(Device); if ( m_MapIterator != m_DeviceMap.end() ) { return m_MapIterator->second; } else { return -1.0; } }
void mitk::TimeStamp::Initialize | ( | ) |
creates a new RealTimeClock
Instanciates a new RealTimeClock, that will be specific for the Operating System. This will only be called internally when no other RealTimeClock has been set by the user.
Definition at line 240 of file mitkTimeStamp.cpp.
References mitk::RealTimeClock::New().
{ if ( m_RealTimeClock.IsNull() ) m_RealTimeClock = mitk::RealTimeClock::New(); }
void mitk::TimeStamp::SetRealTimeClock | ( | mitk::RealTimeClock::Pointer | Clock ) |
setter for the internally used RealTimeClock()
setter for the internally used RealTimeClock
If you want to use a "third-party" RealTimeClock, e.g PocoRealTimeClock, BoostRealTimeClock or ITKRealTimeClock, you can set it using this method: mitk::<bla>RealTimeClock::Pointer RealTimeClock = mitk::<bla>RealTimeClock::New(); mitk::TimeStamp::GetInstance()->SetRealTimeClock(RealTimeClock);
Right now, none of these RealTimeClocks have been implemented!!
Notice: The mitk-implementation of an os-dependant RealTimeClock is used by default.
If you want to use a "third-party" RealTimeClock, e.g PocoRealTimeClock, BoostRealTimeClock or ITKRealTimeClock, you can set it using this method: mitk::<bla>RealTimeClock::Pointer RealTimeClock = mitk::<bla>RealTimeClock::New(); mitk::TimeStamp::GetInstance()->SetRealTimeClock(RealTimeClock);
Notice: The mitk-implementation of an os-dependant RealTimeClock is used by default.
Definition at line 201 of file mitkTimeStamp.cpp.
{ m_RealTimeClock = Clock; }
void mitk::TimeStamp::Start | ( | itk::Object::Pointer | device ) |
starts the time-acquisition
this method starts the time-acquiring
Each device is to call this method when it starts tracking. The current time is saved as a reference-value (m_Time = 0). Internally the device (pointer) and its offset are saved in a map, so that no device can call this method twice. If the user has not set its own RealTimeClock, a default one is created dependant on the OS in use.
This method first checks if a RealTimeClock has been set. If not, initialize() is called After this, a map is searched if any device has already "started tracking". Starting twice does not make sense and is not allowed. An internal variable saves the current time as a reference-time. All returned times are relative to this starting-time. Then the calling device is added to the map of itk::Objects.
Definition at line 93 of file mitkTimeStamp.cpp.
Referenced by mitk::NavigationDataPlayer::NavigationDataPlayer(), mitk::NavigationDataRecorder::NavigationDataRecorder(), mitk::VirtualTrackingDevice::StartTracking(), mitk::NDITrackingDevice::StartTracking(), mitk::MicroBirdTrackingDevice::StartTracking(), and mitk::ClaronTrackingDevice::StartTracking().
{ if (m_RealTimeClock.IsNull()) { Initialize(); } if ( s_Instance.IsNotNull() ) { if (m_DeviceMap.empty()) { m_ReferenceTime = GetCurrentStamp(); m_Time = 0.0; } m_DeviceMap.insert( std::pair<itk::Object::Pointer, double>(device, this->GetElapsed()) ); } else { itkGenericOutputMacro("Trying to use mitk::TimeStamp::Start() " << "without an available singleton instance. Either no instance has " << "been created (use TimeStamp::CreateInstance) or it has already " << "been destroyed."); } }
void mitk::TimeStamp::Stop | ( | itk::Object::Pointer | device ) |
stops the time-acqusition
this method ends the time-acquisition for a device
Each device has to call Stop() when it has finished and its pointer will be erased from the map. When the last device has "stopped" the reference-time and the current-time will be reset to 0.
When this method is called, the device that called will be erased from the map of devices. When the map is empty, the reference-time and the current timestamp are reset to 0.
Definition at line 124 of file mitkTimeStamp.cpp.
Referenced by mitk::VirtualTrackingDevice::StopTracking(), and mitk::TrackingDevice::StopTracking().
{ if ( s_Instance.IsNotNull() ) { m_MapIterator = m_DeviceMap.find(device); if ( m_MapIterator != m_DeviceMap.end() ) { m_DeviceMap.erase( m_MapIterator ); } if (m_DeviceMap.empty()) { m_ReferenceTime = NULL; m_Time = -1; } } else { itkGenericOutputMacro("Trying to use mitk::TimeStamp::Stop() " << "without an available singleton instance. Either no instance has " << "been created (use TimeStamp::CreateInstance) or it has already " << "been destroyed."); } }
std::map<itk::Object::Pointer, double> mitk::TimeStamp::m_DeviceMap [protected] |
Definition at line 180 of file mitkTimeStamp.h.
std::map<itk::Object::Pointer, double>::iterator mitk::TimeStamp::m_MapIterator [protected] |
Definition at line 182 of file mitkTimeStamp.h.
Definition at line 170 of file mitkTimeStamp.h.
double mitk::TimeStamp::m_ReferenceTime [protected] |
Definition at line 165 of file mitkTimeStamp.h.
double mitk::TimeStamp::m_Time [protected] |
Definition at line 160 of file mitkTimeStamp.h.
mitk::TimeStamp::Pointer mitk::TimeStamp::s_Instance = NULL [static, protected] |
Definition at line 175 of file mitkTimeStamp.h.
Referenced by GetInstance().