Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkSimilarity2DTransformView.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 <itkSimilarity2DTransform.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, 2);
43  return m_TransformObject;
44  }
45  return nullptr;
46 }
47 
48 template <class TPixelType, unsigned int VImageDimension>
49 itk::Object::Pointer QmitkSimilarity2DTransformView::GetTransform2(itk::Image<TPixelType, VImageDimension> *itkImage1)
50 {
51  if (VImageDimension == 2)
52  {
53  typedef typename itk::Image<TPixelType, 2> FixedImage2DType;
54  typedef typename itk::Image<TPixelType, 2> MovingImage2DType;
55 
56  // the fixedImage is the input parameter (fix for Bug #14626)
57  typename FixedImage2DType::Pointer fixedImage2D = 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 MovingImage2DType::Pointer movingImage2D = movingImageToItk->GetOutput();
64 
66  transformPointer->SetIdentity();
67  if (m_Controls.m_CenterForInitializerSimilarity2D->isChecked())
68  {
69  typedef typename itk::Similarity2DTransform<double> Similarity2DTransformType;
70  typedef typename itk::CenteredTransformInitializer<Similarity2DTransformType, FixedImage2DType, MovingImage2DType>
71  TransformInitializerType;
72  typename TransformInitializerType::Pointer transformInitializer = TransformInitializerType::New();
73  transformInitializer->SetFixedImage(fixedImage2D);
74  transformInitializer->SetMovingImage(movingImage2D);
75  transformInitializer->SetTransform(transformPointer);
76  if (m_Controls.m_MomentsSimilarity2D->isChecked())
77  {
78  transformInitializer->MomentsOn();
79  }
80  else
81  {
82  transformInitializer->GeometryOn();
83  }
84  transformInitializer->InitializeTransform();
85  }
86  transformPointer->SetScale(m_Controls.m_InitialScaleSimilarity2D->text().toFloat());
87  transformPointer->SetAngle(m_Controls.m_AngleSimilarity2D->text().toFloat());
88  m_TransformObject = transformPointer.GetPointer();
89  return transformPointer.GetPointer();
90  }
91  return nullptr;
92 }
93 
95 {
96  itk::Array<double> transformValues;
97  transformValues.SetSize(9);
98  transformValues.fill(0);
99  transformValues[0] = m_Controls.m_UseOptimizerScalesSimilarity2D->isChecked();
100  transformValues[1] = m_Controls.m_ScalingScaleSimilarity2D->text().toDouble();
101  transformValues[2] = m_Controls.m_RotationScaleSimilarity2D->text().toDouble();
102  transformValues[3] = m_Controls.m_TranslationXScaleSimilarity2D->text().toDouble();
103  transformValues[4] = m_Controls.m_TranslationYScaleSimilarity2D->text().toDouble();
104  transformValues[5] = m_Controls.m_InitialScaleSimilarity2D->text().toFloat();
105  transformValues[6] = m_Controls.m_AngleSimilarity2D->text().toFloat();
106  transformValues[7] = m_Controls.m_CenterForInitializerSimilarity2D->isChecked();
107  transformValues[8] = m_Controls.m_MomentsSimilarity2D->isChecked();
108  return transformValues;
109 }
110 
111 void QmitkSimilarity2DTransformView::SetTransformParameters(itk::Array<double> transformValues)
112 {
113  m_Controls.m_UseOptimizerScalesSimilarity2D->setChecked(transformValues[0]);
114  m_Controls.m_ScalingScaleSimilarity2D->setText(QString::number(transformValues[1]));
115  m_Controls.m_RotationScaleSimilarity2D->setText(QString::number(transformValues[2]));
116  m_Controls.m_TranslationXScaleSimilarity2D->setText(QString::number(transformValues[3]));
117  m_Controls.m_TranslationYScaleSimilarity2D->setText(QString::number(transformValues[4]));
118  m_Controls.m_InitialScaleSimilarity2D->setText(QString::number(transformValues[5]));
119  m_Controls.m_AngleSimilarity2D->setText(QString::number(transformValues[6]));
120  m_Controls.m_CenterForInitializerSimilarity2D->setChecked(transformValues[7]);
121  m_Controls.m_MomentsSimilarity2D->setChecked(transformValues[8]);
122  m_Controls.m_GeometrySimilarity2D->setChecked(!transformValues[8]);
123 }
124 
126 {
127  return "Similarity2D";
128 }
129 
131 {
132  m_Controls.setupUi(parent);
133  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
134  m_Controls.m_ScalingScaleSimilarity2D->setValidator(validatorLineEditInputFloat);
135  m_Controls.m_RotationScaleSimilarity2D->setValidator(validatorLineEditInputFloat);
136  m_Controls.m_TranslationXScaleSimilarity2D->setValidator(validatorLineEditInputFloat);
137  m_Controls.m_TranslationYScaleSimilarity2D->setValidator(validatorLineEditInputFloat);
138 }
139 
141 {
142  itk::Array<double> scales;
143  scales.SetSize(4);
144  scales.Fill(1.0);
145  if (m_Controls.m_UseOptimizerScalesSimilarity2D->isChecked())
146  {
147  scales[0] = m_Controls.m_ScalingScaleSimilarity2D->text().toDouble();
148  scales[1] = m_Controls.m_RotationScaleSimilarity2D->text().toDouble();
149  scales[2] = m_Controls.m_TranslationXScaleSimilarity2D->text().toDouble();
150  scales[3] = m_Controls.m_TranslationYScaleSimilarity2D->text().toDouble();
151  }
152  return scales;
153 }
154 
155 vtkTransform *QmitkSimilarity2DTransformView::Transform(vtkMatrix4x4 * /* vtkmatrix */,
156  vtkTransform *vtktransform,
157  itk::Array<double> transformParams)
158 {
159  if (m_MovingImage.IsNotNull())
160  {
161  mitk::ScalarType angle = transformParams[1] * 45.0 / atan(1.0);
162  vtktransform->PostMultiply();
163  vtktransform->Scale(transformParams[0], transformParams[0], 1);
164  vtktransform->RotateZ(angle);
165  vtktransform->Translate(transformParams[2], transformParams[3], 0);
166  vtktransform->PreMultiply();
167  }
168  return vtktransform;
169 }
170 
172 {
173  if (m_FixedImage.IsNotNull())
174  {
175  if (m_FixedImage->GetDimension() == 2)
176  return 4;
177  else
178  return 0;
179  }
180  else
181  return 0;
182 }
Ui::QmitkSimilarity2DTransformControls m_Controls
itk::SmartPointer< Self > Pointer
virtual itk::Array< double > GetTransformParameters() override
virtual itk::Array< double > GetScales() override
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
double ScalarType
virtual void SetupUI(QWidget *parent) override
virtual itk::Object::Pointer GetTransform() override
TransformType
Unique integer value for every transform.
virtual void SetTransformParameters(itk::Array< double > transformValues) override
virtual mitk::TransformParameters::TransformType GetTransformType() override
static Pointer New()
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
QmitkSimilarity2DTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.