CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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) 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 
34 
35 #include <QPushButton>
36 #include <QLabel>
37 #include "cxTypeConversions.h"
38 #include "cxTrackingService.h"
39 #include "cxLogger.h"
40 #include "cxViewService.h"
41 #include "cxRegistrationService.h"
42 #include "cxPatientModelService.h"
43 #include "cxTrackingService.h"
44 #include "cxLandmark.h"
45 #include "cxViewGroupData.h"
46 
47 namespace cx
48 {
50  RegistrationBaseWidget(services, parent, "PlateRegistrationWidget", "Plate Registration"),
51  mPlateRegistrationButton(new QPushButton("Load registration points", this)),
52  mReferenceToolInfoLabel(new QLabel("", this))
53 {
54  connect(mPlateRegistrationButton, SIGNAL(clicked()), this, SLOT(plateRegistrationSlot()));
55  connect(mServices.trackingService.get(), &TrackingService::stateChanged, this, &PlateRegistrationWidget::internalUpdate);
56 
57  QVBoxLayout* toptopLayout = new QVBoxLayout(this);
58  toptopLayout->addWidget(mReferenceToolInfoLabel);
59  toptopLayout->addWidget(mPlateRegistrationButton);
60  toptopLayout->addStretch();
61 
62  this->internalUpdate();
63 }
64 
66 {
67 
68 }
69 
71 {
72  return "<html>"
73  "<h3>Plate registration.</h3>"
74  "<p>Internally register the reference plates reference points as landmarks.</p>"
75  "<p><i>Click the button to load landmarks.</i></p>"
76  "</html>";
77 }
78 
79 void PlateRegistrationWidget::showEvent(QShowEvent* event)
80 {
81  BaseWidget::showEvent(event);
82  connect(mServices.patientModelService->getPatientLandmarks().get(), &Landmarks::landmarkAdded,
83  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
84  connect(mServices.patientModelService->getPatientLandmarks().get(), &Landmarks::landmarkRemoved,
85  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
86 
87  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsPATIENT_REGISTRATED);
88 }
89 
90 void PlateRegistrationWidget::hideEvent(QHideEvent* event)
91 {
92  BaseWidget::hideEvent(event);
93  disconnect(mServices.patientModelService->getPatientLandmarks().get(), &Landmarks::landmarkAdded,
94  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
95  disconnect(mServices.patientModelService->getPatientLandmarks().get(), &Landmarks::landmarkRemoved,
96  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
97 
98  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsNOT_REGISTRATED);
99 }
100 
101 void PlateRegistrationWidget::landmarkUpdatedSlot()
102 {
103  mServices.registrationService->doFastRegistration_Translation();
104 }
105 
106 void PlateRegistrationWidget::plateRegistrationSlot()
107 {
108  mServices.patientModelService->getPatientLandmarks()->clear();
109 
110  ToolPtr refTool = mServices.trackingService->getReferenceTool();
111  if(!refTool)//cannot register without a reference tool
112  {
113  reportDebug("No refTool");
114  return;
115  }
116  std::map<int, Vector3D> referencePoints = refTool->getReferencePoints();
117  if(referencePoints.empty()) //cannot register without at least 1 reference point
118  {
119  reportDebug("No referenceppoints in reftool "+refTool->getName());
120  return;
121  }
122 
123  std::map<int, Vector3D>::iterator it = referencePoints.begin();
124  for(; it != referencePoints.end(); ++it)
125  {
126  QString uid = mServices.patientModelService->addLandmark();
127  mServices.patientModelService->setLandmarkName(uid, qstring_cast(it->first));
128  mServices.patientModelService->getPatientLandmarks()->setLandmark(Landmark(uid, it->second));
129  }
130 
131  // set all landmarks as not active as default
132  LandmarkPropertyMap map = mServices.patientModelService->getLandmarkProperties();
133  LandmarkPropertyMap::iterator landmarkIt = map.begin();
134  for(; landmarkIt != map.end(); ++landmarkIt)
135  {
136  mServices.patientModelService->setLandmarkActive(landmarkIt->first, false);
137  }
138 
139  //we don't want the user to load the landmarks twice, it will result in alot of global landmarks...
140  mPlateRegistrationButton->setDisabled(true);
141 }
142 
143 void PlateRegistrationWidget::internalUpdate()
144 {
145  ToolPtr refTool = mServices.trackingService->getReferenceTool();
146 
147  QString labelText = "";
148  if(!refTool || refTool->getReferencePoints().size()<1)
149  {
150  mPlateRegistrationButton->setDisabled(true);
151 
152  labelText.append("Configure the tracker to have <br>a reference frame that has at least <br>one reference point.");
153  }else
154  {
155  mPlateRegistrationButton->setEnabled(true);
156 
157  labelText = "<b>Reference tool selected:</b> <br>";
158  labelText.append("Tool name: <i>"+refTool->getName()+"</i><br>");
159  labelText.append("Number of defined reference points: <i>"+qstring_cast(refTool->getReferencePoints().size())+"</i>");
160  }
161 
162  mReferenceToolInfoLabel->setText(labelText);
163 }
164 
165 }//namespace cx
QString qstring_cast(const T &val)
void landmarkAdded(QString uid)
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
virtual void showEvent(QShowEvent *event)
rsNOT_REGISTRATED
PlateRegistrationWidget(RegServices services, QWidget *parent)
VisualizationServicePtr visualizationService
Definition: cxVisServices.h:60
TrackingServicePtr trackingService
std::map< QString, LandmarkProperty > LandmarkPropertyMap
Definition: cxLandmark.h:129
PatientModelServicePtr patientModelService
void landmarkRemoved(QString uid)
void reportDebug(QString msg)
Definition: cxLogger.cpp:89
RegistrationServicePtr registrationService
Definition: cxRegServices.h:60
boost::shared_ptr< class Tool > ToolPtr