CustusX  22.04-rc5
An IGT application
cxPlateRegistrationWidget.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 
13 
14 #include <QPushButton>
15 #include <QLabel>
16 #include "cxTypeConversions.h"
17 #include "cxTrackingService.h"
18 #include "cxLogger.h"
19 #include "cxViewService.h"
20 #include "cxRegistrationService.h"
21 #include "cxPatientModelService.h"
22 #include "cxTrackingService.h"
23 #include "cxLandmark.h"
24 
25 namespace cx
26 {
28  RegistrationBaseWidget(services, parent, "org_custusx_registration_method_plate_reference_landmarks", "Plate Registration Reference landmarks"),
29  mPlateRegistrationButton(new QPushButton("Load registration points", this)),
30  mReferenceToolInfoLabel(new QLabel("", this))
31 {
32  connect(mPlateRegistrationButton, SIGNAL(clicked()), this, SLOT(plateRegistrationSlot()));
33  connect(mServices->tracking().get(), &TrackingService::stateChanged, this, &PlateRegistrationWidget::internalUpdate);
34 
35  QVBoxLayout* toptopLayout = new QVBoxLayout(this);
36  toptopLayout->addWidget(mReferenceToolInfoLabel);
37  toptopLayout->addWidget(mPlateRegistrationButton);
38  toptopLayout->addStretch();
39 
40  this->internalUpdate();
41 }
42 
44 {
45 
46 }
47 
48 void PlateRegistrationWidget::showEvent(QShowEvent* event)
49 {
50  BaseWidget::showEvent(event);
51  connect(mServices->patient()->getPatientLandmarks().get(), &Landmarks::landmarkAdded,
52  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
53  connect(mServices->patient()->getPatientLandmarks().get(), &Landmarks::landmarkRemoved,
54  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
55 
56  mServices->view()->setRegistrationMode(rsPATIENT_REGISTRATED);
57 }
58 
59 void PlateRegistrationWidget::hideEvent(QHideEvent* event)
60 {
61  BaseWidget::hideEvent(event);
62  disconnect(mServices->patient()->getPatientLandmarks().get(), &Landmarks::landmarkAdded,
63  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
64  disconnect(mServices->patient()->getPatientLandmarks().get(), &Landmarks::landmarkRemoved,
65  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
66 
67  mServices->view()->setRegistrationMode(rsNOT_REGISTRATED);
68 }
69 
70 void PlateRegistrationWidget::landmarkUpdatedSlot()
71 {
72  mServices->registration()->doFastRegistration_Translation();
73 }
74 
75 void PlateRegistrationWidget::plateRegistrationSlot()
76 {
77  mServices->patient()->getPatientLandmarks()->clear();
78 
79  ToolPtr refTool = mServices->tracking()->getReferenceTool();
80  if(!refTool)//cannot register without a reference tool
81  {
82  reportDebug("No refTool");
83  return;
84  }
85  std::map<QString, Vector3D> referencePoints = refTool->getReferencePoints();
86  if(referencePoints.empty()) //cannot register without at least 1 reference point
87  {
88  reportDebug("No referenceppoints in reftool "+refTool->getName());
89  return;
90  }
91 
92  std::map<QString, Vector3D>::iterator it = referencePoints.begin();
93  for(; it != referencePoints.end(); ++it)
94  {
95  QString uid = mServices->patient()->addLandmark();
96  mServices->patient()->setLandmarkName(uid, qstring_cast(it->first));
97  mServices->patient()->getPatientLandmarks()->setLandmark(Landmark(uid, it->second));
98  }
99 
100  // set all landmarks as not active as default
101  LandmarkPropertyMap map = mServices->patient()->getLandmarkProperties();
102  LandmarkPropertyMap::iterator landmarkIt = map.begin();
103  for(; landmarkIt != map.end(); ++landmarkIt)
104  {
105  mServices->patient()->setLandmarkActive(landmarkIt->first, false);
106  }
107 
108  //we don't want the user to load the landmarks twice, it will result in alot of global landmarks...
109  mPlateRegistrationButton->setDisabled(true);
110 }
111 
112 void PlateRegistrationWidget::internalUpdate()
113 {
114  ToolPtr refTool = mServices->tracking()->getReferenceTool();
115 
116  QString labelText = "";
117  if(!refTool || refTool->getReferencePoints().size()<1)
118  {
119  mPlateRegistrationButton->setDisabled(true);
120 
121  labelText.append("Configure the tracker to have <br>a reference frame that has at least <br>one reference point.");
122  }else
123  {
124  mPlateRegistrationButton->setEnabled(true);
125 
126  labelText = "<b>Reference tool selected:</b> <br>";
127  labelText.append("Tool name: <i>"+refTool->getName()+"</i><br>");
128  labelText.append("Number of defined reference points: <i>"+qstring_cast(refTool->getReferencePoints().size())+"</i>");
129  }
130 
131  mReferenceToolInfoLabel->setText(labelText);
132 }
133 
134 }//namespace cx
QString qstring_cast(const T &val)
One landmark, or fiducial, coordinate.
Definition: cxLandmark.h:40
void landmarkAdded(QString uid)
virtual void showEvent(QShowEvent *event)
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:20
rsNOT_REGISTRATED
PlateRegistrationWidget(RegServicesPtr services, QWidget *parent)
std::map< QString, LandmarkProperty > LandmarkPropertyMap
Definition: cxLandmark.h:108
void landmarkRemoved(QString uid)
void reportDebug(QString msg)
Definition: cxLogger.cpp:68
Namespace for all CustusX production code.
boost::shared_ptr< class Tool > ToolPtr