CustusX  22.04-rc5
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
QString qstring_cast(const T &val)
virtual void pointSampled(Vector3D p_r)
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:36
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 currently selected landmark.
#define CX_LOG_WARNING
Definition: cxLogger.h:98
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