QmitkIGTTutorial shows a small typically navigation MITK functionality. More...
#include <QmitkImageGuidedTherapyTutorialView.h>
Public Member Functions | |
QmitkImageGuidedTherapyTutorialView () | |
virtual | ~QmitkImageGuidedTherapyTutorialView () |
virtual void | CreateQtPartControl (QWidget *parent) |
virtual void | CreateConnections () |
Creation of the connections of main and control widget. | |
virtual void | Activated () |
Called when the functionality is activated. | |
virtual void | Deactivated () |
virtual void | StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) |
virtual void | StdMultiWidgetNotAvailable () |
Static Public Attributes | |
static const std::string | VIEW_ID = "org.mitk.views.imageguidedtherapytutorial" |
Protected Slots | |
void | OnStartIGT () |
Execute MITK-IGT Tutorial. | |
void | OnStopIGT () |
stop IGT scene and clean up | |
void | OnTimer () |
timer based update of IGT scene | |
Protected Attributes | |
Ui::QmitkImageGuidedTherapyTutorialViewControls * | m_Controls |
QmitkStdMultiWidget * | m_MultiWidget |
our display widget | |
mitk::TrackingDeviceSource::Pointer | m_Source |
source filer that connects to the tracking device | |
mitk::NavigationDataObjectVisualizationFilter::Pointer | m_Visualizer |
visualization filter uses output from m_Source | |
QTimer * | m_Timer |
timer for continuous tracking update |
QmitkIGTTutorial shows a small typically navigation MITK functionality.
Any kind of navigation application will start with the connection to a tracking system and as we do image guided procedures we want to show something on the screen. In this tutorial we connect to the NDI Polaris tracking system (or alternatively use a virtual tracking device) and we will show the movement of a tool as cone in the StdMultiWidget editor.
Definition at line 44 of file QmitkImageGuidedTherapyTutorialView.h.
QmitkImageGuidedTherapyTutorialView::QmitkImageGuidedTherapyTutorialView | ( | ) |
Definition at line 36 of file QmitkImageGuidedTherapyTutorialView.cpp.
: QmitkFunctionality(), m_Controls(NULL), m_MultiWidget(NULL), m_Source(NULL), m_Visualizer(NULL), m_Timer(NULL) { }
QmitkImageGuidedTherapyTutorialView::~QmitkImageGuidedTherapyTutorialView | ( | ) | [virtual] |
Definition at line 43 of file QmitkImageGuidedTherapyTutorialView.cpp.
{ }
void QmitkImageGuidedTherapyTutorialView::Activated | ( | ) | [virtual] |
Called when the functionality is activated.
Reimplemented from QmitkFunctionality.
Definition at line 82 of file QmitkImageGuidedTherapyTutorialView.cpp.
void QmitkImageGuidedTherapyTutorialView::CreateConnections | ( | ) | [virtual] |
Creation of the connections of main and control widget.
Definition at line 72 of file QmitkImageGuidedTherapyTutorialView.cpp.
References m_Controls, Ui_QmitkImageGuidedTherapyTutorialViewControls::m_StartButton, Ui_QmitkImageGuidedTherapyTutorialViewControls::m_StopButton, OnStartIGT(), and OnStopIGT().
Referenced by CreateQtPartControl().
{ if ( m_Controls ) { connect( (QObject*)(m_Controls->m_StartButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnStartIGT())); connect( (QObject*)(m_Controls->m_StopButton), SIGNAL(clicked()),(QObject*) this, SLOT(OnStopIGT())); } }
void QmitkImageGuidedTherapyTutorialView::CreateQtPartControl | ( | QWidget * | parent ) | [virtual] |
Implements berry::QtViewPart.
Definition at line 48 of file QmitkImageGuidedTherapyTutorialView.cpp.
References CreateConnections(), m_Controls, and Ui_QmitkImageGuidedTherapyTutorialViewControls::setupUi().
{ if (!m_Controls) { // create GUI widget m_Controls = new Ui::QmitkImageGuidedTherapyTutorialViewControls; m_Controls->setupUi(parent); this->CreateConnections(); } }
void QmitkImageGuidedTherapyTutorialView::Deactivated | ( | ) | [virtual] |
Only called when IsExclusiveFunctionality() returns true.
Reimplemented from QmitkFunctionality.
Definition at line 88 of file QmitkImageGuidedTherapyTutorialView.cpp.
void QmitkImageGuidedTherapyTutorialView::OnStartIGT | ( | ) | [protected, slot] |
Execute MITK-IGT Tutorial.
Definition at line 94 of file QmitkImageGuidedTherapyTutorialView.cpp.
References QmitkFunctionality::GetDefaultDataStorage(), m_MultiWidget, m_Source, m_Timer, m_Visualizer, mitk::NavigationDataObjectVisualizationFilter::New(), mitk::DataNode::New(), mitk::Cone::New(), mitk::TrackingDeviceSource::New(), mitk::VirtualTrackingDevice::New(), and OnTimer().
Referenced by CreateConnections().
{ //This method is called when when the Do IGT button is pressed. Any kind of navigation application will //start with the connection to a tracking system and as we do image guided procedures we want to show //something on the screen. In this tutorial we connect to the NDI Polaris tracking system and we will //show the movement of a tool as cone in MITK. //Check if we have a widget for visualization. Makes no sense to start otherwise. //If there is no multiwidget, create one. //if (m_MultiWidget == NULL) //{ //} if (m_MultiWidget == NULL) // if creating the multiwidget failed, stop here. { QMessageBox::warning ( NULL, "Error", "Starting the tutorial is not possible without an initialized " "rendering widget. Please load a dataset first."); return; } try { /**************** Variant 1: Use a NDI Polaris Tracking Device ****************/ //mitk::NDITrackingDevice::Pointer tracker = mitk::NDITrackingDevice::New(); //instantiate //tracker->SetPortNumber(mitk::SerialCommunication::COM4); //set the comport //tracker->SetBaudRate(mitk::SerialCommunication::BaudRate115200); //set the baud rate //tracker->SetType(mitk::NDIPolaris); //set the type there you can choose between Polaris and Aurora //mitk::NDIPassiveTool::Pointer tool = mitk::NDIPassiveTool::New(); //tool->SetToolName("MyInstrument"); //Every tool should have a name. //tool->LoadSROMFile("c:\\myinstrument.rom"); //The Polaris system needs a ".rom" file which describes //tracker->Add6DTool(tool); //Add the tool to the TrackingDevice object. /**************** End of Variant 1 ****************/ /**************** Variant 2: Emulate a Tracking Device with mitk::VirtualTrackingDevice ****************/ // For tests, it is useful to simulate a tracking device in software. This is what mitk::VirtualTrackingDevice does. // It will produce random position, orientation and error values for each tool that is added. mitk::VirtualTrackingDevice::Pointer tracker = mitk::VirtualTrackingDevice::New(); // create virtual tracker mitk::ScalarType bounds[] = {0.0, 200.0, 0.0, 200.0, 0.0, 200.0}; tracker->SetBounds(bounds); tracker->AddTool("MyInstrument"); // add a tool to tracker /**************** End of Variant 2 ****************/ //The tracking device object is used for the physical connection to the device. To use the //data inside of our tracking pipeline we need a source. This source encapsulate the tracking device //and provides objects of the type mitk::NavigationData as output. The NavigationData objects stores //position, orientation, if the data is valid or not and special error informations in a covariance //matrix. // //Typically the start of a pipeline is a TrackingDeviceSource. To work correct we have to set a //TrackingDevice object. Attention you have to set the tools before you set the whole TrackingDevice //object to the TrackingDeviceSource because the source need to know how many outputs should be //generated. m_Source = mitk::TrackingDeviceSource::New(); //We need the filter objects to stay alive, //therefore they must be members. m_Source->SetTrackingDevice(tracker); //Here we set the tracking device to the source of the pipeline. m_Source->Connect(); //Now we connect to the tracking system. //Note we do not call this on the TrackingDevice object //As we wish to visualize our tool we need to have a PolyData which shows us the movement of our tool. //Here we take a cone shaped PolyData. In MITK you have to add the PolyData as a node into the DataStorage //to show it inside of the rendering windows. After that you can change the properties of the cone //to manipulate rendering, e.g. the position and orientation as in our case. mitk::Cone::Pointer cone = mitk::Cone::New(); //instantiate a new cone float scale[] = {10.0, 10.0, 10.0}; cone->GetGeometry()->SetSpacing(scale); //scale it a little that so we can see something mitk::DataNode::Pointer node = mitk::DataNode::New(); //generate a new node to store the cone into //the DataStorage. node->SetData(cone); //The data of that node is our cone. node->SetName("My tracked object"); //The node has additional properties like a name node->SetColor(1.0, 0.0, 0.0); //or the color. Here we make it red. this->GetDefaultDataStorage()->Add(node); //After adding the Node with the cone in it to the //DataStorage, MITK will show the cone in the //render windows. //For updating the render windows we use another filter of the MITK-IGT pipeline concept. The //NavigationDataObjectVisualizationFilter needs as input a NavigationData and a //PolyData. In our case the input is the source and the PolyData our cone. //First we create a new filter for the visualization update. m_Visualizer = mitk::NavigationDataObjectVisualizationFilter::New(); m_Visualizer->SetInput(0, m_Source->GetOutput(0)); //Then we connect to the pipeline. m_Visualizer->SetRepresentationObject(0, cone); //After that we have to assign the cone to the input //Now this simple pipeline is ready, so we can start the tracking. Here again: We do not call the //StartTracking method from the tracker object itself. Instead we call this method from our source. m_Source->StartTracking(); //Now every call of m_Visualizer->Update() will show us the cone at the position and orientation //given from the tracking device. //We use a QTimer object to call this Update() method in a fixed interval. if (m_Timer == NULL) { m_Timer = new QTimer(this); //create a new timer } connect(m_Timer, SIGNAL(timeout()), this, SLOT(OnTimer())); //connect the timer to the method OnTimer() m_Timer->start(100); //Every 100ms the method OnTimer() is called. -> 10fps //Now have look at the OnTimer() method. } catch (std::exception& e) { // add cleanup std::cout << "Error in QmitkIGTTutorial::OnDoIGT():" << e.what() << std::endl; } }
void QmitkImageGuidedTherapyTutorialView::OnStopIGT | ( | ) | [protected, slot] |
stop IGT scene and clean up
Definition at line 222 of file QmitkImageGuidedTherapyTutorialView.cpp.
References QmitkFunctionality::GetDefaultDataStorage(), m_Source, m_Timer, m_Visualizer, and OnTimer().
Referenced by CreateConnections().
{ //This method is called when the Stop button is pressed. Here we disconnect the pipeline. if (m_Timer == NULL) { std::cout << "No Timer was set yet!" << std::endl; return; } //To disconnect the pipeline in a save way we first stop the timer than we disconnect the tracking device. //After that we destroy all filters with changing them to NULL. m_Timer->stop(); disconnect(m_Timer, SIGNAL(timeout()), this, SLOT(OnTimer())); m_Timer = NULL; m_Source->StopTracking(); m_Source->Disconnect(); m_Source = NULL; m_Visualizer = NULL; m_Source = NULL; this->GetDefaultDataStorage()->Remove(this->GetDefaultDataStorage()->GetNamedNode("My tracked object")); }
void QmitkImageGuidedTherapyTutorialView::OnTimer | ( | ) | [protected, slot] |
timer based update of IGT scene
Definition at line 212 of file QmitkImageGuidedTherapyTutorialView.cpp.
References mitk::RenderingManager::GetInstance(), and m_Visualizer.
Referenced by OnStartIGT(), and OnStopIGT().
{ //Here we call the Update() method from the Visualization Filter. Internally the filter checks if //new NavigationData is available. If we have a new NavigationData the cone position and orientation //will be adapted. m_Visualizer->Update(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); //update the render windows }
void QmitkImageGuidedTherapyTutorialView::StdMultiWidgetAvailable | ( | QmitkStdMultiWidget & | stdMultiWidget ) | [virtual] |
Called when a StdMultiWidget is available. Should not be used anymore, see GetActiveStdMultiWidget()
Reimplemented from QmitkFunctionality.
Definition at line 60 of file QmitkImageGuidedTherapyTutorialView.cpp.
References m_MultiWidget.
{ m_MultiWidget = &stdMultiWidget; }
void QmitkImageGuidedTherapyTutorialView::StdMultiWidgetNotAvailable | ( | ) | [virtual] |
Called when no StdMultiWidget is available anymore. Should not be used anymore, see GetActiveStdMultiWidget()
Reimplemented from QmitkFunctionality.
Definition at line 66 of file QmitkImageGuidedTherapyTutorialView.cpp.
References m_MultiWidget.
{ m_MultiWidget = NULL; }
Ui::QmitkImageGuidedTherapyTutorialViewControls* QmitkImageGuidedTherapyTutorialView::m_Controls [protected] |
Definition at line 89 of file QmitkImageGuidedTherapyTutorialView.h.
Referenced by CreateConnections(), and CreateQtPartControl().
our display widget
Definition at line 91 of file QmitkImageGuidedTherapyTutorialView.h.
Referenced by OnStartIGT(), StdMultiWidgetAvailable(), and StdMultiWidgetNotAvailable().
source filer that connects to the tracking device
Definition at line 93 of file QmitkImageGuidedTherapyTutorialView.h.
Referenced by OnStartIGT(), and OnStopIGT().
QTimer* QmitkImageGuidedTherapyTutorialView::m_Timer [protected] |
timer for continuous tracking update
Definition at line 95 of file QmitkImageGuidedTherapyTutorialView.h.
Referenced by OnStartIGT(), and OnStopIGT().
mitk::NavigationDataObjectVisualizationFilter::Pointer QmitkImageGuidedTherapyTutorialView::m_Visualizer [protected] |
visualization filter uses output from m_Source
Definition at line 94 of file QmitkImageGuidedTherapyTutorialView.h.
Referenced by OnStartIGT(), OnStopIGT(), and OnTimer().
const std::string QmitkImageGuidedTherapyTutorialView::VIEW_ID = "org.mitk.views.imageguidedtherapytutorial" [static] |
Definition at line 52 of file QmitkImageGuidedTherapyTutorialView.h.