diff --git a/Modules/Bundles/org.mitk.gui.qt.navigationdataplayer/src/internal/QmitkNavigationDataPlayerView.cpp b/Modules/Bundles/org.mitk.gui.qt.navigationdataplayer/src/internal/QmitkNavigationDataPlayerView.cpp index 5908d7c3e1..cc8025bb6a 100644 --- a/Modules/Bundles/org.mitk.gui.qt.navigationdataplayer/src/internal/QmitkNavigationDataPlayerView.cpp +++ b/Modules/Bundles/org.mitk.gui.qt.navigationdataplayer/src/internal/QmitkNavigationDataPlayerView.cpp @@ -1,258 +1,383 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ Version: $Revision: 21975 $ 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. =========================================================================*/ // Blueberry #include #include // Qmitk #include "QmitkNavigationDataPlayerView.h" #include "QmitkStdMultiWidget.h" //mitk #include // Qt #include // vtk #include const std::string QmitkNavigationDataPlayerView::VIEW_ID = "org.mitk.views.navigationdataplayer"; QmitkNavigationDataPlayerView::QmitkNavigationDataPlayerView() : QmitkFunctionality() , m_Controls( 0 ) , m_MultiWidget( NULL ) , m_ColorCycle( NULL ) +, m_Trajectory( NULL ) +, m_TrajectoryIndex( -1 ) , m_ReloadData( true ) +, m_ShowTrajectory( false ) +, m_TrajectorySpline( NULL ) { - m_RepresentationObjectsSet = new std::set(); + m_RepresentationObjects = new std::vector(); + m_TrajectoryPointSet = mitk::PointSet::New(); + m_SplineMapper = mitk::SplineVtkMapper3D::New(); } QmitkNavigationDataPlayerView::~QmitkNavigationDataPlayerView() { delete m_PlayerWidget; delete m_ColorCycle; - delete m_RepresentationObjectsSet; + delete m_RepresentationObjects; + } void QmitkNavigationDataPlayerView::CreateQtPartControl( QWidget *parent ) { // build up qt view, unless already done if ( !m_Controls ) { // create GUI widgets from the Qt Designer's .ui file m_Controls = new Ui::QmitkNavigationDataPlayerViewControls; m_Controls->setupUi( parent ); this->CreateBundleWidgets( parent ); this->CreateConnections(); } } void QmitkNavigationDataPlayerView::CreateBundleWidgets(QWidget* parent) { m_PlayerWidget = new QmitkIGTPlayerWidget( parent ); - m_PlayerWidget->SetWidgetViewToNormalPlayback(); + //m_PlayerWidget->SetWidgetViewToNormalPlayback(); } void QmitkNavigationDataPlayerView::CreateConnections() { - connect( (QObject*) m_PlayerWidget, SIGNAL(PlayingStarted()), this, SLOT(CreatePlaybackVisualization()) ); - connect( (QObject*) m_PlayerWidget, SIGNAL(PlayerUpdated()), this, SLOT(PerformPlaybackVisualization()) ); - connect( (QObject*) m_PlayerWidget, SIGNAL(InputFileChanged()), this, SLOT(Reinit()) ); + connect( m_PlayerWidget, SIGNAL(PlayingStarted()), this, SLOT(CreatePlaybackVisualization()) ); + connect( m_PlayerWidget, SIGNAL(PlayerUpdated()), this, SLOT(PerformPlaybackVisualization()) ); + connect( m_PlayerWidget, SIGNAL(InputFileChanged()), this, SLOT(Reinit()) ); + connect( m_PlayerWidget, SIGNAL(SignalCurrentTrajectoryChanged(int)), this, SLOT (OnShowTrajectory(int)) ); + connect( m_PlayerWidget, SIGNAL(PlayingStarted()), this, SLOT(OnPlayingStarted()) ); } void QmitkNavigationDataPlayerView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_MultiWidget = &stdMultiWidget; } void QmitkNavigationDataPlayerView::StdMultiWidgetNotAvailable() { m_MultiWidget = NULL; } +void QmitkNavigationDataPlayerView::OnPlayingStarted() +{ + m_TrajectoryPointSet->Clear(); +} + void QmitkNavigationDataPlayerView::CreatePlaybackVisualization() { if(m_ReloadData) { - - m_ColorCycle = new mitk::ColorSequenceCycleH(); m_Visualizer = mitk::NavigationDataObjectVisualizationFilter::New(); mitk::DataStorage* ds = this->GetDefaultDataStorage(); unsigned int nrTools = m_PlayerWidget->GetNumberOfTools(); + QStringList toolNames; + toolNames << "No trajectory selected ..."; // info statement at beginning of trajectories list + for(int i=0; iGetColorCircleColor(i); - mitk::DataNode::Pointer playbackRepresentation = this->CreateRepresentationObject( ss.str(), m_ColorCycle->GetNextColor() ); + mitk::DataNode::Pointer playbackRepresentation = this->CreateRepresentationObject( nodeName.toStdString(), color ); m_Visualizer->SetRepresentationObject(i, playbackRepresentation->GetData()); // check if node not already exists in DataStorage and delete if so //mitk::DataNode::Pointer dn = ds->GetNamedNode(ss.str().c_str()); /* if(dn.IsNotNull()) this->RemoveRepresentationObject(this->GetDefaultDataStorage(), dn);*/ //ds->Remove(dn); // adding new representation object to DataStorage - this->AddRepresentationObject(this->GetDefaultDataStorage(), playbackRepresentation); + this->AddRepresentationObject(this->GetDefaultDataStorage(), playbackRepresentation); + } + + this->m_PlayerWidget->SetTrajectoryNames(toolNames); m_ReloadData = false; } + } +mitk::DataNode::Pointer QmitkNavigationDataPlayerView::CreateTrajectory( mitk::PointSet::Pointer points, const std::string& name, const mitk::Color color ) +{ + mitk::DataNode::Pointer result = mitk::DataNode::New(); + + result->SetData(points); + result->SetName(name); + result->SetColor(color); + + /* result->SetProperty("contourcolor", mitk::ColorProperty::New(color)); + result->SetBoolProperty("show contour", true); + result->SetBoolProperty("updateDataOnRender", false);*/ + -mitk::DataNode::Pointer QmitkNavigationDataPlayerView::CreateRepresentationObject(const std::string name, const mitk::Color color) + return result; +} + + +mitk::DataNode::Pointer QmitkNavigationDataPlayerView::CreateRepresentationObject(const std::string& name, const mitk::Color color) { mitk::DataNode::Pointer representationNode = mitk::DataNode::New(); mitk::Cone::Pointer cone = mitk::Cone::New(); vtkConeSource* vtkData = vtkConeSource::New(); + + vtkData->SetRadius(7.5); vtkData->SetHeight(15.0); vtkData->SetDirection(0.0, 0.0, 1.0); vtkData->SetCenter(0.0, 0.0, 0.0); vtkData->SetResolution(20); vtkData->CappingOn(); vtkData->Update(); cone->SetVtkPolyData(vtkData->GetOutput()); vtkData->Delete(); representationNode->SetData(cone); representationNode->GetPropertyList()->SetProperty("name", mitk::StringProperty::New( name.c_str() )); representationNode->GetPropertyList()->SetProperty("layer", mitk::IntProperty::New(0)); representationNode->GetPropertyList()->SetProperty("visible", mitk::BoolProperty::New(true)); representationNode->SetColor(color); - representationNode->SetOpacity(0.9); + representationNode->SetOpacity(1.0); representationNode->Modified(); return representationNode; } void QmitkNavigationDataPlayerView::PerformPlaybackVisualization() { if(m_PlayerWidget == NULL || m_Visualizer.IsNull()) return; + static int update = 0; + update++; + for(unsigned int i = 0 ; i < m_PlayerWidget->GetNavigationDatas().size(); ++i) { m_Visualizer->SetInput(i, m_PlayerWidget->GetNavigationDatas().at(i)); + + if(m_ShowTrajectory && (i == m_TrajectoryIndex) && (update % m_PlayerWidget->GetResolution() == 0) ) + m_TrajectoryPointSet->InsertPoint(update, m_PlayerWidget->GetNavigationDataPoint(i)); } this->RenderScene(); } void QmitkNavigationDataPlayerView::RenderScene() { try { if (m_Visualizer.IsNull() || this->GetActiveStdMultiWidget() == NULL) return; try { m_Visualizer->Update(); } catch(std::exception& e) { std::cout << "Exception during QmitkNavigationDataPlayerView::RenderScene():" << e.what() << "\n"; } //update all Widgets // mitk::RenderingManager::GetInstance()->RequestUpdateAll(mitk::RenderingManager::REQUEST_UPDATE_3DWINDOWS); // update only Widget4 mitk::BaseRenderer::GetInstance(m_MultiWidget->mitkWidget4->GetRenderWindow())->RequestUpdate(); // update 3D render window - } catch (std::exception& e) { std::cout << "RenderAll exception: " << e.what() << "\n"; } catch (...) { std::cout << "RenderAll unknown exception\n"; } - - } void QmitkNavigationDataPlayerView::Reinit() { - std::set::iterator it; + std::vector::iterator it; mitk::DataStorage* ds = this->GetDefaultDataStorage(); - for ( it = m_RepresentationObjectsSet->begin() ; it != m_RepresentationObjectsSet->end(); it++ ) + for ( it = m_RepresentationObjects->begin() ; it != m_RepresentationObjects->end(); it++ ) { + //ds->Remove(*it); mitk::DataNode::Pointer dn = ds->GetNamedNode((*it)->GetName()); if(dn.IsNotNull()) ds->Remove(dn); } - m_RepresentationObjectsSet->clear(); + m_RepresentationObjects->clear(); + + if(m_Trajectory.IsNotNull()) + this->GetDefaultDataStorage()->Remove(m_Trajectory); + + m_TrajectoryPointSet->Clear(); + this->m_PlayerWidget->ClearTrajectorySelectCombobox(); m_ReloadData = true; } +void QmitkNavigationDataPlayerView::AddTrajectory(mitk::DataStorage* ds, mitk::DataNode::Pointer trajectoryNode) +{ + if(ds == NULL) + return; + + if(m_Trajectory.IsNotNull()) + ds->Remove(m_Trajectory); + + + if(ds != NULL && trajectoryNode.IsNotNull()) + { + m_Trajectory = trajectoryNode; + ds->Add(m_Trajectory); + } +} + void QmitkNavigationDataPlayerView::AddRepresentationObject(mitk::DataStorage* ds, mitk::DataNode::Pointer reprObject) { - m_RepresentationObjectsSet->insert(reprObject); + m_RepresentationObjects->push_back(reprObject); // ds->RemoveNodeEvent.AddListener( mitk::MessageDelegate1(this, &QmitkNavigationDataPlayerView::RemoveRepresentationObject)); ds->Add(reprObject); } void QmitkNavigationDataPlayerView::RemoveRepresentationObject(mitk::DataStorage* ds, mitk::DataNode::Pointer reprObject) { - std::set::iterator it; + std::vector::iterator it; - it = m_RepresentationObjectsSet->find(reprObject); + for ( it = m_RepresentationObjects->begin() ; it != m_RepresentationObjects->end(); it++ ) + { + if(*it == reprObject) + { + m_RepresentationObjects->erase(it); + ds->Remove(reprObject); + } + } +} + +void QmitkNavigationDataPlayerView::OnShowTrajectory(int index) +{ + + mitk::DataStorage* ds = this->GetDefaultDataStorage(); + + + if(index == 0) + { + m_ShowTrajectory = false; + m_TrajectoryIndex = -1; + + if(m_Trajectory.IsNotNull()) + ds->Remove(m_Trajectory); + } + + else + { + m_ShowTrajectory = true; -// if(it != m_RepresentationObjectsSet->end()) - m_RepresentationObjectsSet->erase(it); - ds->Remove(reprObject); + // index-1 because combobox is filled with infovalue at index = 0 + mitk::DataNode::Pointer replayObject = m_RepresentationObjects->at(index-1); + + std::string prefix("Trajectory of "); + std::string name = replayObject->GetName(); + + mitk::Color color = this->GetColorCircleColor(index-1); + + if(m_TrajectoryPointSet.IsNotNull()) + m_TrajectoryPointSet->Clear(); + + m_TrajectoryIndex = index-1; + + mitk::DataNode::Pointer trajectory = this->CreateTrajectory( m_TrajectoryPointSet, prefix.append(name), color ); + trajectory->SetMapper(mitk::BaseRenderer::Standard3D, m_SplineMapper); + + this->AddTrajectory(this->GetDefaultDataStorage(), trajectory); + } + + +} + + + +mitk::Color QmitkNavigationDataPlayerView::GetColorCircleColor(int index) +{ + mitk::Color result; + + mitk::ColorSequenceCycleH colorCycle; + + for(int i=0; i <= index; ++i) + { + result = colorCycle.GetNextColor(); + } + return result; } \ No newline at end of file diff --git a/Modules/Bundles/org.mitk.gui.qt.navigationdataplayer/src/internal/QmitkNavigationDataPlayerView.h b/Modules/Bundles/org.mitk.gui.qt.navigationdataplayer/src/internal/QmitkNavigationDataPlayerView.h index 1631f87153..a3e4a15bc3 100644 --- a/Modules/Bundles/org.mitk.gui.qt.navigationdataplayer/src/internal/QmitkNavigationDataPlayerView.h +++ b/Modules/Bundles/org.mitk.gui.qt.navigationdataplayer/src/internal/QmitkNavigationDataPlayerView.h @@ -1,101 +1,126 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-03-31 16:40:27 +0200 (Mi, 31 Mrz 2010) $ Version: $Revision: 21975 $ 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 QmitkNavigationDataPlayerView_h #define QmitkNavigationDataPlayerView_h #include //Qmitk #include #include +#include +#include + // ui #include "ui_QmitkNavigationDataPlayerViewControls.h" //mitk #include #include + /*! \brief QmitkNavigationDataPlayerView \warning This application module is not yet documented. Use "svn blame/praise/annotate" and ask the author to provide basic documentation. \sa QmitkFunctionality \ingroup Functionalities */ class QmitkNavigationDataPlayerView : public QObject, public QmitkFunctionality { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) Q_OBJECT public: static const std::string VIEW_ID; QmitkNavigationDataPlayerView(); virtual ~QmitkNavigationDataPlayerView(); virtual void CreateQtPartControl(QWidget *parent); /** \brief This method creates this bundle's SIGNAL and SLOT connections */ virtual void CreateConnections(); virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); virtual void StdMultiWidgetNotAvailable(); protected slots: void CreatePlaybackVisualization(); void PerformPlaybackVisualization(); void Reinit(); + void OnShowTrajectory(int index); + void OnPlayingStarted(); protected: void CreateBundleWidgets(QWidget* parent); void RenderScene(); - mitk::DataNode::Pointer CreateRepresentationObject( const std::string name , const mitk::Color color ); + mitk::DataNode::Pointer CreateRepresentationObject( const std::string& name , const mitk::Color color ); void AddRepresentationObject(mitk::DataStorage* ds, mitk::DataNode::Pointer reprObject); void RemoveRepresentationObject(mitk::DataStorage* ds, mitk::DataNode::Pointer reprObject); + void AddTrajectory(mitk::DataStorage* ds, mitk::DataNode::Pointer trajectoryNode); + + mitk::DataNode::Pointer CreateTrajectory( mitk::PointSet::Pointer points, const std::string& name, const mitk::Color color ); + Ui::QmitkNavigationDataPlayerViewControls* m_Controls; QmitkStdMultiWidget* m_MultiWidget; QmitkIGTPlayerWidget* m_PlayerWidget; mitk::ColorSequenceCycleH* m_ColorCycle; mitk::NavigationDataObjectVisualizationFilter::Pointer m_Visualizer; // this filter visualizes the navigation data - std::set* m_RepresentationObjectsSet; + std::vector* m_RepresentationObjects; + + mitk::DataNode::Pointer m_Trajectory; + mitk::PointSet::Pointer m_TrajectoryPointSet; + int m_TrajectoryIndex; + bool m_ReloadData; + bool m_ShowTrajectory; + + vtkCardinalSpline *m_TrajectorySpline; + mitk::SplineVtkMapper3D::Pointer m_SplineMapper; + + +private: + + mitk::Color GetColorCircleColor(int index); + }; #endif // _QMITKNAVIGATIONDATAPLAYERVIEW_H_INCLUDED diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataPlayerBase.cpp b/Modules/IGT/IGTFilters/mitkNavigationDataPlayerBase.cpp index fdd1a58318..543812eea9 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataPlayerBase.cpp +++ b/Modules/IGT/IGTFilters/mitkNavigationDataPlayerBase.cpp @@ -1,111 +1,114 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-02-10 18:08:54 +0100 (Di, 10 Feb 2009) $ Version: $Revision: 16228 $ 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 "mitkNavigationDataPlayerBase.h" mitk::NavigationDataPlayerBase::~NavigationDataPlayerBase() { } + + + void mitk::NavigationDataPlayerBase::UpdateOutputInformation() { this->Modified(); // make sure that we need to be updated Superclass::UpdateOutputInformation(); } mitk::NavigationData::Pointer mitk::NavigationDataPlayerBase::ReadNavigationData(TiXmlElement* elem) { 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(); 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); return nd; } diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataPlayerBase.h b/Modules/IGT/IGTFilters/mitkNavigationDataPlayerBase.h index 38941f787f..d18055e449 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataPlayerBase.h +++ b/Modules/IGT/IGTFilters/mitkNavigationDataPlayerBase.h @@ -1,60 +1,66 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-02-10 18:08:54 +0100 (Di, 10 Feb 2009) $ Version: $Revision: 16228 $ 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 MITKNavigationDataPlayerBase_H_HEADER_INCLUDED_ #define MITKNavigationDataPlayerBase_H_HEADER_INCLUDED_ #include #include "tinyxml.h" namespace mitk{ /**Documentation * \brief This class is a slightly changed reimplementation of the * NavigationDataPlayer which does not care about timestamps and just * outputs the navigationdatas in their sequential order * * \ingroup IGT */ class MitkIGT_EXPORT NavigationDataPlayerBase : public NavigationDataSource { public: mitkClassMacro(NavigationDataPlayerBase, NavigationDataSource); /** * \brief Used for pipeline update just to tell the pipeline that we always have to update */ virtual void UpdateOutputInformation(); + /** + * \brief This method checks if player arrived at end of file. + * + *\warning This method is not tested yet. It is not save to use! + */ + const bool IsAtEnd(); protected: virtual ~NavigationDataPlayerBase(); virtual void GenerateData() = 0; /** * \brief Creates NavigationData from XML element and returns it */ mitk::NavigationData::Pointer ReadNavigationData(TiXmlElement* elem); }; } // namespace mitk #endif /* MITKNavigationDataSequentialPlayer_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetPlayer.cpp b/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetPlayer.cpp index 7f15bfb478..1ea2dbc3b2 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetPlayer.cpp +++ b/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetPlayer.cpp @@ -1,261 +1,193 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-02-10 18:08:54 +0100 (Di, 10 Feb 2009) $ Version: $Revision: 16228 $ 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 "mitkNavigationDataToPointSetPlayer.h" //for the pause #include #include #include #include +#include + mitk::NavigationDataToPointSetPlayer::NavigationDataToPointSetPlayer() : m_Doc(new TiXmlDocument) , m_DataElem(0) , m_CurrentElem(0) , m_Repeat(false) , m_NumberOfSnapshots(0) , m_LastGoTo(0) { } mitk::NavigationDataToPointSetPlayer::~NavigationDataToPointSetPlayer() { delete m_Doc; } void mitk::NavigationDataToPointSetPlayer::ReinitXML() { + m_NDPointSet.clear(); + m_PointSetFilter = mitk::NavigationDataToPointSetFilter::New(); + m_DataElem = m_Doc->FirstChildElement("Data"); int toolcount; if(!m_DataElem) MITK_WARN << "Data element not found"; else { m_DataElem->QueryIntAttribute("ToolCount", &toolcount); this->SetNumberOfOutputs(toolcount); mitk::NavigationData::Pointer emptyNd = mitk::NavigationData::New(); mitk::NavigationData::PositionType position; mitk::NavigationData::OrientationType orientation(0.0,0.0,0.0,0.0); position.Fill(0.0); emptyNd->SetPosition(position); emptyNd->SetOrientation(orientation); emptyNd->SetDataValid(false); mitk::NavigationData::Pointer tmp; for (unsigned int index = 0; index < this->GetNumberOfOutputs(); index++) { tmp = mitk::NavigationData::New(); tmp->Graft(emptyNd); this->SetNthOutput(index, tmp); } // find out _NumberOfSnapshots + + NavigationData::Pointer nd; + m_NumberOfSnapshots = 0; TiXmlElement* nextND = m_DataElem->FirstChildElement("ND"); + while(nextND) { ++m_NumberOfSnapshots; nextND = nextND->NextSiblingElement("ND"); - } + } + // e.g. 12 nd found and 2 tools used => number of snapshots is 12:2=6 m_NumberOfSnapshots = m_NumberOfSnapshots/toolcount; + /*NavigationData::TimeStampType recordedTime = (lastTimestamp-firstTimestamp) / 1000; + int frameRate = static_cast(floor(1000 / (float) (m_NumberOfSnapshots/recordedTime) + 0.5));*/ + } } -void mitk::NavigationDataToPointSetPlayer::GoToSnapshot(int i) -{ - assert(m_DataElem); - - int numOfUpdateCalls = 0; - // i.e. number of snapshots 10 - // goto(7), m_LastGoTo=3 => numOfUpdateCalls = 4 - if(m_LastGoTo <= i) - numOfUpdateCalls = i - m_LastGoTo; - // goto(4), m_LastGoTo=7 => numOfUpdateCalls = 7 - else - { - if(!m_Repeat) - { - MITK_WARN << "cannot go back to snapshot " << i << " because the " - << this->GetNameOfClass() << " is configured to not repeat the" - << " navigation data"; - - } - else - { - numOfUpdateCalls = (m_NumberOfSnapshots - m_LastGoTo) + i; - } - } - - for(int j=0; jUpdate(); - - m_LastGoTo = i; -} void mitk::NavigationDataToPointSetPlayer:: SetFileName(const std::string& _FileName) { m_FileName = _FileName; if(!m_Doc->LoadFile(m_FileName)) { this->SetNumberOfOutputs(0); std::ostringstream s; s << "File " << _FileName << " could not be loaded"; throw std::invalid_argument(s.str()); } else + { this->ReinitXML(); + } this->Modified(); } -void mitk::NavigationDataToPointSetPlayer:: - SetXMLString(const std::string& _XMLString) -{ - m_XMLString = _XMLString; - - m_Doc->Parse( m_XMLString.c_str() ); - this->ReinitXML(); - - this->Modified(); -} void mitk::NavigationDataToPointSetPlayer::GenerateData() { assert(m_DataElem); // very important: go through the tools (there could be more then one) mitk::NavigationData::Pointer tmp; for (unsigned int index = 0; index < this->GetNumberOfOutputs(); index++) { // go to the first element if(!m_CurrentElem) m_CurrentElem = m_DataElem->FirstChildElement("ND"); // go to the next element else m_CurrentElem = m_CurrentElem->NextSiblingElement(); // if repeat is on: go back to the first element (prior calls delivered NULL // elem) if(!m_CurrentElem && m_Repeat) m_CurrentElem = m_DataElem->FirstChildElement("ND"); mitk::NavigationData* output = this->GetOutput(index); tmp = this->ReadVersion1(); if(tmp.IsNotNull()) output->Graft(tmp); else // no valid output output->SetDataValid(false); } } -mitk::NavigationData::Pointer mitk::NavigationDataToPointSetPlayer::ReadVersion1() + +void mitk::NavigationDataToPointSetPlayer::StartPlaying() { - 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; + //TODO +} - bool hasPosition = true; - bool hasOrientation = true; - bool dataValid = false; +void mitk::NavigationDataToPointSetPlayer::StopPlaying() +{ + //TODO +} - position.Fill(0.0); - matrix.SetIdentity(); +void mitk::NavigationDataToPointSetPlayer::Pause() +{ + //TODO +} - TiXmlElement* elem = m_CurrentElem; +void mitk::NavigationDataToPointSetPlayer::Resume() +{ + //TODO +} - if(!elem) - return NULL; - //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 - } +//TODO +const bool mitk::NavigationDataToPointSetPlayer::IsAtEnd() +{ + bool result = false; + return result; +} - 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; +mitk::NavigationData::Pointer mitk::NavigationDataToPointSetPlayer::ReadVersion1() +{ + TiXmlElement* elem = m_CurrentElem; - tmpval = 0; - elem->QueryIntAttribute("hO", &tmpval); - if (tmpval == 0) - hasOrientation = false; - else - hasOrientation = true; + if(!elem) + return NULL; - 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; + return this->ReadNavigationData(elem); } void mitk::NavigationDataToPointSetPlayer::UpdateOutputInformation() { this->Modified(); // make sure that we need to be updated Superclass::UpdateOutputInformation(); } diff --git a/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetPlayer.h b/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetPlayer.h index 1ab1fd6156..cc75553f23 100644 --- a/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetPlayer.h +++ b/Modules/IGT/IGTFilters/mitkNavigationDataToPointSetPlayer.h @@ -1,111 +1,159 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-02-10 18:08:54 +0100 (Di, 10 Feb 2009) $ Version: $Revision: 16228 $ 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 MITKNavigationDataToPointSetPlayer_H_HEADER_INCLUDED_ #define MITKNavigationDataToPointSetPlayer_H_HEADER_INCLUDED_ -#include +#include +#include +#include #include "tinyxml.h" namespace mitk { /**Documentation * \brief This class is a slightly changed reimplementation of the * NavigationDataPlayer which does not care about timestamps and just * outputs the navigationdatas in their sequential order * * \ingroup IGT */ class MitkIGT_EXPORT NavigationDataToPointSetPlayer - : public NavigationDataSource + : public NavigationDataPlayerBase { public: - mitkClassMacro(NavigationDataToPointSetPlayer, NavigationDataSource); + mitkClassMacro(NavigationDataToPointSetPlayer, NavigationDataPlayerBase); itkNewMacro(Self); /** * \brief sets the file name and path (if XMLString is set, this is neglected) */ void SetFileName(const std::string& _FileName); /** * \brief returns the file name and path */ itkGetStringMacro(FileName); /** * \brief sets a xml string (by this, the xml string is not read from file) */ void SetXMLString(const std::string& _XMLString); /** * \brief returns the current xml string */ itkGetStringMacro(XMLString); /// /// set to true if the data player should repeat the outputs /// itkSetMacro(Repeat, bool); /// /// set if the data player should repeat the outputs /// itkGetMacro(Repeat, bool); /// /// \return the number of navigation data snapshots available in the file /// itkGetMacro(NumberOfSnapshots, unsigned int); /// /// advance the output to the i-th snapshot /// e.g. if you want to have the NavData of snapshot /// 17 then you can call GoToSnapshot(17). index begins at 1! /// you can then also go back to snapshot 1 with GoToSnapshot(1) /// void GoToSnapshot(int i); /** * \brief Used for pipeline update just to tell the pipeline * that we always have to update */ virtual void UpdateOutputInformation(); + + + /** + * \brief 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*)). + */ + void StartPlaying(); + + /** + * \brief Stops the player and closes the stream. After a call of StopPlaying() + * StartPlaying() must be called to get new output data + * + * \warning the output is generated in this method because we know first about the number of output after + * reading the first lines of the XML file. Therefore you should assign your output after the call of this method + */ + void StopPlaying(); + + /** + * \brief This method pauses the player. If you want to play again call Resume() + * + *\warning This method is not tested yet. It is not save to use! + */ + void Pause(); + + /** + * \brief This method resumes the player when it was paused. + * + *\warning This method is not tested yet. It is not save to use! + */ + void Resume(); + + + + + + + + const bool IsAtEnd(); + protected: NavigationDataToPointSetPlayer(); virtual ~NavigationDataToPointSetPlayer(); void ReinitXML(); mitk::NavigationData::Pointer ReadVersion1(); /// /// do the work here /// virtual void GenerateData(); + + NavigationDataToPointSetFilter::Pointer m_PointSetFilter; + std::string m_FileName; std::string m_XMLString; TiXmlDocument* m_Doc; TiXmlElement* m_DataElem; TiXmlElement* m_CurrentElem; bool m_Repeat; unsigned int m_NumberOfSnapshots; int m_LastGoTo; + + std::vector m_NDPointSet; }; } // namespace mitk #endif /* MITKNavigationDataToPointSetPlayer_H_HEADER_INCLUDED_ */ diff --git a/Modules/IGT/files.cmake b/Modules/IGT/files.cmake index 4db0a79872..fd9fde96d0 100644 --- a/Modules/IGT/files.cmake +++ b/Modules/IGT/files.cmake @@ -1,59 +1,59 @@ SET(CPP_FILES IGTFilters/mitkNavigationDataLandmarkTransformFilter.cpp IGTFilters/mitkNavigationDataReferenceTransformFilter.cpp IGTFilters/mitkNavigationDataTransformFilter.cpp IGTFilters/mitkNavigationDataRecorder.cpp IGTFilters/mitkNavigationDataPlayer.cpp IGTFilters/mitkNavigationDataPlayerBase.cpp IGTFilters/mitkNavigationDataObjectVisualizationFilter.cpp IGTFilters/mitkCameraVisualization.cpp IGTFilters/mitkNavigationData.cpp IGTFilters/mitkNavigationDataDisplacementFilter.cpp IGTFilters/mitkNavigationDataSequentialPlayer.cpp IGTFilters/mitkNavigationDataSource.cpp IGTFilters/mitkNavigationDataToMessageFilter.cpp IGTFilters/mitkNavigationDataToNavigationDataFilter.cpp IGTFilters/mitkNavigationDataToOpenGLFilter.cpp IGTFilters/mitkNavigationDataToPointSetFilter.cpp - IGTFilters/mitkNavigationDataToPointSetPlayer.cpp + IGTFilters/mitkTrackingDeviceSource.cpp IGTFilters/mitkTimeStamp.cpp IGTFilters/mitkRealTimeClock.cpp IGTFilters/mitkTrackingDeviceSourceConfigurator.cpp IGTTrackingDevices/mitkClaronTool.cpp IGTTrackingDevices/mitkClaronTrackingDevice.cpp IGTTrackingDevices/mitkInternalTrackingTool.cpp IGTTrackingDevices/mitkNDIPassiveTool.cpp IGTTrackingDevices/mitkNDIProtocol.cpp IGTTrackingDevices/mitkNDITrackingDevice.cpp IGTTrackingDevices/mitkSerialCommunication.cpp IGTTrackingDevices/mitkTrackingDevice.cpp IGTTrackingDevices/mitkTrackingTool.cpp IGTTrackingDevices/mitkTrackingVolume.cpp IGTTrackingDevices/mitkVirtualTrackingDevice.cpp IGTTrackingDevices/mitkVirtualTrackingTool.cpp IGTToolManagement/mitkNavigationToolStorage.cpp IGTToolManagement/mitkNavigationToolStorageSerializer.cpp IGTToolManagement/mitkNavigationToolStorageDeserializer.cpp IGTToolManagement/mitkNavigationTool.cpp IGTToolManagement/mitkNavigationToolReader.cpp IGTToolManagement/mitkNavigationToolWriter.cpp ) IF(MITK_USE_MICRON_TRACKER) SET(CPP_FILES ${CPP_FILES} IGTTrackingDevices/mitkClaronInterface.cpp) ELSE() SET(CPP_FILES ${CPP_FILES} IGTTrackingDevices/mitkClaronInterfaceStub.cpp) ENDIF(MITK_USE_MICRON_TRACKER) IF(MITK_USE_MICROBIRD_TRACKER) SET(CPP_FILES ${CPP_FILES} IGTTrackingDevices/mitkMicroBirdTrackingDevice.cpp) ENDIF(MITK_USE_MICROBIRD_TRACKER) IF(WIN32) SET(CPP_FILES ${CPP_FILES} IGTFilters/mitkWindowsRealTimeClock.cpp) ELSE() SET(CPP_FILES ${CPP_FILES} IGTFilters/mitkLinuxRealTimeClock.cpp) ENDIF(WIN32) \ No newline at end of file diff --git a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp index 09d809e347..2a154fadb2 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.cpp @@ -1,340 +1,381 @@ /*========================================================================= 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(); } 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->m_pbLoadDir), 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->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->m_pbPlay), SIGNAL(clicked(bool)), this, SLOT(OnPlayButtonClicked(bool)) ); // play button + 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->m_pbBegin), SIGNAL(clicked()), this, SLOT(OnGoToBegin()) ); // reset player and go to begin - connect( (QObject*) (m_Controls->m_pbEnd), SIGNAL(clicked()), this, SLOT(OnGoToEnd()) ); // reset player + 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)) ); } } + bool QmitkIGTPlayerWidget::CheckInputFileValid() { QFile file(m_CmpFilename); 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; if(m_Player.IsNotNull()) result = m_Player->GetNumberOfOutputs(); return result; } void QmitkIGTPlayerWidget::SetUpdateRate(unsigned int msecs) { m_PlayingTimer->setInterval((int) msecs); } 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(); } else // resume play { m_Player->Resume(); m_PlayingTimer->start(100); emit PlayingResumed(); } } else // pause { m_Player->Pause(); m_PlayingTimer->stop(); emit PlayingPaused(); } } else - m_Controls->m_pbPlay->setChecked(false); // uncheck play button if file unvalid + 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(); if(m_Player.IsNotNull()) m_Player->StopPlaying(); m_Player = NULL; m_StartTime = -1; // set starttime back this->ResetLCDNumbers(); - m_Controls->m_pbPlay->setChecked(false); // set play button unchecked + 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->m_lcdNrMsec->display(ms); - m_Controls->m_lcdNrSec->display(s); - m_Controls->m_lcdNrMin->display(min); + m_Controls->msecLCDNumber->display(ms); + m_Controls->secLCDNumber->display(s); + m_Controls->minLCDNumber->display(min); emit PlayerUpdated(); // 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)); } + } + + 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); + } } - return navDatas; + 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()) + { + 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->m_leInputFile->setText(m_CmpFilename); + 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(); } - m_Controls->m_leInputFile->setText(m_CmpFilename); + 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->m_pbPlay->setChecked(false); + 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::SetWidgetViewToNormalPlayback() -{ - m_Controls->m_lblResolution->setHidden(true); - m_Controls->m_sbResolution->setHidden(true); - m_Controls->m_hsPlaybackPosition->setHidden(true); - m_Controls->m_pbFrameBackward->setHidden(true); - m_Controls->m_pbFastBackward->setHidden(true); - m_Controls->m_pbFrameForward->setHidden(true); - m_Controls->m_pbFastForward->setHidden(true); - m_Controls->m_lblSample->setHidden(true); - m_Controls->m_lcdNrSample->setHidden(true); -} +void QmitkIGTPlayerWidget::SetTrajectoryNames(const QStringList toolNames) +{ + QComboBox* cBox = m_Controls->trajectorySelectComboBox; + + if(cBox->count() > 0) + this->ClearTrajectorySelectCombobox(); + + disconnect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SIGNAL(SignalCurrentTrajectoryChanged(int)) ); + if(!toolNames.isEmpty()) + m_Controls->trajectorySelectComboBox->insertItems(0, toolNames); + + connect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SIGNAL(SignalCurrentTrajectoryChanged(int)) ); -void QmitkIGTPlayerWidget::SetWidgetViewToPointSetPlayback() -{ - m_Controls->m_lblResolution->setVisible(true); - m_Controls->m_sbResolution->setVisible(true); - m_Controls->m_hsPlaybackPosition->setHidden(false); - m_Controls->m_pbFrameBackward->setVisible(true); - m_Controls->m_pbFastBackward->setVisible(true); - m_Controls->m_pbFrameForward->setVisible(true); - m_Controls->m_pbFastForward->setVisible(true); - m_Controls->m_lblSample->setVisible(true); - m_Controls->m_lcdNrSample->setVisible(true); } -void QmitkIGTPlayerWidget::OnChangeWidgetView(bool pointSetPlaybackView) +int QmitkIGTPlayerWidget::GetResolution() { - if(pointSetPlaybackView) - this->SetWidgetViewToPointSetPlayback(); + return m_Controls->resolutionSpinBox->value(); +} - else - this->SetWidgetViewToNormalPlayback(); +void QmitkIGTPlayerWidget::ClearTrajectorySelectCombobox() +{ + disconnect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SIGNAL(SignalCurrentTrajectoryChanged(int)) ); + + m_Controls->trajectorySelectComboBox->clear(); + + connect( (QObject*) (m_Controls->trajectorySelectComboBox), SIGNAL(currentIndexChanged(int)), this, SIGNAL(SignalCurrentTrajectoryChanged(int)) ); } -void QmitkIGTPlayerWidget::ResetLCDNumbers() -{ - m_Controls->m_lcdNrMin->display(QString("00")); - m_Controls->m_lcdNrSec->display(QString("00")); - m_Controls->m_lcdNrMsec->display(QString("000")); -} \ No newline at end of file diff --git a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h index c4f4f08114..b729205df3 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidget.h @@ -1,208 +1,227 @@ /*========================================================================= 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 Sets the widget's look for the normal playback - */ - void SetWidgetViewToNormalPlayback(); - /*! - \brief Sets the widget's look for the PointSet playback - */ - void SetWidgetViewToPointSetPlayback(); + const mitk::PointSet::Pointer GetNavigationDatasPointSet(); + + + 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(); - + + void SetTrajectoryNames(const QStringList toolNames); + + int GetResolution(); + + void ClearTrajectorySelectCombobox(); + signals: /*! \brief This signal is emitted when the player starts the playback */ void PlayingStarted(); /*! \brief This signal is emitted when the player resumes after a pause */ void PlayingResumed(); /*! \brief This signal is emitted when the player stops */ void PlayingStopped(); /*! \brief This signal is emitted when the player is paused */ void PlayingPaused(); /*! \brief This signal is emitted when the player reaches the end of the playback */ void PlayingEnded(); /*! \brief This signal is emitted every time the player updated the NavigationDatas */ void PlayerUpdated(); void InputFileChanged(); + void SignalCurrentTrajectoryChanged(int index); + + 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); + + + + ///*! + //\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 a00ad31878..138c6d406d 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui +++ b/Modules/IGTUI/Qmitk/QmitkIGTPlayerWidgetControls.ui @@ -1,459 +1,346 @@ 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 - - - false + + + + 2 + 0 + - Playback in PointSet Mode + Trajectory - - - Qt::Horizontal - - - - 40 - 20 - + + + + 7 + 0 + - + - + + + + 2 + 0 + + Resolution 1 : Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - + + + + 1 + 0 + + 1 - 10 + 25 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 + + + + - - - Sample - - - - - - - background-color: rgb(60, 60, 60); -color: rgb(250, 250, 250); + + + + 1 + 0 + - - 8 + + - - QLCDNumber::Flat + + + :/IGTUI/firstframe.png:/IGTUI/firstframe.png - - - - - - color: rgb(170, 0, 0); - - - 0 - - - 100 - - - 5 - - - Qt::Horizontal - - - false - - - false - - - QSlider::NoTicks - - - - - - - - - - - 0 - 0 - - - - - - - - :/IGTUI/firstframe.png:/IGTUI/firstframe.png - - - - - - - - 0 - 0 - - - - - - - - :/IGTUI/fastbackward.png:/IGTUI/fastbackward.png - - - - 20 - 16 - - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - - - - - :/IGTUI/previousframe.png:/IGTUI/previousframe.png - - - - - - - + - - 0 + + 4 0 Play at normal speed :/IGTUI/play.png :/IGTUI/pause.png:/IGTUI/play.png 16 16 true false - - - - - - 0 - 0 - - - - - - - - :/IGTUI/nextframe.png:/IGTUI/nextframe.png - - - - - - - - 0 - 0 - - - - - - - - :/IGTUI/fastforward.png:/IGTUI/fastforward.png - - - - 20 - 16 - - - - - - - - - 0 - 0 - - - - - - - - :/IGTUI/stop.png:/IGTUI/stop.png - - - - + + + + 1 + 0 + + + + + + + + :/IGTUI/stop.png:/IGTUI/stop.png + + Qt::Vertical 20 40