Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkVersorRigid3DTransformView.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 #include <mitkImageCast.h>
23 
25  : QmitkRigidRegistrationTransformsGUIBase(parent, f), m_CenterX(0), m_CenterY(0), m_CenterZ(0)
26 {
27 }
28 
30 {
31 }
32 
34 {
36 }
37 
39 {
40  if (m_FixedImage.IsNotNull())
41  {
42  AccessFixedDimensionByItk(m_FixedImage, GetTransform2, 3);
43  return m_TransformObject;
44  }
45  return nullptr;
46 }
47 
48 template <class TPixelType, unsigned int VImageDimension>
49 itk::Object::Pointer QmitkVersorRigid3DTransformView::GetTransform2(itk::Image<TPixelType, VImageDimension> *itkImage1)
50 {
51  if (VImageDimension == 3)
52  {
53  typedef typename itk::Image<TPixelType, 3> FixedImage3DType;
54  typedef typename itk::Image<TPixelType, 3> MovingImage3DType;
55 
56  // the fixedImage is the input parameter (fix for Bug #14626)
57  typename FixedImage3DType::Pointer fixedImage = itkImage1;
58 
59  // the movingImage type is known, use the ImageToItk filter (fix for Bug #14626)
61  movingImageToItk->SetInput(m_MovingImage);
62  movingImageToItk->Update();
63  typename MovingImage3DType::Pointer movingImage = movingImageToItk->GetOutput();
64 
66  transformPointer->SetIdentity();
67  typedef typename itk::VersorRigid3DTransform<double> VersorRigid3DTransformType;
68  if (m_Controls.m_CenterForInitializerVersorRigid3D->isChecked())
69  {
70  typedef
71  typename itk::CenteredTransformInitializer<VersorRigid3DTransformType, FixedImage3DType, MovingImage3DType>
72  TransformInitializerType;
73  typename TransformInitializerType::Pointer transformInitializer = TransformInitializerType::New();
74  transformInitializer->SetFixedImage(fixedImage);
75  transformInitializer->SetMovingImage(movingImage);
76  transformInitializer->SetTransform(transformPointer);
77  if (m_Controls.m_MomentsVersorRigid3D->isChecked())
78  {
79  transformInitializer->MomentsOn();
80  }
81  else
82  {
83  transformInitializer->GeometryOn();
84  }
85  transformInitializer->InitializeTransform();
86  }
87  typedef VersorRigid3DTransformType::VersorType VersorType;
89 
90  VersorType rotation;
91  VectorType axis;
92 
93  axis[0] = 0.0;
94  axis[1] = 0.0;
95  axis[2] = 1.0;
96 
97  const double angle = 0;
98 
99  rotation.Set(axis, angle);
100 
101  transformPointer->SetRotation(rotation);
102  m_CenterX = transformPointer->GetCenter()[0];
103  m_CenterY = transformPointer->GetCenter()[1];
104  m_CenterZ = transformPointer->GetCenter()[2];
105  m_TransformObject = transformPointer.GetPointer();
106  return transformPointer.GetPointer();
107  }
108  return nullptr;
109 }
110 
112 {
113  itk::Array<double> transformValues;
114  transformValues.SetSize(9);
115  transformValues.fill(0);
116  transformValues[0] = m_Controls.m_UseOptimizerScalesVersorRigid3D->isChecked();
117  transformValues[1] = m_Controls.m_ScalesVersorRigid3DTransformScale1->text().toDouble();
118  transformValues[2] = m_Controls.m_ScalesVersorRigid3DTransformScale2->text().toDouble();
119  transformValues[3] = m_Controls.m_ScalesVersorRigid3DTransformScale3->text().toDouble();
120  transformValues[4] = m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationX->text().toDouble();
121  transformValues[5] = m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationY->text().toDouble();
122  transformValues[6] = m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationZ->text().toDouble();
123  transformValues[7] = m_Controls.m_CenterForInitializerVersorRigid3D->isChecked();
124  transformValues[8] = m_Controls.m_MomentsVersorRigid3D->isChecked();
125  return transformValues;
126 }
127 
128 void QmitkVersorRigid3DTransformView::SetTransformParameters(itk::Array<double> transformValues)
129 {
130  m_Controls.m_UseOptimizerScalesVersorRigid3D->setChecked(transformValues[0]);
131  m_Controls.m_ScalesVersorRigid3DTransformScale1->setText(QString::number(transformValues[1]));
132  m_Controls.m_ScalesVersorRigid3DTransformScale2->setText(QString::number(transformValues[2]));
133  m_Controls.m_ScalesVersorRigid3DTransformScale3->setText(QString::number(transformValues[3]));
134  m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationX->setText(QString::number(transformValues[4]));
135  m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationY->setText(QString::number(transformValues[5]));
136  m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationZ->setText(QString::number(transformValues[6]));
137  m_Controls.m_CenterForInitializerVersorRigid3D->setChecked(transformValues[7]);
138  m_Controls.m_MomentsVersorRigid3D->setChecked(transformValues[8]);
139  m_Controls.m_GeometryVersorRigid3D->setChecked(!transformValues[8]);
140 }
141 
143 {
144  return "VersorRigid3D";
145 }
146 
148 {
149  m_Controls.setupUi(parent);
150  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
151  m_Controls.m_ScalesVersorRigid3DTransformScale1->setValidator(validatorLineEditInputFloat);
152  m_Controls.m_ScalesVersorRigid3DTransformScale2->setValidator(validatorLineEditInputFloat);
153  m_Controls.m_ScalesVersorRigid3DTransformScale3->setValidator(validatorLineEditInputFloat);
154  m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
155  m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
156  m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationZ->setValidator(validatorLineEditInputFloat);
157 }
158 
160 {
161  itk::Array<double> scales;
162  scales.SetSize(6);
163  scales.Fill(1.0);
164  if (m_Controls.m_UseOptimizerScalesVersorRigid3D->isChecked())
165  {
166  scales[0] = m_Controls.m_ScalesVersorRigid3DTransformScale1->text().toDouble();
167  scales[1] = m_Controls.m_ScalesVersorRigid3DTransformScale2->text().toDouble();
168  scales[2] = m_Controls.m_ScalesVersorRigid3DTransformScale3->text().toDouble();
169  scales[3] = m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationX->text().toDouble();
170  scales[4] = m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationY->text().toDouble();
171  scales[5] = m_Controls.m_ScalesVersorRigid3DTransformScaleTranslationZ->text().toDouble();
172  }
173  return scales;
174 }
175 
176 vtkTransform *QmitkVersorRigid3DTransformView::Transform(vtkMatrix4x4 *vtkmatrix,
177  vtkTransform *vtktransform,
178  itk::Array<double> transformParams)
179 {
180  if (m_MovingImage.IsNotNull())
181  {
183  versorTransform->SetParameters(transformParams);
184  itk::Matrix<double, 3, 3> Matrix = versorTransform->GetMatrix();
185  for (int i = 0; i < 3; i++)
186  {
187  for (int j = 0; j < 3; j++)
188  {
189  vtkmatrix->SetElement(i, j, Matrix[i][j]);
190  }
191  }
192  float center[4];
193  float translation[4];
194  center[0] = m_CenterX;
195  center[1] = m_CenterY;
196  center[2] = m_CenterZ;
197  center[3] = 1;
198  vtkmatrix->MultiplyPoint(center, translation);
199  vtkmatrix->SetElement(0, 3, -translation[0] + center[0] + transformParams[3]);
200  vtkmatrix->SetElement(1, 3, -translation[1] + center[1] + transformParams[4]);
201  vtkmatrix->SetElement(2, 3, -translation[2] + center[2] + transformParams[5]);
202  vtktransform->SetMatrix(vtkmatrix);
203  }
204  return vtktransform;
205 }
206 
208 {
209  if (m_FixedImage.IsNotNull())
210  {
211  if (m_FixedImage->GetDimension() == 2)
212  return 0;
213  else
214  return 6;
215  }
216  else
217  return 0;
218 }
itk::SmartPointer< Self > Pointer
virtual itk::Array< double > GetScales() override
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
static Matrix3D rotation
TransformType
Unique integer value for every transform.
Ui::QmitkVersorRigid3DTransformControls m_Controls
itk::Vector< float, 3 > VectorType
QmitkVersorRigid3DTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
virtual itk::Array< double > GetTransformParameters() override
static Pointer New()
virtual void SetTransformParameters(itk::Array< double > transformValues) override
virtual void SetupUI(QWidget *parent) override
virtual mitk::TransformParameters::TransformType GetTransformType() override
virtual itk::Object::Pointer GetTransform() override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.