Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkEuler3DTransformView.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 <itkEuler3DTransform.h>
22 
23 QmitkEuler3DTransformView::QmitkEuler3DTransformView(QWidget *parent, Qt::WindowFlags f)
24  : QmitkRigidRegistrationTransformsGUIBase(parent, f), m_CenterX(0), m_CenterY(0), m_CenterZ(0)
25 {
26 }
27 
29 {
30 }
31 
33 {
35 }
36 
38 {
39  if (m_FixedImage.IsNotNull())
40  {
41  AccessByItk(m_FixedImage, GetTransform2);
42  return m_TransformObject;
43  }
44  return nullptr;
45 }
46 
47 template <class TPixelType, unsigned int VImageDimension>
48 itk::Object::Pointer QmitkEuler3DTransformView::GetTransform2(itk::Image<TPixelType, VImageDimension> * /*itkImage1*/)
49 {
50  if (VImageDimension == 3)
51  {
53  transformPointer->SetIdentity();
54  m_CenterX = transformPointer->GetCenter()[0];
55  m_CenterY = transformPointer->GetCenter()[1];
56  m_CenterZ = transformPointer->GetCenter()[2];
57  m_TransformObject = transformPointer.GetPointer();
58  return transformPointer.GetPointer();
59  }
60  return nullptr;
61 }
62 
64 {
65  itk::Array<double> transformValues;
66  transformValues.SetSize(9);
67  transformValues.fill(0);
68  transformValues[0] = m_Controls.m_UseOptimizerScalesEuler3D->isChecked();
69  transformValues[1] = m_Controls.m_ScalesEuler3DTransformScale1->text().toDouble();
70  transformValues[2] = m_Controls.m_ScalesEuler3DTransformScale2->text().toDouble();
71  transformValues[3] = m_Controls.m_ScalesEuler3DTransformScale3->text().toDouble();
72  transformValues[4] = m_Controls.m_ScalesEuler3DTransformScaleTranslationX->text().toDouble();
73  transformValues[5] = m_Controls.m_ScalesEuler3DTransformScaleTranslationY->text().toDouble();
74  transformValues[6] = m_Controls.m_ScalesEuler3DTransformScaleTranslationZ->text().toDouble();
75  transformValues[7] = m_Controls.m_CenterForInitializerEuler3D->isChecked();
76  transformValues[8] = m_Controls.m_MomentsEuler3D->isChecked();
77  return transformValues;
78 }
79 
80 void QmitkEuler3DTransformView::SetTransformParameters(itk::Array<double> transformValues)
81 {
82  m_Controls.m_UseOptimizerScalesEuler3D->setChecked(transformValues[0]);
83  m_Controls.m_ScalesEuler3DTransformScale1->setText(QString::number(transformValues[1]));
84  m_Controls.m_ScalesEuler3DTransformScale2->setText(QString::number(transformValues[2]));
85  m_Controls.m_ScalesEuler3DTransformScale3->setText(QString::number(transformValues[3]));
86  m_Controls.m_ScalesEuler3DTransformScaleTranslationX->setText(QString::number(transformValues[4]));
87  m_Controls.m_ScalesEuler3DTransformScaleTranslationY->setText(QString::number(transformValues[5]));
88  m_Controls.m_ScalesEuler3DTransformScaleTranslationZ->setText(QString::number(transformValues[6]));
89  m_Controls.m_CenterForInitializerEuler3D->setChecked(transformValues[7]);
90  m_Controls.m_MomentsEuler3D->setChecked(transformValues[8]);
91  m_Controls.m_GeometryEuler3D->setChecked(!transformValues[8]);
92 }
93 
95 {
96  return "Euler3D";
97 }
98 
100 {
101  m_Controls.setupUi(parent);
102  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
103  m_Controls.m_ScalesEuler3DTransformScale1->setValidator(validatorLineEditInputFloat);
104  m_Controls.m_ScalesEuler3DTransformScale2->setValidator(validatorLineEditInputFloat);
105  m_Controls.m_ScalesEuler3DTransformScale3->setValidator(validatorLineEditInputFloat);
106  m_Controls.m_ScalesEuler3DTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
107  m_Controls.m_ScalesEuler3DTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
108  m_Controls.m_ScalesEuler3DTransformScaleTranslationZ->setValidator(validatorLineEditInputFloat);
109 }
110 
112 {
113  itk::Array<double> scales;
114  scales.SetSize(6);
115  scales.Fill(1.0);
116  if (m_Controls.m_UseOptimizerScalesEuler3D->isChecked())
117  {
118  scales[0] = m_Controls.m_ScalesEuler3DTransformScale1->text().toDouble();
119  scales[1] = m_Controls.m_ScalesEuler3DTransformScale2->text().toDouble();
120  scales[2] = m_Controls.m_ScalesEuler3DTransformScale3->text().toDouble();
121  scales[3] = m_Controls.m_ScalesEuler3DTransformScaleTranslationX->text().toDouble();
122  scales[4] = m_Controls.m_ScalesEuler3DTransformScaleTranslationY->text().toDouble();
123  scales[5] = m_Controls.m_ScalesEuler3DTransformScaleTranslationZ->text().toDouble();
124  }
125  return scales;
126 }
127 
128 vtkTransform *QmitkEuler3DTransformView::Transform(vtkMatrix4x4 * /*vtkmatrix*/,
129  vtkTransform *vtktransform,
130  itk::Array<double> transformParams)
131 {
132  if (m_MovingImage.IsNotNull())
133  {
134  mitk::ScalarType angleX = transformParams[0] * 45.0 / atan(1.0);
135  mitk::ScalarType angleY = transformParams[1] * 45.0 / atan(1.0);
136  mitk::ScalarType angleZ = transformParams[2] * 45.0 / atan(1.0);
137  vtktransform->PostMultiply();
138  vtktransform->Translate(-m_CenterX, -m_CenterY, -m_CenterZ);
139  vtktransform->RotateX(angleX);
140  vtktransform->RotateY(angleY);
141  vtktransform->RotateZ(angleZ);
142  vtktransform->Translate(m_CenterX, m_CenterY, m_CenterZ);
143  vtktransform->Translate(transformParams[3], transformParams[4], transformParams[5]);
144  vtktransform->PreMultiply();
145  }
146  return vtktransform;
147 }
148 
150 {
151  if (m_FixedImage.IsNotNull())
152  {
153  if (m_FixedImage->GetDimension() == 2)
154  return 4;
155  else
156  return 6;
157  }
158  else
159  return 0;
160 }
QmitkEuler3DTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
itk::SmartPointer< Self > Pointer
virtual itk::Object::Pointer GetTransform() override
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
double ScalarType
TransformType
Unique integer value for every transform.
virtual itk::Array< double > GetTransformParameters() override
Ui::QmitkEuler3DTransformControls m_Controls
itk::Object::Pointer m_TransformObject
#define AccessByItk(mitkImage, itkImageTypeFunction)
Access a MITK image by an ITK image.
virtual void SetupUI(QWidget *parent) override
virtual itk::Array< double > GetScales() override
virtual mitk::TransformParameters::TransformType GetTransformType() override
virtual void SetTransformParameters(itk::Array< double > transformValues) override
virtual int GetNumberOfTransformParameters() override
virtual QString GetName() override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.