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