Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkFixedCenterOfRotationAffineTransformView.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 <itkFixedCenterOfRotationAffineTransform.h>
22 #include <mitkImageCast.h>
23 
25  Qt::WindowFlags f)
26  : QmitkRigidRegistrationTransformsGUIBase(parent, f), m_CenterX(0), m_CenterY(0), m_CenterZ(0)
27 {
28 }
29 
31 {
32 }
33 
35 {
37 }
38 
40 {
41  if (m_FixedImage.IsNotNull())
42  {
43  AccessByItk(m_FixedImage, GetTransform2);
44  return m_TransformObject;
45  }
46  return nullptr;
47 }
48 
49 template <class TPixelType, unsigned int VImageDimension>
50 itk::Object::Pointer QmitkFixedCenterOfRotationAffineTransformView::GetTransform2(
51  itk::Image<TPixelType, VImageDimension> *itkImage1)
52 {
53  typedef typename itk::Image<TPixelType, VImageDimension> FixedImageType;
54  typedef typename itk::Image<TPixelType, VImageDimension> 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  typedef typename itk::FixedCenterOfRotationAffineTransform<double, VImageDimension> CenteredAffineTransformType;
68  transformPointer->SetIdentity();
69  if (m_Controls.m_CenterForInitializerFixedCenterOfRotationAffine->isChecked())
70  {
71  typedef typename itk::FixedCenterOfRotationAffineTransform<double, VImageDimension>
72  FixedCenterOfRotationAffineTransformType;
73  typedef typename itk::
74  CenteredTransformInitializer<FixedCenterOfRotationAffineTransformType, FixedImageType, MovingImageType>
75  TransformInitializerType;
76  typename TransformInitializerType::Pointer transformInitializer = TransformInitializerType::New();
77  transformInitializer->SetFixedImage(fixedImage);
78  transformInitializer->SetMovingImage(movingImage);
79  transformInitializer->SetTransform(transformPointer);
80  if (m_Controls.m_MomentsFixedCenterOfRotationAffine->isChecked())
81  {
82  transformInitializer->MomentsOn();
83  }
84  else
85  {
86  transformInitializer->GeometryOn();
87  }
88  m_CenterX = transformPointer->GetCenter()[0];
89  m_CenterY = transformPointer->GetCenter()[1];
90  m_CenterZ = transformPointer->GetCenter()[2];
91  transformInitializer->InitializeTransform();
92  }
93  m_TransformObject = transformPointer.GetPointer();
94  return transformPointer.GetPointer();
95 }
96 
98 {
99  itk::Array<double> transformValues;
100  transformValues.SetSize(15);
101  transformValues.fill(0);
102  transformValues[0] = m_Controls.m_UseOptimizerScalesFixedCenterOfRotationAffine->isChecked();
103  transformValues[1] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale1->text().toDouble();
104  transformValues[2] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale2->text().toDouble();
105  transformValues[3] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale3->text().toDouble();
106  transformValues[4] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale4->text().toDouble();
107  transformValues[5] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale5->text().toDouble();
108  transformValues[6] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale6->text().toDouble();
109  transformValues[7] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale7->text().toDouble();
110  transformValues[8] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale8->text().toDouble();
111  transformValues[9] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale9->text().toDouble();
112  transformValues[10] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationX->text().toDouble();
113  transformValues[11] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationY->text().toDouble();
114  transformValues[12] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationZ->text().toDouble();
115  transformValues[13] = m_Controls.m_CenterForInitializerFixedCenterOfRotationAffine->isChecked();
116  transformValues[14] = m_Controls.m_MomentsFixedCenterOfRotationAffine->isChecked();
117  return transformValues;
118 }
119 
121 {
122  m_Controls.m_UseOptimizerScalesFixedCenterOfRotationAffine->setChecked(transformValues[0]);
123  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale1->setText(QString::number(transformValues[1]));
124  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale2->setText(QString::number(transformValues[2]));
125  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale3->setText(QString::number(transformValues[3]));
126  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale4->setText(QString::number(transformValues[4]));
127  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale5->setText(QString::number(transformValues[5]));
128  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale6->setText(QString::number(transformValues[6]));
129  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale7->setText(QString::number(transformValues[7]));
130  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale8->setText(QString::number(transformValues[8]));
131  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale9->setText(QString::number(transformValues[9]));
132  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationX->setText(
133  QString::number(transformValues[10]));
134  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationY->setText(
135  QString::number(transformValues[11]));
136  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationZ->setText(
137  QString::number(transformValues[12]));
138  m_Controls.m_CenterForInitializerFixedCenterOfRotationAffine->setChecked(transformValues[13]);
139  m_Controls.m_MomentsFixedCenterOfRotationAffine->setChecked(transformValues[14]);
140  m_Controls.m_GeometryFixedCenterOfRotationAffine->setChecked(!transformValues[14]);
141 }
142 
144 {
145  return "FixedCenterOfRotationAffine";
146 }
147 
149 {
150  m_Controls.setupUi(parent);
151  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
152  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale1->setValidator(validatorLineEditInputFloat);
153  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale2->setValidator(validatorLineEditInputFloat);
154  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale3->setValidator(validatorLineEditInputFloat);
155  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale4->setValidator(validatorLineEditInputFloat);
156  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale5->setValidator(validatorLineEditInputFloat);
157  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale6->setValidator(validatorLineEditInputFloat);
158  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale7->setValidator(validatorLineEditInputFloat);
159  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale8->setValidator(validatorLineEditInputFloat);
160  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale9->setValidator(validatorLineEditInputFloat);
161  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
162  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
163  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationZ->setValidator(validatorLineEditInputFloat);
164 }
165 
167 {
168  itk::Array<double> scales;
169  scales.SetSize(12);
170  scales.Fill(1.0);
171  if (m_Controls.m_UseOptimizerScalesFixedCenterOfRotationAffine->isChecked())
172  {
173  scales[0] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale1->text().toDouble();
174  scales[1] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale2->text().toDouble();
175  scales[2] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale3->text().toDouble();
176  scales[3] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale4->text().toDouble();
177  scales[4] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale5->text().toDouble();
178  scales[5] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale6->text().toDouble();
179  scales[6] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale7->text().toDouble();
180  scales[7] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale8->text().toDouble();
181  scales[8] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale9->text().toDouble();
182  scales[9] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationX->text().toDouble();
183  scales[10] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationY->text().toDouble();
184  scales[11] = m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationZ->text().toDouble();
185  }
186  return scales;
187 }
188 
189 vtkTransform *QmitkFixedCenterOfRotationAffineTransformView::Transform(vtkMatrix4x4 *vtkmatrix,
190  vtkTransform *vtktransform,
191  itk::Array<double> transformParams)
192 {
193  if (m_MovingImage.IsNotNull())
194  {
195  int m = 0;
196  for (unsigned int i = 0; i < m_FixedImage->GetDimension(); i++)
197  {
198  for (unsigned int j = 0; j < m_FixedImage->GetDimension(); j++)
199  {
200  vtkmatrix->SetElement(i, j, transformParams[m]);
201  m++;
202  }
203  }
204  float center[4];
205  float translation[4];
206  center[0] = m_CenterX;
207  center[1] = m_CenterY;
208  center[2] = m_CenterZ;
209  center[3] = 1;
210  vtkmatrix->MultiplyPoint(center, translation);
211  if (m_FixedImage->GetDimension() == 2)
212  {
213  vtkmatrix->SetElement(0, 3, -translation[0] + center[0] + transformParams[4]);
214  vtkmatrix->SetElement(1, 3, -translation[1] + center[1] + transformParams[5]);
215  }
216  else if (m_FixedImage->GetDimension() == 3)
217  {
218  vtkmatrix->SetElement(0, 3, -translation[0] + center[0] + transformParams[9]);
219  vtkmatrix->SetElement(1, 3, -translation[1] + center[1] + transformParams[10]);
220  vtkmatrix->SetElement(2, 3, -translation[2] + center[2] + transformParams[11]);
221  }
222  vtktransform->SetMatrix(vtkmatrix);
223  }
224  return vtktransform;
225 }
226 
228 {
229  if (m_FixedImage.IsNotNull())
230  {
231  if (m_FixedImage->GetDimension() == 2)
232  {
233  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale7->hide();
234  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale8->hide();
235  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale9->hide();
236  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationX->hide();
237  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationY->hide();
238  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationZ->hide();
239  m_Controls.textLabel2_7_2_2->setText("Translation Scale X:");
240  m_Controls.textLabel3_6_2_2->setText("Translation Scale Y:");
241  m_Controls.textLabel4_4_3_2->hide();
242  m_Controls.textLabel5_4_2_2->hide();
243  m_Controls.textLabel6_4_2_2->hide();
244  m_Controls.textLabel11_3_2_2->hide();
245  m_Controls.textLabel12_3_2_2->hide();
246  m_Controls.textLabel13_2_2_2->hide();
247  return 6;
248  }
249  else
250  {
251  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale7->show();
252  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale8->show();
253  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScale9->show();
254  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationX->show();
255  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationY->show();
256  m_Controls.m_ScalesFixedCenterOfRotationAffineTransformScaleTranslationZ->show();
257  m_Controls.textLabel2_7_2_2->setText("Scale 5:");
258  m_Controls.textLabel3_6_2_2->setText("Scale 6:");
259  m_Controls.textLabel4_4_3_2->show();
260  m_Controls.textLabel5_4_2_2->show();
261  m_Controls.textLabel6_4_2_2->show();
262  m_Controls.textLabel11_3_2_2->show();
263  m_Controls.textLabel12_3_2_2->show();
264  m_Controls.textLabel13_2_2_2->show();
265  return 12;
266  }
267  }
268  else
269  return 0;
270 }
itk::SmartPointer< Self > Pointer
virtual mitk::TransformParameters::TransformType GetTransformType() override
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
Ui::QmitkFixedCenterOfRotationAffineTransformControls m_Controls
virtual void SetTransformParameters(itk::Array< double > transformValues) override
QmitkFixedCenterOfRotationAffineTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
TransformType
Unique integer value for every transform.
#define AccessByItk(mitkImage, itkImageTypeFunction)
Access a MITK image by an ITK image.
static Pointer New()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.