diff --git a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp index 2a154fadb2..d511b02490 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp @@ -1,381 +1,387 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:14:45 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 1.12 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkIGTPlayerWidget.h" //mitk headers #include "mitkTrackingTypes.h" #include #include #include #include #include #include #include - - //qt headers #include #include #include QmitkIGTPlayerWidget::QmitkIGTPlayerWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f), m_Player(NULL), m_StartTime(-1.0) { m_Controls = NULL; CreateQtPartControl(this); CreateConnections(); - this->ResetLCDNumbers(); + + this->ResetLCDNumbers(); // reset lcd numbers at start } QmitkIGTPlayerWidget::~QmitkIGTPlayerWidget() { m_PlayingTimer->stop(); m_Player = NULL; m_PlayingTimer = NULL; } void QmitkIGTPlayerWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkIGTPlayerWidgetControls; m_Controls->setupUi(parent); m_PlayingTimer = new QTimer(this); // initialize update timer } } void QmitkIGTPlayerWidget::CreateConnections() { if ( m_Controls ) { connect( (QObject*)(m_Controls->selectPushButton), SIGNAL(clicked()), this, SLOT(OnSelectPressed()) ); // open file dialog - //connect( (QObject*) (m_Controls->m_cbPointSetMode), SIGNAL(clicked(bool)), this, SLOT(OnChangeWidgetView(bool)) ); // widget view switcher - connect( (QObject*)(m_Controls->playPushButton), SIGNAL(clicked(bool)), this, SLOT(OnPlayButtonClicked(bool)) ); // play button connect( (QObject*)(m_PlayingTimer), SIGNAL(timeout()), this, SLOT(OnPlaying()) ); // update timer - connect( (QObject*) (m_Controls->beginPushButton), SIGNAL(clicked()), this, SLOT(OnGoToBegin()) ); // reset player and go to begin connect( (QObject*) (m_Controls->stopPushButton), SIGNAL(clicked()), this, SLOT(OnGoToEnd()) ); // reset player - - // passing signal from ui component - connect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SLOT(SignalCurrentTrajectoryChanged(int)) ); + // pass this widgets protected combobox signal to public signal + connect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SIGNAL(SignalCurrentTrajectoryChanged(int)) ); + // pass this widgets protected checkbox signal to public signal + connect( m_Controls->splineModeCheckBox, SIGNAL(toggled(bool)), this, SIGNAL(SignalSplineModeToggled(bool)) ); } } +bool QmitkIGTPlayerWidget::IsTrajectoryInSplineMode() +{ + return m_Controls->splineModeCheckBox->isChecked(); +} + bool QmitkIGTPlayerWidget::CheckInputFileValid() { QFile file(m_CmpFilename); - if(!file.exists()) + // check if file exists + if(!file.exists()) { QMessageBox::warning(NULL, "IGTPlayer: Error", "No valid input file was loaded. Please load input file first!"); return false; } return true; } unsigned int QmitkIGTPlayerWidget::GetNumberOfTools() { unsigned int result = 0; + // at the moment this works only if player is initialized if(m_Player.IsNotNull()) result = m_Player->GetNumberOfOutputs(); return result; } void QmitkIGTPlayerWidget::SetUpdateRate(unsigned int msecs) { - m_PlayingTimer->setInterval((int) msecs); + m_PlayingTimer->setInterval((int) msecs); // set update timer update rate } void QmitkIGTPlayerWidget::OnPlayButtonClicked(bool checked) { if(CheckInputFileValid()) // no playing possible without valid input file { if(checked) // play { if(m_Player.IsNull()) // start play { m_Player = mitk::NavigationDataPlayer::New(); m_Player->SetFileName(m_CmpFilename.toStdString()); m_Player->StartPlaying(); m_PlayingTimer->start(100); - emit PlayingStarted(); + emit SignalPlayingStarted(); } else // resume play { m_Player->Resume(); m_PlayingTimer->start(100); - emit PlayingResumed(); + emit SignalPlayingResumed(); } } else // pause { m_Player->Pause(); m_PlayingTimer->stop(); - emit PlayingPaused(); + emit SignalPlayingPaused(); } } else m_Controls->playPushButton->setChecked(false); // uncheck play button if file unvalid } QTimer* QmitkIGTPlayerWidget::GetPlayingTimer() { return m_PlayingTimer; } void QmitkIGTPlayerWidget::OnStopPlaying() { this->StopPlaying(); } void QmitkIGTPlayerWidget::StopPlaying() { m_PlayingTimer->stop(); - emit PlayingStopped(); + emit SignalPlayingStopped(); if(m_Player.IsNotNull()) m_Player->StopPlaying(); m_Player = NULL; m_StartTime = -1; // set starttime back this->ResetLCDNumbers(); m_Controls->playPushButton->setChecked(false); // set play button unchecked } void QmitkIGTPlayerWidget::OnPlaying() { if(m_Player.IsNull()) return; if(m_StartTime < 0) m_StartTime = m_Player->GetOutput()->GetTimeStamp(); // get playback start time if(!m_Player->IsAtEnd()) { m_Player->Update(); // update player int msc = (int) (m_Player->GetOutput()->GetTimeStamp() - m_StartTime); // calculation for playing time display int ms = msc % 1000; msc = (msc - ms) / 1000; int s = msc % 60; int min = (msc-s) / 60; // set lcd numbers m_Controls->msecLCDNumber->display(ms); m_Controls->secLCDNumber->display(s); m_Controls->minLCDNumber->display(min); - emit PlayerUpdated(); // player successfully updated + emit SignalPlayerUpdated(); // player successfully updated } else this->StopPlaying(); // if player is at EOF } const std::vector QmitkIGTPlayerWidget::GetNavigationDatas() { std::vector navDatas; if(m_Player.IsNotNull()) { for(unsigned int i=0; i < m_Player->GetNumberOfOutputs(); ++i) { - navDatas.push_back(m_Player->GetOutput(i)); + navDatas.push_back(m_Player->GetOutput(i)); // push back current navigation data for each tool } } return navDatas; } const mitk::PointSet::Pointer QmitkIGTPlayerWidget::GetNavigationDatasPointSet() { mitk::PointSet::Pointer result = mitk::PointSet::New(); mitk::PointSet::PointType pointType; if(m_Player.IsNotNull()) { for(unsigned int i=0; i < m_Player->GetNumberOfOutputs(); ++i) { mitk::NavigationData::PositionType position = m_Player->GetOutput(i)->GetPosition(); pointType[0] = position[0]; pointType[1] = position[1]; pointType[2] = position[2]; - result->InsertPoint(i,pointType); + result->InsertPoint(i,pointType); // insert current ND as Pointtype in PointSet for return } } return result; } const mitk::PointSet::PointType QmitkIGTPlayerWidget::GetNavigationDataPoint(unsigned int index) { if( index > this->GetNumberOfTools() || index < 0 ) throw std::out_of_range("Tool Index out of range!"); mitk::PointSet::PointType result; if(m_Player.IsNotNull()) { + // create return PointType from current ND for tool index mitk::NavigationData::PositionType position = m_Player->GetOutput(index)->GetPosition(); - result[0] = position[0]; result[1] = position[1]; result[2] = position[2]; } return result; } void QmitkIGTPlayerWidget::SetInputFileName(const QString& inputFileName) { this->OnGoToEnd(); /// stops playing and resets lcd numbers QString oldName = m_CmpFilename; m_CmpFilename.clear(); m_CmpFilename = inputFileName; QFile file(m_CmpFilename); if(m_CmpFilename.isEmpty() || !file.exists()) { QMessageBox::warning(NULL, "Warning", QString("Please enter valid path! Using previous path again.")); m_CmpFilename=oldName; m_Controls->inputFileLineEdit->setText(m_CmpFilename); } } void QmitkIGTPlayerWidget::SetPlayer( mitk::NavigationDataPlayer::Pointer player ) { if(player.IsNotNull()) m_Player = player; } void QmitkIGTPlayerWidget::OnSelectPressed() { - QString oldName = m_CmpFilename; m_CmpFilename.clear(); m_CmpFilename = QFileDialog::getOpenFileName(this, "Load tracking data", QDir::currentPath(),"XML files (*.xml)"); if (m_CmpFilename.isEmpty())//if something went wrong or user pressed cancel in the save dialog m_CmpFilename=oldName; else { this->OnGoToEnd(); /// stops playing and resets lcd numbers - emit InputFileChanged(); + emit SignalInputFileChanged(); } m_Controls->inputFileLineEdit->setText(m_CmpFilename); } void QmitkIGTPlayerWidget::OnGoToEnd() { this->StopPlaying(); // reset lcd numbers this->ResetLCDNumbers(); } void QmitkIGTPlayerWidget::OnGoToBegin() { // stop player manual so no PlayingStopped() m_PlayingTimer->stop(); if(m_Player.IsNotNull()) m_Player->StopPlaying(); m_Player = NULL; // set player to NULL so it can be initialized again if playback is called afterwards m_StartTime = -1; // set starttime back //reset view elements m_Controls->playPushButton->setChecked(false); this->ResetLCDNumbers(); } void QmitkIGTPlayerWidget::ResetLCDNumbers() { m_Controls->minLCDNumber->display(QString("00")); m_Controls->secLCDNumber->display(QString("00")); m_Controls->msecLCDNumber->display(QString("000")); } void QmitkIGTPlayerWidget::SetTrajectoryNames(const QStringList toolNames) { QComboBox* cBox = m_Controls->trajectorySelectComboBox; if(cBox->count() > 0) this->ClearTrajectorySelectCombobox(); + // before making changed to QComboBox it is recommended to disconnet it's SIGNALS and SLOTS disconnect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SIGNAL(SignalCurrentTrajectoryChanged(int)) ); if(!toolNames.isEmpty()) - m_Controls->trajectorySelectComboBox->insertItems(0, toolNames); + m_Controls->trajectorySelectComboBox->insertItems(0, toolNames); // adding current tool names to combobox + // reconnect after performed changes connect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SIGNAL(SignalCurrentTrajectoryChanged(int)) ); - } int QmitkIGTPlayerWidget::GetResolution() { return m_Controls->resolutionSpinBox->value(); } void QmitkIGTPlayerWidget::ClearTrajectorySelectCombobox() { + // before making changed to QComboBox it is recommended to disconnet it's SIGNALS and SLOTS disconnect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SIGNAL(SignalCurrentTrajectoryChanged(int)) ); m_Controls->trajectorySelectComboBox->clear(); + // reconnect after performed changes connect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SIGNAL(SignalCurrentTrajectoryChanged(int)) ); } diff --git a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h index b729205df3..932f125d7a 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h @@ -1,227 +1,235 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-12 19:14:45 +0200 (Di, 12 Mai 2009) $ Version: $Revision: 1.12 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QmitkIGTPlayerWidget_H #define QmitkIGTPlayerWidget_H //QT headers #include //mitk headers #include "MitkIGTUIExports.h" #include "mitkNavigationTool.h" #include "mitkNavigationDataPlayer.h" #include #include //ui header #include "ui_QmitkIGTPlayerWidgetControls.h" /** Documentation: * \brief GUI to access the IGT Player. * User must specify the file name where the input xml-file is located. The NavigationDatas from the xml-file can be * played in normal mode or in PointSet mode. * * In normal mode the player updates the NavigationDatas every 100ms (can be changed in SetUpdateRate()) and returns * them when GetNavigationDatas() is called. * In PointSet mode the player generates a PointSet with all NavigationDatas from the xml-file. So the playback is * performed on this ND PointSet. * * \ingroup IGTUI */ class MitkIGTUI_EXPORT QmitkIGTPlayerWidget : public QWidget { Q_OBJECT public: static const std::string VIEW_ID; /*! \brief default constructor */ QmitkIGTPlayerWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); /*! \brief default deconstructor */ ~QmitkIGTPlayerWidget(); /*! \brief Sets the player for this player widget */ void SetPlayer(mitk::NavigationDataPlayer::Pointer player); /*! \brief Returns the playing timer of this widget */ QTimer* GetPlayingTimer(); /*! \brief Returns the current playback NavigationDatas from the xml-file */ const std::vector GetNavigationDatas(); - + /*! + \brief Returns a PointSet of the current NavigationDatas for all recorded tools. + */ const mitk::PointSet::Pointer GetNavigationDatasPointSet(); - + /*! + \brief Returns a PointType of the current NavigationData for a specific tool with the given index. + */ const mitk::PointSet::PointType GetNavigationDataPoint(unsigned int index); - ///*! - //\brief Sets the widget's look for the normal playback - //*/ - //void SetWidgetViewToNormalPlayback(); - - ///*! - //\brief Sets the widget's look for the PointSet playback - //*/ - //void SetWidgetViewToPointSetPlayback(); - /*! \brief Sets the update rate of this widget's playing timer */ void SetUpdateRate(unsigned int msecs); /*! \brief Returns the number of different tools from the current playing stream. * * Retuns 0 if playback file is invalid. */ unsigned int GetNumberOfTools(); /*! \brief Stops the playback */ void StopPlaying(); - + /*! + \brief Sets the given tool names list to the trajectory select combobox. + */ void SetTrajectoryNames(const QStringList toolNames); + /*! + \brief Returns the current resolution value from the resolution spinbox. + */ int GetResolution(); + /*! + \brief Clears all items in the trajectory selection combobox. + */ void ClearTrajectorySelectCombobox(); + /*! + \brief Returns whether spline mode checkbox is selected. + */ + bool IsTrajectoryInSplineMode(); + signals: /*! - \brief This signal is emitted when the player starts the playback + \brief This signal is emitted when the player starts the playback. */ - void PlayingStarted(); + void SignalPlayingStarted(); /*! - \brief This signal is emitted when the player resumes after a pause + \brief This signal is emitted when the player resumes after a pause. */ - void PlayingResumed(); + void SignalPlayingResumed(); /*! - \brief This signal is emitted when the player stops + \brief This signal is emitted when the player stops. */ - void PlayingStopped(); + void SignalPlayingStopped(); /*! - \brief This signal is emitted when the player is paused + \brief This signal is emitted when the player is paused. */ - void PlayingPaused(); + void SignalPlayingPaused(); /*! - \brief This signal is emitted when the player reaches the end of the playback + \brief This signal is emitted when the player reaches the end of the playback. */ - void PlayingEnded(); + void SignalPlayingEnded(); /*! - \brief This signal is emitted every time the player updated the NavigationDatas + \brief This signal is emitted every time the player updated the NavigationDatas. */ - void PlayerUpdated(); - - - void InputFileChanged(); + void SignalPlayerUpdated(); + /*! + \brief This signal is emitted if the input file for the replay was changed. + */ + void SignalInputFileChanged(); + /*! + \brief This signal is emitted if the index of the current selected trajectory select combobox item changes. + */ void SignalCurrentTrajectoryChanged(int index); + /*! + \brief This signal is emitted if the spline mode checkbox is toggled or untoggled. + */ + void SignalSplineModeToggled(bool checked); + protected slots: /*! \brief Starts or pauses the playback */ void OnPlayButtonClicked(bool toggled); /*! \brief Updates the playback data */ void OnPlaying(); /*! \brief Stops the playback */ void OnStopPlaying(); /*! \brief Updates the input filename */ void SetInputFileName(const QString& inputFileName); /*! \brief Opens file open dialog for searching the input file */ void OnSelectPressed(); /*! \brief Stops the playback */ void OnGoToEnd(); /*! \brief Stops the playback and resets the player to the beginning */ void OnGoToBegin(); - - ///*! - //\brief Switches between the normal playback view and the PointSet playback view - //*/ - //void OnChangeWidgetView(bool pointSetPlaybackView); - - - protected: /// \brief Creation of the connections virtual void CreateConnections(); virtual void CreateQtPartControl(QWidget *parent); /*! \brief Checks if an imput file with the set filename exists */ bool CheckInputFileValid(); /*! \brief Sets all LCD numbers to 0 */ void ResetLCDNumbers(); Ui::QmitkIGTPlayerWidgetControls* m_Controls; mitk::NavigationDataPlayer::Pointer m_Player; ///< plays NDs from a XML file QString m_CmpFilename; ///< filename of the input file QTimer* m_PlayingTimer; ///< update timer mitk::NavigationData::TimeStampType m_StartTime; ///< start time of playback needed for time display }; #endif \ No newline at end of file diff --git a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui index 138c6d406d..14d04a5314 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui +++ b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui @@ -1,346 +1,405 @@ QmitkIGTPlayerWidgetControls 0 0 398 689 Form - + Settings true false 2 0 Input File 8 0 150 0 true 2 0 90 16777215 50 false Select false - 2 + 1 0 Trajectory - + 7 0 + + + + Qt::Horizontal + + + + 40 + 20 + + + + 2 0 Resolution 1 : - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter 1 0 1 25 + + + + + + Qt::Horizontal + + + QSizePolicy::Expanding + + + + 40 + 20 + + + + + + + + + 0 + 0 + + + + Qt::LeftToRight + + + Spline Trajectory + + + + + - + Player true background-color: rgb(60, 60, 60); color: rgb(250, 250, 250); 3 QLCDNumber::Flat 0 min background-color: rgb(60, 60, 60); color: rgb(250, 250, 250); 2 QLCDNumber::Flat 0 sec background-color: rgb(60, 60, 60); color: rgb(250, 250, 250); 3 QLCDNumber::Flat 0 msec Qt::Horizontal 40 20 + + + + Qt::LeftToRight + + + Sequential Mode + + + 1 0 :/IGTUI/firstframe.png:/IGTUI/firstframe.png 4 0 Play at normal speed :/IGTUI/play.png :/IGTUI/pause.png:/IGTUI/play.png 16 16 true false 1 0 :/IGTUI/stop.png:/IGTUI/stop.png Qt::Vertical 20 40