Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkSPSAOptimizerView.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 
17 #include "QmitkSPSAOptimizerView.h"
18 #include "mitkImageAccessByItk.h"
19 #include <itkSPSAOptimizer.h>
20 
21 QmitkSPSAOptimizerView::QmitkSPSAOptimizerView(QWidget *parent, Qt::WindowFlags f)
22  : QmitkRigidRegistrationOptimizerGUIBase(parent, f), m_NumberTransformParameters(16)
23 {
24 }
25 
27 {
28 }
29 
31 {
33 }
34 
36 {
38  OptimizerPointer->SetMaximize(m_Controls.m_Maximize->isChecked());
39  OptimizerPointer->Seta(m_Controls.m_aSPSA->text().toFloat());
40  OptimizerPointer->SetA(m_Controls.m_ASPSA->text().toFloat());
41  OptimizerPointer->SetAlpha(m_Controls.m_AlphaSPSA->text().toFloat());
42  OptimizerPointer->Setc(m_Controls.m_cSPSA->text().toFloat());
43  OptimizerPointer->SetGamma(m_Controls.m_GammaSPSA->text().toFloat());
44  OptimizerPointer->SetTolerance(m_Controls.m_ToleranceSPSA->text().toFloat());
45  OptimizerPointer->SetStateOfConvergenceDecayRate(m_Controls.m_StateOfConvergenceDecayRateSPSA->text().toFloat());
46  OptimizerPointer->SetMinimumNumberOfIterations(m_Controls.m_MinimumNumberOfIterationsSPSA->text().toInt());
47  OptimizerPointer->SetNumberOfPerturbations(m_Controls.m_NumberOfPerturbationsSPSA->text().toInt());
48  OptimizerPointer->SetMaximumNumberOfIterations(m_Controls.m_IterationsSPSA->text().toInt());
49  return OptimizerPointer.GetPointer();
50 }
51 
53 {
54  itk::Array<double> optimizerValues;
55  optimizerValues.SetSize(3);
56  optimizerValues.fill(0);
57  optimizerValues[0] = m_Controls.m_Maximize->isChecked();
58  optimizerValues[1] = m_Controls.m_aSPSA->text().toFloat();
59  optimizerValues[2] = m_Controls.m_ASPSA->text().toFloat();
60  optimizerValues[3] = m_Controls.m_AlphaSPSA->text().toFloat();
61  optimizerValues[4] = m_Controls.m_cSPSA->text().toFloat();
62  optimizerValues[5] = m_Controls.m_GammaSPSA->text().toFloat();
63  optimizerValues[6] = m_Controls.m_ToleranceSPSA->text().toFloat();
64  optimizerValues[7] = m_Controls.m_StateOfConvergenceDecayRateSPSA->text().toFloat();
65  optimizerValues[8] = m_Controls.m_MinimumNumberOfIterationsSPSA->text().toInt();
66  optimizerValues[9] = m_Controls.m_NumberOfPerturbationsSPSA->text().toInt();
67  optimizerValues[10] = m_Controls.m_IterationsSPSA->text().toInt();
68  return optimizerValues;
69 }
70 
71 void QmitkSPSAOptimizerView::SetOptimizerParameters(itk::Array<double> optimizerValues)
72 {
73  m_Controls.m_Maximize->setChecked(optimizerValues[0]);
74  m_Controls.m_aSPSA->setText(QString::number(optimizerValues[1]));
75  m_Controls.m_ASPSA->setText(QString::number(optimizerValues[2]));
76  m_Controls.m_AlphaSPSA->setText(QString::number(optimizerValues[3]));
77  m_Controls.m_cSPSA->setText(QString::number(optimizerValues[4]));
78  m_Controls.m_GammaSPSA->setText(QString::number(optimizerValues[5]));
79  m_Controls.m_ToleranceSPSA->setText(QString::number(optimizerValues[6]));
80  m_Controls.m_StateOfConvergenceDecayRateSPSA->setText(QString::number(optimizerValues[7]));
81  m_Controls.m_MinimumNumberOfIterationsSPSA->setText(QString::number(optimizerValues[8]));
82  m_Controls.m_NumberOfPerturbationsSPSA->setText(QString::number(optimizerValues[9]));
83  m_Controls.m_IterationsSPSA->setText(QString::number(optimizerValues[10]));
84 }
85 
87 {
88  m_NumberTransformParameters = transformParameters;
89 }
90 
92 {
93  return "SPSA";
94 }
95 
96 void QmitkSPSAOptimizerView::SetupUI(QWidget *parent)
97 {
98  m_Controls.setupUi(parent);
99  QValidator *validatorLineEditInput = new QIntValidator(0, 20000000, this);
100  m_Controls.m_MinimumNumberOfIterationsSPSA->setValidator(validatorLineEditInput);
101  m_Controls.m_NumberOfPerturbationsSPSA->setValidator(validatorLineEditInput);
102  m_Controls.m_IterationsSPSA->setValidator(validatorLineEditInput);
103  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
104  m_Controls.m_aSPSA->setValidator(validatorLineEditInputFloat);
105  m_Controls.m_ASPSA->setValidator(validatorLineEditInputFloat);
106  m_Controls.m_AlphaSPSA->setValidator(validatorLineEditInputFloat);
107  m_Controls.m_cSPSA->setValidator(validatorLineEditInputFloat);
108  m_Controls.m_GammaSPSA->setValidator(validatorLineEditInputFloat);
109  m_Controls.m_ToleranceSPSA->setValidator(validatorLineEditInputFloat);
110  m_Controls.m_StateOfConvergenceDecayRateSPSA->setValidator(validatorLineEditInputFloat);
111 }
virtual void SetupUI(QWidget *parent) override
itk::SmartPointer< Self > Pointer
virtual void SetNumberOfTransformParameters(int transformParameters) override
virtual void SetOptimizerParameters(itk::Array< double > metricValues) override
virtual QString GetName() override
virtual mitk::OptimizerParameters::OptimizerType GetOptimizerType() override
Ui::QmitkSPSAOptimizerControls m_Controls
virtual itk::Object::Pointer GetOptimizer() override
OptimizerType
Unique integer value for every optimizer.
virtual itk::Array< double > GetOptimizerParameters() override
QmitkSPSAOptimizerView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.