Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkRigid3DTransformView.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 #include "mitkImageAccessByItk.h"
19 #include <QValidator>
20 #include <itkCenteredTransformInitializer.h>
21 #include <itkVersorRigid3DTransform.h>
22 
23 QmitkRigid3DTransformView::QmitkRigid3DTransformView(QWidget *parent, Qt::WindowFlags f)
24  : QmitkRigidRegistrationTransformsGUIBase(parent, f), m_CenterX(0), m_CenterY(0), m_CenterZ(0)
25 {
26 }
27 
29 {
30 }
31 
33 {
34  return mitk::TransformParameters::RIGID3DTRANSFORM;
35 }
36 
38 {
39  if (m_FixedImage.IsNotNull())
40  {
41  AccessByItk(m_FixedImage, GetTransform2);
42  return m_TransformObject;
43  }
44  return NULL;
45 }
46 
47 template <class TPixelType, unsigned int VImageDimension>
48 itk::Object::Pointer QmitkRigid3DTransformView::GetTransform2(itk::Image<TPixelType, VImageDimension> * /*itkImage1*/)
49 {
50  typedef typename itk::Image<TPixelType, VImageDimension> FixedImageType;
51  typedef typename itk::Image<TPixelType, VImageDimension> MovingImageType;
52  if (VImageDimension == 3)
53  {
55  transformPointer->SetIdentity();
56  m_CenterX = transformPointer->GetCenter()[0];
57  m_CenterY = transformPointer->GetCenter()[1];
58  m_CenterZ = transformPointer->GetCenter()[2];
59  m_TransformObject = transformPointer.GetPointer();
60  return transformPointer.GetPointer();
61  }
62  return NULL;
63 }
64 
66 {
67  itk::Array<double> transformValues;
68  transformValues.SetSize(15);
69  transformValues.fill(0);
70  transformValues[0] = m_Controls.m_UseOptimizerScalesRigid3D->isChecked();
71  transformValues[1] = m_Controls.m_ScalesRigid3DTransformScale1->text().toDouble();
72  transformValues[2] = m_Controls.m_ScalesRigid3DTransformScale2->text().toDouble();
73  transformValues[3] = m_Controls.m_ScalesRigid3DTransformScale3->text().toDouble();
74  transformValues[4] = m_Controls.m_ScalesRigid3DTransformScale4->text().toDouble();
75  transformValues[5] = m_Controls.m_ScalesRigid3DTransformScale5->text().toDouble();
76  transformValues[6] = m_Controls.m_ScalesRigid3DTransformScale6->text().toDouble();
77  transformValues[7] = m_Controls.m_ScalesRigid3DTransformScale7->text().toDouble();
78  transformValues[8] = m_Controls.m_ScalesRigid3DTransformScale8->text().toDouble();
79  transformValues[9] = m_Controls.m_ScalesRigid3DTransformScale9->text().toDouble();
80  transformValues[10] = m_Controls.m_ScalesRigid3DTransformScaleTranslationX->text().toDouble();
81  transformValues[11] = m_Controls.m_ScalesRigid3DTransformScaleTranslationY->text().toDouble();
82  transformValues[12] = m_Controls.m_ScalesRigid3DTransformScaleTranslationZ->text().toDouble();
83  transformValues[13] = m_Controls.m_CenterForInitializerRigid3D->isChecked();
84  transformValues[14] = m_Controls.m_MomentsRigid3D->isChecked();
85  return transformValues;
86 }
87 
88 void QmitkRigid3DTransformView::SetTransformParameters(itk::Array<double> transformValues)
89 {
90  m_Controls.m_UseOptimizerScalesRigid3D->setChecked(transformValues[0]);
91  m_Controls.m_ScalesRigid3DTransformScale1->setText(QString::number(transformValues[1]));
92  m_Controls.m_ScalesRigid3DTransformScale2->setText(QString::number(transformValues[2]));
93  m_Controls.m_ScalesRigid3DTransformScale3->setText(QString::number(transformValues[3]));
94  m_Controls.m_ScalesRigid3DTransformScale4->setText(QString::number(transformValues[4]));
95  m_Controls.m_ScalesRigid3DTransformScale5->setText(QString::number(transformValues[5]));
96  m_Controls.m_ScalesRigid3DTransformScale6->setText(QString::number(transformValues[6]));
97  m_Controls.m_ScalesRigid3DTransformScale7->setText(QString::number(transformValues[7]));
98  m_Controls.m_ScalesRigid3DTransformScale8->setText(QString::number(transformValues[8]));
99  m_Controls.m_ScalesRigid3DTransformScale9->setText(QString::number(transformValues[9]));
100  m_Controls.m_ScalesRigid3DTransformScaleTranslationX->setText(QString::number(transformValues[10]));
101  m_Controls.m_ScalesRigid3DTransformScaleTranslationY->setText(QString::number(transformValues[11]));
102  m_Controls.m_ScalesRigid3DTransformScaleTranslationZ->setText(QString::number(transformValues[12]));
103  m_Controls.m_CenterForInitializerRigid3D->setChecked(transformValues[13]);
104  m_Controls.m_MomentsRigid3D->setChecked(transformValues[14]);
105  m_Controls.m_GeometryRigid3D->setChecked(!transformValues[14]);
106 }
107 
109 {
110  return "Rigid3D";
111 }
112 
114 {
115  m_Controls.setupUi(parent);
116  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
117  m_Controls.m_ScalesRigid3DTransformScale1->setValidator(validatorLineEditInputFloat);
118  m_Controls.m_ScalesRigid3DTransformScale2->setValidator(validatorLineEditInputFloat);
119  m_Controls.m_ScalesRigid3DTransformScale3->setValidator(validatorLineEditInputFloat);
120  m_Controls.m_ScalesRigid3DTransformScale4->setValidator(validatorLineEditInputFloat);
121  m_Controls.m_ScalesRigid3DTransformScale5->setValidator(validatorLineEditInputFloat);
122  m_Controls.m_ScalesRigid3DTransformScale6->setValidator(validatorLineEditInputFloat);
123  m_Controls.m_ScalesRigid3DTransformScale7->setValidator(validatorLineEditInputFloat);
124  m_Controls.m_ScalesRigid3DTransformScale8->setValidator(validatorLineEditInputFloat);
125  m_Controls.m_ScalesRigid3DTransformScale9->setValidator(validatorLineEditInputFloat);
126  m_Controls.m_ScalesRigid3DTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
127  m_Controls.m_ScalesRigid3DTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
128  m_Controls.m_ScalesRigid3DTransformScaleTranslationZ->setValidator(validatorLineEditInputFloat);
129 }
130 
132 {
133  itk::Array<double> scales;
134  scales.SetSize(12);
135  scales.Fill(1.0);
136  if (m_Controls.m_UseOptimizerScalesRigid3D->isChecked())
137  {
138  scales[0] = m_Controls.m_ScalesRigid3DTransformScale1->text().toDouble();
139  scales[1] = m_Controls.m_ScalesRigid3DTransformScale2->text().toDouble();
140  scales[2] = m_Controls.m_ScalesRigid3DTransformScale3->text().toDouble();
141  scales[3] = m_Controls.m_ScalesRigid3DTransformScale4->text().toDouble();
142  scales[4] = m_Controls.m_ScalesRigid3DTransformScale5->text().toDouble();
143  scales[5] = m_Controls.m_ScalesRigid3DTransformScale6->text().toDouble();
144  scales[6] = m_Controls.m_ScalesRigid3DTransformScale7->text().toDouble();
145  scales[7] = m_Controls.m_ScalesRigid3DTransformScale8->text().toDouble();
146  scales[8] = m_Controls.m_ScalesRigid3DTransformScale9->text().toDouble();
147  scales[9] = m_Controls.m_ScalesRigid3DTransformScaleTranslationX->text().toDouble();
148  scales[10] = m_Controls.m_ScalesRigid3DTransformScaleTranslationY->text().toDouble();
149  scales[11] = m_Controls.m_ScalesRigid3DTransformScaleTranslationZ->text().toDouble();
150  }
151  return scales;
152 }
153 
154 vtkTransform *QmitkRigid3DTransformView::Transform(vtkMatrix4x4 *vtkmatrix,
155  vtkTransform *vtktransform,
156  itk::Array<double> transformParams)
157 {
158  if (m_MovingImage.IsNotNull())
159  {
160  int m = 0;
161  for (int i = 0; i < 3; i++)
162  {
163  for (int j = 0; j < 3; j++)
164  {
165  vtkmatrix->SetElement(i, j, transformParams[m]);
166  m++;
167  }
168  }
169  float center[4];
170  float translation[4];
171  center[0] = m_CenterX;
172  center[1] = m_CenterY;
173  center[2] = m_CenterZ;
174  center[3] = 1;
175  vtkmatrix->MultiplyPoint(center, translation);
176  vtkmatrix->SetElement(0, 3, -translation[0] + center[0] + transformParams[9]);
177  vtkmatrix->SetElement(1, 3, -translation[1] + center[1] + transformParams[10]);
178  vtkmatrix->SetElement(2, 3, -translation[2] + center[2] + transformParams[11]);
179  vtktransform->SetMatrix(vtkmatrix);
180  }
181  return vtktransform;
182 }
183 
185 {
186  if (m_FixedImage.IsNotNull())
187  {
188  if (m_FixedImage->GetDimension() == 2)
189  return 6;
190  else
191  return 12;
192  }
193  else
194  return 0;
195 }
virtual void SetupUI(QWidget *parent)
itk::SmartPointer< Self > Pointer
virtual mitk::TransformParameters::TransformType GetTransformType()
TransformType
Unique integer value for every transform.
virtual void SetTransformParameters(itk::Array< double > transformValues)
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams)
virtual itk::Object::Pointer GetTransform()
#define AccessByItk(mitkImage, itkImageTypeFunction)
Access a MITK image by an ITK image.
itk::Object::Pointer m_TransformObject
QmitkRigid3DTransformView(QWidget *parent=0, Qt::WindowFlags f=0)
virtual itk::Array< double > GetScales()
virtual itk::Array< double > GetTransformParameters()
Ui::QmitkRigid3DTransformControls m_Controls
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.