CustusX  2023.01.05-dev+develop.0da12
An IGT application
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) 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 
13 #include "cxMesh.h"
14 #include "cxPatientModelService.h"
15 #include "cxRegistrationService.h"
16 #include "cxStringProperty.h"
19 #include "cxRecordTrackingWidget.h"
20 #include <QGroupBox>
23 #include "cxMeshHelpers.h"
24 #include "cxICPWidget.h"
25 #include "cxSpaceListener.h"
26 #include "cxSpaceProvider.h"
27 #include "cxAcquisitionService.h"
29 #include "cxLogger.h"
30 #include "cxTrackingService.h"
31 
32 namespace cx
33 {
35  ICPRegistrationBaseWidget(services, parent, "org_custusx_registration_method_pointcloud_frompointer_widget",
36  "Point Cloud Registration")
37 {
38 }
39 
41 {
42  mSpaceListenerMoving = mServices->spaceProvider()->createListener();
43  mSpaceListenerFixed = mServices->spaceProvider()->createListener();
44  mSpaceListenerMoving->setSpace(mServices->spaceProvider()->getPr());
45  connect(mSpaceListenerMoving.get(), &SpaceListener::changed, this, &RMPCFromPointerWidget::onSpacesChanged);
46  connect(mSpaceListenerFixed.get(), &SpaceListener::changed, this, &RMPCFromPointerWidget::onSpacesChanged);
47 
48  mFixedImage.reset(new StringPropertyRegistrationFixedImage(mServices->registration(), mServices->patient()));
49  mFixedImage->setTypeRegexp(Mesh::getTypeName());
50  mFixedImage->setValueName("Select Surface");
51  mFixedImage->setHelp("Select a surface model to register against.");
52 
53  connect(mServices->registration().get(), &RegistrationService::fixedDataChanged,
55 
56  mRecordTrackingWidget = new RecordTrackingWidget(mOptions.descend("recordTracker"),
57  mServices->acquisition(),
58  mServices,
59  "tracker",
60  this);
61  mRecordTrackingWidget->displayToolSelector(false);
62  connect(mRecordTrackingWidget->getSessionSelector().get(), &StringProperty::changed,
64  this->connectAutoRegistration();
65 
67 
68  QVBoxLayout* layout = new QVBoxLayout(this);
69  layout->setMargin(0);
70  layout->addWidget(new LabeledComboBoxWidget(this, mFixedImage));
71 
72  QVBoxLayout* trackLayout = this->createVBoxInGroupBox(layout, "Tracking Recorder");
73  trackLayout->setMargin(0);
74  trackLayout->addWidget(mRecordTrackingWidget);
75  layout->addWidget(mICPWidget);
76  layout->addStretch();
77 
78  this->inputChanged();
79  this->onSettingsChanged();
80 }
81 
82 void RMPCFromPointerWidget::connectAutoRegistration()
83 {
84  // connect queued: we record based on the selected session and not the last one
85  // and must thus wait for the selection to update
86  connect(mRecordTrackingWidget, &RecordTrackingWidget::acquisitionCompleted, this,
87  &RMPCFromPointerWidget::queuedAutoRegistration,
88  Qt::QueuedConnection);
89 }
90 
91 
92 QVBoxLayout* RMPCFromPointerWidget::createVBoxInGroupBox(QVBoxLayout* parent, QString header)
93 {
94  QWidget* widget = new QWidget(this);
95  QVBoxLayout* layout = new QVBoxLayout(widget);
96  layout->setMargin(0);
97 
98  QGroupBox* groupBox = this->wrapInGroupBox(widget, header);
99  parent->addWidget(groupBox);
100 
101  return layout;
102 }
103 
105 {
106  return QString();
107 }
108 
110 {
111  DataPtr fixed = mServices->registration()->getFixedData();
112  MeshPtr moving = this->getTrackerDataAsMesh();
113  QString logPath = mServices->patient()->getActivePatientFolder() + "/Logs/";
114 
115  mRegistrator->initialize(moving, fixed, logPath);
116 }
117 
118 MeshPtr RMPCFromPointerWidget::getTrackerDataAsMesh()
119 {
120  Transform3D rMpr = mServices->patient()->get_rMpr();
121 
122  TimedTransformMap trackerRecordedData_prMt = mRecordTrackingWidget->getSelectRecordSession()->getRecordedTrackerData_prMt();
123  vtkPolyDataPtr trackerdata_r = polydataFromTransforms(trackerRecordedData_prMt, rMpr);
124 
125  MeshPtr moving(new Mesh("tracker_points"));
126  moving->setVtkPolyData(trackerdata_r);
127  return moving;
128 }
129 
131 {
132  if (mObscuredListener->isObscured())
133  return;
134 
135  DataPtr fixed = mServices->registration()->getFixedData();
136  mSpaceListenerFixed->setSpace(mServices->spaceProvider()->getD(fixed));
137 
138  this->onSpacesChanged();
139  this->setModified();
140 }
141 
142 void RMPCFromPointerWidget::queuedAutoRegistration()
143 {
144  if (!mObscuredListener->isObscured())
145  {
146  this->registerSlot();
147  }
148 }
149 
151 {
152  ToolPtr tool = mRecordTrackingWidget->getSelectRecordSession()->getTool();
153  Transform3D rMpr = mServices->patient()->get_rMpr();
154  Transform3D new_rMpr = delta*rMpr;//output
155  mServices->registration()->setLastRegistrationTime(QDateTime::currentDateTime());//Instead of restart
156  QString text = QString("Contour from %1").arg(tool->getName());
157  mServices->registration()->addPatientRegistration(new_rMpr, text);
158 }
159 
161 {
162  this->inputChanged();
163 }
164 
165 
166 
167 } //namespace cx
A mesh data set.
Definition: cxMesh.h:45
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)
boost::shared_ptr< class WidgetObscuredListener > mObscuredListener
vtkPolyDataPtr polydataFromTransforms(TimedTransformMap transformMap_prMt, Transform3D rMpr)
SelectRecordSessionPtr getSelectRecordSession()
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:20
void changed()
emit when the underlying data value is changed: The user interface will be updated.
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
virtual QString defaultWhatsThis() const
static QString getTypeName()
Definition: cxMesh.h:67
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
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr