CustusX  15.3.4-beta
An IGT application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
cxLandmarkImage2ImageRegistrationWidget.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 =========================================================================*/
33 
34 #include <sstream>
35 #include <QVBoxLayout>
36 #include <QPushButton>
37 #include <QTableWidget>
38 #include <QTableWidgetItem>
39 #include <QHeaderView>
40 #include <QLabel>
41 #include <QSlider>
42 #include <QCheckBox>
43 #include <vtkDoubleArray.h>
44 #include <vtkImageData.h>
45 
47 #include "cxSettings.h"
48 #include "cxLandmarkRep.h"
49 #include "cxView.h"
51 #include "cxRegistrationService.h"
52 #include "cxViewService.h"
53 #include "cxViewGroupData.h"
54 #include "cxRepContainer.h"
55 
56 namespace cx
57 {
58 LandmarkImage2ImageRegistrationWidget::LandmarkImage2ImageRegistrationWidget(RegServices services,
59  QWidget* parent, QString objectName, QString windowTitle) :
60  LandmarkRegistrationWidget(services, parent, objectName, windowTitle)
61 {
62  mLandmarkTableWidget->hide();
63 
66 
71 
74 
75  mTranslationCheckBox = new QCheckBox("Translation only", this);
76  mTranslationCheckBox->setChecked(settings()->value("registration/I2ILandmarkTranslation", false).toBool());
77  connect(mTranslationCheckBox, SIGNAL(toggled(bool)), this, SLOT(translationCheckBoxChanged()));
78 
79  mRegisterButton = new QPushButton("Register", this);
80  mRegisterButton->setToolTip("Perform registration");
81  connect(mRegisterButton, SIGNAL(clicked()), this, SLOT(registerSlot()));
82 
87 
88  QHBoxLayout* regLayout = new QHBoxLayout;
89  regLayout->addWidget(mRegisterButton);
90  mVerticalLayout->addLayout(regLayout);
91  mVerticalLayout->addStretch();
92 }
93 
95 {
96  settings()->setValue("registration/I2ILandmarkTranslation", mTranslationCheckBox->isChecked());
97 }
98 
100 {
101  mFixedLandmarkSource->setData(mServices.registrationService->getFixedData());
102  mMovingLandmarkSource->setData(mServices.registrationService->getMovingData());
103 }
104 
106 {
107  this->performRegistration();
108 }
109 
111 {
112 }
113 
115 {
116  return "<html>"
117  "<h3>Landmark based image to image registration.</h3>"
118  "<p>Register moving image to fixed image. </p>"
119  "</html>";
120 }
121 
123 {
125  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsIMAGE_REGISTRATED);
126 
127  LandmarkRepPtr rep = mServices.visualizationService->get3DReps(0, 0)->findFirst<LandmarkRep>();
128 // LandmarkRepPtr rep = RepContainer::findFirstRep<LandmarkRep>(mServices.visualizationService->get3DView(0, 0)->getReps());
129  if (rep)
130  {
132  rep->setSecondarySource(mMovingLandmarkSource);
133  rep->setSecondaryColor(QColor::fromRgbF(0, 0.9, 0.5));
134  }
135 }
136 
138 {
140 
141  if(mServices.visualizationService->get3DView(0, 0))
142  {
143  LandmarkRepPtr rep = mServices.visualizationService->get3DReps(0, 0)->findFirst<LandmarkRep>();
144 // LandmarkRepPtr rep = RepContainer::findFirstRep<LandmarkRep>(mServices.visualizationService->get3DView(0, 0)->getReps());
145  if (rep)
146  {
148  rep->setSecondarySource(LandmarksSourcePtr());
149  }
150  }
151  mServices.visualizationService->getGroup(0)->setRegistrationMode(rsNOT_REGISTRATED);
152 }
153 
155 {
156 }
157 
159 {
160  ImagePtr moving = boost::dynamic_pointer_cast<Image>(mServices.registrationService->getMovingData());
161 
162  if (moving)
163  return moving->getLandmarks()->getLandmarks();
164  else
165  return LandmarkMap();
166 }
167 
169 {
170  mServices.registrationService->doImageRegistration(mTranslationCheckBox->isChecked());
172 }
173 
178 {
179  if (!mServices.registrationService->getMovingData())
180  return Transform3D::Identity();
181  return mServices.registrationService->getMovingData()->get_rMd();
182 }
183 
185 {
186  ImagePtr image = boost::dynamic_pointer_cast<Image>(mServices.registrationService->getMovingData());
187  if (!image)
188  return;
189  image->getLandmarks()->setLandmark(Landmark(uid, p_target));
190 }
191 
193 {
194  DataPtr image = mServices.registrationService->getMovingData();
195  if (!image)
196  return "None";
197  return image->getName();
198 }
199 
200 
201 }//namespace cx
202 
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
virtual void setTargetLandmark(QString uid, Vector3D p_target)
static ImageLandmarksSourcePtr New()
Definition: cxLandmarkRep.h:94
QLabel * mAvarageAccuracyLabel
label showing the average accuracy
One landmark, or fiducial, coordinate.
Definition: cxLandmark.h:61
Transform3D Transform3D
Transform3D is a representation of an affine 3D transform.
LandmarksPtr getLandmarks()
Definition: cxData.cpp:186
boost::shared_ptr< class Image > ImagePtr
Definition: cxDicomWidget.h:48
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
Composite widget for string selection.
QVBoxLayout * mVerticalLayout
vertical layout is used
void fixedDataChanged(QString uid)
virtual void hideEvent(QHideEvent *event)
virtual QString defaultWhatsThis() const
Returns a short description of what this widget will do for you.
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:91
boost::shared_ptr< class Data > DataPtr
A volumetric data set.
Definition: cxImage.h:64
void setPrimarySource(LandmarksSourcePtr primary)
rsNOT_REGISTRATED
Settings * settings()
Shortcut for accessing the settings instance.
Definition: cxSettings.cpp:42
Eigen::Vector3d Vector3D
Vector3D is a representation of a point or vector in 3D.
Definition: cxVector3D.h:63
VisualizationServicePtr visualizationService
Definition: cxVisServices.h:60
void movingDataChanged(QString uid)
boost::shared_ptr< LandmarksSource > LandmarksSourcePtr
Definition: cxLandmarkRep.h:72
std::map< QString, class Landmark > LandmarkMap
PatientModelServicePtr patientModelService
StringPropertyRegistrationMovingImagePtr mMovingProperty
boost::shared_ptr< class LandmarkRep > LandmarkRepPtr
RegistrationServicePtr registrationService
Definition: cxRegServices.h:60
rsIMAGE_REGISTRATED
QTableWidget * mLandmarkTableWidget
the table widget presenting the landmarks