Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkNavigationToolCreationWidget.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 //mitk headers
20 #include <mitkTrackingTypes.h>
21 #include <mitkSurface.h>
22 #include <mitkNavigationData.h>
23 #include <mitkRenderingManager.h>
25 
26 //qt headers
27 #include <qfiledialog.h>
28 #include <qmessagebox.h>
29 #include <QDialog>
30 #include <mitkIOUtil.h>
31 
32 //poco headers
33 #include <Poco/Path.h>
34 
35 // vtk
36 #include <vtkSphereSource.h>
37 #include <vtkConeSource.h>
38 
39 const std::string QmitkNavigationToolCreationWidget::VIEW_ID = "org.mitk.views.navigationtoolcreationwizardwidget";
40 
42  : QWidget(parent, f)
43 {
44  m_Controls = NULL;
46  m_AdvancedWidget->setWindowFlags(Qt::Tool | Qt::WindowStaysOnTopHint);
47  m_AdvancedWidget->setWindowTitle("Tool Creation Advanced Options");
48  m_AdvancedWidget->setModal(false);
49  CreateQtPartControl(this);
51 
53 }
54 
56 {
57  m_Controls->m_CalibrationLandmarksList->SetPointSetNode(NULL);
58  m_Controls->m_RegistrationLandmarksList->SetPointSetNode(NULL);
59  delete m_AdvancedWidget;
60 }
61 
63 {
64  if (!m_Controls)
65  {
66  // create GUI widgets
67  m_Controls = new Ui::QmitkNavigationToolCreationWidgetControls;
68  m_Controls->setupUi(parent);
69  }
70 }
71 
73 {
74  if ( m_Controls )
75  {
76  connect( (QObject*)(m_Controls->m_cancel), SIGNAL(clicked()), this, SLOT(OnCancel()) );
77  connect( (QObject*)(m_Controls->m_finished), SIGNAL(clicked()), this, SLOT(OnFinished()) );
78  connect( (QObject*)(m_Controls->m_LoadSurface), SIGNAL(clicked()), this, SLOT(OnLoadSurface()) );
79  connect( (QObject*)(m_Controls->m_LoadCalibrationFile), SIGNAL(clicked()), this, SLOT(OnLoadCalibrationFile()) );
80  connect( (QObject*)(m_Controls->m_ShowAdvancedOptionsPB), SIGNAL(toggled(bool)), this, SLOT(OnShowAdvancedOptions(bool)) );
81  connect( (QObject*)(m_AdvancedWidget), SIGNAL(DialogCloseRequested()), this, SLOT(OnProcessDialogCloseRequest()) );
82  connect( (QObject*)(m_AdvancedWidget), SIGNAL(RetrieveDataForManualToolTipManipulation()), this, SLOT(OnRetrieveDataForManualTooltipManipulation()) );
83 
84  connect( m_Controls->m_Surface_Use_Other, SIGNAL(toggled(bool)), this, SLOT(OnSurfaceUseOtherToggled(bool)));
85  }
86 }
87 
88 void QmitkNavigationToolCreationWidget::Initialize(mitk::DataStorage* dataStorage, const std::string& supposedIdentifier, const std::string& supposedName)
89 {
90  m_DataStorage = dataStorage;
91 
92  //initialize UI components
93  m_Controls->m_SurfaceChooser->SetDataStorage(m_DataStorage);
94  m_Controls->m_SurfaceChooser->SetAutoSelectNewItems(true);
95  m_Controls->m_SurfaceChooser->SetPredicate(mitk::NodePredicateDataType::New("Surface"));
96 
97  //set default data
98  m_Controls->m_ToolNameEdit->setText(supposedName.c_str());
99  m_Controls->m_CalibrationFileName->setText("none");
100  m_Controls->m_Surface_Use_Sphere->setChecked(true);
102  m_Controls->m_IdentifierEdit->setText(supposedIdentifier.c_str());
104  m_Controls->m_CalibrationLandmarksList->EnableEditButton(false);
105  m_Controls->m_RegistrationLandmarksList->EnableEditButton(false);
106 }
107 
109 {
110  int index = m_Controls->m_TrackingDeviceTypeChooser->findText(QString::fromStdString(type));
111 
112  if (index >= 0)
113  {
114  m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(index);
115  }
116 }
117 
118 
120 {
121  return m_CreatedTool;
122 }
123 
124 //##################################################################################
125 //############################## slots ############################
126 //##################################################################################
127 
129 {
130  //here we create a new tool
132 
133  //create DataNode...
135  if(m_Controls->m_Surface_Use_Sphere->isChecked())
136  {
137  //create small sphere and use it as surface
139  vtkConeSource *vtkData = vtkConeSource::New();
140  vtkData->SetAngle(5.0);
141  vtkData->SetResolution(50);
142  vtkData->SetHeight(6.0f);
143  vtkData->SetRadius(2.0f);
144  vtkData->SetCenter(0.0, 0.0, 0.0);
145  vtkData->Update();
146  mySphere->SetVtkPolyData(vtkData->GetOutput());
147  vtkData->Delete();
148  newNode->SetData(mySphere);
149  }
150  else
151  {
152  newNode->SetData(m_Controls->m_SurfaceChooser->GetSelectedNode()->GetData());
153  }
154  newNode->SetName(m_Controls->m_ToolNameEdit->text().toLatin1());
155 
156  m_CreatedTool->SetDataNode(newNode);
157 
158  //fill NavigationTool object
159  m_CreatedTool->SetCalibrationFile(m_Controls->m_CalibrationFileName->text().toLatin1().data());
160  m_CreatedTool->SetIdentifier(m_Controls->m_IdentifierEdit->text().toLatin1().data());
161  m_CreatedTool->SetSerialNumber(m_Controls->m_SerialNumberEdit->text().toLatin1().data());
162 
163 //Tracking Device
164 m_CreatedTool->SetTrackingDeviceType(m_Controls->m_TrackingDeviceTypeChooser->currentText().toStdString());
165 
166  //ToolType
167  if (m_Controls->m_ToolTypeChooser->currentText()=="Instrument") m_CreatedTool->SetType(mitk::NavigationTool::Instrument);
168  else if (m_Controls->m_ToolTypeChooser->currentText()=="Fiducial") m_CreatedTool->SetType(mitk::NavigationTool::Fiducial);
169  else if (m_Controls->m_ToolTypeChooser->currentText()=="Skinmarker") m_CreatedTool->SetType(mitk::NavigationTool::Skinmarker);
171 
172  //Tool Tip
174  m_CreatedTool->SetToolTipOrientation(tempND->GetOrientation());
175  m_CreatedTool->SetToolTipPosition(tempND->GetPosition());
176 
177  //Tool Landmarks
178  mitk::PointSet::Pointer toolCalLandmarks, toolRegLandmarks;
179  GetUIToolLandmarksLists(toolCalLandmarks,toolRegLandmarks);
180  m_CreatedTool->SetToolCalibrationLandmarks(toolCalLandmarks);
181  m_CreatedTool->SetToolRegistrationLandmarks(toolRegLandmarks);
182 
183  emit NavigationToolFinished();
184 }
185 
187 {
188  m_CreatedTool = NULL;
189 
190  emit Canceled();
191 }
192 
194 {
195  std::string filename = QFileDialog::getOpenFileName(NULL,tr("Open Surface"), "/", tr("STL (*.stl)")).toLatin1().data();
196  try
197  {
198  mitk::IOUtil::Load(filename.c_str(), *m_DataStorage);
199  }
200  catch (mitk::Exception &e)
201  {
202  MITK_ERROR << "Exception occured: " << e.what();
203  }
204 }
205 
207 {
208  m_Controls->m_CalibrationFileName->setText(QFileDialog::getOpenFileName(NULL,tr("Open Calibration File"), "/", "*.*"));
209 }
210 
212 {
213 m_Controls->m_ToolNameEdit->setText(QString(DefaultTool->GetDataNode()->GetName().c_str()));
214 m_Controls->m_IdentifierEdit->setText(QString(DefaultTool->GetIdentifier().c_str()));
215 m_Controls->m_SerialNumberEdit->setText(QString(DefaultTool->GetSerialNumber().c_str()));
216 m_AdvancedWidget->SetDefaultTooltip( DefaultTool->GetToolTipTransform() );
217 int index = m_Controls->m_TrackingDeviceTypeChooser->findText(QString::fromStdString(DefaultTool->GetTrackingDeviceType()));
218 
219 if (index >= 0)
220 {
221  m_Controls->m_TrackingDeviceTypeChooser->setCurrentIndex(index);
222 }
223 
224 m_Controls->m_CalibrationFileName->setText(QString(DefaultTool->GetCalibrationFile().c_str()));
225 m_Controls->m_Surface_Use_Other->setChecked(true);
226 switch(DefaultTool->GetType())
227 {
229 m_Controls->m_ToolTypeChooser->setCurrentIndex(0); break;
231 m_Controls->m_ToolTypeChooser->setCurrentIndex(1); break;
233 m_Controls->m_ToolTypeChooser->setCurrentIndex(2); break;
235 m_Controls->m_ToolTypeChooser->setCurrentIndex(3); break;
236 }
237 
238  m_Controls->m_SurfaceChooser->SetSelectedNode(DefaultTool->GetDataNode());
239  FillUIToolLandmarkLists(DefaultTool->GetToolCalibrationLandmarks(),DefaultTool->GetToolRegistrationLandmarks());
240 }
241 
242 
243 //##################################################################################
244 //############################## internal help methods #############################
245 //##################################################################################
247 {
248  QMessageBox msgBox;
249  msgBox.setText(s.c_str());
250  msgBox.exec();
251 }
252 
254 {
255  if(state)
256  {
257  m_AdvancedWidget->show();
258  m_AdvancedWidget->SetDefaultTooltip(m_AdvancedWidget->GetManipulatedToolTip()); //use the last one, if there is one
260 
261  // reinit the views with the new nodes
263  mitk::TimeGeometry::Pointer bounds = m_DataStorage->ComputeBoundingGeometry3D(rs, "visible"); // initialize the views to the bounding geometry
265  }
266  else
267  {
268  m_AdvancedWidget->hide();
269  }
270 }
271 
273 {
274  m_AdvancedWidget->hide();
275  m_Controls->m_ShowAdvancedOptionsPB->setChecked(false);
276 }
277 
279 {
280  if(m_Controls->m_Surface_Use_Sphere->isChecked())
281  {
283  }
284  else
285  {
287  dynamic_cast<mitk::DataNode*>(m_Controls->m_SurfaceChooser->GetSelectedNode().GetPointer()));
288  }
289 }
290 
292 {
293  m_Controls->m_LoadSurface->setEnabled(checked);
294 }
295 
297 {
298  m_calLandmarkNode->SetData(calLandmarks);
299  m_regLandmarkNode->SetData(regLandmarks);
300  m_Controls->m_CalibrationLandmarksList->SetPointSetNode(m_calLandmarkNode);
301  m_Controls->m_RegistrationLandmarksList->SetPointSetNode(m_regLandmarkNode);
302 }
303 
305 {
306  calLandmarks = dynamic_cast<mitk::PointSet*>(m_calLandmarkNode->GetData());
307  regLandmarks = dynamic_cast<mitk::PointSet*>(m_regLandmarkNode->GetData());
308 }
309 
311 {
315 }
316 
318 {
319  us::ModuleContext* context = us::GetModuleContext();
320  std::vector<us::ServiceReference<mitk::TrackingDeviceTypeCollection> > refs = context->GetServiceReferences<mitk::TrackingDeviceTypeCollection>();
321  if (refs.empty())
322  {
323  MITK_WARN << "No tracking device service found!";
324  return;
325  }
326  mitk::TrackingDeviceTypeCollection* _DeviceTypeCollection = context->GetService<mitk::TrackingDeviceTypeCollection>(refs.front());
327 
328  for (auto name : _DeviceTypeCollection->GetTrackingDeviceTypeNames())
329  {
330  //if the device is not included yet, add name to comboBox and widget to stackedWidget
331  if (m_Controls->m_TrackingDeviceTypeChooser->findText(QString::fromStdString(name)) == -1)
332  {
333  m_Controls->m_TrackingDeviceTypeChooser->addItem(QString::fromStdString(name));
334  }
335  }
336 }
virtual bool InitializeViews(const BaseGeometry *geometry, RequestType type=REQUEST_UPDATE_ALL, bool preserveRoughOrientationInWorldSpace=false)
static Pointer New()
void SetToolTipSurface(bool cone, mitk::DataNode::Pointer node=NULL)
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
void SetTrackingDeviceType(mitk::TrackingDeviceType type, bool changeable=true)
Sets the default tracking device type. You may also define if it is changeable or not...
An object of this class offers an UI to modify a tooltip of an IGT navigation tool.
#define MITK_ERROR
Definition: mitkLogMacros.h:24
static Pointer New()
This class is a collection for information of all Tracking Device Types (derived from abstract Tracki...
void SetDefaultData(mitk::NavigationTool::Pointer DefaultTool)
Sets the default data of all input fields. The default data is used from the default tool which is gi...
void SetDataStorage(mitk::DataStorage::Pointer dataStorage)
itk::SmartPointer< const Self > ConstPointer
virtual SetOfObjects::ConstPointer GetAll() const =0
returns a set of all data objects that are stored in the data storage
#define MITK_WARN
Definition: mitkLogMacros.h:23
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:79
static Pointer New()
An object of this class represents an exception of MITK. Please don't instantiate exceptions manually...
Definition: mitkException.h:49
void SetDefaultTooltip(mitk::AffineTransform3D::Pointer defaultToolTip)
static RenderingManager * GetInstance()
static const std::string filename
mitk::DataStorage * m_DataStorage
holds the DataStorage
void Initialize(mitk::DataStorage *dataStorage, const std::string &supposedIdentifier, const std::string &supposedName="NewTool")
Initializes the widget.
void FillUIToolLandmarkLists(mitk::PointSet::Pointer calLandmarks, mitk::PointSet::Pointer regLandmarks)
QmitkNavigationToolCreationAdvancedWidget * m_AdvancedWidget
static Pointer New()
mitk::TimeGeometry::Pointer ComputeBoundingGeometry3D(const SetOfObjects *input, const char *boolPropertyKey=nullptr, const mitk::BaseRenderer *renderer=nullptr, const char *boolPropertyKey2=nullptr) const
Compute the axis-parallel bounding geometry of the input objects.
static Pointer New(const char *_arg)
QmitkNavigationToolCreationWidget(QWidget *parent=0, Qt::WindowFlags f=0)
std::string TrackingDeviceType
void Canceled()
This signal is emitted if the user canceled the creation of the tool.
Ui::QmitkNavigationToolCreationWidgetControls * m_Controls
static DataStorage::SetOfObjects::Pointer Load(const std::string &path, DataStorage &storage)
Load a file into the given DataStorage.
Definition: mitkIOUtil.cpp:483
void NavigationToolFinished()
This signal is emitted if the user finished the creation of the tool.
virtual void CreateConnections()
Creation of the connections.
static Pointer New()
static ModuleContext * GetModuleContext()
Returns the module context of the calling module.
mitk::NavigationTool::Pointer m_CreatedTool
this pointer holds the tool which is created
void GetUIToolLandmarksLists(mitk::PointSet::Pointer &calLandmarks, mitk::PointSet::Pointer &regLandmarks)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.