Fraxinus  16.5.0-fx-rc1
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 "cxImage.h"
50 #include "cxActiveData.h"
51 
52 namespace cx
53 {
54 
55 PatientLandMarksWidget::PatientLandMarksWidget(RegServicesPtr 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 
62  connect(services->patient().get(), &PatientModelService::rMprChanged, this, &PatientLandMarksWidget::setModified);
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");
71 
72  //toolmanager
73  mActiveToolProxy = ActiveToolProxy::New(services->tracking());
74  connect(mActiveToolProxy.get(), SIGNAL(toolVisible(bool)), this, SLOT(updateToolSampleButton()));
75  connect(mActiveToolProxy.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(updateToolSampleButton()));
76 
77  connect(settings(), &Settings::valueChangedFor, this, &PatientLandMarksWidget::globalConfigurationFileChangedSlot);
78 
79  //layout
84 
85  this->updateToolSampleButton();
86 }
87 
89 {
90 }
91 
92 void PatientLandMarksWidget::globalConfigurationFileChangedSlot(QString key)
93 {
94  if (key == "giveManualToolPhysicalProperties")
95  this->updateToolSampleButton();
96 }
97 
99 {
100  ToolPtr tool = mServices->tracking()->getActiveTool();
101 
102  bool enabled = tool && tool->getVisible() && (!tool->hasType(Tool::TOOL_MANUAL) || settings()->value("giveManualToolPhysicalProperties").toBool()); // enable only for non-manual tools.
103  mToolSampleButton->setEnabled(enabled);
104 
105  if (mServices->tracking()->getActiveTool())
106  mToolSampleButton->setText("Sample " + qstring_cast(tool->getName()));
107  else
108  mToolSampleButton->setText("No tool");
109 }
110 
112 {
113  ToolPtr tool = mServices->tracking()->getActiveTool();
114 
115  if (!tool)
116  {
117  reportError("mToolToSample is NULL!");
118  return;
119  }
120  //TODO What if the reference frame isnt visible?
121  Transform3D lastTransform_prMt = tool->get_prMt();
122  Vector3D p_pr = lastTransform_prMt.coord(Vector3D(0, 0, tool->getTooltipOffset()));
123 
124  // TODO: do we want to allow sampling points not defined in image??
125  if (mActiveLandmark.isEmpty() && !mServices->patient()->getLandmarkProperties().empty())
126  mActiveLandmark = mServices->patient()->getLandmarkProperties().begin()->first;
127 
128  mServices->patient()->getPatientLandmarks()->setLandmark(Landmark(mActiveLandmark, p_pr));
129  reporter()->playSampleSound();
130 
131  this->activateLandmark(this->getNextLandmark());
132 
133  this->performRegistration(); // automatic when sampling in physical patient space (Mantis #0000674)s
134 }
135 
136 void PatientLandMarksWidget::showEvent(QShowEvent* event)
137 {
138  mServices->view()->setRegistrationMode(rsPATIENT_REGISTRATED);
140 }
141 
142 void PatientLandMarksWidget::hideEvent(QHideEvent* event)
143 {
144  mServices->view()->setRegistrationMode(rsNOT_REGISTRATED);
146 }
147 
149 {
150  QString next = this->getNextLandmark();
151  mServices->patient()->getPatientLandmarks()->removeLandmark(mActiveLandmark);
152  this->activateLandmark(next);
153 }
154 
156 {
158 
159  mRemoveLandmarkButton->setEnabled(true);
160 }
161 
163 {
165 
166  std::vector<Landmark> landmarks = this->getAllLandmarks();
167  mRemoveLandmarkButton->setEnabled(!landmarks.empty() && !mActiveLandmark.isEmpty());
168 }
169 
173 {
174  return mServices->patient()->getPatientLandmarks()->getLandmarks();
175 }
176 
181 {
182  Transform3D rMpr = mServices->patient()->get_rMpr();
183  return rMpr;
184 }
185 
187 {
188  mServices->patient()->getPatientLandmarks()->setLandmark(Landmark(uid, p_target));
189  reporter()->playSampleSound();
190 }
191 
193 {
194  ActiveDataPtr activeData = mServices->patient()->getActiveData();
195  if (!mServices->registration()->getFixedData())
196  mServices->registration()->setFixedData(activeData->getActive<Image>());
197 
198  if (mServices->patient()->getPatientLandmarks()->getLandmarks().size() < 3)
199  return;
200 
201  mServices->registration()->doPatientRegistration();
202 
204 }
205 
207 {
208  return "Patient";
209 }
210 
211 } //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
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:41
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.
boost::shared_ptr< class ActiveData > ActiveDataPtr
Definition: cxColorWidget.h:42
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)
A volumetric data set.
Definition: cxImage.h:66
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:106
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
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
boost::shared_ptr< class Tool > ToolPtr