CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 2008-2014, SINTEF Department of Medical Technology
5 All rights reserved.
6 
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 
10 1. Redistributions of source code must retain the above copyright notice,
11  this list of conditions and the following disclaimer.
12 
13 2. Redistributions in binary form must reproduce the above copyright notice,
14  this list of conditions and the following disclaimer in the documentation
15  and/or other materials provided with the distribution.
16 
17 3. Neither the name of the copyright holder nor the names of its contributors
18  may be used to endorse or promote products derived from this software
19  without specific prior written permission.
20 
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
25 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 =========================================================================*/
32 
34 
35 #include <QPushButton>
36 #include <QTableWidget>
37 #include <QLabel>
38 
39 #include "cxActiveToolProxy.h"
40 #include "cxLandmarkListener.h"
41 #include "cxSettings.h"
42 #include "cxPatientModelService.h"
43 #include "cxTrackingService.h"
44 #include "cxRegistrationService.h"
45 #include "cxViewService.h"
46 #include "cxTypeConversions.h"
47 #include "cxReporter.h"
48 #include "cxLandmark.h"
49 #include "cxViewGroupData.h"
50 #include "cxImage.h"
51 
52 namespace cx
53 {
54 
55 PatientLandMarksWidget::PatientLandMarksWidget(RegServices services,
56  QWidget* parent, QString objectName, QString windowTitle) :
57  LandmarkRegistrationWidget(services, parent, objectName, windowTitle),
58  mToolSampleButton(new QPushButton("Sample Tool", this))
59 {
60  mLandmarkListener->useI2IRegistration(false);
61 
63 
64  //buttons
65  mToolSampleButton->setDisabled(true);
66  connect(mToolSampleButton, SIGNAL(clicked()), this, SLOT(toolSampleButtonClickedSlot()));
67 
68  mRemoveLandmarkButton = new QPushButton("Clear", this);
69  mRemoveLandmarkButton->setToolTip("Clear selected landmark");
70  // mRemoveLandmarkButton->setDisabled(true);
72 
73  //toolmanager
75  connect(mActiveToolProxy.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateToolSampleButton()));
76  connect(mActiveToolProxy.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(updateToolSampleButton()));
77 
78  connect(settings(), &Settings::valueChangedFor, this, &PatientLandMarksWidget::globalConfigurationFileChangedSlot);
79 
80  //layout
81 // mVerticalLayout->addWidget(new LabeledComboBoxWidget(this, mFixedProperty));
85 
86  QHBoxLayout* buttonsLayout = new QHBoxLayout;
87 // buttonsLayout->addWidget(mRegisterButton);
88  buttonsLayout->addWidget(mRemoveLandmarkButton);
89  mVerticalLayout->addLayout(buttonsLayout);
90 
91  this->updateToolSampleButton();
92 }
93 
95 {
96 }
97 
98 void PatientLandMarksWidget::globalConfigurationFileChangedSlot(QString key)
99 {
100  if (key == "giveManualToolPhysicalProperties")
101  this->updateToolSampleButton();
102 }
103 
105 {
106  ToolPtr tool = mServices.trackingService->getActiveTool();
107 
108  bool enabled = false;
109  enabled = tool && tool->getVisible() && (!tool->hasType(Tool::TOOL_MANUAL) || settings()->value("giveManualToolPhysicalProperties").toBool()); // enable only for non-manual tools.
110  mToolSampleButton->setEnabled(enabled);
111 
112  if (mServices.trackingService->getActiveTool())
113  mToolSampleButton->setText("Sample " + qstring_cast(tool->getName()));
114  else
115  mToolSampleButton->setText("No tool");
116 }
117 
119 {
120  ToolPtr tool = mServices.trackingService->getActiveTool();
121 
122  if (!tool)
123  {
124  reportError("mToolToSample is NULL!");
125  return;
126  }
127  //TODO What if the reference frame isnt visible?
128  Transform3D lastTransform_prMt = tool->get_prMt();
129  Vector3D p_pr = lastTransform_prMt.coord(Vector3D(0, 0, tool->getTooltipOffset()));
130 
131  // TODO: do we want to allow sampling points not defined in image??
132  if (mActiveLandmark.isEmpty() && !mServices.patientModelService->getLandmarkProperties().empty())
133  mActiveLandmark = mServices.patientModelService->getLandmarkProperties().begin()->first;
134 
135  mServices.patientModelService->getPatientLandmarks()->setLandmark(Landmark(mActiveLandmark, p_pr));
136  reporter()->playSampleSound();
137 
138  this->activateLandmark(this->getNextLandmark());
139 
140  this->performRegistration(); // automatic when sampling in physical patient space (Mantis #0000674)s
141 }
142 
143 void PatientLandMarksWidget::showEvent(QShowEvent* event)
144 {
145 // std::cout << "PatientLandMarksWidget::showEvent" << std::endl;
146  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsPATIENT_REGISTRATED);
148 }
149 
150 void PatientLandMarksWidget::hideEvent(QHideEvent* event)
151 {
152 // std::cout << "PatientLandMarksWidget::hideEvent" << std::endl;
153  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsNOT_REGISTRATED);
155 }
156 
158 {
159  QString next = this->getNextLandmark();
160  mServices.patientModelService->getPatientLandmarks()->removeLandmark(mActiveLandmark);
161  this->activateLandmark(next);
162 }
163 
165 {
167 
168  mRemoveLandmarkButton->setEnabled(true);
169 }
170 
172 {
174 
175  std::vector<Landmark> landmarks = this->getAllLandmarks();
176  mRemoveLandmarkButton->setEnabled(!landmarks.empty() && !mActiveLandmark.isEmpty());
177 }
178 
182 {
183  return mServices.patientModelService->getPatientLandmarks()->getLandmarks();
184 }
185 
190 {
191  Transform3D rMpr = mServices.patientModelService->get_rMpr();
192  return rMpr;
193 }
194 
196 {
197  mServices.patientModelService->getPatientLandmarks()->setLandmark(Landmark(uid, p_target));
198  reporter()->playSampleSound();
199 }
200 
202 {
203  if (!mServices.registrationService->getFixedData())
204  mServices.registrationService->setFixedData(mServices.patientModelService->getActiveImage());
205 
206  if (mServices.patientModelService->getPatientLandmarks()->getLandmarks().size() < 3)
207  return;
208 
209  mServices.registrationService->doPatientRegistration();
210 
212 }
213 
215 {
216  return "Patient";
217 }
218 
219 } //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:92
virtual QString getTargetName() const
ReporterPtr reporter()
Definition: cxReporter.cpp:59
QLabel * mAvarageAccuracyLabel
label showing the average accuracy
One landmark, or fiducial, coordinate.
Definition: cxLandmark.h:61
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:87
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)
virtual void cellClickedSlot(int row, int column)
when a landmark is selected from the table
virtual void prePaintEvent()
populates the table widget
Representation of a mouse/keyboard-controlled virtual tool.
Definition: cxTool.h:91
rsNOT_REGISTRATED
QPushButton * mToolSampleButton
the Sample Tool button
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
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:63
VisualizationServicePtr visualizationService
Definition: cxVisServices.h:60
virtual void hideEvent(QHideEvent *event)
std::map< QString, class Landmark > LandmarkMap
QString mActiveLandmark
uid of surrently selected landmark.
TrackingServicePtr trackingService
std::vector< Landmark > getAllLandmarks() const
get all the landmarks from the image and the datamanager
PatientModelServicePtr patientModelService
RegistrationServicePtr registrationService
Definition: cxRegServices.h:60
QTableWidget * mLandmarkTableWidget
the table widget presenting the landmarks
boost::shared_ptr< class Tool > ToolPtr