NorMIT-nav  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
cx::LabeledComboBoxWidget
Composite widget for string selection.
Definition: cxLabeledComboBoxWidget.h:36
cxLogger.h
cxAcquisitionService.h
cx::RMPCFromPointerWidget::defaultWhatsThis
virtual QString defaultWhatsThis() const
Definition: cxRMPCFromPointerWidget.cpp:104
cx::RecordTrackingWidget::acquisitionCompleted
void acquisitionCompleted()
aquisition complete, and widget internal state is updated accordingly
cxSpaceListener.h
cx::OptimizedUpdateWidget::setModified
virtual void setModified()
Definition: cxOptimizedUpdateWidget.cpp:36
cx::RecordTrackingWidget::getSessionSelector
StringPropertyPtr getSessionSelector()
Definition: cxRecordTrackingWidget.cpp:80
cx
Namespace for all CustusX production code.
Definition: cx_dev_group_definitions.h:13
cxRecordSessionSelector.h
cx::Property::changed
void changed()
emit when the underlying data value is changed: The user interface will be updated.
cx::ICPRegistrationBaseWidget::mICPWidget
ICPWidget * mICPWidget
Definition: cxICPRegistrationBaseWidget.h:97
cx::RMPCFromPointerWidget::RMPCFromPointerWidget
RMPCFromPointerWidget(RegServicesPtr services, QWidget *parent)
Definition: cxRMPCFromPointerWidget.cpp:34
cx::RecordTrackingWidget
Definition: cxRecordTrackingWidget.h:42
cx::SpaceListener::changed
void changed()
cx::XmlOptionFile::descend
XmlOptionFile descend(QString element) const
step one level down in the xml tree
Definition: cxXmlOptionItem.cpp:271
cx::RMPCFromPointerWidget::initializeRegistrator
virtual void initializeRegistrator()
Definition: cxRMPCFromPointerWidget.cpp:109
cxLabeledComboBoxWidget.h
cx::ICPRegistrationBaseWidget
Definition: cxICPRegistrationBaseWidget.h:49
cx::polydataFromTransforms
vtkPolyDataPtr polydataFromTransforms(TimedTransformMap transformMap_prMt, Transform3D rMpr)
Definition: cxMeshHelpers.cpp:26
cx::RMPCFromPointerWidget::onShown
virtual void onShown()
Definition: cxRMPCFromPointerWidget.cpp:160
cx::ICPRegistrationBaseWidget::registerSlot
void registerSlot()
Definition: cxICPRegistrationBaseWidget.cpp:187
cx::ICPRegistrationBaseWidget::onSettingsChanged
void onSettingsChanged()
Definition: cxICPRegistrationBaseWidget.cpp:174
SeansVesselReg.hxx
cxICPWidget.h
cx::RMPCFromPointerWidget::inputChanged
virtual void inputChanged()
Definition: cxRMPCFromPointerWidget.cpp:130
cx::ICPRegistrationBaseWidget::mObscuredListener
boost::shared_ptr< class WidgetObscuredListener > mObscuredListener
Definition: cxICPRegistrationBaseWidget.h:100
cx::Mesh::getTypeName
static QString getTypeName()
Definition: cxMesh.h:67
cx::ICPRegistrationBaseWidget::mRegistrator
SeansVesselRegPtr mRegistrator
Definition: cxICPRegistrationBaseWidget.h:99
cx::RegistrationBaseWidget::mServices
RegServicesPtr mServices
Definition: cxRegistrationBaseWidget.h:35
cx::MeshPtr
boost::shared_ptr< class Mesh > MeshPtr
Definition: cxForwardDeclarations.h:48
cx::ICPRegistrationBaseWidget::mOptions
XmlOptionFile mOptions
Definition: cxICPRegistrationBaseWidget.h:98
cx::Transform3D
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
Definition: cxLandmarkPatientRegistrationWidget.h:33
cx::BaseWidget::wrapInGroupBox
QGroupBox * wrapInGroupBox(QWidget *base, QString name)
Definition: cxBaseWidget.cpp:82
cx::TimedTransformMap
std::map< double, Transform3D > TimedTransformMap
Definition: cxRecordSession.h:36
cxWidgetObscuredListener.h
cx::DataPtr
boost::shared_ptr< class Data > DataPtr
Definition: cxRegistrationApplicator.h:22
cx::RMPCFromPointerWidget::applyRegistration
virtual void applyRegistration(Transform3D delta)
Definition: cxRMPCFromPointerWidget.cpp:150
cxPatientModelService.h
cx::TrackingService::activeToolChanged
void activeToolChanged(const QString &uId)
cx::ICPRegistrationBaseWidget::onSpacesChanged
void onSpacesChanged()
Definition: cxICPRegistrationBaseWidget.cpp:161
cx::RegServicesPtr
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:20
cx::vtkPolyDataPtr
vtkSmartPointer< vtkPolyData > vtkPolyDataPtr
Definition: cxCenterlineRegistration.h:42
cxRegistrationProperties.h
cx::StringPropertyRegistrationFixedImage
Definition: cxRegistrationProperties.h:31
cxMeshHelpers.h
cxRecordTrackingWidget.h
cx::ToolPtr
boost::shared_ptr< class Tool > ToolPtr
Definition: cxVideoConnectionWidget.h:43
cx::Mesh
A mesh data set.
Definition: cxMesh.h:45
cx::RegistrationService::fixedDataChanged
void fixedDataChanged(QString uid)
cxRegistrationService.h
cxStringProperty.h
cx::RMPCFromPointerWidget::setup
virtual void setup()
Definition: cxRMPCFromPointerWidget.cpp:40
cx::RecordTrackingWidget::displayToolSelector
void displayToolSelector(bool on)
Definition: cxRecordTrackingWidget.cpp:75
cx::RecordTrackingWidget::getSelectRecordSession
SelectRecordSessionPtr getSelectRecordSession()
Definition: cxRecordTrackingWidget.h:59
cxRMPCFromPointerWidget.h
cxMesh.h
cxTrackingService.h
cxSpaceProvider.h