Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkAmoebaOptimizerView.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 <itkAmoebaOptimizer.h>
20 
21 QmitkAmoebaOptimizerView::QmitkAmoebaOptimizerView(QWidget *parent, Qt::WindowFlags f)
22  : QmitkRigidRegistrationOptimizerGUIBase(parent, f), m_NumberTransformParameters(15)
23 {
24 }
25 
27 {
28 }
29 
31 {
33 }
34 
36 {
38  OptimizerPointer->SetMaximize(m_Controls.m_Maximize->isChecked());
39  OptimizerPointer->SetParametersConvergenceTolerance(
40  m_Controls.m_ParametersConvergenceToleranceAmoeba->text().toFloat());
41  OptimizerPointer->SetFunctionConvergenceTolerance(m_Controls.m_FunctionConvergenceToleranceAmoeba->text().toFloat());
42  typedef itk::SingleValuedNonLinearOptimizer OptimizerType;
43  OptimizerType::ParametersType simplexDelta(m_NumberTransformParameters);
44  itk::Array<double> simplexDeltaAmoeba = this->GetOptimizerParameters();
45  for (int i = 0; i < m_NumberTransformParameters; i++)
46  {
47  simplexDelta[i] = simplexDeltaAmoeba[i + 1];
48  }
49  OptimizerPointer->AutomaticInitialSimplexOff();
50  OptimizerPointer->SetInitialSimplexDelta(simplexDelta);
51  OptimizerPointer->SetMaximumNumberOfIterations(m_Controls.m_IterationsAmoeba->text().toInt());
52  return OptimizerPointer.GetPointer();
53 }
54 
56 {
57  itk::Array<double> optimizerValues;
58  optimizerValues.SetSize(19);
59  optimizerValues.fill(0);
60  optimizerValues[0] = m_Controls.m_Maximize->isChecked();
61  optimizerValues[1] = m_Controls.m_SimplexDeltaAmoeba1->text().toDouble();
62  optimizerValues[2] = m_Controls.m_SimplexDeltaAmoeba2->text().toDouble();
63  optimizerValues[3] = m_Controls.m_SimplexDeltaAmoeba3->text().toDouble();
64  optimizerValues[4] = m_Controls.m_SimplexDeltaAmoeba4->text().toDouble();
65  optimizerValues[5] = m_Controls.m_SimplexDeltaAmoeba5->text().toDouble();
66  optimizerValues[6] = m_Controls.m_SimplexDeltaAmoeba6->text().toDouble();
67  optimizerValues[7] = m_Controls.m_SimplexDeltaAmoeba7->text().toDouble();
68  optimizerValues[8] = m_Controls.m_SimplexDeltaAmoeba8->text().toDouble();
69  optimizerValues[9] = m_Controls.m_SimplexDeltaAmoeba9->text().toDouble();
70  optimizerValues[10] = m_Controls.m_SimplexDeltaAmoeba10->text().toDouble();
71  optimizerValues[11] = m_Controls.m_SimplexDeltaAmoeba11->text().toDouble();
72  optimizerValues[12] = m_Controls.m_SimplexDeltaAmoeba12->text().toDouble();
73  optimizerValues[13] = m_Controls.m_SimplexDeltaAmoeba13->text().toDouble();
74  optimizerValues[14] = m_Controls.m_SimplexDeltaAmoeba14->text().toDouble();
75  optimizerValues[15] = m_Controls.m_SimplexDeltaAmoeba15->text().toDouble();
76  optimizerValues[16] = m_Controls.m_ParametersConvergenceToleranceAmoeba->text().toFloat();
77  optimizerValues[17] = m_Controls.m_FunctionConvergenceToleranceAmoeba->text().toFloat();
78  optimizerValues[18] = m_Controls.m_IterationsAmoeba->text().toInt();
79  return optimizerValues;
80 }
81 
82 void QmitkAmoebaOptimizerView::SetOptimizerParameters(itk::Array<double> optimizerValues)
83 {
84  m_Controls.m_Maximize->setChecked(optimizerValues[0]);
85  m_Controls.m_SimplexDeltaAmoeba1->setText(QString::number(optimizerValues[1]));
86  m_Controls.m_SimplexDeltaAmoeba2->setText(QString::number(optimizerValues[2]));
87  m_Controls.m_SimplexDeltaAmoeba3->setText(QString::number(optimizerValues[3]));
88  m_Controls.m_SimplexDeltaAmoeba4->setText(QString::number(optimizerValues[4]));
89  m_Controls.m_SimplexDeltaAmoeba5->setText(QString::number(optimizerValues[5]));
90  m_Controls.m_SimplexDeltaAmoeba6->setText(QString::number(optimizerValues[6]));
91  m_Controls.m_SimplexDeltaAmoeba7->setText(QString::number(optimizerValues[7]));
92  m_Controls.m_SimplexDeltaAmoeba8->setText(QString::number(optimizerValues[8]));
93  m_Controls.m_SimplexDeltaAmoeba9->setText(QString::number(optimizerValues[9]));
94  m_Controls.m_SimplexDeltaAmoeba10->setText(QString::number(optimizerValues[10]));
95  m_Controls.m_SimplexDeltaAmoeba11->setText(QString::number(optimizerValues[11]));
96  m_Controls.m_SimplexDeltaAmoeba12->setText(QString::number(optimizerValues[12]));
97  m_Controls.m_SimplexDeltaAmoeba13->setText(QString::number(optimizerValues[13]));
98  m_Controls.m_SimplexDeltaAmoeba14->setText(QString::number(optimizerValues[14]));
99  m_Controls.m_SimplexDeltaAmoeba15->setText(QString::number(optimizerValues[15]));
100  m_Controls.m_ParametersConvergenceToleranceAmoeba->setText(QString::number(optimizerValues[16]));
101  m_Controls.m_FunctionConvergenceToleranceAmoeba->setText(QString::number(optimizerValues[17]));
102  m_Controls.m_IterationsAmoeba->setText(QString::number(optimizerValues[18]));
103 }
104 
106 {
107  m_NumberTransformParameters = transformParameters;
108  this->ShowSimplexDelta();
109 }
110 
112 {
113  return "Amoeba";
114 }
115 
117 {
118  m_Controls.setupUi(parent);
119  QValidator *validatorLineEditInput = new QIntValidator(0, 20000000, this);
120  m_Controls.m_IterationsAmoeba->setValidator(validatorLineEditInput);
121  QValidator *validatorLineEditInputFloat = new QDoubleValidator(0, 20000000, 8, this);
122  m_Controls.m_SimplexDeltaAmoeba1->setValidator(validatorLineEditInputFloat);
123  m_Controls.m_SimplexDeltaAmoeba2->setValidator(validatorLineEditInputFloat);
124  m_Controls.m_SimplexDeltaAmoeba3->setValidator(validatorLineEditInputFloat);
125  m_Controls.m_SimplexDeltaAmoeba4->setValidator(validatorLineEditInputFloat);
126  m_Controls.m_SimplexDeltaAmoeba5->setValidator(validatorLineEditInputFloat);
127  m_Controls.m_SimplexDeltaAmoeba6->setValidator(validatorLineEditInputFloat);
128  m_Controls.m_SimplexDeltaAmoeba7->setValidator(validatorLineEditInputFloat);
129  m_Controls.m_SimplexDeltaAmoeba8->setValidator(validatorLineEditInputFloat);
130  m_Controls.m_SimplexDeltaAmoeba9->setValidator(validatorLineEditInputFloat);
131  m_Controls.m_SimplexDeltaAmoeba10->setValidator(validatorLineEditInputFloat);
132  m_Controls.m_SimplexDeltaAmoeba11->setValidator(validatorLineEditInputFloat);
133  m_Controls.m_SimplexDeltaAmoeba12->setValidator(validatorLineEditInputFloat);
134  m_Controls.m_SimplexDeltaAmoeba13->setValidator(validatorLineEditInputFloat);
135  m_Controls.m_SimplexDeltaAmoeba14->setValidator(validatorLineEditInputFloat);
136  m_Controls.m_SimplexDeltaAmoeba15->setValidator(validatorLineEditInputFloat);
137  m_Controls.m_ParametersConvergenceToleranceAmoeba->setValidator(validatorLineEditInputFloat);
138  m_Controls.m_FunctionConvergenceToleranceAmoeba->setValidator(validatorLineEditInputFloat);
139  simplexDeltaLineEdits.clear();
140  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba1);
141  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba2);
142  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba3);
143  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba4);
144  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba5);
145  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba6);
146  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba7);
147  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba8);
148  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba9);
149  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba10);
150  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba11);
151  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba12);
152  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba13);
153  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba14);
154  simplexDeltaLineEdits.push_back(m_Controls.m_SimplexDeltaAmoeba15);
155  simplexDeltaLabels.clear();
156  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel1);
157  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel2);
158  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel3);
159  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel4);
160  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel5);
161  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel6);
162  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel7);
163  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel8);
164  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel9);
165  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel10);
166  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel11);
167  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel12);
168  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel13);
169  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel14);
170  simplexDeltaLabels.push_back(m_Controls.m_SimplexDeltaAmoebaLabel15);
171 }
172 
173 void QmitkAmoebaOptimizerView::ShowSimplexDelta()
174 {
175  auto it_edit = simplexDeltaLineEdits.begin();
176  for (it_edit = simplexDeltaLineEdits.begin(); it_edit != simplexDeltaLineEdits.end(); it_edit++)
177  {
178  (*it_edit)->hide();
179  }
180  it_edit = simplexDeltaLineEdits.begin();
181  for (int i = 0; i < m_NumberTransformParameters; i++)
182  {
183  (*it_edit)->show();
184  it_edit++;
185  }
186  auto it_label = simplexDeltaLabels.begin();
187  for (it_label = simplexDeltaLabels.begin(); it_label != simplexDeltaLabels.end(); it_label++)
188  {
189  (*it_label)->hide();
190  }
191  it_label = simplexDeltaLabels.begin();
192  for (int i = 0; i < m_NumberTransformParameters; i++)
193  {
194  (*it_label)->show();
195  it_label++;
196  }
197  this->updateGeometry();
198 }
std::list< QLabel * > simplexDeltaLabels
itk::SmartPointer< Self > Pointer
QmitkAmoebaOptimizerView(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
virtual QString GetName() override
virtual mitk::OptimizerParameters::OptimizerType GetOptimizerType() override
std::list< QLineEdit * > simplexDeltaLineEdits
virtual void SetNumberOfTransformParameters(int transformParameters) override
Ui::QmitkAmoebaOptimizerControls m_Controls
virtual void SetupUI(QWidget *parent) override
virtual itk::Object::Pointer GetOptimizer() override
virtual itk::Array< double > GetOptimizerParameters() override
OptimizerType
Unique integer value for every optimizer.
virtual void SetOptimizerParameters(itk::Array< double > metricValues) override
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.