Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkCenteredRigid2DTransformView.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 <itkCenteredRigid2DTransform.h>
21 #include <itkCenteredTransformInitializer.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 QmitkCenteredRigid2DTransformView::GetTransform2(
50  itk::Image<TPixelType, VImageDimension> *itkImage1)
51 {
52  if (VImageDimension == 2)
53  {
54  typedef typename itk::Image<TPixelType, 2> FixedImage2DType;
55  typedef typename itk::Image<TPixelType, 2> MovingImage2DType;
56 
57  // the fixedImage is the input parameter (fix for Bug #14626)
58  typename FixedImage2DType::Pointer fixedImage2D = itkImage1;
59 
60  // the movingImage type is known, use the ImageToItk filter (fix for Bug #14626)
62  movingImageToItk->SetInput(m_MovingImage);
63  movingImageToItk->Update();
64  typename MovingImage2DType::Pointer movingImage2D = movingImageToItk->GetOutput();
65 
66  typename itk::CenteredRigid2DTransform<double>::Pointer transformPointer =
68  transformPointer->SetIdentity();
69  if (m_Controls.m_CenterForInitializerCenteredRigid2D->isChecked())
70  {
71  typedef typename itk::CenteredRigid2DTransform<double> CenteredRigid2DTransformType;
72  typedef
73  typename itk::CenteredTransformInitializer<CenteredRigid2DTransformType, FixedImage2DType, MovingImage2DType>
74  TransformInitializerType;
75  typename TransformInitializerType::Pointer transformInitializer = TransformInitializerType::New();
76  transformInitializer->SetFixedImage(fixedImage2D);
77  transformInitializer->SetMovingImage(movingImage2D);
78  transformInitializer->SetTransform(transformPointer);
79  if (m_Controls.m_MomentsCenteredRigid2D->isChecked())
80  {
81  transformInitializer->MomentsOn();
82  }
83  else
84  {
85  transformInitializer->GeometryOn();
86  }
87  transformInitializer->InitializeTransform();
88  }
89  transformPointer->SetAngle(m_Controls.m_AngleCenteredRigid2D->text().toFloat());
90  m_CenterX = transformPointer->GetCenter()[0];
91  m_CenterY = transformPointer->GetCenter()[1];
92  m_TransformObject = transformPointer.GetPointer();
93  return transformPointer.GetPointer();
94  }
95  return nullptr;
96 }
97 
99 {
100  itk::Array<double> transformValues;
101  transformValues.SetSize(9);
102  transformValues.fill(0);
103  transformValues[0] = m_Controls.m_UseOptimizerScalesCenteredRigid2D->isChecked();
104  transformValues[1] = m_Controls.m_RotationScaleCenteredRigid2D->text().toDouble();
105  transformValues[2] = m_Controls.m_CenterXScaleCenteredRigid2D->text().toDouble();
106  transformValues[3] = m_Controls.m_CenterYScaleCenteredRigid2D->text().toDouble();
107  transformValues[4] = m_Controls.m_TranslationXScaleCenteredRigid2D->text().toDouble();
108  transformValues[5] = m_Controls.m_TranslationYScaleCenteredRigid2D->text().toDouble();
109  transformValues[6] = m_Controls.m_AngleCenteredRigid2D->text().toFloat();
110  transformValues[7] = m_Controls.m_CenterForInitializerCenteredRigid2D->isChecked();
111  transformValues[8] = m_Controls.m_MomentsCenteredRigid2D->isChecked();
112  return transformValues;
113 }
114 
115 void QmitkCenteredRigid2DTransformView::SetTransformParameters(itk::Array<double> transformValues)
116 {
117  m_Controls.m_UseOptimizerScalesCenteredRigid2D->setChecked(transformValues[0]);
118  m_Controls.m_RotationScaleCenteredRigid2D->setText(QString::number(transformValues[1]));
119  m_Controls.m_CenterXScaleCenteredRigid2D->setText(QString::number(transformValues[2]));
120  m_Controls.m_CenterYScaleCenteredRigid2D->setText(QString::number(transformValues[3]));
121  m_Controls.m_TranslationXScaleCenteredRigid2D->setText(QString::number(transformValues[4]));
122  m_Controls.m_TranslationYScaleCenteredRigid2D->setText(QString::number(transformValues[5]));
123  m_Controls.m_AngleCenteredRigid2D->setText(QString::number(transformValues[6]));
124  m_Controls.m_CenterForInitializerCenteredRigid2D->setChecked(transformValues[7]);
125  m_Controls.m_MomentsCenteredRigid2D->setChecked(transformValues[8]);
126  m_Controls.m_GeometryCenteredRigid2D->setChecked(!transformValues[8]);
127 }
128 
130 {
131  return "CenteredRigid2D";
132 }
133 
135 {
136  m_Controls.setupUi(parent);
137  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
138  m_Controls.m_AngleCenteredRigid2D->setValidator(validatorLineEditInputFloat);
139  m_Controls.m_RotationScaleCenteredRigid2D->setValidator(validatorLineEditInputFloat);
140  m_Controls.m_CenterXScaleCenteredRigid2D->setValidator(validatorLineEditInputFloat);
141  m_Controls.m_CenterYScaleCenteredRigid2D->setValidator(validatorLineEditInputFloat);
142  m_Controls.m_TranslationXScaleCenteredRigid2D->setValidator(validatorLineEditInputFloat);
143  m_Controls.m_TranslationYScaleCenteredRigid2D->setValidator(validatorLineEditInputFloat);
144 }
145 
147 {
148  itk::Array<double> scales;
149  scales.SetSize(5);
150  scales.Fill(1.0);
151  if (m_Controls.m_UseOptimizerScalesCenteredRigid2D->isChecked())
152  {
153  scales[0] = m_Controls.m_RotationScaleCenteredRigid2D->text().toDouble();
154  scales[1] = m_Controls.m_CenterXScaleCenteredRigid2D->text().toDouble();
155  scales[2] = m_Controls.m_CenterYScaleCenteredRigid2D->text().toDouble();
156  scales[3] = m_Controls.m_TranslationXScaleCenteredRigid2D->text().toDouble();
157  scales[4] = m_Controls.m_TranslationYScaleCenteredRigid2D->text().toDouble();
158  }
159  return scales;
160 }
161 
162 vtkTransform *QmitkCenteredRigid2DTransformView::Transform(vtkMatrix4x4 * /* vtkmatrix */,
163  vtkTransform *vtktransform,
164  itk::Array<double> transformParams)
165 {
166  if (m_MovingImage.IsNotNull())
167  {
168  mitk::ScalarType angle = transformParams[0] * 45.0 / atan(1.0);
169  ;
170  vtktransform->PostMultiply();
171  vtktransform->Translate(-transformParams[1], -transformParams[2], 0);
172  vtktransform->RotateZ(angle);
173  vtktransform->Translate(transformParams[1], transformParams[2], 0);
174  vtktransform->Translate(transformParams[3], transformParams[4], 0);
175  vtktransform->PreMultiply();
176  }
177  return vtktransform;
178 }
179 
181 {
182  if (m_FixedImage.IsNotNull())
183  {
184  if (m_FixedImage->GetDimension() == 2)
185  return 5;
186  else
187  return 0;
188  }
189  else
190  return 0;
191 }
virtual mitk::TransformParameters::TransformType GetTransformType() override
itk::SmartPointer< Self > Pointer
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
double ScalarType
TransformType
Unique integer value for every transform.
virtual itk::Object::Pointer GetTransform() override
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
virtual itk::Array< double > GetTransformParameters() override
QmitkCenteredRigid2DTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
static Pointer New()
virtual void SetTransformParameters(itk::Array< double > transformValues) override
virtual itk::Array< double > GetScales() override
virtual void SetupUI(QWidget *parent) override
Ui::QmitkCenteredRigid2DTransformControls m_Controls
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.