Medical Imaging Interaction Toolkit  2018.4.99-9a29ffc6
Medical Imaging Interaction Toolkit
mitkNavigationDataPlayer.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 
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 
30 {
31  StopPlaying();
32 }
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
44  {
45  //The output is not valid anymore
46  this->GraftEmptyOutput();
47  return;
48  }
49 
50  // get elapsed time since start of playing
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
62  {
63  // test if the timestamp of the successor is greater than the time stamp
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
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
103 
104  // reset playing timestamps
105  m_PauseTimeStamp = 0;
107 
108  // timestamp for indicating playing start set to current elapsed time
110 }
111 
113 {
115 }
116 
118 {
119  //player runs and pause was called -> pause the player
121  {
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
135  {
137 
138  // in this case m_StartPlayingTimeStamp is set to the total elapsed time with NO playback
141  }
142  else
143  {
144  MITK_ERROR << "Player is not paused!" << std::endl;
145  }
146 }
147 
149 {
150  return m_CurPlayerState;
151 }
152 
154 {
155  return m_TimeStampSinceStart;
156 }
void Resume()
This method resumes the player when it was paused.
NavigationData * GetOutput(void)
return the output (output with id 0) of the filter
void Pause()
This method pauses the player. If you want to play again call Resume()
#define MITK_ERROR
Definition: mitkLogMacros.h:20
Navigation Data.
NavigationDataSet::Pointer m_NavigationDataSet
double GetElapsed()
returns the time elapsed since calling Start() for the first time in milliseconds ...
mitk::NavigationData::TimeStampType TimeStampType
An object of this class represents an exception of the MITK-IGT module.
mitk::NavigationDataSet::NavigationDataSetConstIterator m_NavigationDataSetIterator
Iterator always points to the NavigationData object which is in the outputs at the moment...
void UpdateOutputInformation() override
Used for pipeline update just to tell the pipeline that we always have to update. ...
TimeStampType m_StartPlayingTimeStamp
The start time of the playing. Set in the method mitk::NavigationDataPlayer::StartPlaying().
void GraftEmptyOutput()
Convenience method for subclasses. When there are no further mitk::NavigationData objects available...
TimeStampType m_PauseTimeStamp
Stores the time when a pause began.
void GenerateData() override
Set outputs to the navigation data object corresponding to current time.
#define MITK_WARN
Definition: mitkLogMacros.h:19
void StartPlaying()
This method starts the player.
static IGTTimeStamp * GetInstance()
returns a pointer to the current instance of mitkTimeStamp
void Start(itk::Object::Pointer device)
starts the time-acquisition
void StopPlaying()
Stops the player and closes the stream. After a call of StopPlaying(), StartPlaying() must be called ...
bool m_Repeat
If the player should repeat outputs. Default is false.
#define mitkThrowException(classname)
void Graft(const DataObject *data) override
Graft the data and information from one NavigationData to another.
void InitPlayer()
Initializes the outputs of this NavigationDataSource. Aftwer calling this method, the first Navigatio...