NorMIT-nav  2023.01.05-dev+develop.0da12
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 #include <QCheckBox>
18 
19 #include "cxActiveToolProxy.h"
20 #include "cxLandmarkListener.h"
21 #include "cxSettings.h"
22 #include "cxPatientModelService.h"
23 #include "cxTrackingService.h"
24 #include "cxRegistrationService.h"
25 #include "cxViewService.h"
26 #include "cxTypeConversions.h"
27 #include "cxReporter.h"
28 #include "cxLandmark.h"
29 #include "cxImage.h"
30 #include "cxActiveData.h"
31 
32 namespace cx
33 {
34 
35 PatientLandMarksWidget::PatientLandMarksWidget(RegServicesPtr services,
36  QWidget* parent, QString objectName, QString windowTitle) :
37  LandmarkRegistrationWidget(services, parent, objectName, windowTitle),
38  mToolSampleButton(new QPushButton("Sample Tool", this))
39 {
40  mLandmarkListener->useI2IRegistration(false);
41 
42  connect(services->patient().get(), &PatientModelService::rMprChanged, this, &PatientLandMarksWidget::setModified);
43 
44  //buttons
45  mToolSampleButton->setDisabled(true);
46  connect(mToolSampleButton, SIGNAL(clicked()), this, SLOT(toolSampleButtonClickedSlot()));
47 
48  mRemoveLandmarkButton = new QPushButton("Clear", this);
49  mRemoveLandmarkButton->setToolTip("Clear selected landmark");
51 
52  //toolmanager
53  mActiveToolProxy = ActiveToolProxy::New(services->tracking());
54  connect(mActiveToolProxy.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateToolSampleButton()));
55  connect(mActiveToolProxy.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(updateToolSampleButton()));
56 
57  connect(settings(), &Settings::valueChangedFor, this, &PatientLandMarksWidget::globalConfigurationFileChangedSlot);
58 
59  //layout
64 
65  mMouseClickSample->setText("Sample with mouse clicks in anyplane view.");
66  mMouseClickSample->show();
67  connect(mMouseClickSample, &QCheckBox::stateChanged, this, &PatientLandMarksWidget::mouseClickSampleStateChanged);
68 
70 
71  this->updateToolSampleButton();
72 }
73 
75 {
76 }
77 
78 void PatientLandMarksWidget::globalConfigurationFileChangedSlot(QString key)
79 {
80  if (key == "giveManualToolPhysicalProperties")
81  this->updateToolSampleButton();
82 }
83 
85 {
86  ToolPtr tool = mServices->tracking()->getActiveTool();
87 
88  bool enabled = tool && tool->getVisible() && (!tool->hasType(Tool::TOOL_MANUAL) || settings()->value("giveManualToolPhysicalProperties").toBool()); // enable only for non-manual tools.
89  mToolSampleButton->setEnabled(enabled);
90 
91  if (mServices->tracking()->getActiveTool())
92  mToolSampleButton->setText("Sample " + qstring_cast(tool->getName()));
93  else
94  mToolSampleButton->setText("No tool");
95 }
96 
98 {
99  ToolPtr tool = mServices->tracking()->getActiveTool();
100 
101  if (!tool)
102  {
103  reportError("mToolToSample is NULL!");
104  return;
105  }
106  //TODO What if the reference frame isnt visible?
107  Transform3D lastTransform_prMt = tool->get_prMt();
108  Vector3D p_pr = lastTransform_prMt.coord(Vector3D(0, 0, tool->getTooltipOffset()));
109 
110  // TODO: do we want to allow sampling points not defined in image??
111  if (mActiveLandmark.isEmpty() && !mServices->patient()->getLandmarkProperties().empty())
112  mActiveLandmark = mServices->patient()->getLandmarkProperties().begin()->first;
113 
114  mServices->patient()->getPatientLandmarks()->setLandmark(Landmark(mActiveLandmark, p_pr));
115  reporter()->playSampleSound();
116 
117  this->activateLandmark(this->getNextLandmark());
118 
119  this->performRegistration(); // automatic when sampling in physical patient space (Mantis #0000674)s
120 }
121 
122 void PatientLandMarksWidget::showEvent(QShowEvent* event)
123 {
124  mServices->view()->setRegistrationMode(rsPATIENT_REGISTRATED);
126  mMouseClickSample->setChecked(true);
127 }
128 
129 void PatientLandMarksWidget::hideEvent(QHideEvent* event)
130 {
131  mServices->view()->setRegistrationMode(rsNOT_REGISTRATED);
133 }
134 
136 {
137  QString next = this->getNextLandmark();
138  mServices->patient()->getPatientLandmarks()->removeLandmark(mActiveLandmark);
139  this->activateLandmark(next);
140 }
141 
143 {
145 
146  mRemoveLandmarkButton->setEnabled(true);
147 }
148 
150 {
152 
153  std::vector<Landmark> landmarks = this->getAllLandmarks();
154  mRemoveLandmarkButton->setEnabled(!landmarks.empty() && !mActiveLandmark.isEmpty());
155 }
156 
160 {
161  return mServices->patient()->getPatientLandmarks()->getLandmarks();
162 }
163 
168 {
169  Transform3D rMpr = mServices->patient()->get_rMpr();
170  return rMpr;
171 }
172 
174 {
175  mServices->patient()->getPatientLandmarks()->setLandmark(Landmark(uid, p_target));
176  reporter()->playSampleSound();
177 }
178 
180 {
181  ActiveDataPtr activeData = mServices->patient()->getActiveData();
182  if (!mServices->registration()->getFixedData())
183  mServices->registration()->setFixedData(activeData->getActive<Image>());
184 
185  if (mServices->patient()->getPatientLandmarks()->getLandmarks().size() < 3)
186  return;
187 
188  mServices->registration()->doPatientRegistration();
189 
191 }
192 
194 {
195  return "Patient";
196 }
197 
199 {
200  QTableWidgetItem* item = getLandmarkTableItem();
201  if(!item)
202  {
203  CX_LOG_WARNING() << "PatientLandMarksWidget::pointSampled() Cannot get item from mLandmarkTableWidget";
204  return;
205  }
206  QString uid = item->data(Qt::UserRole).toString();
207 
208  Transform3D rMtarget = this->getTargetTransform();
209  Vector3D p_target = rMtarget.inv().coord(p_r);
210 
211  this->setTargetLandmark(uid, p_target);
212  this->activateLandmark(this->getNextLandmark());
213  this->performRegistration();
214 }
215 } //cx
cx::Settings::valueChangedFor
void valueChangedFor(QString key)
cx::LandmarkRegistrationWidget
Definition: cxLandmarkRegistrationWidget.h:45
cx::LandmarkRegistrationWidget::cellClickedSlot
virtual void cellClickedSlot(int row, int column)
when a landmark is selected from the table
Definition: cxLandmarkRegistrationWidget.cpp:61
cx::LandmarkRegistrationWidget::mLandmarkListener
LandmarkListenerPtr mLandmarkListener
Definition: cxLandmarkRegistrationWidget.h:92
qstring_cast
QString qstring_cast(const T &val)
Definition: cxTypeConversions.h:46
cx::PatientLandMarksWidget::performRegistration
virtual void performRegistration()
Definition: cxPatientLandMarksWidget.cpp:179
cx::LandmarkRegistrationWidget::getLandmarkTableItem
QTableWidgetItem * getLandmarkTableItem()
Definition: cxLandmarkRegistrationWidget.cpp:400
cx::Settings::value
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:66
cx::PatientLandMarksWidget::hideEvent
virtual void hideEvent(QHideEvent *event)
Definition: cxPatientLandMarksWidget.cpp:129
cxActiveData.h
cx::LandmarkRegistrationWidget::getNextLandmark
QString getNextLandmark()
Definition: cxLandmarkRegistrationWidget.cpp:234
cx::OptimizedUpdateWidget::setModified
virtual void setModified()
Definition: cxOptimizedUpdateWidget.cpp:36
rsNOT_REGISTRATED
rsNOT_REGISTRATED
Definition: cxDefinitions.h:128
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cx::Tool::TOOL_MANUAL
@ TOOL_MANUAL
Representation of a mouse/keyboard-controlled virtual tool.
Definition: cxTool.h:85
cxImage.h
cx::LandmarkRegistrationWidget::getAllLandmarks
std::vector< Landmark > getAllLandmarks() const
get all the landmarks from the image and the datamanager
Definition: cxLandmarkRegistrationWidget.cpp:250
cx::LandmarkMap
std::map< QString, class Landmark > LandmarkMap
Definition: cxLandmarkRegistrationWidget.h:31
cx::LandmarkRegistrationWidget::mMouseClickSample
QCheckBox * mMouseClickSample
Definition: cxLandmarkRegistrationWidget.h:88
cxReporter.h
cx::LandmarkRegistrationWidget::mLandmarkTableWidget
QTableWidget * mLandmarkTableWidget
the table widget presenting the landmarks
Definition: cxLandmarkRegistrationWidget.h:86
cx::PatientLandMarksWidget::pointSampled
virtual void pointSampled(Vector3D p_r)
Definition: cxPatientLandMarksWidget.cpp:198
cx::reporter
ReporterPtr reporter()
Definition: cxReporter.cpp:36
cx::PatientLandMarksWidget::toolSampleButtonClickedSlot
void toolSampleButtonClickedSlot()
reacts when the Sample Tool button is clicked
Definition: cxPatientLandMarksWidget.cpp:97
cx::PatientLandMarksWidget::prePaintEvent
virtual void prePaintEvent()
populates the table widget
Definition: cxPatientLandMarksWidget.cpp:149
cx::LandmarkRegistrationWidget::mouseClickSampleStateChanged
void mouseClickSampleStateChanged()
Definition: cxLandmarkRegistrationWidget.cpp:392
cxLandmarkListener.h
cx::LandmarkRegistrationWidget::mAvarageAccuracyLabel
QLabel * mAvarageAccuracyLabel
label showing the average accuracy
Definition: cxLandmarkRegistrationWidget.h:87
cx::PatientLandMarksWidget::mActiveToolProxy
ActiveToolProxyPtr mActiveToolProxy
Definition: cxPatientLandMarksWidget.h:64
cx::Landmark
One landmark, or fiducial, coordinate.
Definition: cxLandmark.h:40
cx::RegistrationBaseWidget::mServices
RegServicesPtr mServices
Definition: cxRegistrationBaseWidget.h:35
cx::LandmarkRegistrationWidget::mActiveLandmark
QString mActiveLandmark
uid of currently selected landmark.
Definition: cxLandmarkRegistrationWidget.h:91
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::PatientModelService::rMprChanged
void rMprChanged()
cxViewService.h
cx::PatientLandMarksWidget::updateToolSampleButton
void updateToolSampleButton()
Definition: cxPatientLandMarksWidget.cpp:84
cx::LandmarkRegistrationWidget::mVerticalLayout
QVBoxLayout * mVerticalLayout
vertical layout is used
Definition: cxLandmarkRegistrationWidget.h:85
cxTypeConversions.h
cx::PatientLandMarksWidget::mRemoveLandmarkButton
QPushButton * mRemoveLandmarkButton
Definition: cxPatientLandMarksWidget.h:61
cxPatientModelService.h
cx::PatientLandMarksWidget::showEvent
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
Definition: cxPatientLandMarksWidget.cpp:122
cx::LandmarkRegistrationWidget::showEvent
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
Definition: cxLandmarkRegistrationWidget.cpp:100
cxSettings.h
cx::PatientLandMarksWidget::cellClickedSlot
virtual void cellClickedSlot(int row, int column)
when a landmark i selected from the table
Definition: cxPatientLandMarksWidget.cpp:142
cx::LandmarkRegistrationWidget::updateAverageAccuracyLabel
void updateAverageAccuracyLabel()
Definition: cxLandmarkRegistrationWidget.cpp:312
cx::PatientLandMarksWidget::getTargetLandmarks
virtual LandmarkMap getTargetLandmarks() const
Definition: cxPatientLandMarksWidget.cpp:159
cx::RegServicesPtr
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:20
cx::PatientLandMarksWidget::getTargetTransform
virtual Transform3D getTargetTransform() const
Definition: cxPatientLandMarksWidget.cpp:167
cx::LandmarkRegistrationWidget::hideEvent
virtual void hideEvent(QHideEvent *event)
Definition: cxLandmarkRegistrationWidget.cpp:133
cx::PatientLandMarksWidget::setTargetLandmark
virtual void setTargetLandmark(QString uid, Vector3D p_target)
Definition: cxPatientLandMarksWidget.cpp:173
cx::PatientLandMarksWidget::getTargetName
virtual QString getTargetName() const
Definition: cxPatientLandMarksWidget.cpp:193
cxActiveToolProxy.h
cx::PatientLandMarksWidget::mToolSampleButton
QPushButton * mToolSampleButton
the Sample Tool button
Definition: cxPatientLandMarksWidget.h:60
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cxPatientLandMarksWidget.h
cx::LandmarkRegistrationWidget::prePaintEvent
virtual void prePaintEvent()
populates the table widget
Definition: cxLandmarkRegistrationWidget.cpp:144
cx::Image
A volumetric data set.
Definition: cxImage.h:45
cxRegistrationService.h
CX_LOG_WARNING
#define CX_LOG_WARNING
Definition: cxLogger.h:98
cx::ActiveToolProxy::New
static ActiveToolProxyPtr New(TrackingServicePtr trackingService)
Definition: cxActiveToolProxy.h:45
cx::ActiveDataPtr
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:21
cx::reportError
void reportError(QString msg)
Definition: cxLogger.cpp:71
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cxTrackingService.h
cx::PatientLandMarksWidget::~PatientLandMarksWidget
virtual ~PatientLandMarksWidget()
empty
Definition: cxPatientLandMarksWidget.cpp:74
cx::PatientLandMarksWidget::removeLandmarkButtonClickedSlot
void removeLandmarkButtonClickedSlot()
Definition: cxPatientLandMarksWidget.cpp:135
cxLandmark.h
cx::settings
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:21
cx::LandmarkRegistrationWidget::activateLandmark
void activateLandmark(QString uid)
Definition: cxLandmarkRegistrationWidget.cpp:224