diff --git a/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.cpp b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.cpp index e293c0148e..e688b4fb98 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.cpp @@ -1,283 +1,209 @@ /*========================================================================= 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 "QmitkIGTConnectionWidget.h" #include "QmitkTrackingDeviceConfigurationWidget.h" #include "mitkClaronTrackingDevice.h" #include "mitkNDITrackingDevice.h" #include "mitkNavigationToolStorageDeserializer.h" #include "mitkTrackingDeviceSourceConfigurator.h" #include #include const std::string QmitkIGTConnectionWidget::VIEW_ID = "org.mitk.views.igtconnectionwidget"; QmitkIGTConnectionWidget::QmitkIGTConnectionWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) { m_Controls = NULL; CreateQtPartControl(this); CreateConnections(); m_TrackingDevice = NULL; m_TrackingDeviceSource = NULL; m_NavigationToolStorage = NULL; m_DataStorage = NULL; m_ErrorMessage = ""; } QmitkIGTConnectionWidget::~QmitkIGTConnectionWidget() { } void QmitkIGTConnectionWidget::CreateQtPartControl(QWidget *parent) { if (!m_Controls) { // create GUI widgets m_Controls = new Ui::QmitkIGTConnectionWidgetControls; m_Controls->setupUi(parent); // configure trackingDeviceConfigurationWidget m_Controls->trackingDeviceConfigurationWidget->SetGUIStyle(QmitkTrackingDeviceConfigurationWidget::SIMPLE); } } void QmitkIGTConnectionWidget::CreateConnections() { if ( m_Controls ) { - //connect( (QObject*)(m_Controls->selectTrackingDeviceComboBox), SIGNAL(currentIndexChanged(int)), this, SLOT(OnTrackingDeviceChanged()) ); connect( (QObject*)(m_Controls->connectButton), SIGNAL(clicked()), this, SLOT(OnConnect()) ); - - ////set a few UI components depending on Windows / Linux - //#ifdef WIN32 - //m_Controls->portTypeLabelPolaris->setVisible(false); - //m_Controls->portTypePolaris->setVisible(false); - //m_Controls->portTypeLabelAurora->setVisible(false); - //m_Controls->portTypeAurora->setVisible(false); - //#else - //m_Controls->comPortLabelAurora->setText("Port Nr:"); - //m_Controls->comPortLabelPolaris->setText("Port Nr:"); - //m_Controls->comPortAurora->setPrefix(""); - //m_Controls->comPortPolaris->setPrefix(""); - //#endif } } -void QmitkIGTConnectionWidget::OnTrackingDeviceChanged() -{ - ////show the correspondig widget for configuring the TrackingDevice - //m_Controls->deviceConfigurationWidget->setCurrentIndex(m_Controls->selectTrackingDeviceComboBox->currentIndex()); -} - void QmitkIGTConnectionWidget::OnConnect() { if (m_Controls->connectButton->isChecked()) // Load tools and connect tracking device { m_Controls->connectButton->setChecked(false); - QString fileName = QFileDialog::getOpenFileName(NULL,tr("Open Navigation tool storage"), "/", tr("Toolfile (*.tfl)")); - if (LoadToolfile(fileName)) + // create TrackingDevice + m_TrackingDevice = m_Controls->trackingDeviceConfigurationWidget->GetTrackingDevice(); + if (m_TrackingDevice.IsNotNull()) { - // create TrackingDevice - m_TrackingDevice = m_Controls->trackingDeviceConfigurationWidget->GetTrackingDevice(); - if (m_TrackingDevice.IsNotNull()) + QString fileName = QFileDialog::getOpenFileName(NULL,tr("Open Navigation tool storage"), "/", tr("Toolfile (*.tfl)")); + if (LoadToolfile(fileName)) { // Create TrackingDeviceSource and add tools mitk::TrackingDeviceSourceConfigurator::Pointer myTrackingDeviceSourceFactory = mitk::TrackingDeviceSourceConfigurator::New(this->m_NavigationToolStorage,m_TrackingDevice); m_TrackingDeviceSource = myTrackingDeviceSourceFactory->CreateTrackingDeviceSource(); m_TrackingDeviceSource->Connect(); m_TrackingDeviceSource->StartTracking(); // change button text m_Controls->connectButton->setText("Disconnect"); m_Controls->connectButton->setChecked(true); + emit TrackingDeviceConnected(); } else { + QString error(m_ErrorMessage.c_str()); + QMessageBox::warning(NULL,"Warning",error); // reset button to unchecked m_Controls->connectButton->setChecked(false); - MITK_ERROR<<"Could not create TrackingDevice"; + // remove tool nodes from DataStorage + this->RemoveToolNodes(); + // reset NavigationToolStorage + m_NavigationToolStorage = NULL; } } else { - QString error(m_ErrorMessage.c_str()); - QMessageBox::warning(NULL,"Warning",error); // reset button to unchecked m_Controls->connectButton->setChecked(false); + MITK_ERROR<<"Could not create TrackingDevice"; } } else // Disconnect tracking device { // disconnect TrackingDeviceSource if (m_TrackingDeviceSource.IsNotNull()) { m_TrackingDeviceSource->StopTracking(); m_TrackingDeviceSource->Disconnect(); } // remove tool nodes from DataStorage this->RemoveToolNodes(); + // reset members + m_NavigationToolStorage = NULL; + m_TrackingDevice = NULL; + m_TrackingDeviceSource = NULL; // change button text m_Controls->connectButton->setText("Connect"); + emit TrackingDeviceDisconnected(); } } bool QmitkIGTConnectionWidget::LoadToolfile(QString qFilename) { if (m_DataStorage.IsNotNull()) { std::string filename = qFilename.toStdString(); mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(this->m_DataStorage); mitk::NavigationToolStorage::Pointer tempStorage = myDeserializer->Deserialize(filename); + m_NavigationToolStorage = tempStorage; if (tempStorage.IsNull()) { m_ErrorMessage = myDeserializer->GetErrorMessage(); return false; } // check if there are tools in the storage mitk::TrackingDeviceType lastDevice; if (tempStorage->GetToolCount()>0) { lastDevice = tempStorage->GetTool(0)->GetTrackingDeviceType(); } else { m_ErrorMessage = "Error: Didn't find a tool in the storage. Do you want to navigate without even an instrument?"; return false; } //check if all tools are from the same device for (int i=1; iGetToolCount(); i++) { if (lastDevice!=tempStorage->GetTool(i)->GetTrackingDeviceType()) { m_ErrorMessage = "Error: Toolfile contains tools of different tracking devices which is not acceptable for this application."; return false; } else lastDevice = tempStorage->GetTool(i)->GetTrackingDeviceType(); } - //// check if tool device type and tracking device type are equal - //if (lastDevice!=m_Controls->trackingDeviceConfigurationWidget->) - //{ - // m_ErrorMessage = "Error: Tools are not applicable for the chosen device"; - // return false; - //} - + // check if tracking device typ of tools corresponds with chosen tracking device + if (m_TrackingDevice->GetType()!=tempStorage->GetTool(0)->GetTrackingDeviceType()) + { + m_ErrorMessage = "Tools are not compliant with this tracking device. Please use correct toolfile for specified device."; + return false; + } m_NavigationToolStorage = tempStorage; return true; } else { m_ErrorMessage = "Error: No DataStorage available! Make sure the widget is initialized with a DataStorage"; return false; } } void QmitkIGTConnectionWidget::RemoveToolNodes() { for (int i=0; iGetToolCount(); i++) { mitk::DataNode::Pointer currentNode = m_NavigationToolStorage->GetTool(i)->GetDataNode(); if (currentNode.IsNotNull()) { m_DataStorage->Remove(currentNode); } } } mitk::TrackingDeviceSource::Pointer QmitkIGTConnectionWidget::GetTrackingDeviceSource() { return m_TrackingDeviceSource; } void QmitkIGTConnectionWidget::SetDataStorage( mitk::DataStorage::Pointer dataStorage ) { m_DataStorage = dataStorage; } -//mitk::TrackingDevice::Pointer QmitkIGTConnectionWidget::ConstructTrackingDevice() -// { -// mitk::TrackingDevice::Pointer returnValue; -// //#### Step 1: configure tracking device: -// if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==0)//NDI Polaris -// { -// if(m_Controls->polarisMode5D->isChecked()) //5D Tracking -// { -// //not yet in the open source part so we'll only get NULL here. -// returnValue = ConfigureNDI5DTrackingDevice(); -// } -// else //6D Tracking -// { -// returnValue = ConfigureNDI6DTrackingDevice(); -// returnValue->SetType(mitk::NDIPolaris); -// } -// } -// else if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==1)//NDI Aurora -// { -// returnValue = ConfigureNDI6DTrackingDevice(); -// returnValue->SetType(mitk::NDIAurora); -// } -// else if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==2)//ClaronTechnology MicronTracker 2 -// { -// returnValue = mitk::ClaronTrackingDevice::New(); -// } -// else -// { -// returnValue = NULL; -// } -// return returnValue; -// } -// -//mitk::TrackingDevice::Pointer QmitkIGTConnectionWidget::ConfigureNDI5DTrackingDevice() -// { -// return NULL; -// } -// -//mitk::TrackingDevice::Pointer QmitkIGTConnectionWidget::ConfigureNDI6DTrackingDevice() -// { -// mitk::NDITrackingDevice::Pointer tempTrackingDevice = mitk::NDITrackingDevice::New(); -// -// //build prefix (depends on linux/win) -// QString prefix = ""; -// #ifdef WIN32 -// prefix ="COM"; -// #else -// if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==1) //Aurora -// prefix = m_Controls->portTypeAurora->currentText(); -// else //Polaris -// prefix = m_Controls->portTypePolaris->currentText(); -// #endif -// //get port -// int port = 0; -// if (m_Controls->selectTrackingDeviceComboBox->currentIndex()==1) port = m_Controls->comPortAurora->value(); -// else port = m_Controls->comPortPolaris->value(); -// //build port name string -// QString portName = prefix + QString::number(port); -// -// tempTrackingDevice->SetDeviceName(portName.toStdString()); //set the port name -// mitk::TrackingDevice::Pointer returnValue = static_cast(tempTrackingDevice); -// return returnValue; -// } - mitk::NavigationToolStorage::Pointer QmitkIGTConnectionWidget::GetNavigationToolStorage() { return m_NavigationToolStorage; } diff --git a/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.h b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.h index a12d5ebcd1..70cfe45b23 100644 --- a/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkIGTConnectionWidget.h @@ -1,119 +1,113 @@ /*========================================================================= 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 QmitkIGTConnectionWidget_H #define QmitkIGTConnectionWidget_H #include #include "MitkIGTUIExports.h" #include "ui_QmitkIGTConnectionWidgetControls.h" #include "mitkDataStorage.h" #include "mitkNavigationToolStorage.h" #include "mitkTrackingDevice.h" #include "mitkTrackingDeviceSource.h" //itk headers /** Documentation: * \brief Simple and fast access to a pre-configured TrackingDeviceSource. * * This widget creates a fully configured, connected and started TrackingDeviceSource. - * Clicking connect requires to specify a NavigationToolStorage that holds all tools to be used + * Clicking "Connect" requires to specify a NavigationToolStorage that holds all tools to be used * in the application. Corresponding surfaces are added to the DataStorage that has to be set for * the widget. * + * Inputs: DataStorage + * Outputs: TrackingDeviceSource, NavigationToolStorage + * * \ingroup IGTUI */ class MitkIGTUI_EXPORT QmitkIGTConnectionWidget : public QWidget { Q_OBJECT public: static const std::string VIEW_ID; QmitkIGTConnectionWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkIGTConnectionWidget(); /* @return Returns the preconfigured and connected TrackingDeviceSource ready to use in an IGT pipeline. */ mitk::TrackingDeviceSource::Pointer GetTrackingDeviceSource(); /*! \brief Get the NavigationToolStorage holding all tools with corresponding surface objects */ mitk::NavigationToolStorage::Pointer GetNavigationToolStorage(); /*! \brief set DataStorage that is used to put the navigation tools */ void SetDataStorage(mitk::DataStorage::Pointer dataStorage); signals: + /*! + \brief signal emitted when TrackingDevice was successfully connected + */ + void TrackingDeviceConnected(); + /*! + \brief signal emitted when TrackingDevice was successfully disconnected + */ + void TrackingDeviceDisconnected(); protected slots: - /* @brief This method is called when the user changes the selection of the trackingdevice (m_trackingDeviceChooser). - It then sets the correct widget for the selected tracking device.*/ - void OnTrackingDeviceChanged(); /*! \brief Asks the user to specify a tool file and finally connects the TrackingDeviceSource */ void OnConnect(); protected: /// \brief Creation of the connections virtual void CreateConnections(); virtual void CreateQtPartControl(QWidget *parent); /*! \brief Load NavigationToolStorage from given filename and set according member \param qFilename file location of the NavigationToolStorage \return success of load operation (true if load successful, false otherwise) m_ErrorMessage holds the problem description */ bool LoadToolfile(QString qFilename); /*! \brief Remove the tool nodes currently associated to the tools hold in the NavigationToolStorage from the DataStorage */ void RemoveToolNodes(); - ///*! - //\brief Construct TrackingDevice according to the selection in the ComboBox. - //\return Preconfigured TrackingDevice to be used in a TrackingDeviceSource - //*/ - //mitk::TrackingDevice::Pointer ConstructTrackingDevice(); - ///* @return Returns a configured NDI 5D tracking device. Unfortunately the NDI 5D tracking device is not yet in the open source part - // * so this method only returns NULL at the moment. - // */ - //virtual mitk::TrackingDevice::Pointer ConfigureNDI5DTrackingDevice(); - - ///* @return Returns a configured NDI 6D tracking device. - // * The type (which means Aurora/Polaris) will not be set in the returnvalue. You have to this later. - // */ - //mitk::TrackingDevice::Pointer ConfigureNDI6DTrackingDevice(); Ui::QmitkIGTConnectionWidgetControls* m_Controls; mitk::DataStorage::Pointer m_DataStorage; ///< data storage to put navigation tools - mitk::TrackingDevice::Pointer m_TrackingDevice; ///< holds an instance of the currently chosen tracking device which may be of type NDI Polaris, NDI Aurora or Claron MicronTracker + mitk::TrackingDevice::Pointer m_TrackingDevice; ///< tracking device currently connected mitk::TrackingDeviceSource::Pointer m_TrackingDeviceSource; ///< holds the preconfigured source of the IGT pipeline which is provided by this widget for further processing mitk::NavigationToolStorage::Pointer m_NavigationToolStorage; ///< holds all navigation tools currently loaded std::string m_ErrorMessage; ///< current problem description }; #endif \ No newline at end of file