Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkSimilarity3DTransformView.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 <itkSimilarity3DTransform.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 QmitkSimilarity3DTransformView::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  if (m_Controls.m_CenterForInitializerSimilarity3D->isChecked())
68  {
69  typedef typename itk::Similarity3DTransform<double> Similarity3DTransformType;
70  typedef typename itk::CenteredTransformInitializer<Similarity3DTransformType, FixedImage3DType, MovingImage3DType>
71  TransformInitializerType;
72  typename TransformInitializerType::Pointer transformInitializer = TransformInitializerType::New();
73  transformInitializer->SetFixedImage(fixedImage);
74  transformInitializer->SetMovingImage(movingImage);
75  transformInitializer->SetTransform(transformPointer);
76  if (m_Controls.m_MomentsSimilarity3D->isChecked())
77  {
78  transformInitializer->MomentsOn();
79  }
80  else
81  {
82  transformInitializer->GeometryOn();
83  }
84  transformInitializer->InitializeTransform();
85  }
86  m_CenterX = transformPointer->GetCenter()[0];
87  m_CenterY = transformPointer->GetCenter()[1];
88  m_CenterZ = transformPointer->GetCenter()[2];
89  m_TransformObject = transformPointer.GetPointer();
90  return transformPointer.GetPointer();
91  }
92  return nullptr;
93 }
94 
96 {
97  itk::Array<double> transformValues;
98  transformValues.SetSize(10);
99  transformValues.fill(0);
100  transformValues[0] = m_Controls.m_UseOptimizerScalesSimilarity3D->isChecked();
101  transformValues[1] = m_Controls.m_ScalesSimilarity3DTransformScale1->text().toDouble();
102  transformValues[2] = m_Controls.m_ScalesSimilarity3DTransformScale2->text().toDouble();
103  transformValues[3] = m_Controls.m_ScalesSimilarity3DTransformScale3->text().toDouble();
104  transformValues[4] = m_Controls.m_ScalesSimilarity3DTransformScale4->text().toDouble();
105  transformValues[5] = m_Controls.m_ScalesSimilarity3DTransformScaleTranslationX->text().toDouble();
106  transformValues[6] = m_Controls.m_ScalesSimilarity3DTransformScaleTranslationY->text().toDouble();
107  transformValues[7] = m_Controls.m_ScalesSimilarity3DTransformScaleTranslationZ->text().toDouble();
108  transformValues[8] = m_Controls.m_CenterForInitializerSimilarity3D->isChecked();
109  transformValues[9] = m_Controls.m_MomentsSimilarity3D->isChecked();
110  return transformValues;
111 }
112 
113 void QmitkSimilarity3DTransformView::SetTransformParameters(itk::Array<double> transformValues)
114 {
115  m_Controls.m_UseOptimizerScalesSimilarity3D->setChecked(transformValues[0]);
116  m_Controls.m_ScalesSimilarity3DTransformScale1->setText(QString::number(transformValues[1]));
117  m_Controls.m_ScalesSimilarity3DTransformScale2->setText(QString::number(transformValues[2]));
118  m_Controls.m_ScalesSimilarity3DTransformScale3->setText(QString::number(transformValues[3]));
119  m_Controls.m_ScalesSimilarity3DTransformScale4->setText(QString::number(transformValues[4]));
120  m_Controls.m_ScalesSimilarity3DTransformScaleTranslationX->setText(QString::number(transformValues[5]));
121  m_Controls.m_ScalesSimilarity3DTransformScaleTranslationY->setText(QString::number(transformValues[6]));
122  m_Controls.m_ScalesSimilarity3DTransformScaleTranslationZ->setText(QString::number(transformValues[7]));
123  m_Controls.m_CenterForInitializerSimilarity3D->setChecked(transformValues[8]);
124  m_Controls.m_MomentsSimilarity3D->setChecked(transformValues[9]);
125  m_Controls.m_GeometrySimilarity3D->setChecked(!transformValues[9]);
126 }
127 
129 {
130  return "Similarity3D";
131 }
132 
134 {
135  m_Controls.setupUi(parent);
136  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
137  m_Controls.m_ScalesSimilarity3DTransformScale1->setValidator(validatorLineEditInputFloat);
138  m_Controls.m_ScalesSimilarity3DTransformScale2->setValidator(validatorLineEditInputFloat);
139  m_Controls.m_ScalesSimilarity3DTransformScale3->setValidator(validatorLineEditInputFloat);
140  m_Controls.m_ScalesSimilarity3DTransformScale4->setValidator(validatorLineEditInputFloat);
141  m_Controls.m_ScalesSimilarity3DTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
142  m_Controls.m_ScalesSimilarity3DTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
143  m_Controls.m_ScalesSimilarity3DTransformScaleTranslationZ->setValidator(validatorLineEditInputFloat);
144 }
145 
147 {
148  itk::Array<double> scales;
149  scales.SetSize(7);
150  scales.Fill(1.0);
151  if (m_Controls.m_UseOptimizerScalesSimilarity3D->isChecked())
152  {
153  scales[0] = m_Controls.m_ScalesSimilarity3DTransformScale1->text().toDouble();
154  scales[1] = m_Controls.m_ScalesSimilarity3DTransformScale2->text().toDouble();
155  scales[2] = m_Controls.m_ScalesSimilarity3DTransformScale3->text().toDouble();
156  scales[3] = m_Controls.m_ScalesSimilarity3DTransformScale4->text().toDouble();
157  scales[4] = m_Controls.m_ScalesSimilarity3DTransformScaleTranslationX->text().toDouble();
158  scales[5] = m_Controls.m_ScalesSimilarity3DTransformScaleTranslationY->text().toDouble();
159  scales[6] = m_Controls.m_ScalesSimilarity3DTransformScaleTranslationZ->text().toDouble();
160  }
161  return scales;
162 }
163 
164 vtkTransform *QmitkSimilarity3DTransformView::Transform(vtkMatrix4x4 *vtkmatrix,
165  vtkTransform *vtktransform,
166  itk::Array<double> transformParams)
167 {
168  if (m_MovingImage.IsNotNull())
169  {
171  similarityTransform->SetParameters(transformParams);
172  itk::Matrix<double, 3, 3> Matrix = similarityTransform->GetMatrix();
173  for (int i = 0; i < 3; i++)
174  {
175  for (int j = 0; j < 3; j++)
176  {
177  vtkmatrix->SetElement(i, j, Matrix[i][j]);
178  }
179  }
180  float center[4];
181  float translation[4];
182  center[0] = m_CenterX;
183  center[1] = m_CenterY;
184  center[2] = m_CenterZ;
185  center[3] = 1;
186  vtkmatrix->MultiplyPoint(center, translation);
187  vtkmatrix->SetElement(0, 3, -translation[0] + center[0] + transformParams[4]);
188  vtkmatrix->SetElement(1, 3, -translation[1] + center[1] + transformParams[5]);
189  vtkmatrix->SetElement(2, 3, -translation[2] + center[2] + transformParams[6]);
190  vtktransform->SetMatrix(vtkmatrix);
191  }
192  return vtktransform;
193 }
194 
196 {
197  if (m_FixedImage.IsNotNull())
198  {
199  if (m_FixedImage->GetDimension() == 2)
200  return 0;
201  else
202  return 7;
203  }
204  else
205  return 0;
206 }
virtual itk::Array< double > GetTransformParameters() override
itk::SmartPointer< Self > Pointer
#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
virtual void SetTransformParameters(itk::Array< double > transformValues) override
Ui::QmitkSimilarity3DTransformControls m_Controls
TransformType
Unique integer value for every transform.
virtual mitk::TransformParameters::TransformType GetTransformType() override
virtual itk::Object::Pointer GetTransform() override
QmitkSimilarity3DTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
virtual void SetupUI(QWidget *parent) override
static Pointer New()
virtual itk::Array< double > GetScales() override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.