Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkCenteredEuler3DTransformView.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 <itkCenteredEuler3DTransform.h>
21 #include <itkCenteredTransformInitializer.h>
22 
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 QmitkCenteredEuler3DTransformView::GetTransform2(
49  itk::Image<TPixelType, VImageDimension> * /*itkImage1*/)
50 {
51  typedef typename itk::Image<TPixelType, VImageDimension> FixedImageType;
52  typedef typename itk::Image<TPixelType, VImageDimension> MovingImageType;
53  if (VImageDimension == 3)
54  {
55  typename itk::CenteredEuler3DTransform<double>::Pointer transformPointer =
57  transformPointer->SetIdentity();
58  m_CenterX = transformPointer->GetCenter()[0];
59  m_CenterY = transformPointer->GetCenter()[1];
60  m_CenterZ = transformPointer->GetCenter()[2];
61  m_TransformObject = transformPointer.GetPointer();
62  return transformPointer.GetPointer();
63  }
64  return nullptr;
65 }
66 
68 {
69  itk::Array<double> transformValues;
70  transformValues.SetSize(9);
71  transformValues.fill(0);
72  transformValues[0] = m_Controls.m_UseOptimizerScalesCenteredEuler3D->isChecked();
73  transformValues[1] = m_Controls.m_ScalesCenteredEuler3DTransformScale1->text().toDouble();
74  transformValues[2] = m_Controls.m_ScalesCenteredEuler3DTransformScale2->text().toDouble();
75  transformValues[3] = m_Controls.m_ScalesCenteredEuler3DTransformScale3->text().toDouble();
76  transformValues[4] = m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationX->text().toDouble();
77  transformValues[5] = m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationY->text().toDouble();
78  transformValues[6] = m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationZ->text().toDouble();
79  transformValues[7] = m_Controls.m_CenterForInitializerCenteredEuler3D->isChecked();
80  transformValues[8] = m_Controls.m_MomentsCenteredEuler3D->isChecked();
81  return transformValues;
82 }
83 
84 void QmitkCenteredEuler3DTransformView::SetTransformParameters(itk::Array<double> transformValues)
85 {
86  m_Controls.m_UseOptimizerScalesCenteredEuler3D->setChecked(transformValues[0]);
87  m_Controls.m_ScalesCenteredEuler3DTransformScale1->setText(QString::number(transformValues[1]));
88  m_Controls.m_ScalesCenteredEuler3DTransformScale2->setText(QString::number(transformValues[2]));
89  m_Controls.m_ScalesCenteredEuler3DTransformScale3->setText(QString::number(transformValues[3]));
90  m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationX->setText(QString::number(transformValues[4]));
91  m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationY->setText(QString::number(transformValues[5]));
92  m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationZ->setText(QString::number(transformValues[6]));
93  m_Controls.m_CenterForInitializerCenteredEuler3D->setChecked(transformValues[7]);
94  m_Controls.m_MomentsCenteredEuler3D->setChecked(transformValues[8]);
95  m_Controls.m_GeometryCenteredEuler3D->setChecked(!transformValues[8]);
96 }
97 
99 {
100  return "CenteredEuler3D";
101 }
102 
104 {
105  m_Controls.setupUi(parent);
106  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
107  m_Controls.m_ScalesCenteredEuler3DTransformScale1->setValidator(validatorLineEditInputFloat);
108  m_Controls.m_ScalesCenteredEuler3DTransformScale2->setValidator(validatorLineEditInputFloat);
109  m_Controls.m_ScalesCenteredEuler3DTransformScale3->setValidator(validatorLineEditInputFloat);
110  m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
111  m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
112  m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationZ->setValidator(validatorLineEditInputFloat);
113 }
114 
116 {
117  itk::Array<double> scales;
118  scales.SetSize(6);
119  scales.Fill(1.0);
120  if (m_Controls.m_UseOptimizerScalesCenteredEuler3D->isChecked())
121  {
122  scales[0] = m_Controls.m_ScalesCenteredEuler3DTransformScale1->text().toDouble();
123  scales[1] = m_Controls.m_ScalesCenteredEuler3DTransformScale2->text().toDouble();
124  scales[2] = m_Controls.m_ScalesCenteredEuler3DTransformScale3->text().toDouble();
125  scales[3] = m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationX->text().toDouble();
126  scales[4] = m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationY->text().toDouble();
127  scales[5] = m_Controls.m_ScalesCenteredEuler3DTransformScaleTranslationZ->text().toDouble();
128  }
129  return scales;
130 }
131 
132 vtkTransform *QmitkCenteredEuler3DTransformView::Transform(vtkMatrix4x4 * /*vtkmatrix*/,
133  vtkTransform *vtktransform,
134  itk::Array<double> transformParams)
135 {
136  if (m_MovingImage.IsNotNull())
137  {
138  mitk::ScalarType angleX = transformParams[0] * 45.0 / atan(1.0);
139  mitk::ScalarType angleY = transformParams[1] * 45.0 / atan(1.0);
140  mitk::ScalarType angleZ = transformParams[2] * 45.0 / atan(1.0);
141  vtktransform->PostMultiply();
142  vtktransform->Translate(-m_CenterX, -m_CenterY, -m_CenterZ);
143  vtktransform->RotateX(angleX);
144  vtktransform->RotateY(angleY);
145  vtktransform->RotateZ(angleZ);
146  vtktransform->Translate(m_CenterX, m_CenterY, m_CenterZ);
147  vtktransform->Translate(transformParams[3], transformParams[4], transformParams[5]);
148  vtktransform->PreMultiply();
149  }
150  return vtktransform;
151 }
152 
154 {
155  if (m_FixedImage.IsNotNull())
156  {
157  if (m_FixedImage->GetDimension() == 2)
158  return 4;
159  else
160  return 6;
161  }
162  else
163  return 0;
164 }
itk::SmartPointer< Self > Pointer
Ui::QmitkCenteredEuler3DTransformControls m_Controls
double ScalarType
TransformType
Unique integer value for every transform.
virtual mitk::TransformParameters::TransformType GetTransformType() override
#define AccessByItk(mitkImage, itkImageTypeFunction)
Access a MITK image by an ITK image.
virtual itk::Array< double > GetTransformParameters() override
virtual itk::Object::Pointer GetTransform() override
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
virtual void SetTransformParameters(itk::Array< double > transformValues) override
virtual void SetupUI(QWidget *parent) override
QmitkCenteredEuler3DTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
virtual itk::Array< double > GetScales() override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.