Fraxinus  17.12
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) 2008-2017, 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 <vtkPolyData.h>
35 #include "cxTransform3D.h"
36 #include "cxDataSelectWidget.h"
37 #include "cxMesh.h"
39 #include "cxView.h"
41 #include "cxLogger.h"
42 #include "cxTypeConversions.h"
43 #include "cxPatientModelService.h"
44 #include "cxRegistrationService.h"
45 #include "cxViewService.h"
46 #include "cxStringProperty.h"
48 #include "cxDoubleProperty.h"
49 #include "cxProfile.h"
50 #include "cxHelperWidgets.h"
51 #include "cxBoolProperty.h"
53 #include "cxViewGroupData.h"
54 #include "cxHelperWidgets.h"
55 #include "cxRegServices.h"
56 
57 namespace cx
58 {
60  RegistrationBaseWidget(services, parent, "org_custusx_registration_method_bronchoscopy_image2image_widget",
61  "Bronchoscopy Registration"),
62  mBronchoscopyRegistration(new BronchoscopyRegistration())
63 {
64  mVerticalLayout = new QVBoxLayout(this);
65 }
66 
68 {
69  this->setup();
70 }
71 
72 void BronchoscopyImage2ImageRegistrationWidget::setup()
73 {
74  mOptions = profile()->getXmlSettings().descend("bronchoscopyregistrationimage2imagewidget");
75 
76  mSelectMeshFixedWidget = StringPropertySelectMesh::New(mServices->patient());
77  mSelectMeshFixedWidget->setValueName("Centerline fixed image: ");
78 
79  mSelectMeshMovingWidget = StringPropertySelectMesh::New(mServices->patient());
80  mSelectMeshMovingWidget->setValueName("Centerline moving image: ");
81 
82  connect(mServices->patient().get(),&PatientModelService::patientChanged,this,&BronchoscopyImage2ImageRegistrationWidget::clearDataOnNewPatient);
83 
84  mRegisterButton = new QPushButton("Register");
85  connect(mRegisterButton, SIGNAL(clicked()), this, SLOT(registerSlot()));
86  mRegisterButton->setToolTip(this->defaultWhatsThis());
87 
88  mVerticalLayout->setMargin(0);
89  mVerticalLayout->addWidget(new DataSelectWidget(mServices->view(), mServices->patient(), this, mSelectMeshFixedWidget));
90  mVerticalLayout->addWidget(new DataSelectWidget(mServices->view(), mServices->patient(), this, mSelectMeshMovingWidget));
91 
92  mVerticalLayout->addWidget(mRegisterButton);
93 
94  mVerticalLayout->addStretch();
95 }
96 
98 {
99  return QString("Registration of CT images based on airway centerlines");
100 }
101 
102 void BronchoscopyImage2ImageRegistrationWidget::registerSlot()
103 {
104 
105  if(!mSelectMeshFixedWidget->getMesh())
106  {
107  reportError("Fixed centerline missing");
108  return;
109  }
110  if(!mSelectMeshMovingWidget->getMesh())
111  {
112  reportError("Moving centerline missing");
113  return;
114  }
115 
116  vtkPolyDataPtr centerlineFixed = mSelectMeshFixedWidget->getMesh()->getVtkPolyData();//input
117  Transform3D rMdFixed = mSelectMeshFixedWidget->getMesh()->get_rMd();
118 
119  vtkPolyDataPtr centerlineMoving = mSelectMeshMovingWidget->getMesh()->getVtkPolyData();//input
120  Transform3D rMdMoving = mSelectMeshMovingWidget->getMesh()->get_rMd();
121 
122  Transform3D updated_rMdMoving = Transform3D(mBronchoscopyRegistration->runBronchoscopyRegistrationImage2Image(centerlineFixed, centerlineMoving));
123 
124  DataPtr fixedData = mSelectMeshFixedWidget->getData();
125  mServices->registration()->setFixedData(fixedData);
126  DataPtr movingData = mSelectMeshMovingWidget->getData();
127  mServices->registration()->setMovingData(movingData);
128 
129  Transform3D new_rMdMoving = updated_rMdMoving * rMdMoving.inv();//output
130  mServices->registration()->addImage2ImageRegistration(new_rMdMoving, "Bronchoscopy: centerline to centerline");
131 }
132 
133 void BronchoscopyImage2ImageRegistrationWidget::clearDataOnNewPatient()
134 {
135  mMeshFixed.reset();
136  mMeshMoving.reset();
137 }
138 
139 } //namespace cx
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:181
void reportError(QString msg)
Definition: cxLogger.cpp:92
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:41
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
Namespace for all CustusX production code.