NorMIT-nav  2023.01.05-dev+develop.0da12
An IGT application
cxOperatingTableWidget.cpp
Go to the documentation of this file.
2 #include <QLayout>
3 #include <QLabel>
5 #include "cxTransform3DWidget.h"
6 #include "cxVector3DProperty.h"
7 #include "cxHelperWidgets.h"
8 #include "cxVector3DWidget.h"
9 #include <QPushButton>
10 #include "cxSpaceProvider.h"
11 
12 namespace cx
13 {
14 
16  QWidget(parent),
17  mServices(services)
18 {
19  mVerticalLayout = new QVBoxLayout(this);
20 
21  mVerticalLayout->setMargin(0);
22 
23  mVerticalLayout->addWidget(new QLabel("Define the operating table up direction. See the preferences help page for more information."));
24 
25  QHBoxLayout* buttonLayout = new QHBoxLayout;
26  mVerticalLayout->addLayout(buttonLayout);
27 
28  QPushButton* toolDefineGravityButton = new QPushButton("Tool direction is down");
29  connect(toolDefineGravityButton, &QPushButton::clicked, this, &OperatingTableWidget::onDefineDownWithTool);
30  buttonLayout->addWidget(toolDefineGravityButton);
31 
32  QPushButton* definePatientAnteriorUpButton = new QPushButton("Patient Anterior Up");
33  connect(definePatientAnteriorUpButton, &QPushButton::clicked, this, &OperatingTableWidget::onDefinePatientAnteriorUp);
34  buttonLayout->addWidget(definePatientAnteriorUpButton);
35 
36  QPushButton* definePatientPosteriorUpButton = new QPushButton("Patient Posterior Up");
37  connect(definePatientPosteriorUpButton, &QPushButton::clicked, this, &OperatingTableWidget::onDefinePatientPosteriorUp);
38  buttonLayout->addWidget(definePatientPosteriorUpButton);
39 
40  QPushButton* definePatientSuperiorUpButton = new QPushButton("Patient Superior Up");
41  connect(definePatientSuperiorUpButton, &QPushButton::clicked, this, &OperatingTableWidget::onDefinePatientSuperiorUp);
42  buttonLayout->addWidget(definePatientSuperiorUpButton);
43 
44  mLabel = new QLabel("Table transformation matrix, rMot:");
45  mVerticalLayout->addWidget(mLabel);
46  mMatrixWidget = new Transform3DWidget(this);
47  mVerticalLayout->addWidget(mMatrixWidget);
48  connect(mMatrixWidget, &Transform3DWidget::changed, this, &OperatingTableWidget::matrixWidgetChanged);
49 
50  mTableUp = Vector3DProperty::initialize("tableUp", "Up direction",
51  "The up direction",
52  Vector3D::Zero(),
53  DoubleRange(-1, 1, 0.01), 2);
54  mVerticalLayout->addWidget(Vector3DWidget::createSmallHorizontal(this, mTableUp));
55 
56  mVerticalLayout->addStretch();
57 
58  connect(mServices->patient().get(), &PatientModelService::operatingTableChanged,
59  this, &OperatingTableWidget::backendChanged);
60 }
61 
62 void OperatingTableWidget::showEvent(QShowEvent* event)
63 {
64  this->backendChanged();
65 }
66 
70 void OperatingTableWidget::backendChanged()
71 {
72  mMatrixWidget->blockSignals(true);
73 
74  OperatingTable table = mServices->patient()->getOperatingTable();
75  mMatrixWidget->setMatrix(table.rMot);
76  mTableUp->setValue(table.getVectorUp());
77 
78  mMatrixWidget->blockSignals(false);
79 }
80 
85 void OperatingTableWidget::matrixWidgetChanged()
86 {
87  OperatingTable table = mServices->patient()->getOperatingTable();
88  table.rMot = mMatrixWidget->getMatrix();
89  mServices->patient()->setOperatingTable(table);
90 }
91 
92 void OperatingTableWidget::onDefineDownWithTool()
93 {
94  Transform3D rMt = mServices->spaceProvider()->getActiveToolTipTransform(CoordinateSystem::reference(), true);
95  Vector3D toolUp = -Vector3D::UnitZ();
96  Vector3D newUp = rMt.vector(toolUp);
97  this->setNewUp(newUp);
98 }
99 void OperatingTableWidget::onDefinePatientAnteriorUp()
100 {
101  this->setNewUp(-Vector3D::UnitY());
102 }
103 void OperatingTableWidget::onDefinePatientPosteriorUp()
104 {
105  this->setNewUp(Vector3D::UnitY());
106 }
107 void OperatingTableWidget::onDefinePatientSuperiorUp()
108 {
109  this->setNewUp(Vector3D::UnitZ());
110 }
111 
112 void OperatingTableWidget::setNewUp(Vector3D newUp)
113 {
114  OperatingTable table = mServices->patient()->getOperatingTable();
115 
116  Transform3D R = createTransformRotationBetweenVectors(table.getVectorUp(), newUp);
117  table.rMot = R * table.rMot;
118 
119  mServices->patient()->setOperatingTable(table);
120 }
121 
122 
123 } // namespace cx
cx::Transform3DWidget::changed
void changed()
cxVector3DWidget.h
cx::Transform3DWidget
Widget for displaying and manipulating an affine matrix, i.e. a rotation+translation matrix.
Definition: cxTransform3DWidget.h:38
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxOperatingTableWidget.h
cx::CoordinateSystem::reference
static CoordinateSystem reference()
Definition: cxCoordinateSystemHelpers.h:38
cxTransform3DWidget.h
cxHelperWidgets.h
cx::PatientModelService::operatingTableChanged
void operatingTableChanged()
cx::OperatingTableWidget::OperatingTableWidget
OperatingTableWidget(CoreServicesPtr services, QWidget *parent=NULL)
Definition: cxOperatingTableWidget.cpp:15
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::CoreServicesPtr
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:37
cxPatientModelService.h
cx::OperatingTable::rMot
Transform3D rMot
Transform from OT to reference space.
Definition: cxPatientModelService.h:62
cx::Transform3DWidget::setMatrix
void setMatrix(const Transform3D &M)
Definition: cxTransform3DWidget.cpp:267
cx::OperatingTableWidget::showEvent
void showEvent(QShowEvent *event)
Definition: cxOperatingTableWidget.cpp:62
cx::Transform3DWidget::getMatrix
Transform3D getMatrix() const
Definition: cxTransform3DWidget.cpp:272
cxVector3DProperty.h
cx::createTransformRotationBetweenVectors
Transform3D createTransformRotationBetweenVectors(Vector3D from, Vector3D to)
Definition: cxTransform3D.cpp:192
cx::OperatingTable
The OperatingTable class.
Definition: cxPatientModelService.h:54
cx::DoubleRange
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
cx::Vector3D
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
cx::Vector3DProperty::initialize
static Vector3DPropertyPtr initialize(const QString &uid, QString name, QString help, Vector3D value, DoubleRange range, int decimals, QDomNode root=QDomNode())
Definition: cxVector3DProperty.cpp:25
cx::Vector3DWidget::createSmallHorizontal
static Vector3DWidget * createSmallHorizontal(QWidget *parent, Vector3DPropertyBasePtr data)
Definition: cxVector3DWidget.cpp:32
cxSpaceProvider.h