CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxPatientOrientationWidget.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 <cmath>
36 #include <QPushButton>
37 #include <QCheckBox>
38 #include <QVBoxLayout>
39 
40 #include "cxRegistrationService.h"
41 #include "cxPatientModelService.h"
42 
43 #include "cxTrackingService.h"
44 #include "cxSettings.h"
45 
46 namespace cx
47 {
48 PatientOrientationWidget::PatientOrientationWidget(RegServices services, QWidget* parent, QString objectName, QString windowTitle) :
49  RegistrationBaseWidget(services, parent, objectName, windowTitle),
50  mPatientOrientationButton(new QPushButton("Patient Orientation")),
51  mInvertButton(new QCheckBox("Back face"))
52 {
53  QVBoxLayout* layout = new QVBoxLayout(this);
54  layout->setMargin(0);
55  layout->addWidget(mInvertButton);
56  layout->addWidget(mPatientOrientationButton);
57  layout->addStretch();
58 
59  mPatientOrientationButton->setToolTip(defaultWhatsThis());
60  connect(mPatientOrientationButton, SIGNAL(clicked()), this, SLOT(setPatientOrientationSlot()));
61 
62  connect(settings(), &Settings::valueChangedFor, this, &PatientOrientationWidget::globalConfigurationFileChangedSlot);
63 
64  mActiveToolProxy = ActiveToolProxy::New(services.trackingService);
65  connect(mActiveToolProxy.get(), SIGNAL(toolVisible(bool)), this, SLOT(enableToolSampleButtonSlot()));
66  connect(mActiveToolProxy.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(enableToolSampleButtonSlot()));
67  this->enableToolSampleButtonSlot();
68 
69 }
70 
72 {}
73 
75 {
76  return "<html>"
77  "<h3>Set patient orientation using the navigation tool.</h3>"
78  "<p><b>Prerequisite:</b> Image registration.</p>"
79  "<p>Only orientation of the reference space is changed - data is not moved.</p>"
80  "Align the Polaris tool so that the tools tip points towards the patients feet and the "
81  "markers face the same way as the patients nose. Click the button. Verify that the "
82  "figure in the upper left corner of the 3D view is correcly aligned.</p>"
83  "<p><b>Tip:</b> If the patient is orientated with the nose down towards the table, try using <i>back face</i>.</p>"
84  "</html>";
85 }
86 
87 void PatientOrientationWidget::globalConfigurationFileChangedSlot(QString key)
88 {
89  if (key == "giveManualToolPhysicalProperties")
90  this->enableToolSampleButtonSlot();
91 }
92 
93 Transform3D PatientOrientationWidget::get_tMtm() const
94 {
95  Transform3D tMtm;
96 
97  if (mInvertButton->isChecked())
98  {
100  }
101  else
102  {
104  }
105 
106  return tMtm;
107 }
108 
109 void PatientOrientationWidget::setPatientOrientationSlot()
110 {
111  Transform3D prMt = mServices.trackingService->getActiveTool()->get_prMt();
112  mServices.registrationService->applyPatientOrientation(this->get_tMtm(), prMt);
113 }
114 
115 void PatientOrientationWidget::enableToolSampleButtonSlot()
116 {
117  ToolPtr tool = mServices.trackingService->getActiveTool();
118  bool enabled = false;
119  enabled = tool &&
120  tool->getVisible() &&
121  (!tool->hasType(Tool::TOOL_MANUAL) || settings()->value("giveManualToolPhysicalProperties").toBool()); // enable only for non-manual tools.
122 
123  mPatientOrientationButton->setEnabled(enabled);
124 }
125 
126 }//namespace cx
Transform3D createTransformRotateY(const double angle)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
QVariant value(const QString &key, const QVariant &defaultValue=QVariant()) const
Definition: cxSettings.cpp:99
static ActiveToolProxyPtr New(TrackingServicePtr trackingService)
void valueChangedFor(QString key)
Representation of a mouse/keyboard-controlled virtual tool.
Definition: cxTool.h:91
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
TrackingServicePtr trackingService
Transform3D createTransformRotateZ(const double angle)
PatientOrientationWidget(RegServices services, QWidget *parent, QString objectName, QString windowTitle)
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
#define M_PI
RegistrationServicePtr registrationService
Definition: cxRegServices.h:60
boost::shared_ptr< class Tool > ToolPtr