CustusX  16.5
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 
46 namespace cx
47 {
49  RegistrationBaseWidget(services, parent, "org_custusx_registration_method_plate_reference_landmarks", "Plate Registration Reference landmarks"),
50  mPlateRegistrationButton(new QPushButton("Load registration points", this)),
51  mReferenceToolInfoLabel(new QLabel("", this))
52 {
53  connect(mPlateRegistrationButton, SIGNAL(clicked()), this, SLOT(plateRegistrationSlot()));
54  connect(mServices->tracking().get(), &TrackingService::stateChanged, this, &PlateRegistrationWidget::internalUpdate);
55 
56  QVBoxLayout* toptopLayout = new QVBoxLayout(this);
57  toptopLayout->addWidget(mReferenceToolInfoLabel);
58  toptopLayout->addWidget(mPlateRegistrationButton);
59  toptopLayout->addStretch();
60 
61  this->internalUpdate();
62 }
63 
65 {
66 
67 }
68 
69 void PlateRegistrationWidget::showEvent(QShowEvent* event)
70 {
71  BaseWidget::showEvent(event);
72  connect(mServices->patient()->getPatientLandmarks().get(), &Landmarks::landmarkAdded,
73  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
74  connect(mServices->patient()->getPatientLandmarks().get(), &Landmarks::landmarkRemoved,
75  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
76 
77  mServices->view()->setRegistrationMode(rsPATIENT_REGISTRATED);
78 }
79 
80 void PlateRegistrationWidget::hideEvent(QHideEvent* event)
81 {
82  BaseWidget::hideEvent(event);
83  disconnect(mServices->patient()->getPatientLandmarks().get(), &Landmarks::landmarkAdded,
84  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
85  disconnect(mServices->patient()->getPatientLandmarks().get(), &Landmarks::landmarkRemoved,
86  this, &PlateRegistrationWidget::landmarkUpdatedSlot);
87 
88  mServices->view()->setRegistrationMode(rsNOT_REGISTRATED);
89 }
90 
91 void PlateRegistrationWidget::landmarkUpdatedSlot()
92 {
93  mServices->registration()->doFastRegistration_Translation();
94 }
95 
96 void PlateRegistrationWidget::plateRegistrationSlot()
97 {
98  mServices->patient()->getPatientLandmarks()->clear();
99 
100  ToolPtr refTool = mServices->tracking()->getReferenceTool();
101  if(!refTool)//cannot register without a reference tool
102  {
103  reportDebug("No refTool");
104  return;
105  }
106  std::map<int, Vector3D> referencePoints = refTool->getReferencePoints();
107  if(referencePoints.empty()) //cannot register without at least 1 reference point
108  {
109  reportDebug("No referenceppoints in reftool "+refTool->getName());
110  return;
111  }
112 
113  std::map<int, Vector3D>::iterator it = referencePoints.begin();
114  for(; it != referencePoints.end(); ++it)
115  {
116  QString uid = mServices->patient()->addLandmark();
117  mServices->patient()->setLandmarkName(uid, qstring_cast(it->first));
118  mServices->patient()->getPatientLandmarks()->setLandmark(Landmark(uid, it->second));
119  }
120 
121  // set all landmarks as not active as default
122  LandmarkPropertyMap map = mServices->patient()->getLandmarkProperties();
123  LandmarkPropertyMap::iterator landmarkIt = map.begin();
124  for(; landmarkIt != map.end(); ++landmarkIt)
125  {
126  mServices->patient()->setLandmarkActive(landmarkIt->first, false);
127  }
128 
129  //we don't want the user to load the landmarks twice, it will result in alot of global landmarks...
130  mPlateRegistrationButton->setDisabled(true);
131 }
132 
133 void PlateRegistrationWidget::internalUpdate()
134 {
135  ToolPtr refTool = mServices->tracking()->getReferenceTool();
136 
137  QString labelText = "";
138  if(!refTool || refTool->getReferencePoints().size()<1)
139  {
140  mPlateRegistrationButton->setDisabled(true);
141 
142  labelText.append("Configure the tracker to have <br>a reference frame that has at least <br>one reference point.");
143  }else
144  {
145  mPlateRegistrationButton->setEnabled(true);
146 
147  labelText = "<b>Reference tool selected:</b> <br>";
148  labelText.append("Tool name: <i>"+refTool->getName()+"</i><br>");
149  labelText.append("Number of defined reference points: <i>"+qstring_cast(refTool->getReferencePoints().size())+"</i>");
150  }
151 
152  mReferenceToolInfoLabel->setText(labelText);
153 }
154 
155 }//namespace cx
QString qstring_cast(const T &val)
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:41
void landmarkAdded(QString uid)
virtual void showEvent(QShowEvent *event)
rsNOT_REGISTRATED
PlateRegistrationWidget(RegServicesPtr services, QWidget *parent)
std::map< QString, LandmarkProperty > LandmarkPropertyMap
Definition: cxLandmark.h:129
void landmarkRemoved(QString uid)
void reportDebug(QString msg)
Definition: cxLogger.cpp:89
boost::shared_ptr< class Tool > ToolPtr