Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkRigid2DTransformView.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 <itkRigid2DTransform.h>
22 #include <mitkImageCast.h>
23 
24 QmitkRigid2DTransformView::QmitkRigid2DTransformView(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, 2);
43  return m_TransformObject;
44  }
45  return nullptr;
46 }
47 
48 template <class TPixelType, unsigned int VImageDimension>
49 itk::Object::Pointer QmitkRigid2DTransformView::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_CenterForInitializerRigid2D->isChecked())
68  {
69  typedef typename itk::Rigid2DTransform<double> Rigid2DTransformType;
70  typedef typename itk::CenteredTransformInitializer<Rigid2DTransformType, 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_MomentsRigid2D->isChecked())
77  {
78  transformInitializer->MomentsOn();
79  }
80  else
81  {
82  transformInitializer->GeometryOn();
83  }
84  transformInitializer->InitializeTransform();
85  }
86  m_TransformObject = transformPointer.GetPointer();
87  return transformPointer.GetPointer();
88  }
89  return nullptr;
90 }
91 
93 {
94  itk::Array<double> transformValues;
95  transformValues.SetSize(6);
96  transformValues.fill(0);
97  transformValues[0] = m_Controls.m_UseOptimizerScalesRigid2D->isChecked();
98  transformValues[1] = m_Controls.m_ScalesRigid2DTransformScale1->text().toDouble();
99  transformValues[2] = m_Controls.m_ScalesRigid2DTransformScaleTranslationX->text().toDouble();
100  transformValues[3] = m_Controls.m_ScalesRigid2DTransformScaleTranslationY->text().toDouble();
101  transformValues[4] = m_Controls.m_CenterForInitializerRigid2D->isChecked();
102  transformValues[5] = m_Controls.m_MomentsRigid2D->isChecked();
103  return transformValues;
104 }
105 
106 void QmitkRigid2DTransformView::SetTransformParameters(itk::Array<double> transformValues)
107 {
108  m_Controls.m_UseOptimizerScalesRigid2D->setChecked(transformValues[0]);
109  m_Controls.m_ScalesRigid2DTransformScale1->setText(QString::number(transformValues[1]));
110  m_Controls.m_ScalesRigid2DTransformScaleTranslationX->setText(QString::number(transformValues[2]));
111  m_Controls.m_ScalesRigid2DTransformScaleTranslationY->setText(QString::number(transformValues[3]));
112  m_Controls.m_CenterForInitializerRigid2D->setChecked(transformValues[4]);
113  m_Controls.m_MomentsRigid2D->setChecked(transformValues[5]);
114  m_Controls.m_GeometryRigid2D->setChecked(!transformValues[5]);
115 }
116 
118 {
119  return "Rigid2D";
120 }
121 
123 {
124  m_Controls.setupUi(parent);
125  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
126  m_Controls.m_ScalesRigid2DTransformScale1->setValidator(validatorLineEditInputFloat);
127  m_Controls.m_ScalesRigid2DTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
128  m_Controls.m_ScalesRigid2DTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
129 }
130 
132 {
133  itk::Array<double> scales;
134  scales.SetSize(3);
135  scales.Fill(1.0);
136  if (m_Controls.m_UseOptimizerScalesRigid2D->isChecked())
137  {
138  scales[0] = m_Controls.m_ScalesRigid2DTransformScale1->text().toDouble();
139  scales[1] = m_Controls.m_ScalesRigid2DTransformScaleTranslationX->text().toDouble();
140  scales[2] = m_Controls.m_ScalesRigid2DTransformScaleTranslationY->text().toDouble();
141  }
142  return scales;
143 }
144 
145 vtkTransform *QmitkRigid2DTransformView::Transform(vtkMatrix4x4 * /*vtkmatrix*/,
146  vtkTransform *vtktransform,
147  itk::Array<double> transformParams)
148 {
149  if (m_MovingImage.IsNotNull())
150  {
151  mitk::ScalarType angle = transformParams[0] * 45.0 / atan(1.0);
152  vtktransform->PostMultiply();
153  vtktransform->RotateZ(angle);
154  vtktransform->Translate(transformParams[1], transformParams[2], 0);
155  vtktransform->PreMultiply();
156  }
157  return vtktransform;
158 }
159 
161 {
162  if (m_FixedImage.IsNotNull())
163  {
164  if (m_FixedImage->GetDimension() == 2)
165  return 3;
166  else
167  return 0;
168  }
169  else
170  return 0;
171 }
itk::Object::Pointer m_TransformObject
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
double ScalarType
virtual QString GetName() override
Ui::QmitkRigid2DTransformControls m_Controls
TransformType
Unique integer value for every transform.
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
virtual itk::Object::Pointer GetTransform() override
virtual int GetNumberOfTransformParameters() override
virtual itk::Array< double > GetTransformParameters() override
virtual void SetTransformParameters(itk::Array< double > transformValues) override
virtual itk::Array< double > GetScales() override
static Pointer New()
QmitkRigid2DTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
virtual void SetupUI(QWidget *parent) override
virtual mitk::TransformParameters::TransformType GetTransformType() override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.