CustusX  16.5.0-rc9
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxRMPCFromPointerWidget.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 =========================================================================*/
33 
34 #include "cxMesh.h"
35 #include "cxPatientModelService.h"
36 #include "cxRegistrationService.h"
37 #include "cxStringProperty.h"
40 #include "cxRecordTrackingWidget.h"
41 #include <QGroupBox>
44 #include "cxMeshHelpers.h"
45 #include "cxICPWidget.h"
46 #include "cxSpaceListener.h"
47 #include "cxSpaceProvider.h"
48 #include "cxAcquisitionService.h"
50 #include "cxLogger.h"
51 #include "cxTrackingService.h"
52 
53 namespace cx
54 {
56  ICPRegistrationBaseWidget(services, parent, "org_custusx_registration_method_pointcloud_frompointer_widget",
57  "Point Cloud Registration")
58 {
59 }
60 
62 {
63  mSpaceListenerMoving = mServices->spaceProvider()->createListener();
64  mSpaceListenerFixed = mServices->spaceProvider()->createListener();
65  mSpaceListenerMoving->setSpace(mServices->spaceProvider()->getPr());
66  connect(mSpaceListenerMoving.get(), &SpaceListener::changed, this, &RMPCFromPointerWidget::onSpacesChanged);
67  connect(mSpaceListenerFixed.get(), &SpaceListener::changed, this, &RMPCFromPointerWidget::onSpacesChanged);
68 
69  mFixedImage.reset(new StringPropertyRegistrationFixedImage(mServices->registration(), mServices->patient()));
70  mFixedImage->setTypeRegexp("mesh");
71  mFixedImage->setValueName("Select Surface");
72  mFixedImage->setHelp("Select a surface model to register against.");
73 
74  connect(mServices->registration().get(), &RegistrationService::fixedDataChanged,
76 
77  mRecordTrackingWidget = new RecordTrackingWidget(mOptions.descend("recordTracker"),
78  mServices->acquisition(),
79  mServices,
80  "tracker",
81  this);
82  mRecordTrackingWidget->displayToolSelector(false);
83  connect(mRecordTrackingWidget->getSessionSelector().get(), &StringProperty::changed,
85  this->connectAutoRegistration();
86 
88 
89  QVBoxLayout* layout = new QVBoxLayout(this);
90  layout->setMargin(0);
91  layout->addWidget(new LabeledComboBoxWidget(this, mFixedImage));
92 
93  QVBoxLayout* trackLayout = this->createVBoxInGroupBox(layout, "Tracking Recorder");
94  trackLayout->setMargin(0);
95  trackLayout->addWidget(mRecordTrackingWidget);
96  layout->addWidget(mICPWidget);
97  layout->addStretch();
98 
99  this->inputChanged();
100  this->onSettingsChanged();
101 }
102 
103 void RMPCFromPointerWidget::connectAutoRegistration()
104 {
105  // connect queued: we record based on the selected session and not the last one
106  // and must thus wait for the selection to update
107  connect(mRecordTrackingWidget, &RecordTrackingWidget::acquisitionCompleted, this,
108  &RMPCFromPointerWidget::queuedAutoRegistration,
109  Qt::QueuedConnection);
110 }
111 
112 
113 QVBoxLayout* RMPCFromPointerWidget::createVBoxInGroupBox(QVBoxLayout* parent, QString header)
114 {
115  QWidget* widget = new QWidget(this);
116  QVBoxLayout* layout = new QVBoxLayout(widget);
117  layout->setMargin(0);
118 
119  QGroupBox* groupBox = this->wrapInGroupBox(widget, header);
120  parent->addWidget(groupBox);
121 
122  return layout;
123 }
124 
126 {
127  return QString();
128 }
129 
131 {
132  DataPtr fixed = mServices->registration()->getFixedData();
133  MeshPtr moving = this->getTrackerDataAsMesh();
134  QString logPath = mServices->patient()->getActivePatientFolder() + "/Logs/";
135 
136  mRegistrator->initialize(moving, fixed, logPath);
137 }
138 
139 MeshPtr RMPCFromPointerWidget::getTrackerDataAsMesh()
140 {
141  Transform3D rMpr = mServices->patient()->get_rMpr();
142 
143  TimedTransformMap trackerRecordedData_prMt = mRecordTrackingWidget->getSelectRecordSession()->getRecordedTrackerData_prMt();
144  vtkPolyDataPtr trackerdata_r = polydataFromTransforms(trackerRecordedData_prMt, rMpr);
145 
146  MeshPtr moving(new Mesh("tracker_points"));
147  moving->setVtkPolyData(trackerdata_r);
148  return moving;
149 }
150 
152 {
153  if (mObscuredListener->isObscured())
154  return;
155 
156  DataPtr fixed = mServices->registration()->getFixedData();
157  mSpaceListenerFixed->setSpace(mServices->spaceProvider()->getD(fixed));
158 
159  this->onSpacesChanged();
160  this->setModified();
161 }
162 
163 void RMPCFromPointerWidget::queuedAutoRegistration()
164 {
165  if (!mObscuredListener->isObscured())
166  {
167  this->registerSlot();
168  }
169 }
170 
172 {
173  ToolPtr tool = mRecordTrackingWidget->getSelectRecordSession()->getTool();
174  Transform3D rMpr = mServices->patient()->get_rMpr();
175  Transform3D new_rMpr = delta*rMpr;//output
176  mServices->registration()->setLastRegistrationTime(QDateTime::currentDateTime());//Instead of restart
177  QString text = QString("Contour from %1").arg(tool->getName());
178  mServices->registration()->applyPatientRegistration(new_rMpr, text);
179 }
180 
182 {
183  this->inputChanged();
184 }
185 
186 
187 
188 } //namespace cx
A mesh data set.
Definition: cxMesh.h:61
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:41
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
virtual void applyRegistration(Transform3D delta)
QGroupBox * wrapInGroupBox(QWidget *base, QString name)
Composite widget for string selection.
void fixedDataChanged(QString uid)
boost::shared_ptr< class Data > DataPtr
RMPCFromPointerWidget(RegServicesPtr services, QWidget *parent)
void activeToolChanged(const QString &uId)
vtkSmartPointer< class vtkPolyData > vtkPolyDataPtr
boost::shared_ptr< class WidgetObscuredListener > mObscuredListener
vtkPolyDataPtr polydataFromTransforms(TimedTransformMap transformMap_prMt, Transform3D rMpr)
SelectRecordSessionPtr getSelectRecordSession()
void changed()
emit when the underlying data value is changed: The user interface will be updated.
virtual QString defaultWhatsThis() const
void acquisitionCompleted()
aquisition complete, and widget internal state is updated accordingly
boost::shared_ptr< class Mesh > MeshPtr
std::map< double, Transform3D > TimedTransformMap
XmlOptionFile descend(QString element) const
step one level down in the xml tree
boost::shared_ptr< class Tool > ToolPtr