Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkQuaternionRigidTransformView.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 <itkQuaternionRigidTransform.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 QmitkQuaternionRigidTransformView::GetTransform2(
50  itk::Image<TPixelType, VImageDimension> *itkImage1)
51 {
52  if (VImageDimension == 3)
53  {
54  typedef typename itk::Image<TPixelType, 3> FixedImageType;
55  typedef typename itk::Image<TPixelType, 3> MovingImageType;
56 
57  // the fixedImage is the input parameter (fix for Bug #14626)
58  typename FixedImageType::Pointer fixedImage = itkImage1;
59 
60  // the movingImage type is known, use the ImageToItk filter (fix for Bug #14626)
62  movingImageToItk->SetInput(m_MovingImage);
63  movingImageToItk->Update();
64  typename MovingImageType::Pointer movingImage = movingImageToItk->GetOutput();
65 
66  typename itk::QuaternionRigidTransform<double>::Pointer transformPointer =
68  transformPointer->SetIdentity();
69  typedef typename itk::QuaternionRigidTransform<double> QuaternionRigidTransformType;
70  if (m_Controls.m_CenterForInitializerQuaternionRigid->isChecked())
71  {
72  typedef typename itk::CenteredTransformInitializer<QuaternionRigidTransformType, FixedImageType, MovingImageType>
73  TransformInitializerType;
74  typename TransformInitializerType::Pointer transformInitializer = TransformInitializerType::New();
75  transformInitializer->SetFixedImage(fixedImage);
76  transformInitializer->SetMovingImage(movingImage);
77  transformInitializer->SetTransform(transformPointer);
78  if (m_Controls.m_MomentsQuaternionRigid->isChecked())
79  {
80  transformInitializer->MomentsOn();
81  }
82  else
83  {
84  transformInitializer->GeometryOn();
85  }
86  transformInitializer->InitializeTransform();
87  }
88  m_CenterX = transformPointer->GetCenter()[0];
89  m_CenterY = transformPointer->GetCenter()[1];
90  m_CenterZ = transformPointer->GetCenter()[2];
91  m_TransformObject = transformPointer.GetPointer();
92  return transformPointer.GetPointer();
93  }
94  return nullptr;
95 }
96 
98 {
99  itk::Array<double> transformValues;
100  transformValues.SetSize(10);
101  transformValues.fill(0);
102  transformValues[0] = m_Controls.m_UseOptimizerScalesQuaternionRigid->isChecked();
103  transformValues[1] = m_Controls.m_ScalesQuaternionRigidTransformScale1->text().toDouble();
104  transformValues[2] = m_Controls.m_ScalesQuaternionRigidTransformScale2->text().toDouble();
105  transformValues[3] = m_Controls.m_ScalesQuaternionRigidTransformScale3->text().toDouble();
106  transformValues[4] = m_Controls.m_ScalesQuaternionRigidTransformScale4->text().toDouble();
107  transformValues[5] = m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationX->text().toDouble();
108  transformValues[6] = m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationY->text().toDouble();
109  transformValues[7] = m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationZ->text().toDouble();
110  transformValues[8] = m_Controls.m_CenterForInitializerQuaternionRigid->isChecked();
111  transformValues[9] = m_Controls.m_MomentsQuaternionRigid->isChecked();
112  return transformValues;
113 }
114 
115 void QmitkQuaternionRigidTransformView::SetTransformParameters(itk::Array<double> transformValues)
116 {
117  m_Controls.m_UseOptimizerScalesQuaternionRigid->setChecked(transformValues[0]);
118  m_Controls.m_ScalesQuaternionRigidTransformScale1->setText(QString::number(transformValues[1]));
119  m_Controls.m_ScalesQuaternionRigidTransformScale2->setText(QString::number(transformValues[2]));
120  m_Controls.m_ScalesQuaternionRigidTransformScale3->setText(QString::number(transformValues[3]));
121  m_Controls.m_ScalesQuaternionRigidTransformScale4->setText(QString::number(transformValues[4]));
122  m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationX->setText(QString::number(transformValues[5]));
123  m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationY->setText(QString::number(transformValues[6]));
124  m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationZ->setText(QString::number(transformValues[7]));
125  m_Controls.m_CenterForInitializerQuaternionRigid->setChecked(transformValues[8]);
126  m_Controls.m_MomentsQuaternionRigid->setChecked(transformValues[9]);
127  m_Controls.m_GeometryQuaternionRigid->setChecked(!transformValues[9]);
128 }
129 
131 {
132  return "QuaternionRigid";
133 }
134 
136 {
137  m_Controls.setupUi(parent);
138  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
139  m_Controls.m_ScalesQuaternionRigidTransformScale1->setValidator(validatorLineEditInputFloat);
140  m_Controls.m_ScalesQuaternionRigidTransformScale2->setValidator(validatorLineEditInputFloat);
141  m_Controls.m_ScalesQuaternionRigidTransformScale3->setValidator(validatorLineEditInputFloat);
142  m_Controls.m_ScalesQuaternionRigidTransformScale4->setValidator(validatorLineEditInputFloat);
143  m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
144  m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
145  m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationZ->setValidator(validatorLineEditInputFloat);
146 }
147 
149 {
150  itk::Array<double> scales;
151  scales.SetSize(7);
152  scales.Fill(1.0);
153  if (m_Controls.m_UseOptimizerScalesQuaternionRigid->isChecked())
154  {
155  scales[0] = m_Controls.m_ScalesQuaternionRigidTransformScale1->text().toDouble();
156  scales[1] = m_Controls.m_ScalesQuaternionRigidTransformScale2->text().toDouble();
157  scales[2] = m_Controls.m_ScalesQuaternionRigidTransformScale3->text().toDouble();
158  scales[3] = m_Controls.m_ScalesQuaternionRigidTransformScale4->text().toDouble();
159  scales[4] = m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationX->text().toDouble();
160  scales[5] = m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationY->text().toDouble();
161  scales[6] = m_Controls.m_ScalesQuaternionRigidTransformScaleTranslationZ->text().toDouble();
162  }
163  return scales;
164 }
165 
166 vtkTransform *QmitkQuaternionRigidTransformView::Transform(vtkMatrix4x4 *vtkmatrix,
167  vtkTransform *vtktransform,
168  itk::Array<double> transformParams)
169 {
170  if (m_MovingImage.IsNotNull())
171  {
173  quaternionTransform->SetParameters(transformParams);
174  itk::Matrix<double, 3, 3> Matrix = quaternionTransform->GetMatrix();
175  for (int i = 0; i < 3; i++)
176  {
177  for (int j = 0; j < 3; j++)
178  {
179  vtkmatrix->SetElement(i, j, Matrix[i][j]);
180  }
181  }
182  float center[4];
183  float translation[4];
184  center[0] = m_CenterX;
185  center[1] = m_CenterY;
186  center[2] = m_CenterZ;
187  center[3] = 1;
188  vtkmatrix->MultiplyPoint(center, translation);
189  vtkmatrix->SetElement(0, 3, -translation[0] + center[0] + transformParams[4]);
190  vtkmatrix->SetElement(1, 3, -translation[1] + center[1] + transformParams[5]);
191  vtkmatrix->SetElement(2, 3, -translation[2] + center[2] + transformParams[6]);
192  vtktransform->SetMatrix(vtkmatrix);
193  }
194  return vtktransform;
195 }
196 
198 {
199  if (m_FixedImage.IsNotNull())
200  {
201  if (m_FixedImage->GetDimension() == 2)
202  return 0;
203  else
204  return 7;
205  }
206  else
207  return 0;
208 }
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
virtual void SetupUI(QWidget *parent) override
TransformType
Unique integer value for every transform.
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
virtual itk::Array< double > GetTransformParameters() override
virtual mitk::TransformParameters::TransformType GetTransformType() override
virtual itk::Array< double > GetScales() override
virtual void SetTransformParameters(itk::Array< double > transformValues) override
static Pointer New()
QmitkQuaternionRigidTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
virtual itk::Object::Pointer GetTransform() override
Ui::QmitkQuaternionRigidTransformControls m_Controls
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.