MITK-IGT
IGT Extension of MITK
Loading...
Searching...
No Matches
mitkNavigationDataPlayer.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
14
15#include <itksys/SystemTools.hxx>
16#include <mitkIGTTimeStamp.h>
17#include <fstream>
18
19#include "mitkIGTException.h"
20
22 : m_CurPlayerState(PlayerStopped),
23 m_StartPlayingTimeStamp(0.0), m_PauseTimeStamp(0.0)
24{
25 // to get a start time
27}
28
33
35{
36 if ( m_NavigationDataSet->Size() == 0 )
37 {
38 MITK_WARN << "Cannot do anything with empty set of navigation datas.";
39 return;
40 }
41
42 //Only produce new output if the player is started
43 if (m_CurPlayerState != PlayerRunning)
44 {
45 //The output is not valid anymore
46 this->GraftEmptyOutput();
47 return;
48 }
49
50 // get elapsed time since start of playing
51 m_TimeStampSinceStart = mitk::IGTTimeStamp::GetInstance()->GetElapsed() - m_StartPlayingTimeStamp;
52
53 // add offset of the first navigation data to the timestamp to start playing
54 // imediatly with the first navigation data (not to wait till the first time
55 // stamp is reached)
56 TimeStampType timeStampSinceStartWithOffset = m_TimeStampSinceStart
57 + m_NavigationDataSet->Begin()->at(0)->GetIGTTimeStamp();
58
59 // iterate through all NavigationData objects of the given tool index
60 // till the timestamp of the NavigationData is greater then the given timestamp
61 for (; m_NavigationDataSetIterator != m_NavigationDataSet->End(); ++m_NavigationDataSetIterator)
62 {
63 // test if the timestamp of the successor is greater than the time stamp
64 if ( m_NavigationDataSetIterator+1 == m_NavigationDataSet->End() ||
65 (m_NavigationDataSetIterator+1)->at(0)->GetIGTTimeStamp() > timeStampSinceStartWithOffset )
66 {
67 break;
68 }
69 }
70
71 for (unsigned int index = 0; index < GetNumberOfOutputs(); index++)
72 {
73 mitk::NavigationData* output = this->GetOutput(index);
74 if( !output ) { mitkThrowException(mitk::IGTException) << "Output of index "<<index<<" is null."; }
75
76 output->Graft(m_NavigationDataSetIterator->at(index));
77 }
78
79 // stop playing if the last NavigationData objects were grafted
80 if (m_NavigationDataSetIterator+1 == m_NavigationDataSet->End())
81 {
82 this->StopPlaying();
83
84 // start playing again if repeat is enabled
85 if ( m_Repeat ) { this->StartPlaying(); }
86 }
87}
88
90{
91 this->Modified(); // make sure that we need to be updated
92 Superclass::UpdateOutputInformation();
93}
94
96{
97 // make sure that player is initialized before playing starts
98 this->InitPlayer();
99
100 // set state and iterator for playing from start
101 m_CurPlayerState = PlayerRunning;
102 m_NavigationDataSetIterator = m_NavigationDataSet->Begin();
103
104 // reset playing timestamps
105 m_PauseTimeStamp = 0;
106 m_TimeStampSinceStart = 0;
107
108 // timestamp for indicating playing start set to current elapsed time
109 m_StartPlayingTimeStamp = mitk::IGTTimeStamp::GetInstance()->GetElapsed();
110}
111
113{
114 m_CurPlayerState = PlayerStopped;
115}
116
118{
119 //player runs and pause was called -> pause the player
120 if(m_CurPlayerState == PlayerRunning)
121 {
122 m_CurPlayerState = PlayerPaused;
123 m_PauseTimeStamp = mitk::IGTTimeStamp::GetInstance()->GetElapsed();
124 }
125 else
126 {
127 MITK_ERROR << "Player is either not started or already is paused" << std::endl;
128 }
129}
130
132{
133 // player is in pause mode -> play at the last position
134 if(m_CurPlayerState == PlayerPaused)
135 {
136 m_CurPlayerState = PlayerRunning;
137
138 // in this case m_StartPlayingTimeStamp is set to the total elapsed time with NO playback
139 m_StartPlayingTimeStamp = mitk::IGTTimeStamp::GetInstance()->GetElapsed()
140 - (m_PauseTimeStamp - m_StartPlayingTimeStamp);
141 }
142 else
143 {
144 MITK_ERROR << "Player is not paused!" << std::endl;
145 }
146}
147
152
An object of this class represents an exception of the MITK-IGT module.
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
void Start(itk::Object::Pointer device)
starts the time-acquisition
double GetElapsed()
returns the time elapsed since calling Start() for the first time in milliseconds
void Resume()
This method resumes the player when it was paused.
mitk::NavigationData::TimeStampType TimeStampType
void UpdateOutputInformation() override
Used for pipeline update just to tell the pipeline that we always have to update.
void StartPlaying()
This method starts the player.
void StopPlaying()
Stops the player and closes the stream. After a call of StopPlaying(), StartPlaying() must be called ...
void GenerateData() override
Set outputs to the navigation data object corresponding to current time.
void Pause()
This method pauses the player. If you want to play again call Resume()
void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.