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 cc8025bb6a..84be4f3956 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,383 +1,450 @@ /*========================================================================= 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_SplineMapper( NULL ) +, m_PointSetMapper( NULL ) { 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_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(); } void QmitkNavigationDataPlayerView::CreateConnections() { 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()) ); + + connect( m_PlayerWidget, SIGNAL(SignalSplineModeToggled(bool)), this, SLOT(OnEnableSplineTrajectoryMapper(bool)) ); + } 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_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( 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->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::PointSetVtkMapper3D::Pointer mapper; + + if(m_PlayerWidget->IsTrajectoryInSplineMode()) + mapper = this->GetTrajectoryMapper(Splines); + else + mapper = this->GetTrajectoryMapper(Points); + result->SetMapper(mitk::BaseRenderer::Standard3D, mapper); + + result->SetProperty("contourcolor", mitk::ColorProperty::New(color)); + result->SetBoolProperty("show contour", true); + result->SetBoolProperty("updateDataOnRender", false); 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(1.0); representationNode->Modified(); return representationNode; } void QmitkNavigationDataPlayerView::PerformPlaybackVisualization() { if(m_PlayerWidget == NULL || m_Visualizer.IsNull()) return; static int update = 0; + static int counter = -1; 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)); + { + mitk::PointSet::PointType lastPoint; + + if(counter == -1) + { + lastPoint[0] = -1; + lastPoint[1] = -1; + lastPoint[2] = -1; + } + else + lastPoint = m_TrajectoryPointSet->GetPoint(counter); + + mitk::PointSet::PointType currentPoint = m_PlayerWidget->GetNavigationDataPoint(i); + + bool diff0 = lastPoint[0] != currentPoint[0]; + bool diff1 = lastPoint[1] != currentPoint[1]; + bool diff2 = lastPoint[2] != currentPoint[2]; + + if(diff0 || diff1 || diff2) + m_TrajectoryPointSet->InsertPoint(++counter, currentPoint); + } } 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::vector::iterator it; mitk::DataStorage* ds = this->GetDefaultDataStorage(); 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_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_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::vector::iterator it; 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; // 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); } } +void QmitkNavigationDataPlayerView::OnEnableSplineTrajectoryMapper(bool enable) +{ + if(m_Trajectory.IsNull()) + return; + + if(enable) + m_Trajectory->SetMapper(mitk::BaseRenderer::Standard3D, this->GetTrajectoryMapper(Splines)); + + else + m_Trajectory->SetMapper(mitk::BaseRenderer::Standard3D, this->GetTrajectoryMapper(Points)); +} + + 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 +} + + +mitk::PointSetVtkMapper3D::Pointer QmitkNavigationDataPlayerView::GetTrajectoryMapper(TrajectoryStyle style) +{ + if(style == Points) + { + if(m_PointSetMapper.IsNull()) + m_PointSetMapper = mitk::PointSetVtkMapper3D::New(); + + return m_PointSetMapper; + } + + else if(style == Splines) + { + if(m_SplineMapper.IsNull()) + m_SplineMapper = mitk::SplineVtkMapper3D::New(); + + return m_SplineMapper; + } +} 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 a3e4a15bc3..5a34a8ac17 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,126 +1,142 @@ /*========================================================================= 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 #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(); + void OnEnableSplineTrajectoryMapper(bool enable); protected: + enum TrajectoryStyle { + Points = 1, + Splines = 2 + }; + void CreateBundleWidgets(QWidget* parent); void RenderScene(); 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::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; + mitk::SplineVtkMapper3D::Pointer m_SplineMapper; // spline trajectory mapper + mitk::PointSetVtkMapper3D::Pointer m_PointSetMapper; // standard trajectroy mapper -private: + + +private: mitk::Color GetColorCircleColor(int index); + mitk::PointSetVtkMapper3D::Pointer GetTrajectoryMapper(TrajectoryStyle style); }; #endif // _QMITKNAVIGATIONDATAPLAYERVIEW_H_INCLUDED