CustusX  22.04-rc5
An IGT application
cxBronchoscopyNavigationWidget.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 #include <QLabel>
35 #include <QVBoxLayout>
36 #include "cxMesh.h"
37 #include "cxDataSelectWidget.h"
38 #include "cxReporter.h"
39 #include <vtkPolyData.h>
41 #include "cxTrackingServiceProxy.h"
43 #include "cxViewServiceProxy.h"
45 #include "cxDoubleProperty.h"
46 #include "cxDataLocations.h"
47 #include "cxBoolProperty.h"
48 #include "cxCheckBoxWidget.h"
49 #include "cxProfile.h"
50 #include "cxHelperWidgets.h"
51 #include "cxVisServices.h"
54 
55 namespace cx
56 {
57 
59  BaseWidget(parent, "bronchoscopy_navigation_widget", "Bronchoscopy Navigation"),
60  mVerticalLayout(new QVBoxLayout(this))
61 {
62  mIsCenerlineProcessed = false;
63 
64  mOptions = profile()->getXmlSettings().descend("bronchoscopynavigationwidget");
65 
66  mPatientModelService = services->patient();
67  mViewService = services->view();
68  mTrackingService = services->tracking();
69 
70 
71  this->setObjectName("BronchoscopyNavigationWidget");
72  this->setWindowTitle("BronchoscopyNavigation");
73  this->setWhatsThis(this->defaultWhatsThis());
74 
75  mToolSelector = StringPropertySelectTool::New(services->tracking());
76 
77  mSelectMeshWidget = StringPropertySelectMesh::New(mPatientModelService);
78  mSelectMeshWidget->setValueName("Centerline: ");
79 
80  mProjectionCenterlinePtr = BronchoscopePositionProjectionPtr(new BronchoscopePositionProjection());
81  mProjectionCenterlinePtr->createMaxDistanceToCenterlineOption(mOptions.getElement());
82  mProjectionCenterlinePtr->createMaxSearchDistanceOption(mOptions.getElement());
83  mProjectionCenterlinePtr->createAlphaOption(mOptions.getElement());
84 
85  mProcessCenterlineButton = new QPushButton("Process centerline");
86  connect(mProcessCenterlineButton, SIGNAL(clicked()), this, SLOT(processCenterlineSlot()));
87  mProcessCenterlineButton->setToolTip(this->defaultWhatsThis());
88 
89  mEnableButton = new QPushButton("Enable", this);
90  connect(mEnableButton, SIGNAL(clicked()), this, SLOT(enableSlot()));
91  mEnableButton->setToolTip(this->defaultWhatsThis());
92 
93  mDisableButton = new QPushButton("Disable", this);
94  connect(mDisableButton, SIGNAL(clicked()), this, SLOT(disableSlot()));
95  mDisableButton->setToolTip(this->defaultWhatsThis());
96 
97  mAdvancedOption = new QCheckBox("Use advanced centerline projection", this);
98  connect(mAdvancedOption, SIGNAL(clicked()), this, SLOT(showAdvancedOptionsSlot()));
99 
100 
101  PropertyPtr maxDistanceToCenterline = mProjectionCenterlinePtr->getMaxDistanceToCenterlineOption();
102  PropertyPtr maxSearchDistance = mProjectionCenterlinePtr->getMaxSearchDistanceOption();
103  PropertyPtr alpha = mProjectionCenterlinePtr->getAlphaOption();
104 
105  mMaxSearchDistanceWidget = createDataWidget(mViewService, mPatientModelService, this, maxSearchDistance);
106  mAlphaWidget = createDataWidget(mViewService, mPatientModelService, this, alpha);
107 
108  mVerticalLayout->addWidget(sscCreateDataWidget(this, mToolSelector));
109  mVerticalLayout->addWidget(new DataSelectWidget(mViewService, mPatientModelService, this, mSelectMeshWidget));
110  mVerticalLayout->addWidget(mProcessCenterlineButton);
111  mVerticalLayout->addWidget(createDataWidget(mViewService, mPatientModelService, this, maxDistanceToCenterline));
112  mVerticalLayout->addWidget(mAdvancedOption);
113 
114  mVerticalLayout->addWidget(mMaxSearchDistanceWidget);
115  mVerticalLayout->addWidget(mAlphaWidget);
116  mVerticalLayout->addWidget(mEnableButton);
117  mVerticalLayout->addWidget(mDisableButton);
118  mVerticalLayout->addWidget(this->createHorizontalLine());
119  mVerticalLayout->addWidget(new VirtualCameraRotationWidget(services, mToolSelector, this));
120  mVerticalLayout->addStretch();
121 
122  mEnableButton->setEnabled(false);
123  mDisableButton->setEnabled(false);
124  this->showAdvancedOptionsSlot();
125 
126 }
127 
129 {
130 }
131 
132 void BronchoscopyNavigationWidget::processCenterlineSlot()
133 {
134  if(!mSelectMeshWidget->getMesh())
135  {
136  reportError("No centerline");
137  return;
138  }
139  vtkPolyDataPtr centerline = mSelectMeshWidget->getMesh()->getVtkPolyData();//input
140  Transform3D rMd = mSelectMeshWidget->getMesh()->get_rMd();
141  Transform3D rMpr = mPatientModelService->get_rMpr();
142  Transform3D prMd = rMpr.inverse()*rMd;
143 
144  mProjectionCenterlinePtr->processCenterline(centerline, rMd, rMpr);
145  mIsCenerlineProcessed = true;
146  mEnableButton->setEnabled(true);
147 }
148 
149 void BronchoscopyNavigationWidget::enableSlot()
150 {
151  if(!mIsCenerlineProcessed)
152  {
153  reportError("Centerline not processed");
154  return;
155  }
156 
157  if(!mToolSelector->getTool())
158  {
159  reportError("Tool not selected");
160  return;
161  }
162 
163 
164  mProjectionCenterlinePtr->setAdvancedCenterlineOption(mAdvancedOption->isChecked());
165  if (!mTrackingSystem)
166  {
167 // std::vector<TrackingSystemServicePtr> trackingSystems = mTrackingService->getTrackingSystems();
168 // for (int i=0; i<trackingSystems.size(); i++ )
169 // if(trackingSystems[i]->getUid() == "org.custusx.bronchoscopynavigation")
170 // mTrackingSystem = trackingSystems[i];
171 // if(!mTrackingService)
172 // CX_LOG_WARNING() << "Did not find bronchoscopy navigation tracking system.";
173 
174  mTrackingSystem = TrackingSystemBronchoscopyServicePtr(new TrackingSystemBronchoscopyService(mTrackingService, mProjectionCenterlinePtr, mToolSelector->getTool()));
175  mTrackingService->unInstallTrackingSystem(mTrackingSystem->getBase());
176  mTrackingService->installTrackingSystem(mTrackingSystem);
177  }
178  mEnableButton->setEnabled(false);
179  mDisableButton->setEnabled(true);
180 
181  std::cout << "BronchoscopyNavigation started. Position locked to centerline." << std::endl;
182 }
183 
184 void BronchoscopyNavigationWidget::disableSlot()
185 {
186  if (mTrackingSystem)
187  {
188  mTrackingService->unInstallTrackingSystem(mTrackingSystem);
189  mTrackingService->installTrackingSystem(mTrackingSystem->getBase());
190  mTrackingSystem.reset();
191  }
192 
193  std::cout << "BronchoscopyNavigation stopped." << std::endl;
194  mEnableButton->setEnabled(true);
195  mDisableButton->setEnabled(false);
196 
197 }
198 
199 
200 void BronchoscopyNavigationWidget::showAdvancedOptionsSlot()
201 {
202  if(mAdvancedOption->isChecked())
203  {
204  mMaxSearchDistanceWidget->show();
205  mAlphaWidget->show();
206  }
207  else{
208  mMaxSearchDistanceWidget->hide();
209  mAlphaWidget->hide();
210  }
211 }
212 
213 QString BronchoscopyNavigationWidget::defaultWhatsThis() const
214 {
215  return "<html>"
216  "<h3>BronchoscopyNavigation plugin.</h3>"
217  "<p>Locks tool position to CT centerline.</p>"
218  "</html>";
219 }
220 
221 
222 } /* namespace cx */
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
void reportError(QString msg)
Definition: cxLogger.cpp:71
boost::shared_ptr< class VisServices > VisServicesPtr
Definition: cxMainWindow.h:40
Interface towards a bronchoscopy navigation tracking system.Wraps another tracking system...
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
QDomElement getElement()
return the current element
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
boost::shared_ptr< class Property > PropertyPtr
static QFrame * createHorizontalLine()
Creates a horizontal line which can be inserted into widgets.
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Interface for QWidget which handles widgets uniformly for the system.
Definition: cxBaseWidget.h:88
static StringPropertySelectToolPtr New(TrackingServicePtr trackingService)
QWidget * sscCreateDataWidget(QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
boost::shared_ptr< class TrackingSystemBronchoscopyService > TrackingSystemBronchoscopyServicePtr
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class BronchoscopePositionProjection > BronchoscopePositionProjectionPtr
BronchoscopyNavigationWidget(VisServicesPtr services, QWidget *parent=0)
Namespace for all CustusX production code.