Fraxinus  16.5.0-fx-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 
33 #include <QLabel>
34 #include <QHBoxLayout>
35 #include <QVBoxLayout>
36 #include <QGroupBox>
37 #include <QSlider>
38 #include <QSpinBox>
39 #include <QGridLayout>
40 #include <QLabel>
41 #include <QDial>
42 
43 #include "cxVBWidget.h"
45 #include "cxViewServiceProxy.h"
46 #include "cxDataSelectWidget.h"
47 #include "cxTrackingServiceProxy.h"
48 #include "cxView.h"
50 #include "cxPatientStorage.h"
51 #include "cxVisServices.h"
52 #include "cxLogger.h"
53 
54 
55 
56 namespace cx
57 {
58 
59 VBWidget::VBWidget(VisServicesPtr services, QWidget *parent) :
60  QWidget(parent),
61  mVerticalLayout(new QVBoxLayout(this)),
62  mControlsEnabled(false),
63  mStorage(new PatientStorage(services->session(), "VirtualBronchoscopy"))
64 {
65  this->setObjectName("Virtual Bronchoscopy Widget");
66  this->setWindowTitle("Virtual Bronchoscopy");
67  this->setWhatsThis(this->defaultWhatsThis());
68 
69  this->setFocusPolicy(Qt::StrongFocus); // Widget needs focus to handle Key events
70 
71  mRouteToTarget = StringPropertySelectMesh::New(services->patient());
72  mRouteToTarget->setValueName("Route to target path: ");
73  mStorage->storeVariable("routeToTarget",
74  boost::bind(&StringPropertySelectMesh::getValue, mRouteToTarget),
75  boost::bind(&StringPropertySelectMesh::setValue, mRouteToTarget, _1));
76 
77  // Selector for route to target
78  QVBoxLayout *inputVbox = new QVBoxLayout;
79  inputVbox->addWidget(new DataSelectWidget(services->view(), services->patient(), this,mRouteToTarget));
80  QGroupBox *inputBox = new QGroupBox(tr("Input"));
81  inputBox->setLayout(inputVbox);
82  mVerticalLayout->addWidget(inputBox);
83 
84  // Selectors for position along path and play/pause
85  QHBoxLayout *playbackHBox = new QHBoxLayout;
86  QGroupBox *playbackBox = new QGroupBox(tr("Playback"));
87  mPlaybackSlider = new QSlider(Qt::Horizontal);
88  QLabel *labelStart = new QLabel(tr("Start "));
89  QLabel *labelTarget = new QLabel(tr(" Target"));
90  playbackHBox->addWidget(labelStart);
91  playbackHBox->addWidget(mPlaybackSlider);
92  playbackHBox->addWidget(labelTarget);
93  playbackBox->setLayout(playbackHBox);
94  mVerticalLayout->addWidget(playbackBox);
95  mPlaybackSlider->setMinimum(0);
96  mPlaybackSlider->setMaximum(100);
97 
98  // Selectors for virtual endoscope control
99  QGroupBox *endoscopeBox = new QGroupBox(tr("Endoscope"));
100  QGridLayout *endoscopeControlLayout = new QGridLayout;
101  QLabel *labelRot = new QLabel(tr("Rotate"));
102  QLabel *labelView = new QLabel(tr("Left/right (30 deg)"));
103  mRotateDial = new QDial;
104  mRotateDial->setMinimum(-180);
105  mRotateDial->setMaximum(180);
106  mViewSlider = new QDial;
107  mViewSlider->setMinimum(-30);
108  mViewSlider->setMaximum(30);
109 
110 
111  endoscopeControlLayout->addWidget(labelRot,0,0,Qt::AlignHCenter);
112  endoscopeControlLayout->addWidget(labelView,0,2,Qt::AlignHCenter);
113  endoscopeControlLayout->addWidget(mRotateDial,1,0);
114  endoscopeControlLayout->addWidget(mViewSlider,1,2);
115  endoscopeBox->setLayout(endoscopeControlLayout);
116  mVerticalLayout->addWidget(endoscopeBox);
117 
118  this->setLayout(mVerticalLayout);
119 
120 
121  this->enableControls(false);
122 
123  mCameraPath = new CXVBcameraPath(services->tracking(), services->patient(), services->view());
124 
125  connect(mRouteToTarget.get(), &SelectDataStringPropertyBase::dataChanged,
126  this, &VBWidget::inputChangedSlot);
128  connect(mPlaybackSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraPathPositionSlot);
129  connect(mViewSlider, &QSlider::valueChanged, mCameraPath, &CXVBcameraPath::cameraViewAngleSlot);
130  connect(mRotateDial, &QDial::valueChanged, mCameraPath, &CXVBcameraPath::cameraRotateAngleSlot);
131 
132  mVerticalLayout->addStretch();
133 }
134 
136 {
137 }
138 
139 void VBWidget::setRouteToTarget(QString uid)
140 {
141  mRouteToTarget->setValue(uid);
142  mPlaybackSlider->setValue(5);
143 }
144 
145 void VBWidget::enableControls(bool enable)
146 {
147  mPlaybackSlider->setEnabled(enable);
148  mRotateDial->setEnabled(enable);
149  mViewSlider->setEnabled(enable);
150  mControlsEnabled = enable;
151 }
152 
153 void VBWidget::inputChangedSlot()
154 {
155  this->enableControls(true);
156  emit cameraPathChanged(mRouteToTarget->getMesh());
157 }
158 
159 void VBWidget::keyPressEvent(QKeyEvent* event)
160 {
161 
162  if (event->key()==Qt::Key_Up)
163  {
164  if(mControlsEnabled) {
165  int currentPos = mPlaybackSlider->value();
166  mPlaybackSlider->setValue(currentPos+1);
167  return;
168  }
169  }
170 
171  if (event->key()==Qt::Key_Down)
172  {
173  if(mControlsEnabled) {
174  int currentPos = mPlaybackSlider->value();
175  mPlaybackSlider->setValue(currentPos-1);
176  return;
177  }
178  }
179 
180  if (event->key()==Qt::Key_Right)
181  {
182  if(mControlsEnabled) {
183  int currentPos = mViewSlider->value();
184  mViewSlider->setValue(currentPos+1);
185  return;
186  }
187  }
188 
189  if (event->key()==Qt::Key_Left)
190  {
191  if(mControlsEnabled) {
192  int currentPos = mViewSlider->value();
193  mViewSlider->setValue(currentPos-1);
194  return;
195  }
196  }
197 
198  // Forward the keyPressevent if not processed
199  QWidget::keyPressEvent(event);
200 }
201 
202 QString VBWidget::defaultWhatsThis() const
203 {
204  return "<html>"
205  "<h3>Virtual Bronchoscopy.</h3>"
206  "<p>GUI for visualizing a route-to-target path</p>"
207  "</html>";
208 }
209 
210 
211 
212 } /* namespace cx */
virtual ~VBWidget()
Definition: cxVBWidget.cpp:135
void cameraRawPointsSlot(MeshPtr mesh)
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:62
Helper class for storing variables in the patient file.
VBWidget(VisServicesPtr services, QWidget *parent=0)
Definition: cxVBWidget.cpp:59
void cameraRotateAngleSlot(int angle)
virtual QString getValue() const
get the data value.
void setRouteToTarget(QString uid)
Definition: cxVBWidget.cpp:139
void cameraViewAngleSlot(int angle)
void cameraPathPositionSlot(int pos)
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
virtual bool setValue(const QString &value)
set the data value.
void cameraPathChanged(MeshPtr pathMesh)