diff --git a/Modules/IGT/DataManagement/mitkNavigationTool.h b/Modules/IGT/DataManagement/mitkNavigationTool.h index ae13af8022..d92b807bdb 100644 --- a/Modules/IGT/DataManagement/mitkNavigationTool.h +++ b/Modules/IGT/DataManagement/mitkNavigationTool.h @@ -1,183 +1,197 @@ /*=================================================================== 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 NAVIGATIONTOOL_H_INCLUDED #define NAVIGATIONTOOL_H_INCLUDED //itk headers #include #include #include //mitk headers #include #include #include #include #include #include #include namespace mitk { /**Documentation * \brief An object of this class represents a navigation tool in the view of the software. * A few informations like an identifier, a toolname, a surface and a itk spatial * object are stored in such an object. The classes NavigationToolReader and * are availiable to write/read tools to/from the harddisc. If you need a collection * of navigation tools the class NavigationToolStorage could be used. * * \ingroup IGT */ class MitkIGT_EXPORT NavigationTool : public itk::DataObject { public: mitkClassMacro(NavigationTool,itk::DataObject); itkFactorylessNewMacro(Self) itkCloneMacro(Self) enum NavigationToolType {Instrument, Fiducial, Skinmarker, Unknown}; //## getter and setter ## //NavigationToolType: itkGetConstMacro(Type,NavigationToolType); itkSetMacro(Type,NavigationToolType); //Identifier: itkGetConstMacro(Identifier,std::string); itkSetMacro(Identifier,std::string); //Datatreenode: itkGetConstMacro(DataNode,mitk::DataNode::Pointer); itkSetMacro(DataNode,mitk::DataNode::Pointer); //SpatialObject: itkGetConstMacro(SpatialObject,itk::SpatialObject<3>::Pointer); itkSetMacro(SpatialObject,itk::SpatialObject<3>::Pointer); //TrackingTool: itkGetConstMacro(TrackingTool,mitk::TrackingTool::Pointer); itkSetMacro(TrackingTool,mitk::TrackingTool::Pointer); //CalibrationFile: itkGetConstMacro(CalibrationFile,std::string); void SetCalibrationFile(const std::string filename); //Tool tip definition: itkGetConstMacro(ToolTipPosition,mitk::Point3D); itkSetMacro(ToolTipPosition,mitk::Point3D); itkGetConstMacro(ToolTipOrientation,mitk::Quaternion); itkSetMacro(ToolTipOrientation,mitk::Quaternion); /** @return Returns the tooltip as transform object. */ mitk::AffineTransform3D::Pointer GetToolTipTransform(); /** @return Returns true if a tooltip is set, false if not. */ bool IsToolTipSet(); //Tool Landmarks: - /** @return Returns the tool registration landmarks which represent markers / special points on a + /** For overview, here are descriptons of the two types of tool landmarks: + * + * tool calibration landmarks: These landmarks may be used clearly define the tools pose only by + * using landmarks in the tool coordinate system. E.g., two landmarks for a 5DoF tool and three + * landmarks for a 6DoF tool. These landmarks may be used, e.g., for a point based registration + * of a tool from image space to tracking space. + * + * tool registration landmarks: These landmarks are designed for representing defined landmarks + * on a tools surface. The number of these landmarks might exeed the number of tool calibration + * landmarks for reasons of redundancy and averaging. They are used for, e.g., manually registering + * the pose of a tool by visual markers in a CT scan. If you would use these landmarks to do a + * point based registration from image space to tracking space later, you might overweight the + * tool because of two many landmarks compared to other markers. + * + * @return Returns the tool registration landmarks which represent markers / special points on a * tool that can be used for registration. The landmarks should be given in tool coordinates. * If there are no landmarks defined for this tool the method returns an empty point set. */ itkGetConstMacro(ToolRegistrationLandmarks,mitk::PointSet::Pointer); /** @brief Sets the tool registration landmarks which represent markers / special points on a * tool that can be used for registration. The landmarks should be given in tool coordinates. */ itkSetMacro(ToolRegistrationLandmarks,mitk::PointSet::Pointer); /** @return Returns the tool calibration landmarks for calibration of the defined points in the * tool coordinate system, e.g. 2 landmarks for a 5DoF tool and 3 landmarks for a 6DoF tool. */ itkGetConstMacro(ToolCalibrationLandmarks,mitk::PointSet::Pointer); /** @brief Sets the tool calibration landmarks for calibration of defined points in the * tool coordinate system, e.g. 2 landmarks for a 5DoF tool and 3 landmarks for a 6DoF tool. */ itkSetMacro(ToolCalibrationLandmarks,mitk::PointSet::Pointer); //SerialNumber: itkGetConstMacro(SerialNumber,std::string); itkSetMacro(SerialNumber,std::string); //TrackingDeviceType: itkGetConstMacro(TrackingDeviceType,mitk::TrackingDeviceType); itkSetMacro(TrackingDeviceType,mitk::TrackingDeviceType); //ToolName (only getter): /** @return Returns the name of this navigation tool. Returns an empty string if there is * no name (for example because the data node has not been set yet). * * Note: There is no setter for the name, * because the name of the corresponding data node is used as tool name. So if you * want to modify the name of this navigation tool only get the data node and modify * its name. */ std::string GetToolName(); //ToolSurface (only getter): /** @return Returns the surface of this navigation tool. Returns NULL if there is * no surface (for example because the data node has not been set yet). * * Note: There is no setter for the surface, * because the surface is the data of the corresponding data node. So if you * want to set a new surface only get the data node and modify its data. */ mitk::Surface::Pointer GetToolSurface(); /** * \brief Graft the data and information from one NavigationTool to another. * * Copies the content of data into this object. * This is a convenience method to setup a second NavigationTool object with all the meta * information of another NavigationTool object. * Note that this method is different than just using two * SmartPointers to the same NavigationTool object since separate DataObjects are * still maintained. */ virtual void Graft(const DataObject *data); //####################### protected: NavigationTool(); ~NavigationTool(); //## data structure of a navigation tool object ## std::string m_Identifier; NavigationToolType m_Type; /** @brief This DataNode holds a toolname and a tool surface */ mitk::DataNode::Pointer m_DataNode; /** @brief This member variable holds a mathamatical description of the tool */ itk::SpatialObject<3>::Pointer m_SpatialObject; /** @brief This member variable holds a pointer to the corresponding tracking tool in the hardware. */ mitk::TrackingTool::Pointer m_TrackingTool; /** @brief The path to the calibration file of the tool. */ std::string m_CalibrationFile; /** @brief A unique serial number of the tool which is needed to identify the tool correctly. This is very important * in case of the NDI Aurora System. */ std::string m_SerialNumber; /** @brief This member holds the tracking device type of the tool. */ mitk::TrackingDeviceType m_TrackingDeviceType; /** @brief Holds landmarks for tool registration. */ mitk::PointSet::Pointer m_ToolRegistrationLandmarks; /** @brief Holds landmarks for calibration of the defined points in the tool coordinate system, * e.g. 2 landmarks for a 5DoF tool and 3 landmarks for a 6DoF tool. */ mitk::PointSet::Pointer m_ToolCalibrationLandmarks; /** @brief Holds the position of the tool tip. */ mitk::Point3D m_ToolTipPosition; /** @brief Holds the orientation of the tool tip. */ mitk::Quaternion m_ToolTipOrientation; //################################################# }; } // namespace mitk #endif //NAVIGATIONTOOL diff --git a/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.cpp b/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.cpp index 837267c939..6293a244d6 100644 --- a/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.cpp +++ b/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.cpp @@ -1,308 +1,341 @@ /*=================================================================== 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. ===================================================================*/ #include "QmitkNavigationToolCreationWidget.h" //mitk headers #include "mitkTrackingTypes.h" #include #include #include "mitkNavigationData.h" #include "mitkRenderingManager.h" //qt headers #include #include #include //poco headers #include // vtk #include #include "vtkConeSource.h" const std::string QmitkNavigationToolCreationWidget::VIEW_ID = "org.mitk.views.navigationtoolcreationwizardwidget"; QmitkNavigationToolCreationWidget::QmitkNavigationToolCreationWidget(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) { - m_Controls = NULL; - m_AdvancedWidget = new QmitkNavigationToolCreationAdvancedWidget(this); - m_AdvancedWidget->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); - m_AdvancedWidget->setWindowTitle("Tool Creation Advanced Options"); - m_AdvancedWidget->setModal(false); - CreateQtPartControl(this); - CreateConnections(); +m_Controls = NULL; +m_AdvancedWidget = new QmitkNavigationToolCreationAdvancedWidget(this); +m_AdvancedWidget->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint); +m_AdvancedWidget->setWindowTitle("Tool Creation Advanced Options"); +m_AdvancedWidget->setModal(false); +CreateQtPartControl(this); +CreateConnections(); } QmitkNavigationToolCreationWidget::~QmitkNavigationToolCreationWidget() { - delete m_AdvancedWidget; +m_Controls->m_CalibrationLandmarksList->SetPointSetNode(NULL); +m_Controls->m_RegistrationLandmarksList->SetPointSetNode(NULL); +delete m_AdvancedWidget; } void QmitkNavigationToolCreationWidget::CreateQtPartControl(QWidget *parent) { - if (!m_Controls) - { - // create GUI widgets - m_Controls = new Ui::QmitkNavigationToolCreationWidgetControls; - m_Controls->setupUi(parent); - } +if (!m_Controls) +{ +// create GUI widgets +m_Controls = new Ui::QmitkNavigationToolCreationWidgetControls; +m_Controls->setupUi(parent); +} } void QmitkNavigationToolCreationWidget::CreateConnections() { - if ( m_Controls ) - { - connect( (QObject*)(m_Controls->m_cancel), SIGNAL(clicked()), this, SLOT(OnCancel()) ); - connect( (QObject*)(m_Controls->m_finished), SIGNAL(clicked()), this, SLOT(OnFinished()) ); - connect( (QObject*)(m_Controls->m_LoadSurface), SIGNAL(clicked()), this, SLOT(OnLoadSurface()) ); - connect( (QObject*)(m_Controls->m_LoadCalibrationFile), SIGNAL(clicked()), this, SLOT(OnLoadCalibrationFile()) ); - connect( (QObject*)(m_Controls->m_ShowAdvancedOptionsPB), SIGNAL(toggled(bool)), this, SLOT(OnShowAdvancedOptions(bool)) ); - connect( (QObject*)(m_AdvancedWidget), SIGNAL(DialogCloseRequested()), this, SLOT(OnProcessDialogCloseRequest()) ); - connect( (QObject*)(m_AdvancedWidget), SIGNAL(RetrieveDataForManualToolTipManipulation()), this, SLOT(OnRetrieveDataForManualTooltipManipulation()) ); - - connect( m_Controls->m_Surface_Use_Other, SIGNAL(toggled(bool)), this, SLOT(OnSurfaceUseOtherToggled(bool))); - } +if ( m_Controls ) +{ +connect( (QObject*)(m_Controls->m_cancel), SIGNAL(clicked()), this, SLOT(OnCancel()) ); +connect( (QObject*)(m_Controls->m_finished), SIGNAL(clicked()), this, SLOT(OnFinished()) ); +connect( (QObject*)(m_Controls->m_LoadSurface), SIGNAL(clicked()), this, SLOT(OnLoadSurface()) ); +connect( (QObject*)(m_Controls->m_LoadCalibrationFile), SIGNAL(clicked()), this, SLOT(OnLoadCalibrationFile()) ); +connect( (QObject*)(m_Controls->m_ShowAdvancedOptionsPB), SIGNAL(toggled(bool)), this, SLOT(OnShowAdvancedOptions(bool)) ); +connect( (QObject*)(m_AdvancedWidget), SIGNAL(DialogCloseRequested()), this, SLOT(OnProcessDialogCloseRequest()) ); +connect( (QObject*)(m_AdvancedWidget), SIGNAL(RetrieveDataForManualToolTipManipulation()), this, SLOT(OnRetrieveDataForManualTooltipManipulation()) ); + +connect( m_Controls->m_Surface_Use_Other, SIGNAL(toggled(bool)), this, SLOT(OnSurfaceUseOtherToggled(bool))); +} } void QmitkNavigationToolCreationWidget::Initialize(mitk::DataStorage* dataStorage, std::string supposedIdentifier, std::string supposedName) { - m_DataStorage = dataStorage; - - //initialize UI components - m_Controls->m_SurfaceChooser->SetDataStorage(m_DataStorage); - m_Controls->m_SurfaceChooser->SetAutoSelectNewItems(true); - m_Controls->m_SurfaceChooser->SetPredicate(mitk::NodePredicateDataType::New("Surface")); - - //set default data - m_Controls->m_ToolNameEdit->setText(supposedName.c_str()); - m_Controls->m_CalibrationFileName->setText("none"); - m_Controls->m_Surface_Use_Sphere->setChecked(true); - m_AdvancedWidget->SetDataStorage(m_DataStorage); - m_Controls->m_IdentifierEdit->setText(supposedIdentifier.c_str()); - +m_DataStorage = dataStorage; + +//initialize UI components +m_Controls->m_SurfaceChooser->SetDataStorage(m_DataStorage); +m_Controls->m_SurfaceChooser->SetAutoSelectNewItems(true); +m_Controls->m_SurfaceChooser->SetPredicate(mitk::NodePredicateDataType::New("Surface")); + +//set default data +m_Controls->m_ToolNameEdit->setText(supposedName.c_str()); +m_Controls->m_CalibrationFileName->setText("none"); +m_Controls->m_Surface_Use_Sphere->setChecked(true); +m_AdvancedWidget->SetDataStorage(m_DataStorage); +m_Controls->m_IdentifierEdit->setText(supposedIdentifier.c_str()); +this->InitializeUIToolLandmarkLists(); +m_Controls->m_CalibrationLandmarksList->EnableEditButton(false); +m_Controls->m_RegistrationLandmarksList->EnableEditButton(false); } void QmitkNavigationToolCreationWidget::SetTrackingDeviceType(mitk::TrackingDeviceType type, bool changeable) { - switch(type) - { - case mitk::NDIAurora: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(0);break; - case mitk::NDIPolaris: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(1);break; - case mitk::ClaronMicron: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(2);break; - case mitk::NPOptitrack: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(3);break; - default: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(0); - } - m_Controls->m_TrackingDeviceTypeChooser->setEnabled(changeable); +switch(type) +{ +case mitk::NDIAurora: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(0);break; +case mitk::NDIPolaris: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(1);break; +case mitk::ClaronMicron: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(2);break; +case mitk::NPOptitrack: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(3);break; +default: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(0); +} +m_Controls->m_TrackingDeviceTypeChooser->setEnabled(changeable); } mitk::NavigationTool::Pointer QmitkNavigationToolCreationWidget::GetCreatedTool() { - return m_CreatedTool; +return m_CreatedTool; } //################################################################################## //############################## slots ############################ //################################################################################## void QmitkNavigationToolCreationWidget::OnFinished() { - //here we create a new tool - m_CreatedTool = mitk::NavigationTool::New(); - - //create DataNode... - mitk::DataNode::Pointer newNode = mitk::DataNode::New(); - if(m_Controls->m_Surface_Use_Sphere->isChecked()) - { - //create small sphere and use it as surface - mitk::Surface::Pointer mySphere = mitk::Surface::New(); - vtkConeSource *vtkData = vtkConeSource::New(); - vtkData->SetAngle(5.0); - vtkData->SetResolution(50); - vtkData->SetHeight(6.0f); - vtkData->SetRadius(2.0f); - vtkData->SetCenter(0.0, 0.0, 0.0); - vtkData->Update(); - mySphere->SetVtkPolyData(vtkData->GetOutput()); - vtkData->Delete(); - newNode->SetData(mySphere); - } - else - { - newNode->SetData(m_Controls->m_SurfaceChooser->GetSelectedNode()->GetData()); - } - newNode->SetName(m_Controls->m_ToolNameEdit->text().toLatin1()); - - m_CreatedTool->SetDataNode(newNode); - - //fill NavigationTool object - m_CreatedTool->SetCalibrationFile(m_Controls->m_CalibrationFileName->text().toAscii().data()); - m_CreatedTool->SetIdentifier(m_Controls->m_IdentifierEdit->text().toAscii().data()); - m_CreatedTool->SetSerialNumber(m_Controls->m_SerialNumberEdit->text().toAscii().data()); - - //Tracking Device - if (m_Controls->m_TrackingDeviceTypeChooser->currentText()=="NDI Aurora") m_CreatedTool->SetTrackingDeviceType(mitk::NDIAurora); - else if (m_Controls->m_TrackingDeviceTypeChooser->currentText()=="NDI Polaris") m_CreatedTool->SetTrackingDeviceType(mitk::NDIPolaris); - else if (m_Controls->m_TrackingDeviceTypeChooser->currentText()=="Claron Technology Micron Tracker") m_CreatedTool->SetTrackingDeviceType(mitk::ClaronMicron); - else if (m_Controls->m_TrackingDeviceTypeChooser->currentText()=="NP Optitrack") m_CreatedTool->SetTrackingDeviceType(mitk::NPOptitrack); - else m_CreatedTool->SetTrackingDeviceType(mitk::TrackingSystemNotSpecified); - - //ToolType - if (m_Controls->m_ToolTypeChooser->currentText()=="Instrument") m_CreatedTool->SetType(mitk::NavigationTool::Instrument); - else if (m_Controls->m_ToolTypeChooser->currentText()=="Fiducial") m_CreatedTool->SetType(mitk::NavigationTool::Fiducial); - else if (m_Controls->m_ToolTypeChooser->currentText()=="Skinmarker") m_CreatedTool->SetType(mitk::NavigationTool::Skinmarker); - else m_CreatedTool->SetType(mitk::NavigationTool::Unknown); - - mitk::NavigationData::Pointer tempND = mitk::NavigationData::New(m_AdvancedWidget->GetManipulatedToolTip()); - m_CreatedTool->SetToolTipOrientation(tempND->GetOrientation()); - m_CreatedTool->SetToolTipPosition(tempND->GetPosition()); - - emit NavigationToolFinished(); +//here we create a new tool +m_CreatedTool = mitk::NavigationTool::New(); + +//create DataNode... +mitk::DataNode::Pointer newNode = mitk::DataNode::New(); +if(m_Controls->m_Surface_Use_Sphere->isChecked()) +{ +//create small sphere and use it as surface +mitk::Surface::Pointer mySphere = mitk::Surface::New(); +vtkConeSource *vtkData = vtkConeSource::New(); +vtkData->SetAngle(5.0); +vtkData->SetResolution(50); +vtkData->SetHeight(6.0f); +vtkData->SetRadius(2.0f); +vtkData->SetCenter(0.0, 0.0, 0.0); +vtkData->Update(); +mySphere->SetVtkPolyData(vtkData->GetOutput()); +vtkData->Delete(); +newNode->SetData(mySphere); +} +else +{ +newNode->SetData(m_Controls->m_SurfaceChooser->GetSelectedNode()->GetData()); +} +newNode->SetName(m_Controls->m_ToolNameEdit->text().toLatin1()); + +m_CreatedTool->SetDataNode(newNode); + +//fill NavigationTool object +m_CreatedTool->SetCalibrationFile(m_Controls->m_CalibrationFileName->text().toAscii().data()); +m_CreatedTool->SetIdentifier(m_Controls->m_IdentifierEdit->text().toAscii().data()); +m_CreatedTool->SetSerialNumber(m_Controls->m_SerialNumberEdit->text().toAscii().data()); + +//Tracking Device +if (m_Controls->m_TrackingDeviceTypeChooser->currentText()=="NDI Aurora") m_CreatedTool->SetTrackingDeviceType(mitk::NDIAurora); +else if (m_Controls->m_TrackingDeviceTypeChooser->currentText()=="NDI Polaris") m_CreatedTool->SetTrackingDeviceType(mitk::NDIPolaris); +else if (m_Controls->m_TrackingDeviceTypeChooser->currentText()=="Claron Technology Micron Tracker") m_CreatedTool->SetTrackingDeviceType(mitk::ClaronMicron); +else if (m_Controls->m_TrackingDeviceTypeChooser->currentText()=="NP Optitrack") m_CreatedTool->SetTrackingDeviceType(mitk::NPOptitrack); +else m_CreatedTool->SetTrackingDeviceType(mitk::TrackingSystemNotSpecified); + +//ToolType +if (m_Controls->m_ToolTypeChooser->currentText()=="Instrument") m_CreatedTool->SetType(mitk::NavigationTool::Instrument); +else if (m_Controls->m_ToolTypeChooser->currentText()=="Fiducial") m_CreatedTool->SetType(mitk::NavigationTool::Fiducial); +else if (m_Controls->m_ToolTypeChooser->currentText()=="Skinmarker") m_CreatedTool->SetType(mitk::NavigationTool::Skinmarker); +else m_CreatedTool->SetType(mitk::NavigationTool::Unknown); + +//Tool Tip +mitk::NavigationData::Pointer tempND = mitk::NavigationData::New(m_AdvancedWidget->GetManipulatedToolTip()); +m_CreatedTool->SetToolTipOrientation(tempND->GetOrientation()); +m_CreatedTool->SetToolTipPosition(tempND->GetPosition()); + +//Tool Landmarks +mitk::PointSet::Pointer toolCalLandmarks, toolRegLandmarks; +GetUIToolLandmarksLists(toolCalLandmarks,toolRegLandmarks); +m_CreatedTool->SetToolCalibrationLandmarks(toolCalLandmarks); +m_CreatedTool->SetToolRegistrationLandmarks(toolRegLandmarks); + +emit NavigationToolFinished(); } void QmitkNavigationToolCreationWidget::OnCancel() { - m_CreatedTool = NULL; +m_CreatedTool = NULL; - emit Canceled(); +emit Canceled(); } void QmitkNavigationToolCreationWidget::OnLoadSurface() { - std::string filename = QFileDialog::getOpenFileName(NULL,tr("Open Surface"), "/", tr("STL (*.stl)")).toLatin1().data(); - mitk::STLFileReader::Pointer stlReader = mitk::STLFileReader::New(); - try - { - stlReader->SetFileName( filename.c_str() ); - stlReader->Update(); - } - catch (...) - { - } - - if ( stlReader->GetOutput() == NULL ); - else - { - mitk::DataNode::Pointer newNode = mitk::DataNode::New(); - newNode->SetName(filename); - newNode->SetData(stlReader->GetOutput()); - m_DataStorage->Add(newNode); - } +std::string filename = QFileDialog::getOpenFileName(NULL,tr("Open Surface"), "/", tr("STL (*.stl)")).toLatin1().data(); +mitk::STLFileReader::Pointer stlReader = mitk::STLFileReader::New(); +try +{ +stlReader->SetFileName( filename.c_str() ); +stlReader->Update(); +} +catch (...) +{ +} + +if ( stlReader->GetOutput() == NULL ); +else +{ +mitk::DataNode::Pointer newNode = mitk::DataNode::New(); +newNode->SetName(filename); +newNode->SetData(stlReader->GetOutput()); +m_DataStorage->Add(newNode); +} } void QmitkNavigationToolCreationWidget::OnLoadCalibrationFile() { - m_Controls->m_CalibrationFileName->setText(QFileDialog::getOpenFileName(NULL,tr("Open Calibration File"), "/", "*.*")); +m_Controls->m_CalibrationFileName->setText(QFileDialog::getOpenFileName(NULL,tr("Open Calibration File"), "/", "*.*")); } void QmitkNavigationToolCreationWidget::SetDefaultData(mitk::NavigationTool::Pointer DefaultTool) { - m_Controls->m_ToolNameEdit->setText(QString(DefaultTool->GetDataNode()->GetName().c_str())); - m_Controls->m_IdentifierEdit->setText(QString(DefaultTool->GetIdentifier().c_str())); - m_Controls->m_SerialNumberEdit->setText(QString(DefaultTool->GetSerialNumber().c_str())); - m_AdvancedWidget->SetDefaultTooltip( DefaultTool->GetToolTipTransform() ); - switch(DefaultTool->GetTrackingDeviceType()) - { - case mitk::NDIAurora: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(0);break; - case mitk::NDIPolaris: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(1);break; - case mitk::ClaronMicron: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(2);break; - case mitk::NPOptitrack: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(3);break; - default: - m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(0); - } - m_Controls->m_CalibrationFileName->setText(QString(DefaultTool->GetCalibrationFile().c_str())); - m_Controls->m_Surface_Use_Other->setChecked(true); - switch(DefaultTool->GetType()) - { - case mitk::NavigationTool::Instrument: - m_Controls->m_ToolTypeChooser->setCurrentIndex(0); break; - case mitk::NavigationTool::Fiducial: - m_Controls->m_ToolTypeChooser->setCurrentIndex(1); break; - case mitk::NavigationTool::Skinmarker: - m_Controls->m_ToolTypeChooser->setCurrentIndex(2); break; - case mitk::NavigationTool::Unknown: - m_Controls->m_ToolTypeChooser->setCurrentIndex(3); break; - } - - m_Controls->m_SurfaceChooser->SetSelectedNode(DefaultTool->GetDataNode()); +m_Controls->m_ToolNameEdit->setText(QString(DefaultTool->GetDataNode()->GetName().c_str())); +m_Controls->m_IdentifierEdit->setText(QString(DefaultTool->GetIdentifier().c_str())); +m_Controls->m_SerialNumberEdit->setText(QString(DefaultTool->GetSerialNumber().c_str())); +m_AdvancedWidget->SetDefaultTooltip( DefaultTool->GetToolTipTransform() ); +switch(DefaultTool->GetTrackingDeviceType()) +{ +case mitk::NDIAurora: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(0);break; +case mitk::NDIPolaris: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(1);break; +case mitk::ClaronMicron: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(2);break; +case mitk::NPOptitrack: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(3);break; +default: +m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(0); +} +m_Controls->m_CalibrationFileName->setText(QString(DefaultTool->GetCalibrationFile().c_str())); +m_Controls->m_Surface_Use_Other->setChecked(true); +switch(DefaultTool->GetType()) +{ +case mitk::NavigationTool::Instrument: +m_Controls->m_ToolTypeChooser->setCurrentIndex(0); break; +case mitk::NavigationTool::Fiducial: +m_Controls->m_ToolTypeChooser->setCurrentIndex(1); break; +case mitk::NavigationTool::Skinmarker: +m_Controls->m_ToolTypeChooser->setCurrentIndex(2); break; +case mitk::NavigationTool::Unknown: +m_Controls->m_ToolTypeChooser->setCurrentIndex(3); break; +} +m_Controls->m_SurfaceChooser->SetSelectedNode(DefaultTool->GetDataNode()); +FillUIToolLandmarkLists(DefaultTool->GetToolCalibrationLandmarks(),DefaultTool->GetToolRegistrationLandmarks()); } //################################################################################## //############################## internal help methods ############################# //################################################################################## void QmitkNavigationToolCreationWidget::MessageBox(std::string s) { - QMessageBox msgBox; - msgBox.setText(s.c_str()); - msgBox.exec(); +QMessageBox msgBox; +msgBox.setText(s.c_str()); +msgBox.exec(); } void QmitkNavigationToolCreationWidget::OnShowAdvancedOptions(bool state) { - if(state) - { - m_AdvancedWidget->show(); - m_AdvancedWidget->SetDefaultTooltip(m_AdvancedWidget->GetManipulatedToolTip()); //use the last one, if there is one - m_AdvancedWidget->ReInitialize(); - - // reinit the views with the new nodes - mitk::DataStorage::SetOfObjects::ConstPointer rs = m_DataStorage->GetAll(); - mitk::TimeGeometry::Pointer bounds = m_DataStorage->ComputeBoundingGeometry3D(rs, "visible"); // initialize the views to the bounding geometry - mitk::RenderingManager::GetInstance()->InitializeViews(bounds); - } - else - { - m_AdvancedWidget->hide(); - } +if(state) +{ +m_AdvancedWidget->show(); +m_AdvancedWidget->SetDefaultTooltip(m_AdvancedWidget->GetManipulatedToolTip()); //use the last one, if there is one +m_AdvancedWidget->ReInitialize(); + +// reinit the views with the new nodes +mitk::DataStorage::SetOfObjects::ConstPointer rs = m_DataStorage->GetAll(); +mitk::TimeGeometry::Pointer bounds = m_DataStorage->ComputeBoundingGeometry3D(rs, "visible"); // initialize the views to the bounding geometry +mitk::RenderingManager::GetInstance()->InitializeViews(bounds); +} +else +{ +m_AdvancedWidget->hide(); +} } void QmitkNavigationToolCreationWidget::OnProcessDialogCloseRequest() { - m_AdvancedWidget->hide(); - m_Controls->m_ShowAdvancedOptionsPB->setChecked(false); +m_AdvancedWidget->hide(); +m_Controls->m_ShowAdvancedOptionsPB->setChecked(false); } void QmitkNavigationToolCreationWidget::OnRetrieveDataForManualTooltipManipulation() { - if(m_Controls->m_Surface_Use_Sphere->isChecked()) - { - m_AdvancedWidget->SetToolTipSurface(true); - } - else - { - m_AdvancedWidget->SetToolTipSurface(false, - dynamic_cast(m_Controls->m_SurfaceChooser->GetSelectedNode().GetPointer())); - } +if(m_Controls->m_Surface_Use_Sphere->isChecked()) +{ +m_AdvancedWidget->SetToolTipSurface(true); +} +else +{ +m_AdvancedWidget->SetToolTipSurface(false, +dynamic_cast(m_Controls->m_SurfaceChooser->GetSelectedNode().GetPointer())); +} } void QmitkNavigationToolCreationWidget::OnSurfaceUseOtherToggled(bool checked) { - m_Controls->m_LoadSurface->setEnabled(checked); +m_Controls->m_LoadSurface->setEnabled(checked); +} + +void QmitkNavigationToolCreationWidget::FillUIToolLandmarkLists(mitk::PointSet::Pointer calLandmarks, mitk::PointSet::Pointer regLandmarks) +{ +m_calLandmarkNode->SetData(calLandmarks); +m_regLandmarkNode->SetData(regLandmarks); +m_Controls->m_CalibrationLandmarksList->SetPointSetNode(m_calLandmarkNode); +m_Controls->m_RegistrationLandmarksList->SetPointSetNode(m_regLandmarkNode); + +} + +void QmitkNavigationToolCreationWidget::GetUIToolLandmarksLists(mitk::PointSet::Pointer& calLandmarks, mitk::PointSet::Pointer& regLandmarks) +{ +calLandmarks = dynamic_cast(m_calLandmarkNode->GetData()); +regLandmarks = dynamic_cast(m_regLandmarkNode->GetData()); +} + +void QmitkNavigationToolCreationWidget::InitializeUIToolLandmarkLists() +{ +m_calLandmarkNode = mitk::DataNode::New(); +m_regLandmarkNode = mitk::DataNode::New(); +FillUIToolLandmarkLists(mitk::PointSet::New(),mitk::PointSet::New()); } diff --git a/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.h b/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.h index 4aad403635..042b27cd15 100644 --- a/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.h +++ b/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.h @@ -1,109 +1,125 @@ /*=================================================================== 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 QmitkNavigationToolCreationWidget_H #define QmitkNavigationToolCreationWidget_H //QT headers #include //mitk headers #include "MitkIGTUIExports.h" #include #include #include // Qmitk headers #include "QmitkNavigationToolCreationAdvancedWidget.h" //ui header #include "ui_QmitkNavigationToolCreationWidget.h" /** Documentation: * \brief An object of this class offers an UI to create or modify NavigationTools. * * Be sure to call the initialize method before you start the widget * otherwise some errors might occure. * * \ingroup IGTUI */ class MitkIGTUI_EXPORT QmitkNavigationToolCreationWidget : public QWidget { Q_OBJECT public: static const std::string VIEW_ID; /** @brief Initializes the widget. * @param dataStorage The data storage is needed to offer the possibility to choose surfaces from the data storage for tool visualization. * @param supposedIdentifier This Identifier is supposed for the user. It is needed because every identifier in a navigation tool storage must be unique and we don't know the others. */ void Initialize(mitk::DataStorage* dataStorage, std::string supposedIdentifier, std::string supposedName = "NewTool"); /** @brief Sets the default tracking device type. You may also define if it is changeable or not.*/ void SetTrackingDeviceType(mitk::TrackingDeviceType type, bool changeable = true); /** @brief Sets the default data of all input fields. The default data is used from the default tool which is given as parameter. */ void SetDefaultData(mitk::NavigationTool::Pointer DefaultTool); QmitkNavigationToolCreationWidget(QWidget* parent = 0, Qt::WindowFlags f = 0); ~QmitkNavigationToolCreationWidget(); /** @return Returns the created tool. Returns NULL if no tool was created yet. */ mitk::NavigationTool::Pointer GetCreatedTool(); signals: /** @brief This signal is emitted if the user finished the creation of the tool. */ void NavigationToolFinished(); /** @brief This signal is emitted if the user canceled the creation of the tool. */ void Canceled(); protected slots: void OnCancel(); void OnFinished(); void OnLoadSurface(); void OnLoadCalibrationFile(); void OnShowAdvancedOptions(bool state); void OnProcessDialogCloseRequest(); void OnRetrieveDataForManualTooltipManipulation(); void OnSurfaceUseOtherToggled(bool checked); protected: /// \brief Creation of the connections virtual void CreateConnections(); virtual void CreateQtPartControl(QWidget *parent); Ui::QmitkNavigationToolCreationWidgetControls* m_Controls; QmitkNavigationToolCreationAdvancedWidget* m_AdvancedWidget; /** @brief holds the DataStorage */ mitk::DataStorage* m_DataStorage; /** @brief this pointer holds the tool which is created */ mitk::NavigationTool::Pointer m_CreatedTool; //############## private help methods ####################### + /** Shows a message box with the given message s. */ void MessageBox(std::string s); + /** Hold the data nodes which are needed for the landmark widgets. */ + mitk::DataNode::Pointer m_calLandmarkNode, m_regLandmarkNode; + + /** Set the tool landmark lists in the UI.*/ + void FillUIToolLandmarkLists(mitk::PointSet::Pointer calLandmarks, mitk::PointSet::Pointer regLandmarks); + + /** Returns the tool landmark lists from the UI. + * @param[out] calLandmarks Returns a pointer to the calibration landmarks point set. + * @param[out] regLandmarks Returns a pointer to the registration landmarks point set. + */ + void GetUIToolLandmarksLists(mitk::PointSet::Pointer& calLandmarks, mitk::PointSet::Pointer& regLandmarks); + + /** Initializes the tool landmark lists in the UI. */ + void InitializeUIToolLandmarkLists(); + }; #endif diff --git a/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.ui b/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.ui index 0572c457bd..28beb9ffb6 100644 --- a/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.ui +++ b/Modules/IGTUI/Qmitk/QmitkNavigationToolCreationWidget.ui @@ -1,483 +1,531 @@ QmitkNavigationToolCreationWidgetControls 0 0 - 358 - 371 + 254 + 309 Form Device Type: 150 0 150 16777215 NDI Aurora NDI Polaris Claron Technology Micron Tracker NP Optitrack 0 0 0 - 340 - 205 + 236 + 90 Basic Information 100 0 Name: NewTool 100 0 Calibration File: none 40 16777215 Load Qt::Vertical 20 40 0 0 - 340 - 205 + 310 + 113 Tool Visualization Use Simple Cone true Use Surface: Qt::Horizontal QSizePolicy::Fixed 25 20 200 0 150 16777215 false 40 16777215 Load Qt::Horizontal 40 20 Qt::Vertical 20 8 + + + + 0 + 0 + 232 + 85 + + + + Tool Landmarks + + + + + + 0 + + + + Calibration Landmarks + + + + + + + + + + Registration Landmarks + + + + + + + + + + + 0 0 - 340 - 129 + 281 + 152 Advanced 100 0 Tool Type: 150 0 150 16777215 Instrument Fiducial Skinmarker Unkown 100 0 Identifier: <not given> 100 0 Serial Number: <not given> Tooltip: Qt::Horizontal 40 20 Edit Tooltip true Qt::Vertical 20 40 Qt::Horizontal Qt::Horizontal 40 20 Cancel Finished QmitkDataStorageComboBox QComboBox
QmitkDataStorageComboBox.h
1
+ + QmitkPointListWidget + QWidget +
QmitkPointListWidget.h
+ 1 +
diff --git a/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkIGTTracking_NavigationToolManagemantStartScreen.png b/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkIGTTracking_NavigationToolManagemantStartScreen.png index 759c88ccf1..44b30bdd24 100644 Binary files a/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkIGTTracking_NavigationToolManagemantStartScreen.png and b/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkIGTTracking_NavigationToolManagemantStartScreen.png differ diff --git a/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkIGTTracking_NavigationToolManagementAddTool.png b/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkIGTTracking_NavigationToolManagementAddTool.png index 03124a951c..c6214c0764 100644 Binary files a/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkIGTTracking_NavigationToolManagementAddTool.png and b/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkIGTTracking_NavigationToolManagementAddTool.png differ diff --git a/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkMITKIGTNavigationToolManager.dox b/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkMITKIGTNavigationToolManager.dox index 06dbdc0955..31bfbb4df8 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkMITKIGTNavigationToolManager.dox +++ b/Plugins/org.mitk.gui.qt.igttracking/documentation/UserManual/QmitkMITKIGTNavigationToolManager.dox @@ -1,47 +1,55 @@ /** \page org_mitk_views_igtnavigationtoolmanager The MITK-IGT Navigation Tool Manager \image html QmitkIGTTracking_IconNavigationToolManager.png "Icon of the Module" \section QmitkMITKIGTNavigationToolManager Introduction This view allows for creating and editing NavigationToolStorages. These storages contains naviagtion tools of a tracking device, can be saved permanently and used later for any other IGT application. Available sections: - \ref QmitkMITKIGTNavigationToolManager - \ref QmitkMITKIGTNavigationToolManagerToolOverview - \ref QmitkMITKIGTNavigationToolManagerManagingNavigationToolStorage - \ref QmitkMITKIGTNavigationToolManagerAddingEditingNavigationTools \section QmitkMITKIGTNavigationToolManagerToolOverview Navigation Tools Overview A navigation tool of MITK-IGT represents a tracking tool (e.g. an emt sensor or an optically tracked tool) and it's corresponding data, like it's name and it's surface. A navigation tool is a generalized container for any trackable object in combination with it's additional information. Every navigation tool has different properties which are:
  • Name
  • Unique identifier
  • Tool definition file
  • Serial number
  • Surface for visualization
  • Type of tracking device
  • Type of the tool +
  • Tool landmarks
-Note that not all properties are needed for all types of tools. A tool definition file, for example, is only needed by optical tracking tools (e.g. a .rom file for Polaris or a toolfile for the MicronTracker). A tool associated with the aurora system is alwalys identified by it's serial number. You can also detect Aurora tools automatically with the TrackingToolbox view and edit the automatically detected tool storage later with this view. +Note that not all properties are needed for all types of tools. A tool definition file, for example, is only needed by optical tracking tools (e.g. a .rom file for Polaris or a toolfile for the MicronTracker). A tool associated with the aurora system is alwalys identified by it's serial number. You can also detect Aurora tools automatically with the TrackingToolbox view and edit the automatically detected tool storage later with this view. \section QmitkMITKIGTNavigationToolManagerManagingNavigationToolStorage Managing Navigation Tool Storage -In order to create a new storage container, or edit an existing one, you can use the buttons "add", "edit" and "delete" to manage the contained navigation tools. If you click "edit" or "delete" the operation is applied on the currently selected tool, as shown in the screenshot below. If you want to create a new storage container, just start adding tools when you start the program and save the storage container. To edit an existing tool storage container click "load" and add/edit/delete tools. +In order to create edit a tool storage container, you can select one of the available tool storages listed in the upper part of the UI. The list shows all tool storages which are available throug the micro services concept of MITK. The list also shows the current tool storage of the IGT tracking toolbox view if it is active. In addition to the listed tool storages, you can load new storages from the hard disc which will then appear in the list and might be edited as all other storage by simply selecting it in the list. You may also save a selected tool storage to the hard disc or create a new one. + +In the lower part of the UI you always see the list of tools of the tool storage which is currently selected in the upper part. Use the buttons "add", "edit" and "delete" to manage the contained navigation tools. If you click "edit" or "delete" the operation is applied on the currently selected tool, as shown in the screenshot below. \image html QmitkIGTTracking_NavigationToolManagemantStartScreen.png "Screenshot of the main view of NavigationToolManagent" \section QmitkMITKIGTNavigationToolManagerAddingEditingNavigationTools Adding / Editing Navigation Tools -If you add or edit a navigation tool, an input mask, as shown in the screenshot below, appears. The tool identifier is filled automatically, if you change it, remember that it is unique in the current storage. Also, choose a valid surface for every tool, this is nessesary for correct tool visualization. The other information depends on the tracking system type. So choose a tool file for the Polaris or the MicronTracker system and type in a serial number for the Aurora system. Two identical tools with the same serial number are also possible, they are assigned by the order in which they are attached to the device. As long as they also have the same surface, this should not be a problem. +If you add or edit a navigation tool, an input mask, as shown in the screenshot below, appears. The tool identifier is filled automatically, if you change it, remember that it is unique in the current storage. Also, choose a valid surface for every tool, this is nessesary for correct tool visualization. The other information depends on the tracking system type. So choose a tool file for the Polaris or the MicronTracker system and type in a serial number for the Aurora system. Two identical tools with the same serial number are also possible, they are assigned by the order in which they are attached to the device. As long as they also have the same surface as representation, this should not be a problem for most of the use cases. + +The tool type is additional information which is not needed by the tracking device but might be needed by further IGT applications. The same applies to the tool landmarks which might be defined for a tool. There are two different types of landmarks which are designed as described here: -The tool type is additional information which is not needed by the tracking device but might be needed by further IGT applications. +
    +
  • Tool Calibration Landmarks: These landmarks may be used clearly define the tools pose only by using landmarks in the tool coordinate system. E.g., two landmarks for a 5DoF tool and three landmarks for a 6DoF tool. These landmarks may be used, e.g., for a point based registration of a tool from image space to tracking space. +
  • Tool Registration Landmarks: These landmarks are designed for representing defined landmarks on a tools surface. The number of these landmarks might exeed the number of tool calibration landmarks for reasons of redundancy and averaging. They are used for, e.g., manually registering the pose of a tool by visual markers in a CT scan. If you would use these landmarks to do a point based registration from image space to tracking space later, you might overweight the tool because of two many landmarks compared to other markers. +
\image html QmitkIGTTracking_NavigationToolManagementAddTool.png "Screenshot of add/edit navigation tool screen" */ \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp index c6081e312a..9eca91eb8d 100644 --- a/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp +++ b/Plugins/org.mitk.gui.qt.igttracking/src/internal/QmitkMITKIGTTrackingToolboxView.cpp @@ -1,1100 +1,1106 @@ /*=================================================================== 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 "QmitkMITKIGTTrackingToolboxView.h" #include "QmitkStdMultiWidget.h" // Qt #include #include // MITK #include #include #include #include #include #include #include #include // vtk #include //for exceptions #include #include const std::string QmitkMITKIGTTrackingToolboxView::VIEW_ID = "org.mitk.views.mitkigttrackingtoolbox"; QmitkMITKIGTTrackingToolboxView::QmitkMITKIGTTrackingToolboxView() : QmitkFunctionality() , m_Controls( 0 ) , m_MultiWidget( NULL ) { m_TrackingTimer = new QTimer(this); m_tracking = false; m_logging = false; m_loggedFrames = 0; //initialize worker thread m_WorkerThread = new QThread(); m_Worker = new QmitkMITKIGTTrackingToolboxViewWorker(); } QmitkMITKIGTTrackingToolboxView::~QmitkMITKIGTTrackingToolboxView() { -//clean up worker thread -if(m_WorkerThread) delete m_WorkerThread; -if(m_Worker) delete m_Worker; -//remove the tracking volume -this->GetDataStorage()->Remove(m_TrackingVolumeNode); -//remove the tool storage -m_toolStorage->UnRegisterMicroservice(); +try + { + //clean up worker thread + if(m_WorkerThread) {delete m_WorkerThread;} + if(m_Worker) {delete m_Worker;} + //remove the tracking volume + this->GetDataStorage()->Remove(m_TrackingVolumeNode); + //remove the tool storage + if(m_toolStorage) {m_toolStorage->UnRegisterMicroservice();} + if(m_TrackingDeviceSource) {m_TrackingDeviceSource->UnRegisterMicroservice();} + } +catch(std::exception& e) {MITK_WARN << "Unexpected exception during clean up of tracking toolbox view: " << e.what();} +catch(...) {MITK_WARN << "Unexpected unknown error during clean up of tracking toolbox view!";} } void QmitkMITKIGTTrackingToolboxView::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::QmitkMITKIGTTrackingToolboxViewControls; m_Controls->setupUi( parent ); //create connections connect( m_Controls->m_LoadTools, SIGNAL(clicked()), this, SLOT(OnLoadTools()) ); connect( m_Controls->m_Connect, SIGNAL(clicked()), this, SLOT(OnConnect()) ); connect( m_Controls->m_Disconnect, SIGNAL(clicked()), this, SLOT(OnDisconnect()) ); connect( m_Controls->m_StartTracking, SIGNAL(clicked()), this, SLOT(OnStartTracking()) ); connect( m_Controls->m_StopTracking, SIGNAL(clicked()), this, SLOT(OnStopTracking()) ); connect( m_TrackingTimer, SIGNAL(timeout()), this, SLOT(UpdateTrackingTimer())); connect( m_Controls->m_ChooseFile, SIGNAL(clicked()), this, SLOT(OnChooseFileClicked())); connect( m_Controls->m_StartLogging, SIGNAL(clicked()), this, SLOT(StartLogging())); connect( m_Controls->m_StopLogging, SIGNAL(clicked()), this, SLOT(StopLogging())); connect( m_Controls->m_VolumeSelectionBox, SIGNAL(currentIndexChanged(QString)), this, SLOT(OnTrackingVolumeChanged(QString))); connect( m_Controls->m_ShowTrackingVolume, SIGNAL(clicked()), this, SLOT(OnShowTrackingVolumeChanged())); connect( m_Controls->m_AutoDetectTools, SIGNAL(clicked()), this, SLOT(OnAutoDetectTools())); connect( m_Controls->m_ResetTools, SIGNAL(clicked()), this, SLOT(OnResetTools())); connect( m_Controls->m_AddSingleTool, SIGNAL(clicked()), this, SLOT(OnAddSingleTool())); connect( m_Controls->m_NavigationToolCreationWidget, SIGNAL(NavigationToolFinished()), this, SLOT(OnAddSingleToolFinished())); connect( m_Controls->m_NavigationToolCreationWidget, SIGNAL(Canceled()), this, SLOT(OnAddSingleToolCanceled())); connect( m_Controls->m_csvFormat, SIGNAL(clicked()), this, SLOT(OnToggleFileExtension())); connect( m_Controls->m_xmlFormat, SIGNAL(clicked()), this, SLOT(OnToggleFileExtension())); //connections for the tracking device configuration widget connect( m_Controls->m_configurationWidget, SIGNAL(TrackingDeviceSelectionChanged()), this, SLOT(OnTrackingDeviceChanged())); connect( m_Controls->m_configurationWidget, SIGNAL(ProgressStarted()), this, SLOT(DisableOptionsButtons())); connect( m_Controls->m_configurationWidget, SIGNAL(ProgressStarted()), this, SLOT(DisableTrackingConfigurationButtons())); connect( m_Controls->m_configurationWidget, SIGNAL(ProgressStarted()), this, SLOT(DisableTrackingControls())); connect( m_Controls->m_configurationWidget, SIGNAL(ProgressFinished()), this, SLOT(EnableOptionsButtons())); connect( m_Controls->m_configurationWidget, SIGNAL(ProgressFinished()), this, SLOT(EnableTrackingConfigurationButtons())); connect( m_Controls->m_configurationWidget, SIGNAL(ProgressFinished()), this, SLOT(EnableTrackingControls())); //connect worker thread connect(m_Worker, SIGNAL(AutoDetectToolsFinished(bool,QString)), this, SLOT(OnAutoDetectToolsFinished(bool,QString)) ); connect(m_Worker, SIGNAL(ConnectDeviceFinished(bool,QString)), this, SLOT(OnConnectFinished(bool,QString)) ); connect(m_Worker, SIGNAL(StartTrackingFinished(bool,QString)), this, SLOT(OnStartTrackingFinished(bool,QString)) ); connect(m_Worker, SIGNAL(StopTrackingFinished(bool,QString)), this, SLOT(OnStopTrackingFinished(bool,QString)) ); connect(m_Worker, SIGNAL(DisconnectDeviceFinished(bool,QString)), this, SLOT(OnDisconnectFinished(bool,QString)) ); connect(m_WorkerThread,SIGNAL(started()), m_Worker, SLOT(ThreadFunc()) ); //move the worker to the thread m_Worker->moveToThread(m_WorkerThread); //initialize widgets m_Controls->m_configurationWidget->EnableAdvancedUserControl(false); m_Controls->m_TrackingToolsStatusWidget->SetShowPositions(true); m_Controls->m_TrackingToolsStatusWidget->SetTextAlignment(Qt::AlignLeft); //initialize tracking volume node m_TrackingVolumeNode = mitk::DataNode::New(); m_TrackingVolumeNode->SetName("TrackingVolume"); m_TrackingVolumeNode->SetOpacity(0.25); m_TrackingVolumeNode->SetBoolProperty("Backface Culling",true); mitk::Color red; red.SetRed(1); m_TrackingVolumeNode->SetColor(red); GetDataStorage()->Add(m_TrackingVolumeNode); //initialize buttons m_Controls->m_Connect->setEnabled(true); m_Controls->m_Disconnect->setEnabled(false); m_Controls->m_StartTracking->setEnabled(false); m_Controls->m_StopTracking->setEnabled(false); m_Controls->m_AutoDetectTools->setVisible(false); //only visible if tracking device is Aurora //Update List of available models for selected tool. std::vector Compatibles = mitk::GetDeviceDataForLine( m_Controls->m_configurationWidget->GetTrackingDevice()->GetType()); m_Controls->m_VolumeSelectionBox->clear(); for(int i = 0; i < Compatibles.size(); i++) { m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str()); } //initialize tool storage m_toolStorage = mitk::NavigationToolStorage::New(GetDataStorage()); m_toolStorage->SetName("TrackingToolbox Default Storage"); m_toolStorage->RegisterAsMicroservice("no tracking device"); //set home directory as default path for logfile m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(QDir::homePath()) + QDir::separator() + "logfile.csv"); } } void QmitkMITKIGTTrackingToolboxView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_MultiWidget = &stdMultiWidget; } void QmitkMITKIGTTrackingToolboxView::StdMultiWidgetNotAvailable() { m_MultiWidget = NULL; } void QmitkMITKIGTTrackingToolboxView::OnLoadTools() { //read in filename QString filename = QFileDialog::getOpenFileName(NULL,tr("Open Tool Storage"), "/", tr("Tool Storage Files (*.IGTToolStorage)")); if (filename.isNull()) return; //read tool storage from disk std::string errorMessage = ""; mitk::NavigationToolStorageDeserializer::Pointer myDeserializer = mitk::NavigationToolStorageDeserializer::New(GetDataStorage()); // try-catch block for exceptions try { this->ReplaceCurrentToolStorage(myDeserializer->Deserialize(filename.toStdString()),filename.toStdString()); } catch(mitk::IGTException) { std::string errormessage = "Error during deserializing. Problems with file,please check the file?"; QMessageBox::warning(NULL, "IGTPlayer: Error", errormessage.c_str()); return; } if(m_toolStorage->isEmpty()) { errorMessage = myDeserializer->GetErrorMessage(); MessageBox(errorMessage); return; } //update label Poco::Path myPath = Poco::Path(filename.toStdString()); //use this to seperate filename from path QString toolLabel = QString("Loaded Tools: ") + QString::number(m_toolStorage->GetToolCount()) + " Tools from " + myPath.getFileName().c_str(); m_Controls->m_toolLabel->setText(toolLabel); //update tool preview m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); } void QmitkMITKIGTTrackingToolboxView::OnResetTools() { this->ReplaceCurrentToolStorage(mitk::NavigationToolStorage::New(GetDataStorage()),"TrackingToolbox Default Storage"); m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); QString toolLabel = QString("Loaded Tools: "); m_Controls->m_toolLabel->setText(toolLabel); } void QmitkMITKIGTTrackingToolboxView::OnConnect() { MITK_INFO << "Connect Clicked"; //check if everything is ready to start tracking if (this->m_toolStorage.IsNull()) { MessageBox("Error: No Tools Loaded Yet!"); return; } else if (this->m_toolStorage->GetToolCount() == 0) { MessageBox("Error: No Way To Track Without Tools!"); return; } //parse tracking device data mitk::TrackingDeviceData data = mitk::DeviceDataUnspecified; QString qstr = m_Controls->m_VolumeSelectionBox->currentText(); if ( (! qstr.isNull()) || (! qstr.isEmpty()) ) { std::string str = qstr.toStdString(); data = mitk::GetDeviceDataByName(str); //Data will be set later, after device generation } //initialize worker thread m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eConnectDevice); m_Worker->SetTrackingDevice(this->m_Controls->m_configurationWidget->GetTrackingDevice()); m_Worker->SetInverseMode(m_Controls->m_InverseMode->isChecked()); m_Worker->SetNavigationToolStorage(this->m_toolStorage); m_Worker->SetTrackingDeviceData(data); //start worker thread m_WorkerThread->start(); //disable buttons this->m_Controls->m_MainWidget->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::OnConnectFinished(bool success, QString errorMessage) { m_WorkerThread->quit(); //enable buttons this->m_Controls->m_MainWidget->setEnabled(true); if (!success) { MITK_WARN << errorMessage.toStdString(); MessageBox(errorMessage.toStdString()); return; } //get data from worker thread m_TrackingDeviceSource = m_Worker->GetTrackingDeviceSource(); m_TrackingDeviceData = m_Worker->GetTrackingDeviceData(); m_ToolVisualizationFilter = m_Worker->GetToolVisualizationFilter(); //enable/disable Buttons m_Controls->m_Disconnect->setEnabled(true); m_Controls->m_StartTracking->setEnabled(true); m_Controls->m_StopTracking->setEnabled(false); m_Controls->m_Connect->setEnabled(false); DisableOptionsButtons(); DisableTrackingConfigurationButtons(); m_Controls->m_configurationWidget->ConfigurationFinished(); m_Controls->m_TrackingControlLabel->setText("Status: connected"); } void QmitkMITKIGTTrackingToolboxView::OnDisconnect() { m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eDisconnectDevice); m_WorkerThread->start(); m_Controls->m_MainWidget->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::OnDisconnectFinished(bool success, QString errorMessage) { m_WorkerThread->quit(); m_Controls->m_MainWidget->setEnabled(true); if (!success) { MITK_WARN << errorMessage.toStdString(); MessageBox(errorMessage.toStdString()); return; } //enable/disable Buttons m_Controls->m_Disconnect->setEnabled(false); m_Controls->m_StartTracking->setEnabled(false); m_Controls->m_StopTracking->setEnabled(false); m_Controls->m_Connect->setEnabled(true); EnableOptionsButtons(); EnableTrackingConfigurationButtons(); m_Controls->m_configurationWidget->Reset(); m_Controls->m_TrackingControlLabel->setText("Status: disconnected"); } void QmitkMITKIGTTrackingToolboxView::OnStartTracking() { m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eStartTracking); m_WorkerThread->start(); this->m_Controls->m_MainWidget->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::OnStartTrackingFinished(bool success, QString errorMessage) { m_WorkerThread->quit(); this->m_Controls->m_MainWidget->setEnabled(true); if(!success) { MessageBox(errorMessage.toStdString()); MITK_WARN << errorMessage.toStdString(); return; } m_TrackingTimer->start(1000/(m_Controls->m_UpdateRate->value())); m_Controls->m_TrackingControlLabel->setText("Status: tracking"); //connect the tool visualization widget for(int i=0; iGetNumberOfOutputs(); i++) { m_Controls->m_TrackingToolsStatusWidget->AddNavigationData(m_TrackingDeviceSource->GetOutput(i)); } m_Controls->m_TrackingToolsStatusWidget->ShowStatusLabels(); if (m_Controls->m_ShowToolQuaternions->isChecked()) {m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(true);} else {m_Controls->m_TrackingToolsStatusWidget->SetShowQuaternions(false);} //show tracking volume this->OnTrackingVolumeChanged(m_Controls->m_VolumeSelectionBox->currentText()); //enable/disable Buttons m_Controls->m_Disconnect->setEnabled(true); m_Controls->m_StartTracking->setEnabled(false); m_Controls->m_StopTracking->setEnabled(true); m_Controls->m_Connect->setEnabled(false); m_tracking = true; this->GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnStopTracking() { if (!m_tracking) return; m_TrackingTimer->stop(); m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eStopTracking); m_WorkerThread->start(); m_Controls->m_MainWidget->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::OnStopTrackingFinished(bool success, QString errorMessage) { m_WorkerThread->quit(); m_Controls->m_MainWidget->setEnabled(true); if(!success) { MessageBox(errorMessage.toStdString()); MITK_WARN << errorMessage.toStdString(); return; } m_Controls->m_TrackingControlLabel->setText("Status: connected"); if (m_logging) StopLogging(); m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); m_tracking = false; //enable/disable Buttons m_Controls->m_Disconnect->setEnabled(true); m_Controls->m_StartTracking->setEnabled(true); m_Controls->m_StopTracking->setEnabled(false); m_Controls->m_Connect->setEnabled(false); this->GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnTrackingDeviceChanged() { mitk::TrackingDeviceType Type; if (m_Controls->m_configurationWidget->GetTrackingDevice().IsNotNull()) { Type = m_Controls->m_configurationWidget->GetTrackingDevice()->GetType(); //enable controls because device is valid m_Controls->m_TrackingToolsGoupBox->setEnabled(true); m_Controls->m_TrackingControlsGroupBox->setEnabled(true); } else { Type = mitk::TrackingSystemNotSpecified; MessageBox("Error: This tracking device is not included in this project. Please make sure that the device is installed and activated in your MITK build."); m_Controls->m_TrackingToolsGoupBox->setEnabled(false); m_Controls->m_TrackingControlsGroupBox->setEnabled(false); return; } // Code to enable/disable device specific buttons if (Type == mitk::NDIAurora) //Aurora { m_Controls->m_AutoDetectTools->setVisible(true); m_Controls->m_AddSingleTool->setEnabled(false); } else //Polaris or Microntracker { m_Controls->m_AutoDetectTools->setVisible(false); m_Controls->m_AddSingleTool->setEnabled(true); } // Code to select appropriate tracking volume for current type std::vector Compatibles = mitk::GetDeviceDataForLine(Type); m_Controls->m_VolumeSelectionBox->clear(); for(int i = 0; i < Compatibles.size(); i++) { m_Controls->m_VolumeSelectionBox->addItem(Compatibles[i].Model.c_str()); } } void QmitkMITKIGTTrackingToolboxView::OnTrackingVolumeChanged(QString qstr) { if (qstr.isNull()) return; if (qstr.isEmpty()) return; if (m_Controls->m_ShowTrackingVolume->isChecked()) { mitk::TrackingVolumeGenerator::Pointer volumeGenerator = mitk::TrackingVolumeGenerator::New(); std::string str = qstr.toStdString(); mitk::TrackingDeviceData data = mitk::GetDeviceDataByName(str); m_TrackingDeviceData = data; volumeGenerator->SetTrackingDeviceData(data); volumeGenerator->Update(); mitk::Surface::Pointer volumeSurface = volumeGenerator->GetOutput(); m_TrackingVolumeNode->SetData(volumeSurface); GlobalReinit(); } } void QmitkMITKIGTTrackingToolboxView::OnShowTrackingVolumeChanged() { if (m_Controls->m_ShowTrackingVolume->isChecked()) { OnTrackingVolumeChanged(m_Controls->m_VolumeSelectionBox->currentText()); GetDataStorage()->Add(m_TrackingVolumeNode); } else { GetDataStorage()->Remove(m_TrackingVolumeNode); GlobalReinit(); } } void QmitkMITKIGTTrackingToolboxView::OnAutoDetectTools() { if (m_Controls->m_configurationWidget->GetTrackingDevice()->GetType() == mitk::NDIAurora) { DisableTrackingConfigurationButtons(); m_Worker->SetWorkerMethod(QmitkMITKIGTTrackingToolboxViewWorker::eAutoDetectTools); m_Worker->SetTrackingDevice(m_Controls->m_configurationWidget->GetTrackingDevice().GetPointer()); m_Worker->SetDataStorage(this->GetDataStorage()); m_WorkerThread->start(); //disable controls until worker thread is finished this->m_Controls->m_MainWidget->setEnabled(false); } } void QmitkMITKIGTTrackingToolboxView::OnAutoDetectToolsFinished(bool success, QString errorMessage) { m_WorkerThread->quit(); //enable controls again this->m_Controls->m_MainWidget->setEnabled(true); if(!success) { MITK_WARN << errorMessage.toStdString(); MessageBox(errorMessage.toStdString()); EnableTrackingConfigurationButtons(); return; } mitk::NavigationToolStorage::Pointer autoDetectedStorage = m_Worker->GetNavigationToolStorage(); //save detected tools this->ReplaceCurrentToolStorage(autoDetectedStorage,"Autodetected NDI Aurora Storage"); //update label QString toolLabel = QString("Loaded Tools: ") + QString::number(m_toolStorage->GetToolCount()) + " Tools (Auto Detected)"; m_Controls->m_toolLabel->setText(toolLabel); //update tool preview m_Controls->m_TrackingToolsStatusWidget->RemoveStatusLabels(); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); EnableTrackingConfigurationButtons(); if (m_toolStorage->GetToolCount()>0) { //ask the user if he wants to save the detected tools QMessageBox msgBox; switch(m_toolStorage->GetToolCount()) { case 1: msgBox.setText("Found one tool!"); break; default: msgBox.setText("Found " + QString::number(m_toolStorage->GetToolCount()) + " tools!"); } msgBox.setInformativeText("Do you want to save this tools as tool storage, so you can load them again?"); msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No); msgBox.setDefaultButton(QMessageBox::No); int ret = msgBox.exec(); if (ret == 16384) //yes { //ask the user for a filename QString fileName = QFileDialog::getSaveFileName(NULL, tr("Save File"),"/",tr("*.IGTToolStorage")); //check for empty filename if(fileName == "") {return;} mitk::NavigationToolStorageSerializer::Pointer mySerializer = mitk::NavigationToolStorageSerializer::New(); //when Serialize method is used exceptions are thrown, need to be adapted //try-catch block for exception handling in Serializer try { mySerializer->Serialize(fileName.toStdString(),m_toolStorage); } catch(mitk::IGTException) { std::string errormessage = "Error during serialization. Please check the Zip file."; QMessageBox::warning(NULL, "IGTPlayer: Error", errormessage.c_str());} return; } else if (ret == 65536) //no { return; } } } void QmitkMITKIGTTrackingToolboxView::MessageBox(std::string s) { QMessageBox msgBox; msgBox.setText(s.c_str()); msgBox.exec(); } void QmitkMITKIGTTrackingToolboxView::UpdateTrackingTimer() { m_ToolVisualizationFilter->Update(); MITK_DEBUG << "Number of outputs ToolVisualizationFilter: " << m_ToolVisualizationFilter->GetNumberOfIndexedOutputs(); MITK_DEBUG << "Number of inputs ToolVisualizationFilter: " << m_ToolVisualizationFilter->GetNumberOfIndexedInputs(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); if (m_logging) { this->m_loggingFilter->Update(); m_loggedFrames = this->m_loggingFilter->GetRecordCounter(); this->m_Controls->m_LoggedFramesLabel->setText("Logged Frames: "+QString::number(m_loggedFrames)); //check if logging stopped automatically if((m_loggedFrames>1)&&(!m_loggingFilter->GetRecording())){StopLogging();} } m_Controls->m_TrackingToolsStatusWidget->Refresh(); } void QmitkMITKIGTTrackingToolboxView::OnChooseFileClicked() { QDir currentPath = QFileInfo(m_Controls->m_LoggingFileName->text()).dir(); // if no path was selected (QDir would select current working dir then) or the // selected path does not exist -> use home directory if ( currentPath == QDir() || ! currentPath.exists() ) { currentPath = QDir(QDir::homePath()); } QString filename = QFileDialog::getSaveFileName(NULL,tr("Choose Logging File"), currentPath.absolutePath(), "*.*"); if (filename == "") return; this->m_Controls->m_LoggingFileName->setText(filename); this->OnToggleFileExtension(); } // bug-16470: toggle file extension after clicking on radio button void QmitkMITKIGTTrackingToolboxView::OnToggleFileExtension() { QString currentInputText = this->m_Controls->m_LoggingFileName->text(); QString currentFile = QFileInfo(currentInputText).baseName(); QDir currentPath = QFileInfo(currentInputText).dir(); if(currentFile.isEmpty()) { currentFile = "logfile"; } // Setting currentPath to default home path when currentPath is empty or it does not exist if(currentPath == QDir() || !currentPath.exists()) { currentPath = QDir::homePath(); } // check if csv radio button is clicked if(this->m_Controls->m_csvFormat->isChecked()) { // you needn't add a seperator to the input text when currentpath is the rootpath if(currentPath.isRoot()) { this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + currentFile + ".csv"); } else { this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + QDir::separator() + currentFile + ".csv"); } } // check if xml radio button is clicked else if(this->m_Controls->m_xmlFormat->isChecked()) { // you needn't add a seperator to the input text when currentpath is the rootpath if(currentPath.isRoot()) { this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + currentFile + ".xml"); } else { this->m_Controls->m_LoggingFileName->setText(QDir::toNativeSeparators(currentPath.absolutePath()) + QDir::separator() + currentFile + ".xml"); } } } void QmitkMITKIGTTrackingToolboxView::StartLogging() { if (m_ToolVisualizationFilter.IsNull()) { MessageBox("Cannot activate logging without a connected device. Configure and connect a tracking device first."); return; } if (!m_logging) { //initialize logging filter m_loggingFilter = mitk::NavigationDataRecorder::New(); m_loggingFilter->SetRecordingMode(mitk::NavigationDataRecorder::NormalFile); if (m_Controls->m_xmlFormat->isChecked()) m_loggingFilter->SetOutputFormat(mitk::NavigationDataRecorder::xml); else if (m_Controls->m_csvFormat->isChecked()) m_loggingFilter->SetOutputFormat(mitk::NavigationDataRecorder::csv); std::string filename = m_Controls->m_LoggingFileName->text().toStdString().c_str(); // this part has been changed in order to prevent crash of the program if(!filename.empty()) m_loggingFilter->SetFileName(filename); else if(filename.empty()){ std::string errormessage = "File name has not been set, please set the file name"; mitkThrowException(mitk::IGTIOException)<SetFileName(filename); } if (m_Controls->m_LoggingLimit->isChecked()){m_loggingFilter->SetRecordCountLimit(m_Controls->m_LoggedFramesLimit->value());} //connect filter for(int i=0; iGetNumberOfOutputs(); i++){m_loggingFilter->AddNavigationData(m_ToolVisualizationFilter->GetOutput(i));} //start filter with try-catch block for exceptions try { m_loggingFilter->StartRecording(); } catch(mitk::IGTException) { std::string errormessage = "Error during start recording. Recorder already started recording?"; QMessageBox::warning(NULL, "IGTPlayer: Error", errormessage.c_str()); m_loggingFilter->StopRecording(); return; } //update labels / logging variables this->m_Controls->m_LoggingLabel->setText("Logging ON"); this->m_Controls->m_LoggedFramesLabel->setText("Logged Frames: 0"); m_loggedFrames = 0; m_logging = true; DisableLoggingButtons(); } } void QmitkMITKIGTTrackingToolboxView::StopLogging() { if (m_logging) { //update label this->m_Controls->m_LoggingLabel->setText("Logging OFF"); m_loggingFilter->StopRecording(); m_logging = false; EnableLoggingButtons(); } } void QmitkMITKIGTTrackingToolboxView::OnAddSingleTool() { QString Identifier = "Tool#"; if (m_toolStorage.IsNotNull()) Identifier += QString::number(m_toolStorage->GetToolCount()); else Identifier += "0"; m_Controls->m_NavigationToolCreationWidget->Initialize(GetDataStorage(),Identifier.toStdString()); m_Controls->m_NavigationToolCreationWidget->SetTrackingDeviceType(m_Controls->m_configurationWidget->GetTrackingDevice()->GetType(),false); m_Controls->m_TrackingToolsWidget->setCurrentIndex(1); //disable tracking volume during tool editing lastTrackingVolumeState = m_Controls->m_ShowTrackingVolume->isChecked(); if (lastTrackingVolumeState) m_Controls->m_ShowTrackingVolume->click(); GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnAddSingleToolFinished() { m_Controls->m_TrackingToolsWidget->setCurrentIndex(0); if (this->m_toolStorage.IsNull()) { //this shouldn't happen! MITK_WARN << "No ToolStorage available, cannot add tool, aborting!"; return; } m_toolStorage->AddTool(m_Controls->m_NavigationToolCreationWidget->GetCreatedTool()); m_Controls->m_TrackingToolsStatusWidget->PreShowTools(m_toolStorage); QString toolLabel = QString("Loaded Tools: "); //enable tracking volume again if (lastTrackingVolumeState) m_Controls->m_ShowTrackingVolume->click(); GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::OnAddSingleToolCanceled() { m_Controls->m_TrackingToolsWidget->setCurrentIndex(0); //enable tracking volume again if (lastTrackingVolumeState) m_Controls->m_ShowTrackingVolume->click(); GlobalReinit(); } void QmitkMITKIGTTrackingToolboxView::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); } void QmitkMITKIGTTrackingToolboxView::DisableLoggingButtons() { m_Controls->m_StartLogging->setEnabled(false); m_Controls->m_LoggingFileName->setEnabled(false); m_Controls->m_ChooseFile->setEnabled(false); m_Controls->m_LoggingLimit->setEnabled(false); m_Controls->m_LoggedFramesLimit->setEnabled(false); m_Controls->m_csvFormat->setEnabled(false); m_Controls->m_xmlFormat->setEnabled(false); m_Controls->m_StopLogging->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::EnableLoggingButtons() { m_Controls->m_StartLogging->setEnabled(true); m_Controls->m_LoggingFileName->setEnabled(true); m_Controls->m_ChooseFile->setEnabled(true); m_Controls->m_LoggingLimit->setEnabled(true); m_Controls->m_LoggedFramesLimit->setEnabled(true); m_Controls->m_csvFormat->setEnabled(true); m_Controls->m_xmlFormat->setEnabled(true); m_Controls->m_StopLogging->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::DisableOptionsButtons() { m_Controls->m_ShowTrackingVolume->setEnabled(false); m_Controls->m_UpdateRate->setEnabled(false); m_Controls->m_ShowToolQuaternions->setEnabled(false); m_Controls->m_OptionsUpdateRateLabel->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::EnableOptionsButtons() { m_Controls->m_ShowTrackingVolume->setEnabled(true); m_Controls->m_UpdateRate->setEnabled(true); m_Controls->m_ShowToolQuaternions->setEnabled(true); m_Controls->m_OptionsUpdateRateLabel->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::EnableTrackingControls() { m_Controls->m_TrackingControlsGroupBox->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::DisableTrackingControls() { m_Controls->m_TrackingControlsGroupBox->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::EnableTrackingConfigurationButtons() { m_Controls->m_AutoDetectTools->setEnabled(true); if (m_Controls->m_configurationWidget->GetTrackingDevice()->GetType() != mitk::NDIAurora) m_Controls->m_AddSingleTool->setEnabled(true); m_Controls->m_LoadTools->setEnabled(true); m_Controls->m_ResetTools->setEnabled(true); } void QmitkMITKIGTTrackingToolboxView::DisableTrackingConfigurationButtons() { m_Controls->m_AutoDetectTools->setEnabled(false); if (m_Controls->m_configurationWidget->GetTrackingDevice()->GetType() != mitk::NDIAurora) m_Controls->m_AddSingleTool->setEnabled(false); m_Controls->m_LoadTools->setEnabled(false); m_Controls->m_ResetTools->setEnabled(false); } void QmitkMITKIGTTrackingToolboxView::ReplaceCurrentToolStorage(mitk::NavigationToolStorage::Pointer newStorage, std::string newStorageName) { //first: get rid of the old one m_toolStorage->UnLockStorage(); //only to be sure... m_toolStorage->UnRegisterMicroservice(); m_toolStorage = NULL; //now: replace by the new one m_toolStorage = newStorage; m_toolStorage->SetName(newStorageName); m_toolStorage->RegisterAsMicroservice("no tracking device"); } void QmitkMITKIGTTrackingToolboxViewWorker::SetWorkerMethod(WorkerMethod w) { m_WorkerMethod = w; } void QmitkMITKIGTTrackingToolboxViewWorker::SetTrackingDevice(mitk::TrackingDevice::Pointer t) { m_TrackingDevice = t; } void QmitkMITKIGTTrackingToolboxViewWorker::SetDataStorage(mitk::DataStorage::Pointer d) { m_DataStorage = d; } void QmitkMITKIGTTrackingToolboxViewWorker::SetInverseMode(bool mode) { m_InverseMode = mode; } void QmitkMITKIGTTrackingToolboxViewWorker::SetTrackingDeviceData(mitk::TrackingDeviceData d) { m_TrackingDeviceData = d; } void QmitkMITKIGTTrackingToolboxViewWorker::SetNavigationToolStorage(mitk::NavigationToolStorage::Pointer n) { m_NavigationToolStorage = n; } void QmitkMITKIGTTrackingToolboxViewWorker::ThreadFunc() { switch(m_WorkerMethod) { case eAutoDetectTools: this->AutoDetectTools(); break; case eConnectDevice: this->ConnectDevice(); break; case eStartTracking: this->StartTracking(); break; case eStopTracking: this->StopTracking(); break; case eDisconnectDevice: this->DisconnectDevice(); break; default: MITK_WARN << "Undefined worker method was set ... something went wrong!"; break; } } void QmitkMITKIGTTrackingToolboxViewWorker::AutoDetectTools() { mitk::ProgressBar::GetInstance()->AddStepsToDo(4); mitk::NavigationToolStorage::Pointer autoDetectedStorage = mitk::NavigationToolStorage::New(m_DataStorage); mitk::NDITrackingDevice::Pointer currentDevice = dynamic_cast(m_TrackingDevice.GetPointer()); try { currentDevice->OpenConnection(); mitk::ProgressBar::GetInstance()->Progress(); currentDevice->StartTracking(); } catch(mitk::Exception& e) { QString message = QString("Warning, can not auto-detect tools! (") + QString(e.GetDescription()) + QString(")"); //MessageBox(message.toStdString()); //TODO: give message to the user here! MITK_WARN << message.toStdString(); mitk::ProgressBar::GetInstance()->Progress(4); emit AutoDetectToolsFinished(false,message.toStdString().c_str()); return; } for (int i=0; iGetToolCount(); i++) { //create a navigation tool with sphere as surface std::stringstream toolname; toolname << "AutoDetectedTool" << i; mitk::NavigationTool::Pointer newTool = mitk::NavigationTool::New(); newTool->SetSerialNumber(dynamic_cast(currentDevice->GetTool(i))->GetSerialNumber()); newTool->SetIdentifier(toolname.str()); newTool->SetTrackingDeviceType(mitk::NDIAurora); mitk::DataNode::Pointer newNode = mitk::DataNode::New(); mitk::Surface::Pointer mySphere = mitk::Surface::New(); vtkSphereSource *vtkData = vtkSphereSource::New(); vtkData->SetRadius(3.0f); vtkData->SetCenter(0.0, 0.0, 0.0); vtkData->Update(); mySphere->SetVtkPolyData(vtkData->GetOutput()); vtkData->Delete(); newNode->SetData(mySphere); newNode->SetName(toolname.str()); newTool->SetDataNode(newNode); autoDetectedStorage->AddTool(newTool); } m_NavigationToolStorage = autoDetectedStorage; currentDevice->StopTracking(); mitk::ProgressBar::GetInstance()->Progress(); currentDevice->CloseConnection(); emit AutoDetectToolsFinished(true,""); mitk::ProgressBar::GetInstance()->Progress(4); } void QmitkMITKIGTTrackingToolboxViewWorker::ConnectDevice() { std::string message = ""; mitk::ProgressBar::GetInstance()->AddStepsToDo(10); //build the IGT pipeline mitk::TrackingDevice::Pointer trackingDevice = m_TrackingDevice; trackingDevice->SetData(m_TrackingDeviceData); //set device to rotation mode transposed becaus we are working with VNL style quaternions if(m_InverseMode) {trackingDevice->SetRotationMode(mitk::TrackingDevice::RotationTransposed);} //Get Tracking Volume Data mitk::TrackingDeviceData data = m_TrackingDeviceData; mitk::ProgressBar::GetInstance()->Progress(); //Create Navigation Data Source with the factory class mitk::TrackingDeviceSourceConfigurator::Pointer myTrackingDeviceSourceFactory = mitk::TrackingDeviceSourceConfigurator::New(m_NavigationToolStorage,trackingDevice); m_TrackingDeviceSource = myTrackingDeviceSourceFactory->CreateTrackingDeviceSource(m_ToolVisualizationFilter); mitk::ProgressBar::GetInstance()->Progress(); if ( m_TrackingDeviceSource.IsNull() ) { message = std::string("Cannot connect to device: ") + myTrackingDeviceSourceFactory->GetErrorMessage(); emit ConnectDeviceFinished(false,QString(message.c_str())); return; } //set filter to rotation mode transposed becaus we are working with VNL style quaternions if(m_InverseMode) m_ToolVisualizationFilter->SetRotationMode(mitk::NavigationDataObjectVisualizationFilter::RotationTransposed); //First check if the created object is valid if (m_TrackingDeviceSource.IsNull()) { message = myTrackingDeviceSourceFactory->GetErrorMessage(); emit ConnectDeviceFinished(false,QString(message.c_str())); return; } MITK_INFO << "Number of tools: " << m_TrackingDeviceSource->GetNumberOfOutputs(); mitk::ProgressBar::GetInstance()->Progress(); //The tools are maybe reordered after initialization, e.g. in case of auto-detected tools of NDI Aurora mitk::NavigationToolStorage::Pointer toolsInNewOrder = myTrackingDeviceSourceFactory->GetUpdatedNavigationToolStorage(); if ((toolsInNewOrder.IsNotNull()) && (toolsInNewOrder->GetToolCount() > 0)) { //so delete the old tools in wrong order and add them in the right order //we cannot simply replace the tool storage because the new storage is //not correctly initialized with the right data storage m_NavigationToolStorage->DeleteAllTools(); for (int i=0; i < toolsInNewOrder->GetToolCount(); i++) {m_NavigationToolStorage->AddTool(toolsInNewOrder->GetTool(i));} } mitk::ProgressBar::GetInstance()->Progress(); //connect to device try { m_TrackingDeviceSource->Connect(); mitk::ProgressBar::GetInstance()->Progress(); //Microservice registration: m_TrackingDeviceSource->RegisterAsMicroservice(); m_NavigationToolStorage->UnRegisterMicroservice(); m_NavigationToolStorage->RegisterAsMicroservice(m_TrackingDeviceSource->GetMicroserviceID()); m_NavigationToolStorage->LockStorage(); } catch (...) //todo: change to mitk::IGTException { message = "Error on connecting the tracking device."; emit ConnectDeviceFinished(false,QString(message.c_str())); return; } emit ConnectDeviceFinished(true,QString(message.c_str())); mitk::ProgressBar::GetInstance()->Progress(10); } void QmitkMITKIGTTrackingToolboxViewWorker::StartTracking() { QString errorMessage = ""; try { m_TrackingDeviceSource->StartTracking(); } catch (...) //todo: change to mitk::IGTException { errorMessage += "Error while starting the tracking device!"; emit StartTrackingFinished(false,errorMessage); return; } emit StartTrackingFinished(true,errorMessage); } void QmitkMITKIGTTrackingToolboxViewWorker::StopTracking() { try { m_TrackingDeviceSource->StopTracking(); } catch(mitk::Exception& e) { emit StopTrackingFinished(false, e.GetDescription()); } emit StopTrackingFinished(true, ""); } void QmitkMITKIGTTrackingToolboxViewWorker::DisconnectDevice() { try { if (m_TrackingDeviceSource->IsTracking()) {m_TrackingDeviceSource->StopTracking();} m_TrackingDeviceSource->Disconnect(); m_TrackingDeviceSource->UnRegisterMicroservice(); m_NavigationToolStorage->UnLockStorage(); } catch(mitk::Exception& e) { emit DisconnectDeviceFinished(false, e.GetDescription()); } emit DisconnectDeviceFinished(true, ""); }