CustusX  22.04-rc5
An IGT application
cxBronchoscopyImage2ImageRegistrationWidget.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 =========================================================================*/
12 #include <vtkPolyData.h>
13 #include "cxTransform3D.h"
14 #include "cxDataSelectWidget.h"
15 #include "cxMesh.h"
17 #include "cxView.h"
19 #include "cxLogger.h"
20 #include "cxTypeConversions.h"
21 #include "cxPatientModelService.h"
22 #include "cxRegistrationService.h"
23 #include "cxViewService.h"
24 #include "cxStringProperty.h"
26 #include "cxDoubleProperty.h"
27 #include "cxProfile.h"
28 #include "cxHelperWidgets.h"
29 #include "cxBoolProperty.h"
31 #include "cxViewGroupData.h"
32 #include "cxHelperWidgets.h"
33 #include "cxRegServices.h"
34 
35 namespace cx
36 {
38  RegistrationBaseWidget(services, parent, "org_custusx_registration_method_bronchoscopy_image2image_widget",
39  "Bronchoscopy Registration"),
40  mBronchoscopyRegistration(new BronchoscopyRegistration())
41 {
42  mVerticalLayout = new QVBoxLayout(this);
43 }
44 
46 {
47  this->setup();
48 }
49 
50 void BronchoscopyImage2ImageRegistrationWidget::setup()
51 {
52  mOptions = profile()->getXmlSettings().descend("bronchoscopyregistrationimage2imagewidget");
53 
54  mSelectMeshFixedWidget = StringPropertySelectMesh::New(mServices->patient());
55  mSelectMeshFixedWidget->setValueName("Centerline fixed image: ");
56 
57  mSelectMeshMovingWidget = StringPropertySelectMesh::New(mServices->patient());
58  mSelectMeshMovingWidget->setValueName("Centerline moving image: ");
59 
60  connect(mServices->patient().get(),&PatientModelService::patientChanged,this,&BronchoscopyImage2ImageRegistrationWidget::clearDataOnNewPatient);
61 
62  mRegisterButton = new QPushButton("Register");
63  connect(mRegisterButton, SIGNAL(clicked()), this, SLOT(registerSlot()));
64  mRegisterButton->setToolTip(this->defaultWhatsThis());
65 
66  mVerticalLayout->setMargin(0);
67  mVerticalLayout->addWidget(new DataSelectWidget(mServices->view(), mServices->patient(), this, mSelectMeshFixedWidget));
68  mVerticalLayout->addWidget(new DataSelectWidget(mServices->view(), mServices->patient(), this, mSelectMeshMovingWidget));
69 
70  mVerticalLayout->addWidget(mRegisterButton);
71 
72  mVerticalLayout->addStretch();
73 }
74 
76 {
77  return QString("Registration of CT images based on airway centerlines");
78 }
79 
80 void BronchoscopyImage2ImageRegistrationWidget::registerSlot()
81 {
82 
83  if(!mSelectMeshFixedWidget->getMesh())
84  {
85  reportError("Fixed centerline missing");
86  return;
87  }
88  if(!mSelectMeshMovingWidget->getMesh())
89  {
90  reportError("Moving centerline missing");
91  return;
92  }
93 
94  vtkPolyDataPtr centerlineFixed = mSelectMeshFixedWidget->getMesh()->getVtkPolyData();//input
95  Transform3D rMdFixed = mSelectMeshFixedWidget->getMesh()->get_rMd();
96 
97  vtkPolyDataPtr centerlineMoving = mSelectMeshMovingWidget->getMesh()->getVtkPolyData();//input
98  Transform3D rMdMoving = mSelectMeshMovingWidget->getMesh()->get_rMd();
99 
100  Transform3D d_M_d = Transform3D(mBronchoscopyRegistration->runBronchoscopyRegistrationImage2Image(centerlineFixed, centerlineMoving));
101 
102  DataPtr fixedData = mSelectMeshFixedWidget->getData();
103  mServices->registration()->setFixedData(fixedData);
104  DataPtr movingData = mSelectMeshMovingWidget->getData();
105  mServices->registration()->setMovingData(movingData);
106 
107  Transform3D delta_pre_rMd = rMdFixed * d_M_d * rMdMoving.inv();//output
108  mServices->registration()->addImage2ImageRegistration(delta_pre_rMd, "Bronchoscopy: centerline to centerline");
109 }
110 
111 void BronchoscopyImage2ImageRegistrationWidget::clearDataOnNewPatient()
112 {
113  mMeshFixed.reset();
114  mMeshMoving.reset();
115 }
116 
117 } //namespace cx
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:160
void reportError(QString msg)
Definition: cxLogger.cpp:71
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
boost::shared_ptr< class Data > DataPtr
BronchoscopyImage2ImageRegistrationWidget(RegServicesPtr services, QWidget *parent)
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:20
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
Namespace for all CustusX production code.