Fraxinus  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 
117  table.rMot = R * table.rMot;
118 
119  mServices->patient()->setOperatingTable(table);
120 }
121 
122 
123 } // namespace cx
Widget for displaying and manipulating an affine matrix, i.e. a rotation+translation matrix...
OperatingTableWidget(CoreServicesPtr services, QWidget *parent=NULL)
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Transform3D createTransformRotationBetweenVectors(Vector3D from, Vector3D to)
void showEvent(QShowEvent *event)
Utility class for describing a bounded numeric range.
Definition: cxDoubleRange.h:32
static CoordinateSystem reference()
void setMatrix(const Transform3D &M)
static Vector3DWidget * createSmallHorizontal(QWidget *parent, Vector3DPropertyBasePtr data)
static Vector3DPropertyPtr initialize(const QString &uid, QString name, QString help, Vector3D value, DoubleRange range, int decimals, QDomNode root=QDomNode())
Vector3D getVectorUp() const
Returns the table&#39;s up vector in R space.
Transform3D rMot
Transform from OT to reference space.
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:42
boost::shared_ptr< class CoreServices > CoreServicesPtr
Definition: cxCameraStyle.h:37
Transform3D getMatrix() const
The OperatingTable class.
Namespace for all CustusX production code.