This class is used to play recorded (see mitkNavigationDataRecorder class) files. More...
#include <mitkNavigationDataPlayer.h>
Public Types | |
enum | PlayerMode { NormalFile, ZipFile } |
The PlayerMode is used for generating a presetted output stream. You do not need to set it if you want to use your own stream. More... | |
Public Member Functions | |
mitkClassMacro (NavigationDataPlayer, NavigationDataSource) | |
virtual void | SetFileName (const char *_arg) |
sets the file name and path for the PlayerMode NormalFile and ZipFile | |
virtual const char * | GetFileName () const |
returns the file name and path for the PlayerMode NormalFile and ZipFile | |
virtual void | UpdateOutputInformation () |
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 to get new output data. | |
void | Pause () |
This method pauses the player. If you want to play again call Resume() | |
void | Resume () |
This method resumes the player when it was paused. | |
void | SetStream (PlayerMode mode) |
sets the recording mode which causes different types of output streams This method is overloaded with SetStream( ostream* ) | |
void | SetStream (std::istream *stream) |
sets the recording mode which causes different types of output streams This method is overloaded with SetStream( PlayerMode ) | |
Static Public Member Functions | |
static Pointer | New () |
Protected Types | |
typedef mitk::NavigationData::TimeStampType | TimeStampType |
Protected Member Functions | |
NavigationDataPlayer () | |
virtual | ~NavigationDataPlayer () |
virtual void | GenerateData () |
filter execute method | |
unsigned int | GetFileVersion (std::istream *stream) |
Returns the file version out of the XML document. | |
unsigned int | GetNumberOfNavigationDatas (std::istream *stream) |
Returns the number of tracked tools out of the XML document. | |
void | GetFirstData () |
Gets the first data for initializing the player. | |
mitk::NavigationData::Pointer | ReadVersion1 () |
This method reads one line of the XML document and returns the data as a NavigationData object If there is a new file version another method must be added which reads this data. | |
void | InitPlayer () |
This method initializes the player with first data. | |
Protected Attributes | |
std::istream * | m_Stream |
stores a pointer to the input stream | |
PlayerMode | m_PlayerMode |
stores the mode for the presetted PlayerMode sieh enum PlayerMode | |
std::string | m_FileName |
stores the filename | |
unsigned int | m_FileVersion |
indicates which XML encoding is used | |
bool | m_Playing |
indicates whether the generateoutput method generates new output or not | |
bool | m_Pause |
indicates if the player is paused | |
unsigned int | m_NumberOfOutputs |
stores the number of outputs known from the XML document | |
TimeStampType | m_StartPlayingTimeStamp |
the starttime of the playing set in the method StartPlaying() | |
TimeStampType | m_PauseTimeStamp |
stores the beginning of a pause | |
std::vector < NavigationData::Pointer > | m_NextToPlayNavigationData |
stores the next possible candidate for playing | |
std::vector< TimeStampType > | m_StartTimeOfData |
stores the start time of the different tools | |
TiXmlElement * | m_parentElement |
TiXmlNode * | m_currentNode |
This class is used to play recorded (see mitkNavigationDataRecorder class) files.
Documentation If you want to play a file you have to set an input stream. This can be an own one (use StartPlaying(std::istream*)) or a preset (use StartPlaying()). The presets are NormalFile and ZipFile and can be set with the method SetPlayerMode(PlayerMode). The presets need a FileName. Therefore the FileName must be set before the preset. For pausing the player call Pause(). A call of Resume() will continue the playing.
Definition at line 44 of file mitkNavigationDataPlayer.h.
typedef mitk::NavigationData::TimeStampType mitk::NavigationDataPlayer::TimeStampType [protected] |
Definition at line 128 of file mitkNavigationDataPlayer.h.
The PlayerMode is used for generating a presetted output stream. You do not need to set it if you want to use your own stream.
There are: NormalFile: ifstream ZipFile: not implemented yet
Definition at line 106 of file mitkNavigationDataPlayer.h.
{ NormalFile, ZipFile };
mitk::NavigationDataPlayer::NavigationDataPlayer | ( | ) | [protected] |
Definition at line 26 of file mitkNavigationDataPlayer.cpp.
References mitk::TimeStamp::GetInstance(), m_currentNode, m_FileName, m_FileVersion, m_NumberOfOutputs, m_parentElement, m_Pause, m_PauseTimeStamp, m_PlayerMode, m_Playing, m_StartPlayingTimeStamp, m_Stream, NormalFile, and mitk::TimeStamp::Start().
{ m_NumberOfOutputs = 0; m_Pause = false; m_Playing = false; m_Stream = NULL; m_PlayerMode = NormalFile; m_FileName = ""; m_FileVersion = 1; m_Playing = false; m_Pause = false; m_NumberOfOutputs = 0; m_StartPlayingTimeStamp = 0.0; m_PauseTimeStamp = 0.0; m_parentElement = NULL; m_currentNode = NULL; //To get a start time mitk::TimeStamp::GetInstance()->Start(this); }
mitk::NavigationDataPlayer::~NavigationDataPlayer | ( | ) | [protected, virtual] |
Definition at line 50 of file mitkNavigationDataPlayer.cpp.
{ StopPlaying(); delete m_parentElement; }
void mitk::NavigationDataPlayer::GenerateData | ( | ) | [protected, virtual] |
filter execute method
Definition at line 57 of file mitkNavigationDataPlayer.cpp.
References mitk::TimeStamp::GetElapsed(), mitk::TimeStamp::GetInstance(), mitk::NavigationData::Graft(), and mitk::NavigationData::New().
{ //Only produce new output if the player is started if (!m_Playing) { //The output is not valid anymore for (unsigned int index = 0; index < m_NumberOfOutputs; index++) { mitk::NavigationData* output = this->GetOutput(index); assert(output); mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); mitk::NavigationData::PositionType position; mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0); position.Fill(0.0); nd->SetPosition(position); nd->SetOrientation(orientation); nd->SetDataValid(false); output->Graft(nd); } return; } //first of all get current time TimeStampType now = mitk::TimeStamp::GetInstance()->GetElapsed(); //now we make a little time arithmetic //to get the elapsed time since the start of the player TimeStampType timeSinceStart = now - m_StartPlayingTimeStamp; //init the vectors std::vector< NavigationData::Pointer > nextCandidates; std::vector< NavigationData::Pointer > lastCandidates; std::vector< NavigationData::TimeStampType > currentTimeOfData; for (unsigned int index=0; index < m_NumberOfOutputs; index++) { nextCandidates.push_back(m_NextToPlayNavigationData.at(index)); lastCandidates.push_back(m_NextToPlayNavigationData.at(index)); currentTimeOfData.push_back(timeSinceStart + m_StartTimeOfData.at(index)); } if (m_NextToPlayNavigationData.size() != m_NumberOfOutputs) { std::cout << "Mismatch in data" << std::endl; return; } // Now we try to find next NavigationData in the stream: // This means we step through the stream of NavigationDatas until we find // a NavigationData which has a current timestamp (currentTimeOfData) greater // then the current playing time. Then we store the data in // m_NextToPlayNavigationData and take the last data (lastCandidates) for the // output of this filter. // // The loop will stop when a suitable NavigationData is found or we reach EOF. // The timestamps of each recorded NavigationData should be equal // therefore we take always the time from the first. while(nextCandidates[0]->GetTimeStamp() < currentTimeOfData[0]) { for (unsigned int index=0; index < m_NumberOfOutputs; index++) { lastCandidates[index] = nextCandidates.at(index); switch(m_FileVersion) { case 1: nextCandidates[index] = ReadVersion1(); break; default: //this case should not happen! therefore the return at this point return; break; } //check if the input stream delivered a correct NavigationData object for (unsigned int i = 0; i < m_NumberOfOutputs; i++) { if (nextCandidates.at(index).IsNull()) { StopPlaying(); return; //the case if no NavigationData is found, e.g. EOF, bad stream } } } } //Now lastCandidates stores the new output and nextCandidates is stored to the m_NextToPlay vector for (unsigned int index = 0; index < m_NumberOfOutputs; index++) { mitk::NavigationData* output = this->GetOutput(index); assert(output); output->Graft(lastCandidates.at(index)); m_NextToPlayNavigationData[index] = nextCandidates.at(index); } }
virtual const char* mitk::NavigationDataPlayer::GetFileName | ( | ) | const [virtual] |
returns the file name and path for the PlayerMode NormalFile and ZipFile
unsigned int mitk::NavigationDataPlayer::GetFileVersion | ( | std::istream * | stream ) | [protected] |
Returns the file version out of the XML document.
Definition at line 215 of file mitkNavigationDataPlayer.cpp.
{ if (stream==NULL) { std::cout << "No input stream set!" << std::endl; return 0; } if (!stream->good()) { std::cout << "Stream not good!" << std::endl; return 0; } int version = 1; TiXmlDeclaration* dec = new TiXmlDeclaration(); *stream >> *dec; if(strcmp(dec->Version(),"") == 0){ std::cout << "The input stream seems to have XML incompatible format" << std::endl; return 0; } m_parentElement = new TiXmlElement(""); *stream >> *m_parentElement; //2nd line this is the file version std::string tempValue = m_parentElement->Value(); if(tempValue != "Version") { if(tempValue == "Data"){ m_parentElement->QueryIntAttribute("version",&version); } } else { m_parentElement->QueryIntAttribute("Ver",&version); } if (version > 0) return version; else return 0; }
void mitk::NavigationDataPlayer::GetFirstData | ( | ) | [protected] |
Gets the first data for initializing the player.
Definition at line 442 of file mitkNavigationDataPlayer.cpp.
{ //Here we read the first lines of input (dependend on the number of inputs) for (unsigned int index=0; index < m_NumberOfOutputs; index++) { //Here we init the vector for later use m_NextToPlayNavigationData.push_back(NULL); m_StartTimeOfData.push_back(0.0); mitk::NavigationData::Pointer nd = this->GetOutput(index); switch(m_FileVersion) { case 1: m_NextToPlayNavigationData[index] = ReadVersion1(); //check if there is valid data in it if (m_NextToPlayNavigationData[index].IsNull()) { StopPlaying(); std::cout << "XML File is corrupt or has no NavigationData" << std::endl; return; } //Have a look it the output was set already without this check the pipline will disconnect after a start/stop cycle if (nd.IsNull()) this->SetNthOutput(index, m_NextToPlayNavigationData[index]); m_StartTimeOfData[index] = m_NextToPlayNavigationData[index]->GetTimeStamp(); break; default: //this case should not happen! therefore the return at this point return; break; } } }
unsigned int mitk::NavigationDataPlayer::GetNumberOfNavigationDatas | ( | std::istream * | stream ) | [protected] |
Returns the number of tracked tools out of the XML document.
Definition at line 259 of file mitkNavigationDataPlayer.cpp.
{ if (stream == NULL) { std::cout << "No input stream set!" << std::endl; return 0; } if (!stream->good()) { std::cout << "Stream not good!" << std::endl; return 0; } //If something has changed in a future version of the XML definition e.g. navigationcount or addional parameters //catch this here with a select case block (see GenerateData() method) int numberOfTools = 0; std::string tempValue = m_parentElement->Value(); if(tempValue == "Version"){ *stream >> *m_parentElement; } m_parentElement->QueryIntAttribute("ToolCount",&numberOfTools); if (numberOfTools > 0) return numberOfTools; return 0; }
void mitk::NavigationDataPlayer::InitPlayer | ( | ) | [protected] |
This method initializes the player with first data.
Definition at line 167 of file mitkNavigationDataPlayer.cpp.
{ if (m_Stream == NULL) { StopPlaying(); std::cout << "Playing not possible. Wrong file name or path? " << std::endl; return; } if (!m_Stream->good()) { StopPlaying(); std::cout << "Playing not possible. Stream is not good!" << std::endl; return; } m_FileVersion = GetFileVersion(m_Stream); //first get the file version //check if we have a valid version if (m_FileVersion < 1) { StopPlaying(); std::cout << "Playing not possible. Stream is not good!" << std::endl; return; } if(m_NumberOfOutputs == 0){ m_NumberOfOutputs = GetNumberOfNavigationDatas(m_Stream); //now read the number of Tracked Tools } //with the information about the tracked tool number we can generate the output if (m_NumberOfOutputs > 0) { //Generate the output only if there are changes to the amount of outputs //This happens when the player is stopped and start again with different file if (this->GetNumberOfOutputs() != m_NumberOfOutputs) { this->SetNumberOfOutputs(m_NumberOfOutputs); } GetFirstData(); //initialize the player with first data } else { std::cout << "The input stream seems to have NavigationData incompatible format" << std::endl; StopPlaying(); } }
mitk::NavigationDataPlayer::mitkClassMacro | ( | NavigationDataPlayer | , |
NavigationDataSource | |||
) |
static Pointer mitk::NavigationDataPlayer::New | ( | ) | [static] |
Referenced by main(), mitkNavigationDataPlayerTest(), and QmitkIGTExampleView::OnPlayingToggle().
void mitk::NavigationDataPlayer::Pause | ( | ) |
This method pauses the player. If you want to play again call Resume()
Definition at line 480 of file mitkNavigationDataPlayer.cpp.
References mitk::TimeStamp::GetElapsed(), and mitk::TimeStamp::GetInstance().
{ //player runs and pause was called -> pause the player if(m_Playing && !m_Pause) { m_Playing = false; m_Pause = true; m_PauseTimeStamp = mitk::TimeStamp::GetInstance()->GetElapsed(); } else { std::cout << "Player is either not started or already in paused" << std::endl; } }
mitk::NavigationData::Pointer mitk::NavigationDataPlayer::ReadVersion1 | ( | ) | [protected] |
This method reads one line of the XML document and returns the data as a NavigationData object If there is a new file version another method must be added which reads this data.
Definition at line 291 of file mitkNavigationDataPlayer.cpp.
References matrix(), mitk::NavigationData::New(), TiXmlElement::QueryDoubleAttribute(), TiXmlElement::QueryFloatAttribute(), TiXmlElement::QueryIntAttribute(), and TiXmlElement::ToElement().
{ if (m_Stream == NULL) { m_Playing = false; std::cout << "Playing not possible. Wrong file name or path? " << std::endl; return NULL; } if (!m_Stream->good()) { m_Playing = false; std::cout << "Playing not possible. Stream is not good!" << std::endl; return NULL; } mitk::NavigationData::Pointer nd = mitk::NavigationData::New(); mitk::NavigationData::PositionType position; mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0); mitk::NavigationData::TimeStampType timestamp = -1; mitk::NavigationData::CovarianceMatrixType matrix; bool hasPosition = true; bool hasOrientation = true; bool dataValid = false; position.Fill(0.0); matrix.SetIdentity(); TiXmlElement* elem = new TiXmlElement(""); m_currentNode = m_parentElement->IterateChildren(m_currentNode); if(m_currentNode){ elem = m_currentNode->ToElement(); } //check here if EOF (the query don't change the timestamp value which should always be > 0) elem->QueryDoubleAttribute("Time",×tamp); if (timestamp == -1) { return NULL; //the calling method should check the return value if it is valid/not NULL } elem->QueryFloatAttribute("X", &position[0]); elem->QueryFloatAttribute("Y", &position[1]); elem->QueryFloatAttribute("Z", &position[2]); elem->QueryFloatAttribute("QX", &orientation[0]); elem->QueryFloatAttribute("QY", &orientation[1]); elem->QueryFloatAttribute("QZ", &orientation[2]); elem->QueryFloatAttribute("QR", &orientation[3]); elem->QueryFloatAttribute("C00", &matrix[0][0]); elem->QueryFloatAttribute("C01", &matrix[0][1]); elem->QueryFloatAttribute("C02", &matrix[0][2]); elem->QueryFloatAttribute("C03", &matrix[0][3]); elem->QueryFloatAttribute("C04", &matrix[0][4]); elem->QueryFloatAttribute("C05", &matrix[0][5]); elem->QueryFloatAttribute("C10", &matrix[1][0]); elem->QueryFloatAttribute("C11", &matrix[1][1]); elem->QueryFloatAttribute("C12", &matrix[1][2]); elem->QueryFloatAttribute("C13", &matrix[1][3]); elem->QueryFloatAttribute("C14", &matrix[1][4]); elem->QueryFloatAttribute("C15", &matrix[1][5]); int tmpval = 0; elem->QueryIntAttribute("Valid", &tmpval); if (tmpval == 0) dataValid = false; else dataValid = true; tmpval = 0; elem->QueryIntAttribute("hO", &tmpval); if (tmpval == 0) hasOrientation = false; else hasOrientation = true; tmpval = 0; elem->QueryIntAttribute("hP", &tmpval); if (tmpval == 0) hasPosition = false; else hasPosition = true; nd->SetTimeStamp(timestamp); nd->SetPosition(position); nd->SetOrientation(orientation); nd->SetCovErrorMatrix(matrix); nd->SetDataValid(dataValid); nd->SetHasOrientation(hasOrientation); nd->SetHasPosition(hasPosition); //delete elem; return nd; }
void mitk::NavigationDataPlayer::Resume | ( | ) |
This method resumes the player when it was paused.
Definition at line 497 of file mitkNavigationDataPlayer.cpp.
References mitk::TimeStamp::GetElapsed(), and mitk::TimeStamp::GetInstance().
{ //player is in pause mode -> play at the last position if(!m_Playing && m_Pause) { m_Playing = true; mitk::NavigationData::TimeStampType now = mitk::TimeStamp::GetInstance()->GetElapsed(); m_StartPlayingTimeStamp = now + (m_PauseTimeStamp - m_StartPlayingTimeStamp); } else { std::cout << "Player is not paused!" << std::endl; } }
virtual void mitk::NavigationDataPlayer::SetFileName | ( | const char * | _arg ) | [virtual] |
sets the file name and path for the PlayerMode NormalFile and ZipFile
void mitk::NavigationDataPlayer::SetStream | ( | std::istream * | stream ) |
sets the recording mode which causes different types of output streams This method is overloaded with SetStream( PlayerMode )
Definition at line 545 of file mitkNavigationDataPlayer.cpp.
{ if (!stream->good()) { std::cout << "The stream is not good" << std::endl; return; } m_Stream = stream; this->Modified(); InitPlayer(); }
void mitk::NavigationDataPlayer::SetStream | ( | PlayerMode | mode ) |
sets the recording mode which causes different types of output streams This method is overloaded with SetStream( ostream* )
Definition at line 513 of file mitkNavigationDataPlayer.cpp.
{ m_Stream = NULL; if (!itksys::SystemTools::FileExists(m_FileName.c_str())) { std::cout << "File dont exist!" << std::endl; return; } switch(m_PlayerMode) { case NormalFile: m_Stream = new std::ifstream(m_FileName.c_str()); break; case ZipFile: m_Stream = NULL; std::cout << "Sorry no ZipFile support yet"; break; default: m_Stream = NULL; break; } this->Modified(); InitPlayer(); }
void mitk::NavigationDataPlayer::StartPlaying | ( | ) |
This method starts the player.
Before the stream has to be set. Either with a PlayingMode (SetStream(PlayerMode)) and FileName. Or with an own inputstream (SetStream(istream*)).
Definition at line 388 of file mitkNavigationDataPlayer.cpp.
References mitk::TimeStamp::GetElapsed(), and mitk::TimeStamp::GetInstance().
{ if (m_Stream == NULL) { m_Playing = false; //Perhaps the SetStream method was not called so we do this when a FileName is set with SetStream(PlayerMode) if (m_FileName != "") { //The PlayerMode is initialized with LastSetStream //SetStream also calls InitPlayer() SetStream(m_PlayerMode); } //now check again if (m_Stream == NULL) { StopPlaying(); std::cout << "Playing not possible. Wrong file name or path? " << std::endl; return; } } if (!m_Playing && m_Stream->good()) { m_Playing = true; //starts the player m_StartPlayingTimeStamp = mitk::TimeStamp::GetInstance()->GetElapsed(); } else { std::cout << "Player already started or stream is not good" << std::endl; StopPlaying(); } }
void mitk::NavigationDataPlayer::StopPlaying | ( | ) |
Stops the player and closes the stream. After a call of StopPlaying() StartPlaying() must be called to get new output data.
Definition at line 425 of file mitkNavigationDataPlayer.cpp.
{ //re init all data!! for playing again with different data //only PlayerMode and FileName are not changed m_Pause = false; m_Playing = false; m_Stream = NULL; m_FileVersion = 1; m_Playing = false; m_Pause = false; m_StartPlayingTimeStamp = 0.0; m_PauseTimeStamp = 0.0; m_NextToPlayNavigationData.clear(); m_StartTimeOfData.clear(); }
void mitk::NavigationDataPlayer::UpdateOutputInformation | ( | ) | [virtual] |
Used for pipeline update just to tell the pipeline that we always have to update.
Definition at line 160 of file mitkNavigationDataPlayer.cpp.
{ this->Modified(); // make sure that we need to be updated Superclass::UpdateOutputInformation(); }
TiXmlNode* mitk::NavigationDataPlayer::m_currentNode [protected] |
Definition at line 185 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
std::string mitk::NavigationDataPlayer::m_FileName [protected] |
stores the filename
Definition at line 165 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
unsigned int mitk::NavigationDataPlayer::m_FileVersion [protected] |
indicates which XML encoding is used
Definition at line 167 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
std::vector<NavigationData::Pointer> mitk::NavigationDataPlayer::m_NextToPlayNavigationData [protected] |
stores the next possible candidate for playing
Definition at line 179 of file mitkNavigationDataPlayer.h.
unsigned int mitk::NavigationDataPlayer::m_NumberOfOutputs [protected] |
stores the number of outputs known from the XML document
Definition at line 173 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
TiXmlElement* mitk::NavigationDataPlayer::m_parentElement [protected] |
Definition at line 183 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
bool mitk::NavigationDataPlayer::m_Pause [protected] |
indicates if the player is paused
Definition at line 171 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
stores the beginning of a pause
Definition at line 177 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
PlayerMode mitk::NavigationDataPlayer::m_PlayerMode [protected] |
stores the mode for the presetted PlayerMode sieh enum PlayerMode
Definition at line 163 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
bool mitk::NavigationDataPlayer::m_Playing [protected] |
indicates whether the generateoutput method generates new output or not
Definition at line 169 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
the starttime of the playing set in the method StartPlaying()
Definition at line 175 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().
std::vector<TimeStampType> mitk::NavigationDataPlayer::m_StartTimeOfData [protected] |
stores the start time of the different tools
Definition at line 181 of file mitkNavigationDataPlayer.h.
std::istream* mitk::NavigationDataPlayer::m_Stream [protected] |
stores a pointer to the input stream
Definition at line 161 of file mitkNavigationDataPlayer.h.
Referenced by NavigationDataPlayer().