NorMIT-nav  22.09
An IGT application
cxBronchoscopyRegistrationWidget.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 
13 #include <vtkPolyData.h>
14 #include "cxTransform3D.h"
15 #include "cxDataSelectWidget.h"
16 #include "cxTrackingService.h"
17 #include "cxMesh.h"
19 #include "cxRecordSessionWidget.h"
20 #include "cxRecordSession.h"
21 #include "cxView.h"
22 #include "cxToolRep3D.h"
23 #include "cxToolTracer.h"
25 #include "cxLogger.h"
26 #include "cxTypeConversions.h"
27 #include "cxPatientModelService.h"
28 #include "cxRegistrationService.h"
29 #include "cxViewService.h"
30 #include "cxStringProperty.h"
32 #include "cxTrackingService.h"
33 #include "cxDoubleProperty.h"
34 #include "cxProfile.h"
35 #include "cxHelperWidgets.h"
36 #include "cxBoolProperty.h"
37 #include "cxCheckBoxWidget.h"
38 #include "cxRepContainer.h"
40 #include "cxViewGroupData.h"
42 #include "cxHelperWidgets.h"
43 #include "cxAcquisitionService.h"
44 #include "cxRegServices.h"
45 #include "cxRecordTrackingWidget.h"
46 
47 
48 namespace cx
49 {
51  RegistrationBaseWidget(services, parent, "org_custusx_registration_method_bronchoscopy_widget",
52  "Bronchoscopy Registration"),
53  mBronchoscopyRegistration(new BronchoscopyRegistration()),
54  mServices(services),
55  mRecordTrackingWidget(NULL)
56 {
57  mVerticalLayout = new QVBoxLayout(this);
58 }
59 
61 {
62  if (!mRecordTrackingWidget)
63  {
64  this->setup();
65  }
66 }
67 
68 void BronchoscopyRegistrationWidget::setup()
69 {
70  mOptions = profile()->getXmlSettings().descend("bronchoscopyregistrationwidget");
71 
72  mSelectMeshWidget = StringPropertySelectMesh::New(mServices->patient());
73  mSelectMeshWidget->setValueName("Centerline: ");
74 
75  //this->initializeTrackingService();
76 
77  connect(mServices->patient().get(),&PatientModelService::patientChanged,this,&BronchoscopyRegistrationWidget::clearDataOnNewPatient);
78 
79  mProcessCenterlineButton = new QPushButton("Process centerline");
80  connect(mProcessCenterlineButton, SIGNAL(clicked()), this, SLOT(processCenterlineSlot()));
81  mProcessCenterlineButton->setToolTip(this->defaultWhatsThis());
82 
83  // mBronchoscopeRegistrationPtr = BronchoscopeRegistrationPtr(new BronchoscopePositionProjection());
84  // mProjectionCenterlinePtr->createMaxDistanceToCenterlineOption(mOptions.getElement());
85 
86  mRegisterButton = new QPushButton("Register");
87  connect(mRegisterButton, SIGNAL(clicked()), this, SLOT(registerSlot()));
88  mRegisterButton->setToolTip(this->defaultWhatsThis());
89 
90  mRecordTrackingWidget = new RecordTrackingWidget(mOptions.descend("recordTracker"),
91  mServices->acquisition(), mServices,
92  "bronc_path",
93  this);
94  mRecordTrackingWidget->getSessionSelector()->setHelp("Select bronchoscope path for registration");
95  mRecordTrackingWidget->getSessionSelector()->setDisplayName("Bronchoscope path");
96 
97  mVerticalLayout->setMargin(0);
98  mVerticalLayout->addWidget(new DataSelectWidget(mServices->view(), mServices->patient(), this, mSelectMeshWidget));
99 
100  this->selectSubsetOfBranches(mOptions.getElement());
101  this->createMaxNumberOfGenerations(mOptions.getElement());
102  this->useLocalRegistration(mOptions.getElement());
103  this->createMaxLocalRegistrationDistance(mOptions.getElement());
104 
105  // PropertyPtr maxLocalRegistrationDistance = mProjectionCenterlinePtr->getMaxLocalRegistrationDistanceOption();
106 
107  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseSubsetOfGenerations));
108  mVerticalLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), this, mMaxNumberOfGenerations));
109  mVerticalLayout->addWidget(mProcessCenterlineButton);
110  mVerticalLayout->addWidget(mRecordTrackingWidget);
111  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseLocalRegistration));
112  mVerticalLayout->addWidget(createDataWidget(mServices->view(), mServices->patient(), this, mMaxLocalRegistrationDistance));
113  mVerticalLayout->addWidget(mRegisterButton);
114 
115  mVerticalLayout->addStretch();
116 }
117 
119 {
120  return QString();
121 }
122 
123 void BronchoscopyRegistrationWidget::initializeTrackingService()
124 {
125  if(mServices->tracking()->getState() < Tool::tsCONFIGURED)
126  mServices->tracking()->setState(Tool::tsCONFIGURED);
127 }
128 
129 void BronchoscopyRegistrationWidget::processCenterlineSlot()
130 {
131  this->initializeTrackingService();
132 
133  if(!mSelectMeshWidget->getMesh())
134  {
135  reportError("No centerline");
136  return;
137  }
138  vtkPolyDataPtr centerline = mSelectMeshWidget->getMesh()->getVtkPolyData();//input
139  Transform3D rMd = mSelectMeshWidget->getMesh()->get_rMd();
140  vtkPolyDataPtr processedCenterline;
141  if (mUseSubsetOfGenerations->getValue())
142  processedCenterline = mBronchoscopyRegistration->processCenterline(centerline, rMd, mMaxNumberOfGenerations->getValue());
143  else
144  processedCenterline = mBronchoscopyRegistration->processCenterline(centerline, rMd);
145 
146  if (!mMesh)
147  {
148  QString uid = mSelectMeshWidget->getMesh()->getUid() + "_cl%1";
149  QString name = mSelectMeshWidget->getMesh()->getName()+" cl_processed%1";
150  std::cout << "name: " << name << std::endl;
151  std::cout << "uid: " << uid << std::endl;
152  mMesh = mServices->patient()->createSpecificData<Mesh>(uid, name);
153  }
154  mMesh->setVtkPolyData(processedCenterline);
155  mMesh->setColor(QColor(0, 0, 255, 255));
156  mServices->patient()->insertData(mMesh);
157  mServices->view()->autoShowData(mMesh);
158 }
159 
160 void BronchoscopyRegistrationWidget::registerSlot()
161 {
162  if(!mBronchoscopyRegistration->isCenterlineProcessed())
163  {
164  reportError("Centerline not processed");
165  return;
166  }
167 
168  Transform3D old_rMpr = mServices->patient()->get_rMpr();//input to registrationAlgorithm
169  //std::cout << "rMpr: " << std::endl;
170  //std::cout << old_rMpr << std::endl;
171 
172  TimedTransformMap trackerRecordedData_prMt = mRecordTrackingWidget->getRecordedTrackerData_prMt();
173 
174  if(trackerRecordedData_prMt.empty())
175  {
176  reportError("No positions");
177  return;
178  }
179 
180  Transform3D new_rMpr;
181 
182  if(mUseLocalRegistration->getValue()){
183  std::cout << "Running local registration with max distance " << mMaxLocalRegistrationDistance->getValue() << " mm." << std::endl;
184  new_rMpr = Transform3D(mBronchoscopyRegistration->runBronchoscopyRegistration(trackerRecordedData_prMt,old_rMpr,mMaxLocalRegistrationDistance->getValue()));
185  }
186  else{
187  std::cout << "Running global registration." << std::endl;
188  new_rMpr = Transform3D(mBronchoscopyRegistration->runBronchoscopyRegistration(trackerRecordedData_prMt,old_rMpr,0));
189  }
190 
191  new_rMpr = new_rMpr*old_rMpr;//output
192  mServices->registration()->addPatientRegistration(new_rMpr, "Bronchoscopy centerline to tracking data");
193 
194  Eigen::Matrix4d display_rMpr = Eigen::Matrix4d::Identity();
195  display_rMpr = new_rMpr*display_rMpr;
196  std::cout << "New prMt: " << std::endl;
197  for (int i = 0; i < 4; i++)
198  std::cout << display_rMpr.row(i) << std::endl;
199 
200  // mRecordTrackingWidget->showSelectedRecordingInView();
201 
202 }
203 
204 void BronchoscopyRegistrationWidget::createMaxNumberOfGenerations(QDomElement root)
205 {
206  mMaxNumberOfGenerations = DoubleProperty::initialize("Max number of generations in centerline", "",
207  "Set max number of generations centerline", 4, DoubleRange(0, 10, 1), 0,
208  root);
209  mMaxNumberOfGenerations->setGuiRepresentation(DoublePropertyBase::grSLIDER);
210 }
211 
212 void BronchoscopyRegistrationWidget::selectSubsetOfBranches(QDomElement root)
213 {
214  mUseSubsetOfGenerations = BoolProperty::initialize("Select branch generations to be used in registration", "",
215  "Select branch generations to be used in registration", false,
216  root);
217 }
218 
219 void BronchoscopyRegistrationWidget::useLocalRegistration(QDomElement root)
220 {
221  mUseLocalRegistration = BoolProperty::initialize("Use local registration", "",
222  "Use local registration", false,
223  root);
224 }
225 
226 void BronchoscopyRegistrationWidget::createMaxLocalRegistrationDistance(QDomElement root)
227 {
228  mMaxLocalRegistrationDistance = DoubleProperty::initialize("Max local registration distance (mm)", "",
229  "Set max distance for local registration in mm", 30, DoubleRange(1, 200, 1), 0,
230  root);
231  mMaxLocalRegistrationDistance->setGuiRepresentation(DoubleProperty::grSLIDER);
232 }
233 
234 void BronchoscopyRegistrationWidget::clearDataOnNewPatient()
235 {
236  mMesh.reset();
237 }
238 } //namespace cx
cx::BoolProperty::initialize
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
Definition: cxBoolProperty.cpp:30
cx::createDataWidget
QWidget * createDataWidget(ViewServicePtr viewService, PatientModelServicePtr patientModelService, QWidget *parent, PropertyPtr data, QGridLayout *gridLayout, int row)
Create a widget capable of displaying the input data.
Definition: cxHelperWidgets.cpp:41
cxBronchoscopyRegistrationWidget.h
cx::StringPropertySelectMesh::New
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
Definition: cxSelectDataStringProperty.h:131
cxLogger.h
cxAcquisitionService.h
cx::BronchoscopyRegistrationWidget::BronchoscopyRegistrationWidget
BronchoscopyRegistrationWidget(RegServicesPtr services, QWidget *parent)
Definition: cxBronchoscopyRegistrationWidget.cpp:50
cx::RecordTrackingWidget::getSessionSelector
StringPropertyPtr getSessionSelector()
Definition: cxRecordTrackingWidget.cpp:80
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxCheckBoxWidget.h
cxToolTracer.h
cx::RecordTrackingWidget
Definition: cxRecordTrackingWidget.h:42
cx::PatientModelService::patientChanged
void patientChanged()
cxToolRep3D.h
cx::XmlOptionFile::descend
XmlOptionFile descend(QString element) const
step one level down in the xml tree
Definition: cxXmlOptionItem.cpp:271
cxLabeledComboBoxWidget.h
cxViewGroupData.h
cx::BronchoscopyRegistration
Definition: cxBronchoscopyRegistration.h:28
cxDoubleProperty.h
cx::RegistrationBaseWidget
Definition: cxRegistrationBaseWidget.h:28
cx::DoublePropertyBase::grSLIDER
@ grSLIDER
Definition: cxDoublePropertyBase.h:81
cx::RecordTrackingWidget::getRecordedTrackerData_prMt
TimedTransformMap getRecordedTrackerData_prMt()
Definition: cxRecordTrackingWidget.cpp:202
cxHelperWidgets.h
cxStringPropertySelectTool.h
vtkPolyDataPtr
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
Definition: cxAirwaysFilterService.h:35
cx::DoubleProperty::initialize
static DoublePropertyPtr initialize(const QString &uid, QString name, QString help, double value, DoubleRange range, int decimals, QDomNode root=QDomNode())
Definition: cxDoubleProperty.cpp:30
cxProfile.h
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::BronchoscopyRegistrationWidget::prePaintEvent
virtual void prePaintEvent()
Definition: cxBronchoscopyRegistrationWidget.cpp:60
cxViewService.h
cx::XmlOptionFile::getElement
QDomElement getElement()
return the current element
Definition: cxXmlOptionItem.cpp:365
cx::TimedTransformMap
std::map< double, Transform3D > TimedTransformMap
Definition: cxRecordSession.h:36
cx::CheckBoxWidget
Widget for the BoolPropertyBase.
Definition: cxCheckBoxWidget.h:41
cxWidgetObscuredListener.h
cxRepContainer.h
cxTypeConversions.h
cxView.h
cxPatientModelService.h
cx::BronchoscopyRegistrationWidget::defaultWhatsThis
virtual QString defaultWhatsThis() const
Definition: cxBronchoscopyRegistrationWidget.cpp:118
cx::RegServicesPtr
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:20
cx::Tool::tsCONFIGURED
@ tsCONFIGURED
configured with basic info
Definition: cxTool.h:75
cx::profile
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
cxDataSelectWidget.h
cxRecordTrackingWidget.h
cxRecordSession.h
cxRegistrationService.h
cxStringProperty.h
cxSelectDataStringProperty.h
cx::DataSelectWidget
Definition: cxDataSelectWidget.h:38
cxTransform3D.h
cxRecordSessionWidget.h
cxBoolProperty.h
cxRegServices.h
cxBronchoscopyRegistration.h
cx::reportError
void reportError(QString msg)
Definition: cxLogger.cpp:71
cxMesh.h
cxTrackingService.h