CustusX  22.09
An IGT application
cxVBWidget.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) SINTEF Department of Medical Technology.
5 All rights reserved.
6 
7 CustusX is released under a BSD 3-Clause license.
8 
9 See Lisence.txt (https://github.com/SINTEFMedtek/CustusX/blob/master/License.txt) for details.
10 =========================================================================*/
11 
12 #include <QLabel>
13 #include <QHBoxLayout>
14 #include <QVBoxLayout>
15 #include <QGroupBox>
16 #include <QSlider>
17 #include <QSpinBox>
18 #include <QGridLayout>
19 #include <QLabel>
20 #include <QDial>
21 #include <QPushButton>
22 
23 #include "cxVBWidget.h"
25 #include "cxViewServiceProxy.h"
26 #include "cxDataSelectWidget.h"
27 #include "cxTrackingServiceProxy.h"
28 #include "cxView.h"
30 #include "cxPatientStorage.h"
31 #include "cxVisServices.h"
32 #include "cxLogger.h"
33 #include "cxRouteToTarget.h"
34 
35 
36 
37 namespace cx
38 {
39 
40 VBWidget::VBWidget(VisServicesPtr services, QWidget *parent) :
41  QWidget(parent),
42  mVerticalLayout(new QVBoxLayout(this)),
43  mControlsEnabled(false),
44  mAutomaticRotation(true),
45  mStorage(new PatientStorage(services->session(), "VirtualBronchoscopy"))
46 {
47  this->setObjectName("virtual_bronchoscopy_widget");
48  this->setWindowTitle("Virtual Bronchoscopy");
49  this->setWhatsThis(this->defaultWhatsThis());
50 
51  this->setFocusPolicy(Qt::StrongFocus); // Widget needs focus to handle Key events
52 
53  mRouteToTarget = StringPropertySelectMesh::New(services->patient());
54  mRouteToTarget->setValueName("Route to target path: ");
55  mStorage->storeVariable("routeToTarget",
58 
59  // Selector for route to target
60  QVBoxLayout *inputVbox = new QVBoxLayout;
61  inputVbox->addWidget(new DataSelectWidget(services->view(), services->patient(), this,mRouteToTarget));
62  QGroupBox *inputBox = new QGroupBox(tr("Input"));
63  inputBox->setLayout(inputVbox);
64  mVerticalLayout->addWidget(inputBox);
65 
66  // Selectors for position along path and play/pause
67  QHBoxLayout *playbackHBox = new QHBoxLayout;
68  QGroupBox *playbackBox = new QGroupBox(tr("Playback"));
69  mPlaybackSlider = new QSlider(Qt::Horizontal);
70  QLabel *labelStart = new QLabel(tr("Start "));
71  QLabel *labelTarget = new QLabel(tr(" Target"));
72  playbackHBox->addWidget(labelStart);
73  playbackHBox->addWidget(mPlaybackSlider);
74  playbackHBox->addWidget(labelTarget);
75  playbackBox->setLayout(playbackHBox);
76  mVerticalLayout->addWidget(playbackBox);
77  mPlaybackSlider->setMinimum(0);
78  mPlaybackSlider->setMaximum(100);
79 
80  // Selectors for virtual endoscope control
81  QGroupBox *endoscopeBox = new QGroupBox(tr("Bronchoscope"));
82  QGridLayout *endoscopeControlLayout = new QGridLayout;
83  QLabel *labelRot = new QLabel(tr("Rotate (360 deg)"));
84  QLabel *labelView = new QLabel(tr("Left/right (+/- 60 deg)"));
85  mRotateDial = new QDial;
86  mRotateDial->setMinimum(-180);
87  mRotateDial->setMaximum(180);
88  mViewDial = new QDial;
89  mViewDial->setMinimum(-60);
90  mViewDial->setMaximum(60);
91  mResetEndoscopeButton = new QPushButton("Reset");
92  mUseAutomaticRotationButton = new QPushButton("Automatic rotation");
94  mAutomaticRotationButtonBackgroundColor.setColor(QPalette::Button, Qt::green);
96 
97  endoscopeControlLayout->addWidget(labelRot,0,0,Qt::AlignHCenter);
98  endoscopeControlLayout->addWidget(labelView,0,2,Qt::AlignHCenter);
99  endoscopeControlLayout->addWidget(mRotateDial,1,0);
100  endoscopeControlLayout->addWidget(mViewDial,1,2);
101  endoscopeControlLayout->addWidget(mResetEndoscopeButton,2,0);
102  endoscopeControlLayout->addWidget(mUseAutomaticRotationButton,3,0);
103  endoscopeBox->setLayout(endoscopeControlLayout);
104  mVerticalLayout->addWidget(endoscopeBox);
105 
106  this->setLayout(mVerticalLayout);
107 
108 
109  this->enableControls(false);
110 
111  mCameraPath = new CXVBcameraPath(services->tracking(), services->patient(), services->view());
112 
114  this, &VBWidget::inputChangedSlot, Qt::UniqueConnection);
116  connect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot);
117  connect(mViewDial, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraViewAngleSlot);
118  connect(mRotateDial, &QDial::valueChanged, mCameraPath, &CXVBcameraPath::cameraRotateAngleSlot);
119  connect(mResetEndoscopeButton, &QPushButton::clicked, this, &VBWidget::resetEndoscopeSlot);
120  connect(mUseAutomaticRotationButton, &QPushButton::clicked, this, &VBWidget::automaticRotationSlot);
121  connect(mCameraPath, &CXVBcameraPath::rotationChanged, this, &VBWidget::updateRotationDialSlot);
122 
123  mVerticalLayout->addStretch();
124 }
125 
127 {
128 }
129 
130 void VBWidget::setRouteToTarget(QString uid)
131 {
132  disconnect(mRouteToTarget.get(), &SelectDataStringPropertyBase::dataChanged, this, &VBWidget::inputChangedSlot);
133  mRouteToTarget->setValue("");
134  connect(mRouteToTarget.get(), &SelectDataStringPropertyBase::dataChanged, this, &VBWidget::inputChangedSlot, Qt::UniqueConnection);
135  mRouteToTarget->setValue(uid);
136 
137  disconnect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot);
138  mPlaybackSlider->setValue(1);
139  connect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot, Qt::UniqueConnection);
140  mPlaybackSlider->setValue(5);
141 }
142 
143 void VBWidget::setRoutePositions(std::vector< Eigen::Vector3d > routePositions)
144 {
145  mCameraPath->setRoutePositions(routePositions);
146 }
147 
148 void VBWidget::setCameraRotationAlongRoute(std::vector< double > cameraRotations)
149 {
150  mCameraPath->setCameraRotations(cameraRotations);
151 }
152 
153 void VBWidget::enableControls(bool enable)
154 {
155  mPlaybackSlider->setEnabled(enable);
156  mRotateDial->setEnabled(enable);
157  mViewDial->setEnabled(enable);
158  mControlsEnabled = enable;
159 }
160 
161 void VBWidget::inputChangedSlot()
162 {
163  this->enableControls(true);
164  emit cameraPathChanged(mRouteToTarget->getMesh());
165 }
166 
167 void VBWidget::keyPressEvent(QKeyEvent* event)
168 {
169  if (event->key()==Qt::Key_Up || event->key()==Qt::Key_8)
170  {
171  if(mControlsEnabled) {
172  int currentPos = mPlaybackSlider->value();
173  mPlaybackSlider->setValue(currentPos+1);
174  return;
175  }
176  }
177 
178  if (event->key()==Qt::Key_Down || event->key()==Qt::Key_2)
179  {
180  if(mControlsEnabled) {
181  int currentPos = mPlaybackSlider->value();
182  mPlaybackSlider->setValue(currentPos-1);
183  return;
184  }
185  }
186 
187  if (event->key()==Qt::Key_Right || event->key()==Qt::Key_6)
188  {
189  if(mControlsEnabled) {
190  int currentPos = mViewDial->value();
191  mViewDial->setValue(currentPos+1);
192  return;
193  }
194  }
195 
196  if (event->key()==Qt::Key_Left || event->key()==Qt::Key_4)
197  {
198  if(mControlsEnabled) {
199  int currentPos = mViewDial->value();
200  mViewDial->setValue(currentPos-1);
201  return;
202  }
203  }
204 
205  if (event->key()==Qt::Key_PageUp || event->key()==Qt::Key_9)
206  {
207  if(mControlsEnabled) {
208  int currentPos = mRotateDial->value();
209  mRotateDial->setValue(currentPos+1);
210  return;
211  }
212  }
213 
214  if (event->key()==Qt::Key_PageDown || event->key()==Qt::Key_3)
215  {
216  if(mControlsEnabled) {
217  int currentPos = mRotateDial->value();
218  mRotateDial->setValue(currentPos-1);
219  return;
220  }
221  }
222 
223  if (event->key()==Qt::Key_5)
224  {
225  if(mControlsEnabled) {
226  this->resetEndoscopeSlot();
227  return;
228  }
229  }
230 
231  // Forward the keyPressevent if not processed
232  QWidget::keyPressEvent(event);
233 }
234 
235 void VBWidget::resetEndoscopeSlot()
236 {
237  mRotateDial->setValue(0);
238  mViewDial->setValue(0);
239 }
240 
241 void VBWidget::automaticRotationSlot()
242 {
246  {
247  mAutomaticRotationButtonBackgroundColor.setColor(QPalette::Button, Qt::green);
249  }
250  else
251  {
252  mAutomaticRotationButtonBackgroundColor.setColor(QPalette::Button, Qt::gray);
254  }
255 }
256 
257 void VBWidget::updateRotationDialSlot(int value)
258 {
259  mRotateDial->setValue(value);
260 }
261 
263 {
264  return "<html>"
265  "<h3>Virtual Bronchoscopy.</h3>"
266  "<p>GUI for visualizing a route-to-target path</p>"
267  "</html>";
268 }
269 
270 
271 
272 } /* namespace cx */
virtual ~VBWidget()
Definition: cxVBWidget.cpp:126
void rotationChanged(int value)
void setAutomaticRotation(bool automaticRotation)
void cameraRawPointsSlot(MeshPtr mesh)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
Helper class for storing variables in the patient file.
VBWidget(VisServicesPtr services, QWidget *parent=0)
Definition: cxVBWidget.cpp:40
void setCameraRotations(std::vector< double > cameraRotations)
QDial * mViewDial
Definition: cxVBWidget.h:59
QPalette mAutomaticRotationButtonBackgroundColor
Definition: cxVBWidget.h:62
PatientStoragePtr mStorage
Definition: cxVBWidget.h:71
void cameraPathPositionSlot(int positionPercentage)
void cameraRotateAngleSlot(int angle)
StringPropertySelectMeshPtr mRouteToTarget
Definition: cxVBWidget.h:64
virtual QString getValue() const
get the data value.
virtual void keyPressEvent(QKeyEvent *event)
Definition: cxVBWidget.cpp:167
QDial * mRotateDial
Definition: cxVBWidget.h:58
void setRouteToTarget(QString uid)
Definition: cxVBWidget.cpp:130
bool mControlsEnabled
Definition: cxVBWidget.h:66
void setCameraRotationAlongRoute(std::vector< double > cameraRotations)
Definition: cxVBWidget.cpp:148
QSlider * mPlaybackSlider
Definition: cxVBWidget.h:57
void cameraViewAngleSlot(int angle)
QPushButton * mUseAutomaticRotationButton
Definition: cxVBWidget.h:61
QString defaultWhatsThis() const
Definition: cxVBWidget.cpp:262
void setRoutePositions(std::vector< Eigen::Vector3d > routePositions)
QVBoxLayout * mVerticalLayout
Definition: cxVBWidget.h:56
void enableControls(bool enable)
Definition: cxVBWidget.cpp:153
CXVBcameraPath * mCameraPath
Definition: cxVBWidget.h:65
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
void setRoutePositions(std::vector< Eigen::Vector3d > routePositions)
Definition: cxVBWidget.cpp:143
QPushButton * mResetEndoscopeButton
Definition: cxVBWidget.h:60
virtual bool setValue(const QString &value)
set the data value.
void cameraPathChanged(MeshPtr pathMesh)
bool mAutomaticRotation
Definition: cxVBWidget.h:67
Namespace for all CustusX production code.