CustusX  15.8
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxImageLandmarksWidget.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 
33 #include "cxImageLandmarksWidget.h"
34 
35 #include <sstream>
36 #include <QVBoxLayout>
37 #include <QPushButton>
38 #include <QTableWidget>
39 #include <QTableWidgetItem>
40 #include <QHeaderView>
41 #include <QLabel>
42 #include <QSlider>
43 #include <vtkDoubleArray.h>
44 #include <vtkImageData.h>
45 #include "cxLogger.h"
46 #include "cxPickerRep.h"
48 #include "cxSettings.h"
49 #include "cxLandmarkRep.h"
50 #include "cxView.h"
51 #include "cxTypeConversions.h"
53 #include "cxRegistrationService.h"
54 #include "cxPatientModelService.h"
55 #include "cxViewService.h"
56 #include "cxViewGroupData.h"
57 #include "cxRepContainer.h"
58 #include "cxTrackingService.h"
59 #include "cxLandmarkListener.h"
60 
61 namespace cx
62 {
63 ImageLandmarksWidget::ImageLandmarksWidget(RegServices services, QWidget* parent,
64  QString objectName, QString windowTitle, bool useRegistrationFixedPropertyInsteadOfActiveImage) :
65  LandmarkRegistrationWidget(services, parent, objectName, windowTitle),
66  mUseRegistrationFixedPropertyInsteadOfActiveImage(useRegistrationFixedPropertyInsteadOfActiveImage)
67 {
68  if(mUseRegistrationFixedPropertyInsteadOfActiveImage)
70  else
73 
74  mLandmarkListener->useOnlyOneSourceUpdatedFromOutside();
75 
77  connect(mActiveToolProxy.get(), SIGNAL(toolVisible(bool)), this, SLOT(enableButtons()));
78  connect(mActiveToolProxy.get(), SIGNAL(activeToolChanged(const QString&)), this, SLOT(enableButtons()));
79 
80  //pushbuttons
81  mAddLandmarkButton = new QPushButton("New Landmark", this);
82  mAddLandmarkButton->setToolTip("Add landmark");
83  mAddLandmarkButton->setDisabled(true);
84  connect(mAddLandmarkButton, SIGNAL(clicked()), this, SLOT(addLandmarkButtonClickedSlot()));
85 
86  mEditLandmarkButton = new QPushButton("Resample", this);
87  mEditLandmarkButton->setToolTip("Resample existing landmark");
88  mEditLandmarkButton->setDisabled(true);
89  connect(mEditLandmarkButton, SIGNAL(clicked()), this, SLOT(editLandmarkButtonClickedSlot()));
90 
91  mRemoveLandmarkButton = new QPushButton("Clear", this);
92  mRemoveLandmarkButton->setToolTip("Clear selected landmark");
93  mRemoveLandmarkButton->setDisabled(true);
94  connect(mRemoveLandmarkButton, SIGNAL(clicked()), this, SLOT(removeLandmarkButtonClickedSlot()));
95 
96  //layout
100 
101  QHBoxLayout* landmarkButtonsLayout = new QHBoxLayout;
102  landmarkButtonsLayout->addWidget(mAddLandmarkButton);
103  landmarkButtonsLayout->addWidget(mEditLandmarkButton);
104  landmarkButtonsLayout->addWidget(mRemoveLandmarkButton);
105  mVerticalLayout->addLayout(landmarkButtonsLayout);
106 }
107 
109 {
110 }
111 
113 {
114  DataPtr data = mCurrentProperty->getData();
115 
116  mLandmarkListener->setLandmarkSource(data);
117  this->enableButtons();
118 
119  if (data && !mServices.registrationService->getFixedData())
120  mServices.registrationService->setFixedData(data);
121 
122  this->setModified();
123 }
124 
126 {
127  return mServices.visualizationService->get3DReps(0, 0)->findFirst<PickerRep>();
128 }
129 
130 DataPtr ImageLandmarksWidget::getCurrentData() const
131 {
132  return mLandmarkListener->getLandmarkSource();
133 }
134 
136 {
138  if (!PickerRep)
139  {
140  reportError("Could not find a rep to add the landmark to.");
141  return;
142  }
143 
144  DataPtr image = this->getCurrentData();
145  if (!image)
146  return;
147 
148  QString uid = mServices.patientModelService->addLandmark();
149  Vector3D pos_r = PickerRep->getPosition();
150  Vector3D pos_d = image->get_rMd().inv().coord(pos_r);
151  image->getLandmarks()->setLandmark(Landmark(uid, pos_d));
152 
153  this->activateLandmark(uid);
154 }
155 
156 
158 {
160  if (!PickerRep)
161  {
162  reportError("Could not find a rep to edit the landmark for.");
163  return;
164  }
165 
166  DataPtr image = this->getCurrentData();
167  if (!image)
168  return;
169 
170  QString uid = mActiveLandmark;
171  Vector3D pos_r = PickerRep->getPosition();
172  Vector3D pos_d = image->get_rMd().inv().coord(pos_r);
173  image->getLandmarks()->setLandmark(Landmark(uid, pos_d));
174 
175  this->activateLandmark(this->getNextLandmark());
176 }
177 
179 {
180  DataPtr image = this->getCurrentData();
181  if (!image)
182  return;
183 
184  QString next = this->getNextLandmark();
185  image->getLandmarks()->removeLandmark(mActiveLandmark);
186  this->activateLandmark(next);
187 }
188 
189 void ImageLandmarksWidget::cellClickedSlot(int row, int column)
190 {
192  this->enableButtons();
193 }
194 
196 {
197  bool selected = !mLandmarkTableWidget->selectedItems().isEmpty();
198  bool loaded = this->getCurrentData() != 0;
199 
200  mEditLandmarkButton->setEnabled(selected);
201  mRemoveLandmarkButton->setEnabled(selected);
202  mAddLandmarkButton->setEnabled(loaded);
203 
204  DataPtr image = this->getCurrentData();
205  if (image)
206  {
207  mAddLandmarkButton->setToolTip(QString("Add landmark to image %1").arg(image->getName()));
208  mEditLandmarkButton->setToolTip(QString("Resample landmark in image %1").arg(image->getName()));
209  }
210 // this->setModified();
211 }
212 
213 void ImageLandmarksWidget::showEvent(QShowEvent* event)
214 {
215  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsIMAGE_REGISTRATED);
217 
218  if(!mUseRegistrationFixedPropertyInsteadOfActiveImage)
219  {
220  ImagePtr image = mServices.patientModelService->getActiveImage();
221  if (image)
222  mCurrentProperty->setValue(image->getUid());
223  }
224 }
225 
226 void ImageLandmarksWidget::hideEvent(QHideEvent* event)
227 {
228  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsNOT_REGISTRATED);
230 
231 }
232 
234 {
236 
237  std::vector<Landmark> landmarks = this->getAllLandmarks();
238 
239  //update buttons
240  mRemoveLandmarkButton->setEnabled(!landmarks.empty() && !mActiveLandmark.isEmpty());
241  mEditLandmarkButton->setEnabled(!landmarks.empty() && !mActiveLandmark.isEmpty());
242 }
243 
245 {
246  DataPtr image = this->getCurrentData();
247  if (!image)
248  return LandmarkMap();
249 
250  return image->getLandmarks()->getLandmarks();
251 }
252 
257 {
258  DataPtr image = this->getCurrentData();
259  if (!image)
260  return Transform3D::Identity();
261  return image->get_rMd();
262 }
263 
265 {
266  DataPtr image = this->getCurrentData();
267  if (!image)
268  return;
269  image->getLandmarks()->setLandmark(Landmark(uid, p_target));
270 }
271 
273 {
274  DataPtr image = this->getCurrentData();
275  if (!image)
276  return "None";
277  return image->getName();
278 }
279 
280 
281 }//namespace cx
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
virtual void editLandmarkButtonClickedSlot()
reacts when the Edit Landmark button is clicked
QPushButton * mRemoveLandmarkButton
the Remove Landmark button
void reportError(QString msg)
Definition: cxLogger.cpp:92
void removeLandmarkButtonClickedSlot()
reacts when the Remove Landmark button is clicked
QPushButton * mEditLandmarkButton
the Edit Landmark button
QLabel * mAvarageAccuracyLabel
label showing the average accuracy
QPushButton * mAddLandmarkButton
the Add Landmark button
One landmark, or fiducial, coordinate.
Definition: cxLandmark.h:61
virtual Transform3D getTargetTransform() const
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
virtual void hideEvent(QHideEvent *event)
Composite widget for string selection.
QVBoxLayout * mVerticalLayout
vertical layout is used
virtual void setTargetLandmark(QString uid, Vector3D p_target)
virtual void hideEvent(QHideEvent *event)
static ActiveToolProxyPtr New(TrackingServicePtr trackingService)
boost::shared_ptr< class Data > DataPtr
boost::shared_ptr< class PickerRep > PickerRepPtr
ActiveToolProxyPtr mActiveToolProxy
Picking of points in an image.
Definition: cxPickerRep.h:70
void addLandmarkButtonClickedSlot()
reacts when the Add Landmark button is clicked
virtual void cellClickedSlot(int row, int column)
when a landmark is selected from the table
virtual void prePaintEvent()
populates the table widget
rsNOT_REGISTRATED
static StringPropertySelectDataPtr New(PatientModelServicePtr patientModelService)
virtual void prePaintEvent()
populates the table widget
void changed()
emit when the underlying data value is changed: The user interface will be updated.
virtual QString getTargetName() const
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
VisualizationServicePtr visualizationService
Definition: cxVisServices.h:60
std::map< QString, class Landmark > LandmarkMap
QString mActiveLandmark
uid of surrently selected landmark.
TrackingServicePtr trackingService
std::vector< Landmark > getAllLandmarks() const
get all the landmarks from the image and the datamanager
SelectDataStringPropertyBasePtr mCurrentProperty
PatientModelServicePtr patientModelService
virtual LandmarkMap getTargetLandmarks() const
RegistrationServicePtr registrationService
Definition: cxRegServices.h:60
virtual void cellClickedSlot(int row, int column)
when a landmark is selected from the table
rsIMAGE_REGISTRATED
QTableWidget * mLandmarkTableWidget
the table widget presenting the landmarks