Fraxinus  16.5.0-fx-rc1
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 "cxRepContainer.h"
54 #include "cxLandmarkListener.h"
55 
56 namespace cx
57 {
58 LandmarkImage2ImageRegistrationWidget::LandmarkImage2ImageRegistrationWidget(RegServicesPtr services,
59  QWidget* parent, QString objectName, QString windowTitle) :
60  LandmarkRegistrationWidget(services, parent, objectName, windowTitle)
61 {
62  mLandmarkTableWidget->hide();
63 
64  mLandmarkListener->useI2IRegistration();
65 
66  mFixedProperty.reset(new StringPropertyRegistrationFixedImage(services->registration(), services->patient()));
67  mMovingProperty.reset(new StringPropertyRegistrationMovingImage(services->registration(), services->patient()));
68 
69  mTranslationCheckBox = new QCheckBox("Translation only", this);
70  mTranslationCheckBox->setChecked(settings()->value("registration/I2ILandmarkTranslation", false).toBool());
71  connect(mTranslationCheckBox, SIGNAL(toggled(bool)), this, SLOT(translationCheckBoxChanged()));
72 
73  mRegisterButton = new QPushButton("Register", this);
74  mRegisterButton->setToolTip("Perform registration");
75  connect(mRegisterButton, SIGNAL(clicked()), this, SLOT(registerSlot()));
76 
81 
82  QHBoxLayout* regLayout = new QHBoxLayout;
83  regLayout->addWidget(mRegisterButton);
84  mVerticalLayout->addLayout(regLayout);
85  mVerticalLayout->addStretch();
86 }
87 
89 {
90  settings()->setValue("registration/I2ILandmarkTranslation", mTranslationCheckBox->isChecked());
91 }
92 
94 {
95  this->performRegistration();
96 }
97 
99 {
100 }
101 
103 {
104  return "<html>"
105  "<h3>Landmark based image to image registration.</h3>"
106  "<p>Register moving image to fixed image. </p>"
107  "</html>";
108 }
109 
111 {
112  mServices->view()->setRegistrationMode(rsIMAGE_REGISTRATED);
114 }
115 
117 {
118  mServices->view()->setRegistrationMode(rsNOT_REGISTRATED);
120 }
121 
123 {
124 }
125 
127 {
128  ImagePtr moving = boost::dynamic_pointer_cast<Image>(mServices->registration()->getMovingData());
129 
130  if (moving)
131  return moving->getLandmarks()->getLandmarks();
132  else
133  return LandmarkMap();
134 }
135 
137 {
138  mServices->registration()->doImageRegistration(mTranslationCheckBox->isChecked());
140 }
141 
146 {
147  if (!mServices->registration()->getMovingData())
148  return Transform3D::Identity();
149  return mServices->registration()->getMovingData()->get_rMd();
150 }
151 
153 {
154  ImagePtr image = boost::dynamic_pointer_cast<Image>(mServices->registration()->getMovingData());
155  if (!image)
156  return;
157  image->getLandmarks()->setLandmark(Landmark(uid, p_target));
158 }
159 
161 {
162  DataPtr image = mServices->registration()->getMovingData();
163  if (!image)
164  return "None";
165  return image->getName();
166 }
167 
168 
169 }//namespace cx
170 
virtual void showEvent(QShowEvent *event)
updates internal info before showing the widget
virtual void setTargetLandmark(QString uid, Vector3D p_target)
boost::shared_ptr< class RegServices > RegServicesPtr
Definition: cxRegServices.h:41
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:207
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
virtual void hideEvent(QHideEvent *event)
void setValue(const QString &key, const QVariant &value)
Definition: cxSettings.cpp:79
boost::shared_ptr< class Data > DataPtr
A volumetric data set.
Definition: cxImage.h:66
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
std::map< QString, class Landmark > LandmarkMap
StringPropertyRegistrationMovingImagePtr mMovingProperty
rsIMAGE_REGISTRATED
QTableWidget * mLandmarkTableWidget
the table widget presenting the landmarks