CustusX  15.8
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, "org_custusx_registration_method_plate_reference_landmarks", "Plate Registration Reference landmarks"),
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 
70 void PlateRegistrationWidget::showEvent(QShowEvent* event)
71 {
72  BaseWidget::showEvent(event);
73  connect(mServices.patientModelService->getPatientLandmarks().get(), &Landmarks::landmarkAdded,
74  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
75  connect(mServices.patientModelService->getPatientLandmarks().get(), &Landmarks::landmarkRemoved,
76  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
77 
78  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsPATIENT_REGISTRATED);
79 }
80 
81 void PlateRegistrationWidget::hideEvent(QHideEvent* event)
82 {
83  BaseWidget::hideEvent(event);
84  disconnect(mServices.patientModelService->getPatientLandmarks().get(), &Landmarks::landmarkAdded,
85  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
86  disconnect(mServices.patientModelService->getPatientLandmarks().get(), &Landmarks::landmarkRemoved,
87  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
88 
89  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsNOT_REGISTRATED);
90 }
91 
92 void PlateRegistrationWidget::landmarkUpdatedSlot()
93 {
94  mServices.registrationService->doFastRegistration_Translation();
95 }
96 
97 void PlateRegistrationWidget::plateRegistrationSlot()
98 {
99  mServices.patientModelService->getPatientLandmarks()->clear();
100 
101  ToolPtr refTool = mServices.trackingService->getReferenceTool();
102  if(!refTool)//cannot register without a reference tool
103  {
104  reportDebug("No refTool");
105  return;
106  }
107  std::map<int, Vector3D> referencePoints = refTool->getReferencePoints();
108  if(referencePoints.empty()) //cannot register without at least 1 reference point
109  {
110  reportDebug("No referenceppoints in reftool "+refTool->getName());
111  return;
112  }
113 
114  std::map<int, Vector3D>::iterator it = referencePoints.begin();
115  for(; it != referencePoints.end(); ++it)
116  {
117  QString uid = mServices.patientModelService->addLandmark();
118  mServices.patientModelService->setLandmarkName(uid, qstring_cast(it->first));
119  mServices.patientModelService->getPatientLandmarks()->setLandmark(Landmark(uid, it->second));
120  }
121 
122  // set all landmarks as not active as default
123  LandmarkPropertyMap map = mServices.patientModelService->getLandmarkProperties();
124  LandmarkPropertyMap::iterator landmarkIt = map.begin();
125  for(; landmarkIt != map.end(); ++landmarkIt)
126  {
127  mServices.patientModelService->setLandmarkActive(landmarkIt->first, false);
128  }
129 
130  //we don't want the user to load the landmarks twice, it will result in alot of global landmarks...
131  mPlateRegistrationButton->setDisabled(true);
132 }
133 
134 void PlateRegistrationWidget::internalUpdate()
135 {
136  ToolPtr refTool = mServices.trackingService->getReferenceTool();
137 
138  QString labelText = "";
139  if(!refTool || refTool->getReferencePoints().size()<1)
140  {
141  mPlateRegistrationButton->setDisabled(true);
142 
143  labelText.append("Configure the tracker to have <br>a reference frame that has at least <br>one reference point.");
144  }else
145  {
146  mPlateRegistrationButton->setEnabled(true);
147 
148  labelText = "<b>Reference tool selected:</b> <br>";
149  labelText.append("Tool name: <i>"+refTool->getName()+"</i><br>");
150  labelText.append("Number of defined reference points: <i>"+qstring_cast(refTool->getReferencePoints().size())+"</i>");
151  }
152 
153  mReferenceToolInfoLabel->setText(labelText);
154 }
155 
156 }//namespace cx
QString qstring_cast(const T &val)
void landmarkAdded(QString uid)
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