Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkVersorTransformView.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 <itkVersorTransform.h>
22 #include <mitkImageCast.h>
23 
24 QmitkVersorTransformView::QmitkVersorTransformView(QWidget *parent, Qt::WindowFlags f)
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 QmitkVersorTransformView::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::VersorTransform<double> VersorTransformType;
68  if (m_Controls.m_CenterForInitializerVersor->isChecked())
69  {
70  typedef typename itk::CenteredTransformInitializer<VersorTransformType, 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_MomentsVersor->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(6);
99  transformValues.fill(0);
100  transformValues[0] = m_Controls.m_UseOptimizerScalesVersor->isChecked();
101  transformValues[1] = m_Controls.m_ScalesVersorTransformScale1->text().toDouble();
102  transformValues[2] = m_Controls.m_ScalesVersorTransformScale2->text().toDouble();
103  transformValues[3] = m_Controls.m_ScalesVersorTransformScale3->text().toDouble();
104  transformValues[4] = m_Controls.m_CenterForInitializerVersor->isChecked();
105  transformValues[5] = m_Controls.m_MomentsVersor->isChecked();
106  return transformValues;
107 }
108 
109 void QmitkVersorTransformView::SetTransformParameters(itk::Array<double> transformValues)
110 {
111  m_Controls.m_UseOptimizerScalesVersor->setChecked(transformValues[0]);
112  m_Controls.m_ScalesVersorTransformScale1->setText(QString::number(transformValues[1]));
113  m_Controls.m_ScalesVersorTransformScale2->setText(QString::number(transformValues[2]));
114  m_Controls.m_ScalesVersorTransformScale3->setText(QString::number(transformValues[3]));
115  m_Controls.m_CenterForInitializerVersor->setChecked(transformValues[4]);
116  m_Controls.m_MomentsVersor->setChecked(transformValues[5]);
117  m_Controls.m_GeometryVersor->setChecked(!transformValues[5]);
118 }
119 
121 {
122  return "Versor";
123 }
124 
126 {
127  m_Controls.setupUi(parent);
128  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
129  m_Controls.m_ScalesVersorTransformScale1->setValidator(validatorLineEditInputFloat);
130  m_Controls.m_ScalesVersorTransformScale2->setValidator(validatorLineEditInputFloat);
131  m_Controls.m_ScalesVersorTransformScale3->setValidator(validatorLineEditInputFloat);
132 }
133 
135 {
136  itk::Array<double> scales;
137  scales.SetSize(3);
138  scales.Fill(1.0);
139  if (m_Controls.m_UseOptimizerScalesVersor->isChecked())
140  {
141  scales[0] = m_Controls.m_ScalesVersorTransformScale1->text().toDouble();
142  scales[1] = m_Controls.m_ScalesVersorTransformScale2->text().toDouble();
143  scales[2] = m_Controls.m_ScalesVersorTransformScale3->text().toDouble();
144  }
145  return scales;
146 }
147 
148 vtkTransform *QmitkVersorTransformView::Transform(vtkMatrix4x4 *vtkmatrix,
149  vtkTransform *vtktransform,
150  itk::Array<double> transformParams)
151 {
152  if (m_MovingImage.IsNotNull())
153  {
155  versorTransform->SetParameters(transformParams);
156  itk::Matrix<double, 3, 3> Matrix = versorTransform->GetMatrix();
157  for (int i = 0; i < 3; i++)
158  {
159  for (int j = 0; j < 3; j++)
160  {
161  vtkmatrix->SetElement(i, j, Matrix[i][j]);
162  }
163  }
164  float center[4];
165  float translation[4];
166  center[0] = m_CenterX;
167  center[1] = m_CenterY;
168  center[2] = m_CenterZ;
169  center[3] = 1;
170  vtkmatrix->MultiplyPoint(center, translation);
171  vtkmatrix->SetElement(0, 3, -translation[0] + center[0]);
172  vtkmatrix->SetElement(1, 3, -translation[1] + center[1]);
173  vtkmatrix->SetElement(2, 3, -translation[2] + center[2]);
174  vtktransform->SetMatrix(vtkmatrix);
175  }
176  return vtktransform;
177 }
178 
180 {
181  if (m_FixedImage.IsNotNull())
182  {
183  if (m_FixedImage->GetDimension() == 2)
184  return 0;
185  else
186  return 3;
187  }
188  else
189  return 0;
190 }
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 void SetTransformParameters(itk::Array< double > transformValues) override
virtual itk::Array< double > GetScales() override
Ui::QmitkVersorTransformControls m_Controls
virtual itk::Array< double > GetTransformParameters() override
TransformType
Unique integer value for every transform.
virtual mitk::TransformParameters::TransformType GetTransformType() override
virtual itk::Object::Pointer GetTransform() override
virtual int GetNumberOfTransformParameters() override
static Pointer New()
itk::Object::Pointer m_TransformObject
virtual QString GetName() override
QmitkVersorTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
virtual void SetupUI(QWidget *parent) override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.