NorMIT-nav  18.04
An IGT application
cxPatientLandMarksWidget.cpp
Go to the documentation of this file.
1 /*=========================================================================
2 This file is part of CustusX, an Image Guided Therapy Application.
3 
4 Copyright (c) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
13 
14 #include <QPushButton>
15 #include <QTableWidget>
16 #include <QLabel>
17 
18 #include "cxActiveToolProxy.h"
19 #include "cxLandmarkListener.h"
20 #include "cxSettings.h"
21 #include "cxPatientModelService.h"
22 #include "cxTrackingService.h"
23 #include "cxRegistrationService.h"
24 #include "cxViewService.h"
25 #include "cxTypeConversions.h"
26 #include "cxReporter.h"
27 #include "cxLandmark.h"
28 #include "cxImage.h"
29 #include "cxActiveData.h"
30 
31 namespace cx
32 {
33 
34 PatientLandMarksWidget::PatientLandMarksWidget(RegServicesPtr services,
35  QWidget* parent, QString objectName, QString windowTitle) :
36  LandmarkRegistrationWidget(services, parent, objectName, windowTitle),
37  mToolSampleButton(new QPushButton("Sample Tool", this))
38 {
39  mLandmarkListener->useI2IRegistration(false);
40 
41  connect(services->patient().get(), &PatientModelService::rMprChanged, this, &PatientLandMarksWidget::setModified);
42 
43  //buttons
44  mToolSampleButton->setDisabled(true);
45  connect(mToolSampleButton, SIGNAL(clicked()), this, SLOT(toolSampleButtonClickedSlot()));
46 
47  mRemoveLandmarkButton = new QPushButton("Clear", this);
48  mRemoveLandmarkButton->setToolTip("Clear selected landmark");
50 
51  //toolmanager
52  mActiveToolProxy = ActiveToolProxy::New(services->tracking());
53  connect(mActiveToolProxy.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateToolSampleButton()));
54  connect(mActiveToolProxy.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(updateToolSampleButton()));
55 
56  connect(settings(), &Settings::valueChangedFor, this, &PatientLandMarksWidget::globalConfigurationFileChangedSlot);
57 
58  //layout
63 
64  this->updateToolSampleButton();
65 }
66 
68 {
69 }
70 
71 void PatientLandMarksWidget::globalConfigurationFileChangedSlot(QString key)
72 {
73  if (key == "giveManualToolPhysicalProperties")
74  this->updateToolSampleButton();
75 }
76 
78 {
79  ToolPtr tool = mServices->tracking()->getActiveTool();
80 
81  bool enabled = tool && tool->getVisible() && (!tool->hasType(Tool::TOOL_MANUAL) || settings()->value("giveManualToolPhysicalProperties").toBool()); // enable only for non-manual tools.
82  mToolSampleButton->setEnabled(enabled);
83 
84  if (mServices->tracking()->getActiveTool())
85  mToolSampleButton->setText("Sample " + qstring_cast(tool->getName()));
86  else
87  mToolSampleButton->setText("No tool");
88 }
89 
91 {
92  ToolPtr tool = mServices->tracking()->getActiveTool();
93 
94  if (!tool)
95  {
96  reportError("mToolToSample is NULL!");
97  return;
98  }
99  //TODO What if the reference frame isnt visible?
100  Transform3D lastTransform_prMt = tool->get_prMt();
101  Vector3D p_pr = lastTransform_prMt.coord(Vector3D(0, 0, tool->getTooltipOffset()));
102 
103  // TODO: do we want to allow sampling points not defined in image??
104  if (mActiveLandmark.isEmpty() && !mServices->patient()->getLandmarkProperties().empty())
105  mActiveLandmark = mServices->patient()->getLandmarkProperties().begin()->first;
106 
107  mServices->patient()->getPatientLandmarks()->setLandmark(Landmark(mActiveLandmark, p_pr));
108  reporter()->playSampleSound();
109 
110  this->activateLandmark(this->getNextLandmark());
111 
112  this->performRegistration(); // automatic when sampling in physical patient space (Mantis #0000674)s
113 }
114 
115 void PatientLandMarksWidget::showEvent(QShowEvent* event)
116 {
117  mServices->view()->setRegistrationMode(rsPATIENT_REGISTRATED);
119 }
120 
121 void PatientLandMarksWidget::hideEvent(QHideEvent* event)
122 {
123  mServices->view()->setRegistrationMode(rsNOT_REGISTRATED);
125 }
126 
128 {
129  QString next = this->getNextLandmark();
130  mServices->patient()->getPatientLandmarks()->removeLandmark(mActiveLandmark);
131  this->activateLandmark(next);
132 }
133 
135 {
137 
138  mRemoveLandmarkButton->setEnabled(true);
139 }
140 
142 {
144 
145  std::vector<Landmark> landmarks = this->getAllLandmarks();
146  mRemoveLandmarkButton->setEnabled(!landmarks.empty() && !mActiveLandmark.isEmpty());
147 }
148 
152 {
153  return mServices->patient()->getPatientLandmarks()->getLandmarks();
154 }
155 
160 {
161  Transform3D rMpr = mServices->patient()->get_rMpr();
162  return rMpr;
163 }
164 
166 {
167  mServices->patient()->getPatientLandmarks()->setLandmark(Landmark(uid, p_target));
168  reporter()->playSampleSound();
169 }
170 
172 {
173  ActiveDataPtr activeData = mServices->patient()->getActiveData();
174  if (!mServices->registration()->getFixedData())
175  mServices->registration()->setFixedData(activeData->getActive<Image>());
176 
177  if (mServices->patient()->getPatientLandmarks()->getLandmarks().size() < 3)
178  return;
179 
180  mServices->registration()->doPatientRegistration();
181 
183 }
184 
186 {
187  return "Patient";
188 }
189 
190 } //cx
QString qstring_cast(const T &val)
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
void reportError(QString msg)
Definition: cxLogger.cpp:71
virtual QString getTargetName() const
ReporterPtr reporter()
Definition: cxReporter.cpp:38
QLabel * mAvarageAccuracyLabel
label showing the average accuracy
One landmark, or fiducial, coordinate.
Definition: cxLandmark.h:40
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
virtual void cellClickedSlot(int row, int column)
when a landmark i selected from the table
QVBoxLayout * mVerticalLayout
vertical layout is used
virtual void hideEvent(QHideEvent *event)
static ActiveToolProxyPtr New(TrackingServicePtr trackingService)
virtual Transform3D getTargetTransform() const
virtual void setTargetLandmark(QString uid, Vector3D p_target)
virtual void prePaintEvent()
populates the table widget
void toolSampleButtonClickedSlot()
reacts when the Sample Tool button is clicked
void valueChangedFor(QString key)
A volumetric data set.
Definition: cxImage.h:45
virtual void cellClickedSlot(int row, int column)
when a landmark is selected from the table
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:20
virtual void prePaintEvent()
populates the table widget
Representation of a mouse/keyboard-controlled virtual tool.
Definition: cxTool.h:85
rsNOT_REGISTRATED
QPushButton * mToolSampleButton
the Sample Tool button
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
virtual LandmarkMap getTargetLandmarks() const
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
virtual void hideEvent(QHideEvent *event)
std::map< QString, class Landmark > LandmarkMap
QString mActiveLandmark
uid of surrently selected landmark.
std::vector< Landmark > getAllLandmarks() const
get all the landmarks from the image and the datamanager
QTableWidget * mLandmarkTableWidget
the table widget presenting the landmarks
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr