ITK  6.0.0
Insight Toolkit
itkCommandIterationUpdatev4.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkCommandIterationUpdatev4_h
19#define itkCommandIterationUpdatev4_h
20
21#include "itkCommand.h"
22#include "itkWeakPointer.h"
23
24namespace itk
25{
26
32template <typename TOptimizer>
34{
35public:
36
41
42
47
48
53
58
62 void
63 Execute(itk::Object * caller, const itk::EventObject & event) override
64 {
65 Execute((const itk::Object *)caller, event);
66 }
67
68 void
69 Execute(const itk::Object *, const itk::EventObject & event) override
70 {
71 if (typeid(event) == typeid(itk::StartEvent))
72 {
73 std::cout << std::endl << "Position Value" << std::endl << std::endl;
74 }
75 else if (typeid(event) == typeid(itk::IterationEvent))
76 {
77 std::cout << m_Optimizer->GetCurrentIteration() << " = " << m_Optimizer->GetValue();
79 {
80 std::cout << " : " << m_Optimizer->GetCurrentPosition();
81 }
82 std::cout << std::endl;
83 }
84 else if (typeid(event) == typeid(itk::EndEvent))
85 {
86 std::cout << std::endl
87 << std::endl
88 << "After " << m_Optimizer->GetCurrentIteration() << " iterations " << std::endl;
90 {
91 std::cout << " Solution is = " << m_Optimizer->GetCurrentPosition() << std::endl;
92 }
93 std::cout << "Solution value = " << m_Optimizer->GetValue() << std::endl
94 << "Stop condition = " << m_Optimizer->GetStopConditionDescription() << std::endl;
95 }
96 }
97
98
102 itkOverrideGetNameOfClassMacro(CommandIterationUpdatev4);
103
104
108 itkNewMacro(Self);
109
110
114 using OptimizerType = TOptimizer;
115
116
120 void
122 {
123 m_Optimizer = optimizer;
124 m_Optimizer->AddObserver(itk::IterationEvent(), this);
125 }
131 itkSetMacro(PrintParameters, bool);
132 itkGetMacro(PrintParameters, bool);
133 itkBooleanMacro(PrintParameters);
137protected:
142
143private:
148
149 bool m_PrintParameters{ false };
150};
151
152} // end namespace itk
153
154#endif
Implementation of the Command Pattern to be invoked every iteration.
void Execute(const itk::Object *, const itk::EventObject &event) override
WeakPointer< OptimizerType > m_Optimizer
void Execute(itk::Object *caller, const itk::EventObject &event) override
void SetOptimizer(OptimizerType *optimizer)
Superclass for callback/observer methods.
Definition: itkCommand.h:46
Abstraction of the Events used to communicating among filters and with GUIs.
Base class for most ITK classes.
Definition: itkObject.h:62
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
class ITK_FORWARD_EXPORT Command
Definition: itkObject.h:42