Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkTranslationTransformView.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 <itkTranslationTransform.h>
21 
24 {
25 }
26 
28 {
29 }
30 
32 {
33  if (m_FixedImage.IsNotNull())
34  {
35  AccessByItk(m_FixedImage, GetTransform2);
36  return m_TransformObject;
37  }
38  return nullptr;
39 }
40 
42 {
44 }
45 
46 template <class TPixelType, unsigned int VImageDimension>
47 itk::Object::Pointer QmitkTranslationTransformView::GetTransform2(
48  itk::Image<TPixelType, VImageDimension> * /*itkImage1*/)
49 {
50  typedef typename itk::Image<TPixelType, VImageDimension> FixedImageType;
51  typedef typename itk::Image<TPixelType, VImageDimension> MovingImageType;
52  typedef itk::TranslationTransform<double, VImageDimension> TransformType;
53  typename TransformType::Pointer transform = TransformType::New();
54  transform->SetIdentity();
55  m_TransformObject = transform;
56  return transform.GetPointer();
57 }
58 
60 {
61  itk::Array<double> transformValues;
62  transformValues.SetSize(4);
63  transformValues.fill(0);
64  transformValues[0] = m_Controls.m_UseOptimizerScalesTranslation->isChecked();
65  transformValues[1] = m_Controls.m_ScalesTranslationTransformTranslationX->text().toDouble();
66  transformValues[2] = m_Controls.m_ScalesTranslationTransformTranslationY->text().toDouble();
67  transformValues[3] = m_Controls.m_ScalesTranslationTransformTranslationZ->text().toDouble();
68  return transformValues;
69 }
70 
71 void QmitkTranslationTransformView::SetTransformParameters(itk::Array<double> transformValues)
72 {
73  m_Controls.m_UseOptimizerScalesTranslation->setChecked(transformValues[0]);
74  m_Controls.m_ScalesTranslationTransformTranslationX->setText(QString::number(transformValues[1]));
75  m_Controls.m_ScalesTranslationTransformTranslationY->setText(QString::number(transformValues[2]));
76  m_Controls.m_ScalesTranslationTransformTranslationZ->setText(QString::number(transformValues[3]));
77 }
78 
80 {
81  return "Translation";
82 }
83 
85 {
86  m_Controls.setupUi(parent);
87  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
88  m_Controls.m_ScalesTranslationTransformTranslationX->setValidator(validatorLineEditInputFloat);
89  m_Controls.m_ScalesTranslationTransformTranslationY->setValidator(validatorLineEditInputFloat);
90  m_Controls.m_ScalesTranslationTransformTranslationZ->setValidator(validatorLineEditInputFloat);
91 }
92 
94 {
95  itk::Array<double> scales;
96  scales.SetSize(3);
97  scales.Fill(1.0);
98  if (m_Controls.m_UseOptimizerScalesTranslation->isChecked())
99  {
100  scales[0] = m_Controls.m_ScalesTranslationTransformTranslationX->text().toDouble();
101  scales[1] = m_Controls.m_ScalesTranslationTransformTranslationY->text().toDouble();
102  scales[2] = m_Controls.m_ScalesTranslationTransformTranslationZ->text().toDouble();
103  }
104  return scales;
105 }
106 
107 vtkTransform *QmitkTranslationTransformView::Transform(vtkMatrix4x4 * /*vtkmatrix*/,
108  vtkTransform *vtktransform,
109  itk::Array<double> transformParams)
110 {
111  if (m_MovingImage.IsNotNull())
112  {
113  if (transformParams.size() == 2)
114  {
115  vtktransform->Translate(transformParams[0], transformParams[1], 0);
116  }
117  else if (transformParams.size() == 3)
118  {
119  vtktransform->Translate(transformParams[0], transformParams[1], transformParams[2]);
120  std::cout << "Translation is: " << transformParams[0] << transformParams[1] << transformParams[2] << std::endl;
121  }
122  }
123  return vtktransform;
124 }
125 
127 {
128  if (m_FixedImage.IsNotNull())
129  {
130  if (m_FixedImage->GetDimension() == 2)
131  {
132  m_Controls.m_ScalesTranslationTransformTranslationZ->hide();
133  m_Controls.textLabel4_4_2->hide();
134 
135  return 2;
136  }
137  else
138  {
139  m_Controls.m_ScalesTranslationTransformTranslationZ->show();
140  m_Controls.textLabel4_4_2->show();
141 
142  return 3;
143  }
144  }
145  else
146  return 0;
147 }
virtual void SetupUI(QWidget *parent) override
virtual itk::Object::Pointer GetTransform() override
virtual vtkTransform * Transform(vtkMatrix4x4 *vtkmatrix, vtkTransform *vtktransform, itk::Array< double > transformParams) override
itk::SmartPointer< Self > Pointer
QmitkTranslationTransformView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
TransformType
Unique integer value for every transform.
#define AccessByItk(mitkImage, itkImageTypeFunction)
Access a MITK image by an ITK image.
virtual itk::Array< double > GetScales() override
virtual mitk::TransformParameters::TransformType GetTransformType() override
virtual void SetTransformParameters(itk::Array< double > transformValues) override
virtual itk::Array< double > GetTransformParameters() override
Ui::QmitkTranslationTransformControls m_Controls
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.