diff --git a/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkExample.cpp b/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkExample.cpp index 427b561d5a..e3767d44ff 100644 --- a/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkExample.cpp +++ b/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkExample.cpp @@ -1,186 +1,174 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Blueberry #include #include // Qmitk #include "QmitkRenderWindow.h" // Qt #include // mitk #include #include #include #include #include // vtk #include // #include "OpenIGTLinkExample.h" //igtl #include "igtlStringMessage.h" #include "igtlTrackingDataMessage.h" const std::string OpenIGTLinkExample::VIEW_ID = "org.mitk.views.OpenIGTLinkExample"; void OpenIGTLinkExample::SetFocus() { } OpenIGTLinkExample::~OpenIGTLinkExample() { this->GetDataStorage()->Remove(m_DemoNodeT1); this->GetDataStorage()->Remove(m_DemoNodeT2); this->GetDataStorage()->Remove(m_DemoNodeT3); } void OpenIGTLinkExample::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); // connect the widget items with the methods connect( m_Controls.butStart, SIGNAL(clicked()), this, SLOT(Start()) ); connect( &m_Timer, SIGNAL(timeout()), this, SLOT(UpdatePipeline())); //Setup the pipeline this->CreatePipeline(); } void OpenIGTLinkExample::CreatePipeline() { //create a new OpenIGTLinkExample Client m_IGTLClient = mitk::IGTLClient::New(); m_IGTLClient->SetName("OIGTL Example Client Device"); //create a new OpenIGTLinkExample Device source m_IGTLDeviceSource = mitk::IGTLDeviceSource::New(); //set the client as the source for the device source m_IGTLDeviceSource->SetIGTLDevice(m_IGTLClient); m_IGTLDeviceSource->RegisterAsMicroservice(); //create a filter that converts OpenIGTLinkExample messages into navigation data m_IGTLMsgToNavDataFilter = mitk::IGTLMessageToNavigationDataFilter::New(); //create a visualization filter m_VisFilter = mitk::NavigationDataObjectVisualizationFilter::New(); //we expect a tracking data message with three tools. Since we cannot change //the outputs at runtime we have to set it manually. m_IGTLMsgToNavDataFilter->SetNumberOfExpectedOutputs(3); //connect the filters with each other //the OpenIGTLinkExample messages will be passed to the first filter that converts //it to navigation data, then it is passed to the visualization filter that //will visualize the transformation m_IGTLMsgToNavDataFilter->ConnectTo(m_IGTLDeviceSource); m_VisFilter->ConnectTo(m_IGTLMsgToNavDataFilter); //create an object that will be moved respectively to the navigation data m_DemoNodeT1 = mitk::DataNode::New(); m_DemoNodeT1->SetName("DemoNode IGTLExmpl T1"); m_DemoNodeT2 = mitk::DataNode::New(); m_DemoNodeT2->SetName("DemoNode IGTLExmpl T2"); m_DemoNodeT3 = mitk::DataNode::New(); m_DemoNodeT3->SetName("DemoNode IGTLExmpl T3"); //create small sphere and use it as surface mitk::Surface::Pointer mySphere = mitk::Surface::New(); vtkSphereSource *vtkData = vtkSphereSource::New(); vtkData->SetRadius(2.0f); vtkData->SetCenter(0.0, 0.0, 0.0); vtkData->Update(); mySphere->SetVtkPolyData(vtkData->GetOutput()); vtkData->Delete(); m_DemoNodeT1->SetData(mySphere); mitk::Surface::Pointer mySphere2 = mySphere->Clone(); m_DemoNodeT2->SetData(mySphere2); mitk::Surface::Pointer mySphere3 = mySphere->Clone(); m_DemoNodeT3->SetData(mySphere3); // add node to DataStorage this->GetDataStorage()->Add(m_DemoNodeT1); this->GetDataStorage()->Add(m_DemoNodeT2); this->GetDataStorage()->Add(m_DemoNodeT3); //use this sphere as representation object m_VisFilter->SetRepresentationObject(0, mySphere); m_VisFilter->SetRepresentationObject(1, mySphere2); m_VisFilter->SetRepresentationObject(2, mySphere3); } void OpenIGTLinkExample::DestroyPipeline() { m_VisFilter = NULL; this->GetDataStorage()->Remove(m_DemoNodeT1); + this->GetDataStorage()->Remove(m_DemoNodeT2); + this->GetDataStorage()->Remove(m_DemoNodeT3); } void OpenIGTLinkExample::Start() { if ( this->m_Controls.butStart->text().contains("Start Pipeline") ) { - m_Timer.setInterval(100); + m_Timer.setInterval(90); m_Timer.start(); this->m_Controls.butStart->setText("Stop Pipeline"); } else { m_Timer.stop(); igtl::StopTrackingDataMessage::Pointer stopStreaming = igtl::StopTrackingDataMessage::New(); this->m_IGTLClient->SendMessage(stopStreaming.GetPointer()); this->m_Controls.butStart->setText("Start Pipeline"); } } void OpenIGTLinkExample::UpdatePipeline() { + //update the pipeline m_VisFilter->Update(); + //update the boundings + mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); + //Update rendering - QmitkRenderWindow* renWindow = - this->GetRenderWindowPart()->GetQmitkRenderWindow("3d"); - renWindow->GetRenderer()->GetVtkRenderer()->Render(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - - this->GlobalReinit(); -} - -void OpenIGTLinkExample::GlobalReinit() -{ - // get all nodes that have not set "includeInBoundingBox" to false - mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false))); - - mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred); - // calculate bounding geometry of these nodes - mitk::TimeGeometry::Pointer bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible"); - - // initialize the views to the bounding geometry - mitk::RenderingManager::GetInstance()->InitializeViews(bounds); } diff --git a/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkExample.h b/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkExample.h index 2a5afcbb0b..1ddedc5621 100644 --- a/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkExample.h +++ b/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkExample.h @@ -1,86 +1,84 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef OpenIGTLinkExample_h #define OpenIGTLinkExample_h #include #include #include "ui_OpenIGTLinkExampleControls.h" #include "mitkIGTLClient.h" #include "mitkIGTLServer.h" #include "mitkIGTLDeviceSource.h" #include "mitkNavigationDataObjectVisualizationFilter.h" #include "mitkIGTLMessageToNavigationDataFilter.h" #include "qtimer.h" /** \brief OpenIGTLinkExample \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class OpenIGTLinkExample : public QmitkAbstractView { // 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: ~OpenIGTLinkExample(); static const std::string VIEW_ID; protected slots: void Start(); void UpdatePipeline(); protected: virtual void CreateQtPartControl(QWidget *parent); virtual void SetFocus(); void CreatePipeline(); void DestroyPipeline(); - void GlobalReinit(); - Ui::OpenIGTLinkExampleControls m_Controls; mitk::IGTLClient::Pointer m_IGTLClient; mitk::IGTLDeviceSource::Pointer m_IGTLDeviceSource; mitk::IGTLMessageToNavigationDataFilter::Pointer m_IGTLMsgToNavDataFilter; mitk::NavigationDataObjectVisualizationFilter::Pointer m_VisFilter; mitk::DataNode::Pointer m_DemoNodeT1; mitk::DataNode::Pointer m_DemoNodeT2; mitk::DataNode::Pointer m_DemoNodeT3; //REMOVE LATER // mitk::IGTLServer::Pointer m_IGTLServer; // mitk::IGTLDeviceSource::Pointer m_IGTLDeviceSource2; QTimer m_Timer; }; #endif // OpenIGTLinkExample_h diff --git a/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkProviderExample.cpp b/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkProviderExample.cpp index 8602e13c72..f9f42fd052 100644 --- a/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkProviderExample.cpp +++ b/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkProviderExample.cpp @@ -1,249 +1,235 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ // Blueberry #include #include // Qmitk #include "QmitkRenderWindow.h" // Qt #include #include // mitk #include #include #include #include #include #include // vtk #include // #include "OpenIGTLinkProviderExample.h" //igtl #include "igtlStringMessage.h" const std::string OpenIGTLinkProviderExample::VIEW_ID = "org.mitk.views.OpenIGTLinkProviderExample"; OpenIGTLinkProviderExample::~OpenIGTLinkProviderExample() { this->GetDataStorage()->Remove(m_DemoNodeT1); this->GetDataStorage()->Remove(m_DemoNodeT2); this->GetDataStorage()->Remove(m_DemoNodeT3); } void OpenIGTLinkProviderExample::SetFocus() { } void OpenIGTLinkProviderExample::CreateQtPartControl( QWidget *parent ) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi( parent ); // connect the widget items with the methods connect( m_Controls.butStart, SIGNAL(clicked()), this, SLOT(Start()) ); connect( m_Controls.butOpenNavData, SIGNAL(clicked()), this, SLOT(OnOpenFile()) ); connect( &m_VisualizerTimer, SIGNAL(timeout()), this, SLOT(UpdateVisualization())); } void OpenIGTLinkProviderExample::CreatePipeline() { //create a new OpenIGTLink Client m_IGTLServer = mitk::IGTLServer::New(); m_IGTLServer->SetName("OIGTL Provider Example Device"); //create a new OpenIGTLink Device source m_IGTLMessageProvider = mitk::IGTLMessageProvider::New(); //set the OpenIGTLink server as the source for the device source m_IGTLMessageProvider->SetIGTLDevice(m_IGTLServer); //register the provider so that it can be configured with the IGTL manager //plugin. This could be hardcoded but now I already have the fancy plugin. m_IGTLMessageProvider->RegisterAsMicroservice(); //create a filter that converts navigation data into IGTL messages m_NavDataToIGTLMsgFilter = mitk::NavigationDataToIGTLMessageFilter::New(); //define the operation mode for this filter, we want to send tracking data //messages m_NavDataToIGTLMsgFilter->SetOperationMode( mitk::NavigationDataToIGTLMessageFilter::ModeSendTDataMsg); //register this filter as micro service. The message provider looks for //provided IGTLMessageSources, once it found this microservice and someone //requested this data type then the provider will connect with this filter //automatically (this is not implemented so far, check m_StreamingConnector //for more information) m_NavDataToIGTLMsgFilter->RegisterAsMicroservice(); //create a navigation data player object that will play nav data from a //recorded file m_NavDataPlayer = mitk::NavigationDataPlayer::New(); //set the currently read navigation data set m_NavDataPlayer->SetNavigationDataSet(m_NavDataSet); //connect the filters with each other //the navigation data player reads a file with recorded navigation data, //passes this data to a filter that converts it into a IGTLMessage. //The provider is not connected because it will search for fitting services. //Once it found the filter it will automatically connect to it (this is not // implemented so far, check m_StreamingConnector for more information). m_NavDataToIGTLMsgFilter->ConnectTo(m_NavDataPlayer); //create an object that will be moved respectively to the navigation data m_DemoNodeT1 = mitk::DataNode::New(); m_DemoNodeT1->SetName("DemoNode IGTLProviderExmpl T1"); m_DemoNodeT2 = mitk::DataNode::New(); m_DemoNodeT2->SetName("DemoNode IGTLProviderExmpl T2"); m_DemoNodeT3 = mitk::DataNode::New(); m_DemoNodeT3->SetName("DemoNode IGTLProviderExmpl T3"); //create small sphere and use it as surface mitk::Surface::Pointer mySphere = mitk::Surface::New(); vtkSphereSource *vtkData = vtkSphereSource::New(); vtkData->SetRadius(2.0f); vtkData->SetCenter(0.0, 0.0, 0.0); vtkData->Update(); mySphere->SetVtkPolyData(vtkData->GetOutput()); vtkData->Delete(); m_DemoNodeT1->SetData(mySphere); mitk::Surface::Pointer mySphere2 = mySphere->Clone(); m_DemoNodeT2->SetData(mySphere2); mitk::Surface::Pointer mySphere3 = mySphere->Clone(); m_DemoNodeT3->SetData(mySphere3); // add node to DataStorage this->GetDataStorage()->Add(m_DemoNodeT1); this->GetDataStorage()->Add(m_DemoNodeT2); this->GetDataStorage()->Add(m_DemoNodeT3); //initialize the streaming connector //the streaming connector is checking if the data from the filter has to be //streamed. The message provider is used for sending the messages. m_StreamingConnector.Initialize(m_NavDataToIGTLMsgFilter.GetPointer(), m_IGTLMessageProvider); //also create a visualize filter to visualize the data m_NavDataVisualizer = mitk::NavigationDataObjectVisualizationFilter::New(); m_NavDataVisualizer->SetRepresentationObject(0, mySphere); m_NavDataVisualizer->SetRepresentationObject(1, mySphere2); m_NavDataVisualizer->SetRepresentationObject(2, mySphere3); m_NavDataVisualizer->ConnectTo(m_NavDataPlayer); //start the player this->Start(); - this->GlobalReinit(); + mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); } void OpenIGTLinkProviderExample::DestroyPipeline() { m_NavDataPlayer->StopPlaying(); this->GetDataStorage()->Remove(m_DemoNodeT1); } void OpenIGTLinkProviderExample::Start() { if ( this->m_Controls.butStart->text().contains("Start") ) { m_NavDataPlayer->SetRepeat(true); m_NavDataPlayer->StartPlaying(); this->m_Controls.butStart->setText("Stop Playing Recorded Navigation Data "); //start the visualization this->m_VisualizerTimer.start(100); } else { m_NavDataPlayer->StopPlaying(); this->m_Controls.butStart->setText("Start Playing Recorded Navigation Data "); //stop the visualization this->m_VisualizerTimer.stop(); } } void OpenIGTLinkProviderExample::OnOpenFile(){ mitk::NavigationDataReaderXML::Pointer reader = mitk::NavigationDataReaderXML::New(); // FIXME Filter for correct files and use correct Reader QString fileName = QFileDialog::getOpenFileName(NULL, "Open Navigation Data Set", "", "XML files (*.xml)"); if ( fileName.isNull() ) { return; } // user pressed cancel try { m_NavDataSet = reader->Read(fileName.toStdString()); } catch ( const mitk::Exception &e ) { MITK_WARN("NavigationDataPlayerView") << "could not open file " << fileName.toStdString(); QMessageBox::critical(0, "Error Reading File", "The file '" + fileName +"' could not be read.\n" + e.GetDescription() ); return; } this->m_Controls.butStart->setEnabled(true); //Setup the pipeline this->CreatePipeline(); // Update Labels // m_Controls->m_LblFilePath->setText(fileName); // m_Controls->m_LblTools->setText(QString::number(m_NavDataSet->GetNumberOfTools())); } void OpenIGTLinkProviderExample::UpdateVisualization() { + //update the filter this->m_NavDataVisualizer->Update(); - //Update rendering - QmitkRenderWindow* renWindow = - this->GetRenderWindowPart()->GetQmitkRenderWindow("3d"); - renWindow->GetRenderer()->GetVtkRenderer()->Render(); - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - - this->GlobalReinit(); -} + //update the bounds + mitk::RenderingManager::GetInstance()->InitializeViewsByBoundingObjects(this->GetDataStorage()); -void OpenIGTLinkProviderExample::GlobalReinit() -{ - // get all nodes that have not set "includeInBoundingBox" to false - mitk::NodePredicateNot::Pointer pred = mitk::NodePredicateNot::New(mitk::NodePredicateProperty::New("includeInBoundingBox", mitk::BoolProperty::New(false))); - - mitk::DataStorage::SetOfObjects::ConstPointer rs = this->GetDataStorage()->GetSubset(pred); - // calculate bounding geometry of these nodes - mitk::TimeGeometry::Pointer bounds = this->GetDataStorage()->ComputeBoundingGeometry3D(rs, "visible"); - - // initialize the views to the bounding geometry - mitk::RenderingManager::GetInstance()->InitializeViews(bounds); + //update rendering + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } diff --git a/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkProviderExample.h b/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkProviderExample.h index 748bba3989..edec2ae0b5 100644 --- a/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkProviderExample.h +++ b/Plugins/org.mitk.gui.qt.igtlplugin/src/internal/OpenIGTLinkProviderExample.h @@ -1,87 +1,85 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef OpenIGTLinkProviderExample_h #define OpenIGTLinkProviderExample_h #include #include #include #include "ui_OpenIGTLinkProviderExampleControls.h" #include "mitkIGTLServer.h" #include "mitkIGTLMessageProvider.h" #include "mitkNavigationDataToIGTLMessageFilter.h" #include "mitkNavigationDataPlayer.h" #include "mitkNavigationDataObjectVisualizationFilter.h" #include "qtimer.h" /** \brief OpenIGTLinkProviderExample \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkAbstractView \ingroup ${plugin_target}_internal */ class OpenIGTLinkProviderExample : public QmitkAbstractView { // 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: ~OpenIGTLinkProviderExample(); static const std::string VIEW_ID; protected slots: void Start(); void OnOpenFile(); void UpdateVisualization(); protected: virtual void CreateQtPartControl(QWidget *parent); virtual void SetFocus(); void CreatePipeline(); void DestroyPipeline(); - void GlobalReinit(); - Ui::OpenIGTLinkProviderExampleControls m_Controls; mitk::IGTLServer::Pointer m_IGTLServer; mitk::IGTLMessageProvider::Pointer m_IGTLMessageProvider; mitk::NavigationDataToIGTLMessageFilter::Pointer m_NavDataToIGTLMsgFilter; mitk::NavigationDataPlayer::Pointer m_NavDataPlayer; mitk::NavigationDataObjectVisualizationFilter::Pointer m_NavDataVisualizer; mitk::DataNode::Pointer m_DemoNodeT1; mitk::DataNode::Pointer m_DemoNodeT2; mitk::DataNode::Pointer m_DemoNodeT3; mitk::NavigationDataSet::Pointer m_NavDataSet; QmitkIGTLStreamingConnector m_StreamingConnector; QTimer m_VisualizerTimer; }; #endif // OpenIGTLinkProviderExample_h