NorMIT-nav  22.09
An IGT application
cxCenterlineRegistrationWidget.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 
14 #include <vtkPolyData.h>
15 #include "cxTransform3D.h"
16 #include "cxDataSelectWidget.h"
17 #include "cxTrackingService.h"
18 #include "cxMesh.h"
20 #include "cxRecordSessionWidget.h"
21 #include "cxRecordSession.h"
22 #include "cxView.h"
23 #include "cxToolRep3D.h"
24 #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_centerline_widget",
52  "Centerline Registration"),
53  mServices(services),
54  mRecordTrackingWidget(NULL)
55 {
56  mVerticalLayout = new QVBoxLayout(this);
57 }
58 
60 {
61  if (!mRecordTrackingWidget)
62  {
63  this->setup();
64  }
65 }
66 
67 void CenterlineRegistrationWidget::setup()
68 {
69  mOptions = profile()->getXmlSettings().descend("centerlineregistrationwidget");
70 
71  mSelectMeshWidget = StringPropertySelectMesh::New(mServices->patient());
72  mSelectMeshWidget->setValueName("Centerline: ");
73 
74  mCenterlineRegistration = CenterlineRegistrationPtr(new CenterlineRegistration());
75 
76  connect(mServices->patient().get(),&PatientModelService::patientChanged,this,&CenterlineRegistrationWidget::clearDataOnNewPatient);
77 
78 
79  mRegisterButton = new QPushButton("Register");
80  connect(mRegisterButton, SIGNAL(clicked()), this, SLOT(registerSlot()));
81  mRegisterButton->setToolTip(this->defaultWhatsThis());
82 
83  mRecordTrackingWidget = new RecordTrackingWidget(mOptions.descend("recordTracker"),
84  mServices->acquisition(), mServices,
85  "bronc_path",
86  this);
87  mRecordTrackingWidget->getSessionSelector()->setHelp("Select tool path for registration");
88  mRecordTrackingWidget->getSessionSelector()->setDisplayName("Tool path");
89 
90  mVerticalLayout->setMargin(0);
91  mVerticalLayout->addWidget(new DataSelectWidget(mServices->view(), mServices->patient(), this, mSelectMeshWidget));
92 
93  this->selectXtranslation(mOptions.getElement());
94  this->selectYtranslation(mOptions.getElement());
95  this->selectZtranslation(mOptions.getElement());
96  this->selectXrotation(mOptions.getElement());
97  this->selectYrotation(mOptions.getElement());
98  this->selectZrotation(mOptions.getElement());
99 
100  mVerticalLayout->addWidget(mRecordTrackingWidget);
101  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseXtranslation));
102  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseYtranslation));
103  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseZtranslation));
104  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseXrotation));
105  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseYrotation));
106  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseZrotation));
107  mVerticalLayout->addWidget(mRegisterButton);
108 
109  mVerticalLayout->addStretch();
110 }
111 
113 {
114  return QString();
115 }
116 
117 void CenterlineRegistrationWidget::initializeTrackingService()
118 {
119  if(mServices->tracking()->getState() < Tool::tsCONFIGURED)
120  mServices->tracking()->setState(Tool::tsCONFIGURED);
121 }
122 
123 
124 void CenterlineRegistrationWidget::registerSlot()
125 {
126 
127  if(!mSelectMeshWidget->getMesh())
128  {
129  reportError("No centerline");
130  return;
131  }
132  vtkPolyDataPtr centerline = mSelectMeshWidget->getMesh()->getVtkPolyData();//input
133  Transform3D rMd = mSelectMeshWidget->getMesh()->get_rMd();
134 
135  mCenterlineRegistration->UpdateScales(
136  mUseXrotation->getValue(), mUseYrotation->getValue(), mUseZrotation->getValue(),
137  mUseXtranslation->getValue(), mUseYtranslation->getValue(), mUseZtranslation->getValue());
138 
139  Transform3D old_rMpr = mServices->patient()->get_rMpr();//input to registrationAlgorithm
140 
141  TimedTransformMap trackerRecordedData_prMt = mRecordTrackingWidget->getRecordedTrackerData_prMt();
142 
143  if(trackerRecordedData_prMt.empty())
144  {
145  reportError("No positions");
146  return;
147  }
148 
149  Transform3D new_rMpr;
150 
151  new_rMpr = mCenterlineRegistration->runCenterlineRegistration(centerline, rMd, trackerRecordedData_prMt, old_rMpr);
152 
153  std::cout << "Running centerline registration." << std::endl;
154 
155  new_rMpr = new_rMpr*old_rMpr;//output
156  mServices->registration()->addPatientRegistration(new_rMpr, "Centerline centerline to tracking data");
157 
158  Eigen::Matrix4d display_rMpr = Eigen::Matrix4d::Identity();
159  display_rMpr = new_rMpr*display_rMpr;
160  std::cout << "New prMt: " << std::endl;
161  for (int i = 0; i < 4; i++)
162  std::cout << display_rMpr.row(i) << std::endl;
163 
164 
165 }
166 
167 void CenterlineRegistrationWidget::selectXtranslation(QDomElement root)
168 {
169  mUseXtranslation = BoolProperty::initialize("X translation:", "",
170  "Select if X translation be used in registration", true,
171  root);
172 }
173 
174 void CenterlineRegistrationWidget::selectYtranslation(QDomElement root)
175 {
176  mUseYtranslation = BoolProperty::initialize("Y translation:", "",
177  "Select if Y translation be used in registration", true,
178  root);
179 }
180 
181 void CenterlineRegistrationWidget::selectZtranslation(QDomElement root)
182 {
183  mUseZtranslation = BoolProperty::initialize("Z translation:", "",
184  "Select if Z translation be used in registration", true,
185  root);
186 }
187 
188 void CenterlineRegistrationWidget::selectXrotation(QDomElement root)
189 {
190  mUseXrotation = BoolProperty::initialize("X rotation: ", "",
191  "Select if X rotation be used in registration", true,
192  root);
193 }
194 
195 void CenterlineRegistrationWidget::selectYrotation(QDomElement root)
196 {
197  mUseYrotation = BoolProperty::initialize("Y rotation: ", "",
198  "Select if Y rotation be used in registration", true,
199  root);
200 }
201 
202 void CenterlineRegistrationWidget::selectZrotation(QDomElement root)
203 {
204  mUseZrotation = BoolProperty::initialize("Z rotation: ", "",
205  "Select if Z rotation be used in registration", true,
206  root);
207 }
208 
209 
210 
211 void CenterlineRegistrationWidget::clearDataOnNewPatient()
212 {
213  mMesh.reset();
214 }
215 } //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::StringPropertySelectMesh::New
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
Definition: cxSelectDataStringProperty.h:131
cxLogger.h
cxAcquisitionService.h
cxCenterlineRegistrationWidget.h
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
cx::CenterlineRegistrationWidget::prePaintEvent
virtual void prePaintEvent()
Definition: cxCenterlineRegistrationWidget.cpp:59
cxLabeledComboBoxWidget.h
cxViewGroupData.h
cxDoubleProperty.h
cx::RegistrationBaseWidget
Definition: cxRegistrationBaseWidget.h:28
cx::RecordTrackingWidget::getRecordedTrackerData_prMt
TimedTransformMap getRecordedTrackerData_prMt()
Definition: cxRecordTrackingWidget.cpp:202
cxHelperWidgets.h
cxStringPropertySelectTool.h
vtkPolyDataPtr
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
Definition: cxAirwaysFilterService.h:35
cxProfile.h
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cxViewService.h
cx::CenterlineRegistration
Definition: cxCenterlineRegistration.h:44
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
cx::CenterlineRegistrationWidget::defaultWhatsThis
virtual QString defaultWhatsThis() const
Definition: cxCenterlineRegistrationWidget.cpp:112
cxRepContainer.h
cxTypeConversions.h
cxView.h
cxPatientModelService.h
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
cxCenterlineRegistration.h
cxDataSelectWidget.h
cx::CenterlineRegistrationPtr
boost::shared_ptr< class CenterlineRegistration > CenterlineRegistrationPtr
Definition: cxCenterlineRegistrationWidget.h:32
cxRecordTrackingWidget.h
cxRecordSession.h
cxRegistrationService.h
cxStringProperty.h
cxSelectDataStringProperty.h
cx::DataSelectWidget
Definition: cxDataSelectWidget.h:38
cx::CenterlineRegistrationWidget::CenterlineRegistrationWidget
CenterlineRegistrationWidget(RegServicesPtr services, QWidget *parent)
Definition: cxCenterlineRegistrationWidget.cpp:50
cxTransform3D.h
cxRecordSessionWidget.h
cxBoolProperty.h
cxRegServices.h
cx::reportError
void reportError(QString msg)
Definition: cxLogger.cpp:71
cxMesh.h
cxTrackingService.h