Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkCenteredSimilarity2DTransformView.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 <itkCenteredSimilarity2DTransform.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 QmitkCenteredSimilarity2DTransformView::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::CenteredSimilarity2DTransform<double>::Pointer transformPointer =
68  transformPointer->SetIdentity();
69  if (m_Controls.m_CenterForInitializerCenteredSimilarity2D->isChecked())
70  {
71  typedef typename itk::CenteredSimilarity2DTransform<double> CenteredSimilarity2DTransformType;
72  typedef typename itk::
73  CenteredTransformInitializer<CenteredSimilarity2DTransformType, 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_MomentsCenteredSimilarity2D->isChecked())
80  {
81  transformInitializer->MomentsOn();
82  }
83  else
84  {
85  transformInitializer->GeometryOn();
86  }
87  transformInitializer->InitializeTransform();
88  }
89  transformPointer->SetScale(m_Controls.m_InitialScaleCenteredSimilarity2D->text().toFloat());
90  transformPointer->SetAngle(m_Controls.m_AngleCenteredSimilarity2D->text().toFloat());
91  m_CenterX = transformPointer->GetCenter()[0];
92  m_CenterY = transformPointer->GetCenter()[1];
93  m_TransformObject = transformPointer.GetPointer();
94  return transformPointer.GetPointer();
95  }
96  return nullptr;
97 }
98 
100 {
101  itk::Array<double> transformValues;
102  transformValues.SetSize(11);
103  transformValues.fill(0);
104  transformValues[0] = m_Controls.m_UseOptimizerScalesCenteredSimilarity2D->isChecked();
105  transformValues[1] = m_Controls.m_ScalesCenteredSimilarity2DTransformScale1->text().toDouble();
106  transformValues[2] = m_Controls.m_ScalesCenteredSimilarity2DTransformScale2->text().toDouble();
107  transformValues[3] = m_Controls.m_ScalesCenteredSimilarity2DTransformScale3->text().toDouble();
108  transformValues[4] = m_Controls.m_ScalesCenteredSimilarity2DTransformScale4->text().toDouble();
109  transformValues[5] = m_Controls.m_ScalesCenteredSimilarity2DTransformScaleTranslationX->text().toDouble();
110  transformValues[6] = m_Controls.m_ScalesCenteredSimilarity2DTransformScaleTranslationY->text().toDouble();
111  transformValues[7] = m_Controls.m_InitialScaleCenteredSimilarity2D->text().toFloat();
112  transformValues[8] = m_Controls.m_AngleCenteredSimilarity2D->text().toFloat();
113  transformValues[9] = m_Controls.m_CenterForInitializerCenteredSimilarity2D->isChecked();
114  transformValues[10] = m_Controls.m_MomentsCenteredSimilarity2D->isChecked();
115  return transformValues;
116 }
117 
119 {
120  m_Controls.m_UseOptimizerScalesCenteredSimilarity2D->setChecked(transformValues[0]);
121  m_Controls.m_ScalesCenteredSimilarity2DTransformScale1->setText(QString::number(transformValues[1]));
122  m_Controls.m_ScalesCenteredSimilarity2DTransformScale2->setText(QString::number(transformValues[2]));
123  m_Controls.m_ScalesCenteredSimilarity2DTransformScale3->setText(QString::number(transformValues[3]));
124  m_Controls.m_ScalesCenteredSimilarity2DTransformScale4->setText(QString::number(transformValues[4]));
125  m_Controls.m_ScalesCenteredSimilarity2DTransformScaleTranslationX->setText(QString::number(transformValues[5]));
126  m_Controls.m_ScalesCenteredSimilarity2DTransformScaleTranslationY->setText(QString::number(transformValues[6]));
127  m_Controls.m_InitialScaleCenteredSimilarity2D->setText(QString::number(transformValues[7]));
128  m_Controls.m_AngleCenteredSimilarity2D->setText(QString::number(transformValues[8]));
129  m_Controls.m_CenterForInitializerCenteredSimilarity2D->setChecked(transformValues[9]);
130  m_Controls.m_MomentsCenteredSimilarity2D->setChecked(transformValues[10]);
131  m_Controls.m_GeometryCenteredSimilarity2D->setChecked(!transformValues[10]);
132 }
133 
135 {
136  return "CenteredSimilarity2D";
137 }
138 
140 {
141  m_Controls.setupUi(parent);
142  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
143  m_Controls.m_ScalesCenteredSimilarity2DTransformScale1->setValidator(validatorLineEditInputFloat);
144  m_Controls.m_ScalesCenteredSimilarity2DTransformScale2->setValidator(validatorLineEditInputFloat);
145  m_Controls.m_ScalesCenteredSimilarity2DTransformScale3->setValidator(validatorLineEditInputFloat);
146  m_Controls.m_ScalesCenteredSimilarity2DTransformScale4->setValidator(validatorLineEditInputFloat);
147  m_Controls.m_ScalesCenteredSimilarity2DTransformScaleTranslationX->setValidator(validatorLineEditInputFloat);
148  m_Controls.m_ScalesCenteredSimilarity2DTransformScaleTranslationY->setValidator(validatorLineEditInputFloat);
149 }
150 
152 {
153  itk::Array<double> scales;
154  scales.SetSize(6);
155  scales.Fill(1.0);
156  if (m_Controls.m_UseOptimizerScalesCenteredSimilarity2D->isChecked())
157  {
158  scales[0] = m_Controls.m_ScalesCenteredSimilarity2DTransformScale1->text().toDouble();
159  scales[1] = m_Controls.m_ScalesCenteredSimilarity2DTransformScale2->text().toDouble();
160  scales[2] = m_Controls.m_ScalesCenteredSimilarity2DTransformScale3->text().toDouble();
161  scales[3] = m_Controls.m_ScalesCenteredSimilarity2DTransformScale4->text().toDouble();
162  scales[4] = m_Controls.m_ScalesCenteredSimilarity2DTransformScaleTranslationX->text().toDouble();
163  scales[5] = m_Controls.m_ScalesCenteredSimilarity2DTransformScaleTranslationY->text().toDouble();
164  }
165  return scales;
166 }
167 
168 vtkTransform *QmitkCenteredSimilarity2DTransformView::Transform(vtkMatrix4x4 * /*vtkmatrix*/,
169  vtkTransform *vtktransform,
170  itk::Array<double> transformParams)
171 {
172  if (m_MovingImage.IsNotNull())
173  {
174  mitk::ScalarType angle = transformParams[1] * 45.0 / atan(1.0);
175  vtktransform->PostMultiply();
176  vtktransform->Translate(-transformParams[2], -transformParams[3], 0);
177  vtktransform->Scale(transformParams[0], transformParams[0], 1);
178  vtktransform->RotateZ(angle);
179  vtktransform->Translate(transformParams[2], transformParams[3], 0);
180  vtktransform->Translate(transformParams[4], transformParams[5], 0);
181  vtktransform->PreMultiply();
182  }
183  return vtktransform;
184 }
185 
187 {
188  if (m_FixedImage.IsNotNull())
189  {
190  if (m_FixedImage->GetDimension() == 2)
191  return 6;
192  else
193  return 0;
194  }
195  else
196  return 0;
197 }
itk::SmartPointer< Self > Pointer
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
#define AccessFixedDimensionByItk(mitkImage, itkImageTypeFunction, dimension)
Access a mitk-image with known dimension by an itk-image.
double ScalarType
QmitkCenteredSimilarity2DTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
TransformType
Unique integer value for every transform.
Ui::QmitkCenteredSimilarity2DTransformControls m_Controls
static Pointer New()
virtual itk::Array< double > GetTransformParameters() override
virtual void SetTransformParameters(itk::Array< double > transformValues) override
virtual mitk::TransformParameters::TransformType GetTransformType() override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.