Fraxinus  17.12
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) 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 
35 #include <vtkPolyData.h>
36 #include "cxTransform3D.h"
37 #include "cxDataSelectWidget.h"
38 #include "cxTrackingService.h"
39 #include "cxMesh.h"
41 #include "cxRecordSessionWidget.h"
42 #include "cxRecordSession.h"
43 #include "cxView.h"
44 #include "cxToolRep3D.h"
45 #include "cxToolTracer.h"
46 #include "cxLogger.h"
47 #include "cxTypeConversions.h"
48 #include "cxPatientModelService.h"
49 #include "cxRegistrationService.h"
50 #include "cxViewService.h"
51 #include "cxStringProperty.h"
53 #include "cxTrackingService.h"
54 #include "cxDoubleProperty.h"
55 #include "cxProfile.h"
56 #include "cxHelperWidgets.h"
57 #include "cxBoolProperty.h"
58 #include "cxCheckBoxWidget.h"
59 #include "cxRepContainer.h"
61 #include "cxViewGroupData.h"
63 #include "cxHelperWidgets.h"
64 #include "cxAcquisitionService.h"
65 #include "cxRegServices.h"
66 #include "cxRecordTrackingWidget.h"
67 
68 
69 namespace cx
70 {
72  RegistrationBaseWidget(services, parent, "org_custusx_registration_method_centerline_widget",
73  "Centerline Registration"),
74  mServices(services),
75  mRecordTrackingWidget(NULL)
76 {
77  mVerticalLayout = new QVBoxLayout(this);
78 }
79 
81 {
82  if (!mRecordTrackingWidget)
83  {
84  this->setup();
85  }
86 }
87 
88 void CenterlineRegistrationWidget::setup()
89 {
90  mOptions = profile()->getXmlSettings().descend("centerlineregistrationwidget");
91 
92  mSelectMeshWidget = StringPropertySelectMesh::New(mServices->patient());
93  mSelectMeshWidget->setValueName("Centerline: ");
94 
95  mCenterlineRegistration = CenterlineRegistrationPtr(new CenterlineRegistration());
96 
97  connect(mServices->patient().get(),&PatientModelService::patientChanged,this,&CenterlineRegistrationWidget::clearDataOnNewPatient);
98 
99 
100  mRegisterButton = new QPushButton("Register");
101  connect(mRegisterButton, SIGNAL(clicked()), this, SLOT(registerSlot()));
102  mRegisterButton->setToolTip(this->defaultWhatsThis());
103 
104  mRecordTrackingWidget = new RecordTrackingWidget(mOptions.descend("recordTracker"),
105  mServices->acquisition(), mServices,
106  "bronc_path",
107  this);
108  mRecordTrackingWidget->getSessionSelector()->setHelp("Select tool path for registration");
109  mRecordTrackingWidget->getSessionSelector()->setDisplayName("Tool path");
110 
111  mVerticalLayout->setMargin(0);
112  mVerticalLayout->addWidget(new DataSelectWidget(mServices->view(), mServices->patient(), this, mSelectMeshWidget));
113 
114  this->selectXtranslation(mOptions.getElement());
115  this->selectYtranslation(mOptions.getElement());
116  this->selectZtranslation(mOptions.getElement());
117  this->selectXrotation(mOptions.getElement());
118  this->selectYrotation(mOptions.getElement());
119  this->selectZrotation(mOptions.getElement());
120 
121  mVerticalLayout->addWidget(mRecordTrackingWidget);
122  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseXtranslation));
123  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseYtranslation));
124  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseZtranslation));
125  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseXrotation));
126  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseYrotation));
127  mVerticalLayout->addWidget(new CheckBoxWidget(this, mUseZrotation));
128  mVerticalLayout->addWidget(mRegisterButton);
129 
130  mVerticalLayout->addStretch();
131 }
132 
134 {
135  return QString();
136 }
137 
138 void CenterlineRegistrationWidget::initializeTrackingService()
139 {
140  if(mServices->tracking()->getState() < Tool::tsCONFIGURED)
141  mServices->tracking()->setState(Tool::tsCONFIGURED);
142 }
143 
144 
145 void CenterlineRegistrationWidget::registerSlot()
146 {
147 
148  if(!mSelectMeshWidget->getMesh())
149  {
150  reportError("No centerline");
151  return;
152  }
153  vtkPolyDataPtr centerline = mSelectMeshWidget->getMesh()->getVtkPolyData();//input
154  Transform3D rMd = mSelectMeshWidget->getMesh()->get_rMd();
155 
156  mCenterlineRegistration->UpdateScales(
157  mUseXrotation->getValue(), mUseYrotation->getValue(), mUseZrotation->getValue(),
158  mUseXtranslation->getValue(), mUseYtranslation->getValue(), mUseZtranslation->getValue());
159 
160  Transform3D old_rMpr = mServices->patient()->get_rMpr();//input to registrationAlgorithm
161 
162  TimedTransformMap trackerRecordedData_prMt = mRecordTrackingWidget->getRecordedTrackerData_prMt();
163 
164  if(trackerRecordedData_prMt.empty())
165  {
166  reportError("No positions");
167  return;
168  }
169 
170  Transform3D new_rMpr;
171 
172  new_rMpr = mCenterlineRegistration->runCenterlineRegistration(centerline, rMd, trackerRecordedData_prMt, old_rMpr);
173 
174  std::cout << "Running centerline registration." << std::endl;
175 
176  new_rMpr = new_rMpr*old_rMpr;//output
177  mServices->registration()->addPatientRegistration(new_rMpr, "Centerline centerline to tracking data");
178 
179  Eigen::Matrix4d display_rMpr = Eigen::Matrix4d::Identity();
180  display_rMpr = new_rMpr*display_rMpr;
181  std::cout << "New prMt: " << std::endl;
182  for (int i = 0; i < 4; i++)
183  std::cout << display_rMpr.row(i) << std::endl;
184 
185 
186 }
187 
188 void CenterlineRegistrationWidget::selectXtranslation(QDomElement root)
189 {
190  mUseXtranslation = BoolProperty::initialize("X translation:", "",
191  "Select if X translation be used in registration", true,
192  root);
193 }
194 
195 void CenterlineRegistrationWidget::selectYtranslation(QDomElement root)
196 {
197  mUseYtranslation = BoolProperty::initialize("Y translation:", "",
198  "Select if Y translation be used in registration", true,
199  root);
200 }
201 
202 void CenterlineRegistrationWidget::selectZtranslation(QDomElement root)
203 {
204  mUseZtranslation = BoolProperty::initialize("Z translation:", "",
205  "Select if Z translation be used in registration", true,
206  root);
207 }
208 
209 void CenterlineRegistrationWidget::selectXrotation(QDomElement root)
210 {
211  mUseXrotation = BoolProperty::initialize("X rotation: ", "",
212  "Select if X rotation be used in registration", true,
213  root);
214 }
215 
216 void CenterlineRegistrationWidget::selectYrotation(QDomElement root)
217 {
218  mUseYrotation = BoolProperty::initialize("Y rotation: ", "",
219  "Select if Y rotation be used in registration", true,
220  root);
221 }
222 
223 void CenterlineRegistrationWidget::selectZrotation(QDomElement root)
224 {
225  mUseZrotation = BoolProperty::initialize("Z rotation: ", "",
226  "Select if Z rotation be used in registration", true,
227  root);
228 }
229 
230 
231 
232 void CenterlineRegistrationWidget::clearDataOnNewPatient()
233 {
234  mMesh.reset();
235 }
236 } //namespace cx
cxResource_EXPORT ProfilePtr profile()
Definition: cxProfile.cpp:181
static BoolPropertyPtr initialize(const QString &uid, QString name, QString help, bool value, QDomNode root=QDomNode())
void reportError(QString msg)
Definition: cxLogger.cpp:92
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Widget for the BoolPropertyBase.
TimedTransformMap getRecordedTrackerData_prMt()
StringPropertyPtr getSessionSelector()
QDomElement getElement()
return the current element
configured with basic info
Definition: cxTool.h:96
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:41
CenterlineRegistrationWidget(RegServicesPtr services, QWidget *parent)
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
static StringPropertySelectMeshPtr New(PatientModelServicePtr patientModelService)
boost::shared_ptr< class CenterlineRegistration > CenterlineRegistrationPtr
std::map< double, Transform3D > TimedTransformMap
XmlOptionFile descend(QString element) const
step one level down in the xml tree
Namespace for all CustusX production code.