Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkScaleSkewVersor3DTransformView.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 <itkScaleSkewVersor3DTransform.h>
22 #include <mitkImageCast.h>
23 
25  : QmitkRigidRegistrationTransformsGUIBase(parent, f), m_CenterX(0), m_CenterY(0), m_CenterZ(0)
26 {
27 }
28 
30 {
31 }
33 {
35 }
36 
38 {
39  if (m_FixedImage.IsNotNull())
40  {
41  AccessFixedDimensionByItk(m_FixedImage, GetTransform2, 3);
42  return m_TransformObject;
43  }
44  return nullptr;
45 }
46 
47 template <class TPixelType, unsigned int VImageDimension>
48 itk::Object::Pointer QmitkScaleSkewVersor3DTransformView::GetTransform2(
49  itk::Image<TPixelType, VImageDimension> *itkImage1)
50 {
51  if (VImageDimension == 3)
52  {
53  typedef typename itk::Image<TPixelType, 3> FixedImageType;
54  typedef typename itk::Image<TPixelType, 3> MovingImageType;
55 
56  // the fixedImage is the input parameter (fix for Bug #14626)
57  typename FixedImageType::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 MovingImageType::Pointer movingImage = movingImageToItk->GetOutput();
64 
65  typename itk::ScaleSkewVersor3DTransform<double>::Pointer transformPointer =
67  transformPointer->SetIdentity();
68  if (m_Controls.m_CenterForInitializerScaleSkewVersorRigid3D->isChecked())
69  {
70  typedef typename itk::ScaleSkewVersor3DTransform<double> ScaleSkewVersor3DTransformType;
71  typedef
72  typename itk::CenteredTransformInitializer<ScaleSkewVersor3DTransformType, 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_MomentsScaleSkewVersorRigid3D->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(18);
101  transformValues.fill(0);
102  transformValues[0] = m_Controls.m_UseOptimizerScalesScaleSkewVersorRigid3DTransform->isChecked();
103  transformValues[1] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale1->text().toDouble();
104  transformValues[2] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale2->text().toDouble();
105  transformValues[3] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale3->text().toDouble();
106  transformValues[4] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScaleTranslationX->text().toDouble();
107  transformValues[5] = m_Controls.m_ScaleScaleSkewVersorRigid3DTransformScaleTranslationY->text().toDouble();
108  transformValues[6] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScaleTranslationZ->text().toDouble();
109  transformValues[7] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale7->text().toDouble();
110  transformValues[8] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale8->text().toDouble();
111  transformValues[9] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale9->text().toDouble();
112  transformValues[10] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale10->text().toDouble();
113  transformValues[11] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale11->text().toDouble();
114  transformValues[12] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale12->text().toDouble();
115  transformValues[13] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale13->text().toDouble();
116  transformValues[14] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale14->text().toDouble();
117  transformValues[15] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale15->text().toDouble();
118  transformValues[16] = m_Controls.m_CenterForInitializerScaleSkewVersorRigid3D->isChecked();
119  transformValues[17] = m_Controls.m_MomentsScaleSkewVersorRigid3D->isChecked();
120  return transformValues;
121 }
122 
123 void QmitkScaleSkewVersor3DTransformView::SetTransformParameters(itk::Array<double> transformValues)
124 {
125  m_Controls.m_UseOptimizerScalesScaleSkewVersorRigid3DTransform->setChecked(transformValues[0]);
126  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale1->setText(QString::number(transformValues[1]));
127  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale2->setText(QString::number(transformValues[2]));
128  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale3->setText(QString::number(transformValues[3]));
129  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScaleTranslationX->setText(QString::number(transformValues[4]));
130  m_Controls.m_ScaleScaleSkewVersorRigid3DTransformScaleTranslationY->setText(QString::number(transformValues[5]));
131  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScaleTranslationZ->setText(QString::number(transformValues[6]));
132  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale7->setText(QString::number(transformValues[7]));
133  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale8->setText(QString::number(transformValues[8]));
134  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale9->setText(QString::number(transformValues[9]));
135  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale10->setText(QString::number(transformValues[10]));
136  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale11->setText(QString::number(transformValues[11]));
137  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale12->setText(QString::number(transformValues[12]));
138  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale13->setText(QString::number(transformValues[13]));
139  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale14->setText(QString::number(transformValues[14]));
140  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale15->setText(QString::number(transformValues[15]));
141  m_Controls.m_CenterForInitializerScaleSkewVersorRigid3D->setChecked(transformValues[16]);
142  m_Controls.m_MomentsScaleSkewVersorRigid3D->setChecked(transformValues[17]);
143  m_Controls.m_GeometryScaleSkewVersorRigid3D->setChecked(!transformValues[17]);
144 }
145 
147 {
148  return "ScaleSkewVersor3D";
149 }
150 
152 {
153  m_Controls.setupUi(parent);
154  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
155  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale1->setValidator(validatorLineEditInputFloat);
156  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale2->setValidator(validatorLineEditInputFloat);
157  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale3->setValidator(validatorLineEditInputFloat);
158  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
159  m_Controls.m_ScaleScaleSkewVersorRigid3DTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
160  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScaleTranslationZ->setValidator(validatorLineEditInputFloat);
161  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale7->setValidator(validatorLineEditInputFloat);
162  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale8->setValidator(validatorLineEditInputFloat);
163  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale9->setValidator(validatorLineEditInputFloat);
164  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale10->setValidator(validatorLineEditInputFloat);
165  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale11->setValidator(validatorLineEditInputFloat);
166  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale12->setValidator(validatorLineEditInputFloat);
167  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale13->setValidator(validatorLineEditInputFloat);
168  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale14->setValidator(validatorLineEditInputFloat);
169  m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale15->setValidator(validatorLineEditInputFloat);
170 }
171 
173 {
174  itk::Array<double> scales;
175  scales.SetSize(15);
176  scales.Fill(1.0);
177  if (m_Controls.m_UseOptimizerScalesScaleSkewVersorRigid3DTransform->isChecked())
178  {
179  scales[0] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale1->text().toDouble();
180  scales[1] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale2->text().toDouble();
181  scales[2] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale3->text().toDouble();
182  scales[3] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScaleTranslationX->text().toDouble();
183  scales[4] = m_Controls.m_ScaleScaleSkewVersorRigid3DTransformScaleTranslationY->text().toDouble();
184  scales[5] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScaleTranslationZ->text().toDouble();
185  scales[6] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale7->text().toDouble();
186  scales[7] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale8->text().toDouble();
187  scales[8] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale9->text().toDouble();
188  scales[9] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale10->text().toDouble();
189  scales[10] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale11->text().toDouble();
190  scales[11] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale12->text().toDouble();
191  scales[12] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale13->text().toDouble();
192  scales[13] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale14->text().toDouble();
193  scales[14] = m_Controls.m_ScalesScaleSkewVersorRigid3DTransformScale15->text().toDouble();
194  }
195  return scales;
196 }
197 
198 vtkTransform *QmitkScaleSkewVersor3DTransformView::Transform(vtkMatrix4x4 *vtkmatrix,
199  vtkTransform *vtktransform,
200  itk::Array<double> transformParams)
201 {
202  if (m_MovingImage.IsNotNull())
203  {
205  versorTransform->SetParameters(transformParams);
206  itk::Matrix<double, 3, 3> Matrix = versorTransform->GetMatrix();
207  for (int i = 0; i < 3; i++)
208  {
209  for (int j = 0; j < 3; j++)
210  {
211  vtkmatrix->SetElement(i, j, Matrix[i][j]);
212  }
213  }
214  float center[4];
215  float translation[4];
216  center[0] = m_CenterX;
217  center[1] = m_CenterY;
218  center[2] = m_CenterZ;
219  center[3] = 1;
220  vtkmatrix->MultiplyPoint(center, translation);
221  vtkmatrix->SetElement(0, 3, -translation[0] + center[0] + transformParams[3]);
222  vtkmatrix->SetElement(1, 3, -translation[1] + center[1] + transformParams[4]);
223  vtkmatrix->SetElement(2, 3, -translation[2] + center[2] + transformParams[5]);
224  vtktransform->SetMatrix(vtkmatrix);
225  }
226  return vtktransform;
227 }
228 
230 {
231  if (m_FixedImage.IsNotNull())
232  {
233  if (m_FixedImage->GetDimension() == 2)
234  return 0;
235  else
236  return 15;
237  }
238  else
239  return 0;
240 }
QmitkScaleSkewVersor3DTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
itk::SmartPointer< Self > Pointer
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
virtual itk::Array< double > GetScales() override
virtual itk::Array< double > GetTransformParameters() override
virtual void SetupUI(QWidget *parent) override
TransformType
Unique integer value for every transform.
virtual void SetTransformParameters(itk::Array< double > transformValues) override
virtual itk::Object::Pointer GetTransform() override
static Pointer New()
virtual mitk::TransformParameters::TransformType GetTransformType() override
Ui::QmitkScaleSkewVersor3DTransformControls m_Controls
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.