ITK  5.2.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  * http://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 
24 namespace itk
25 {
26 
32 template <typename TOptimizer>
34 {
35 public:
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";
74  std::cout << std::endl << std::endl;
75  }
76  else if (typeid(event) == typeid(itk::IterationEvent))
77  {
78  std::cout << m_Optimizer->GetCurrentIteration() << " = ";
79  std::cout << m_Optimizer->GetValue();
81  {
82  std::cout << " : " << m_Optimizer->GetCurrentPosition();
83  }
84  std::cout << std::endl;
85  }
86  else if (typeid(event) == typeid(itk::EndEvent))
87  {
88  std::cout << std::endl << std::endl;
89  std::cout << "After " << m_Optimizer->GetCurrentIteration();
90  std::cout << " iterations " << std::endl;
92  {
93  std::cout << " Solution is = " << m_Optimizer->GetCurrentPosition();
94  std::cout << std::endl;
95  }
96  std::cout << "Solution value = " << m_Optimizer->GetValue();
97  std::cout << std::endl;
98  std::cout << "Stop condition = " << m_Optimizer->GetStopConditionDescription();
99  std::cout << std::endl;
100  }
101  }
102 
103 
107  itkTypeMacro(CommandIterationUpdatev4, ::itk::Command);
108 
109 
113  itkNewMacro(Self);
114 
115 
119  using OptimizerType = TOptimizer;
120 
121 
125  void
127  {
128  m_Optimizer = optimizer;
129  m_Optimizer->AddObserver(itk::IterationEvent(), this);
130  }
132 
136  itkSetMacro(PrintParameters, bool);
137  itkGetMacro(PrintParameters, bool);
138  itkBooleanMacro(PrintParameters);
140 
141 
142 protected:
147 
148 private:
153 
154  bool m_PrintParameters{ false };
155 };
156 
157 } // end namespace itk
158 
159 #endif
itk::CommandIterationUpdatev4::OptimizerType
TOptimizer OptimizerType
Definition: itkCommandIterationUpdatev4.h:119
itk::CommandIterationUpdatev4::Self
CommandIterationUpdatev4 Self
Definition: itkCommandIterationUpdatev4.h:40
itkWeakPointer.h
itk::SmartPointer< Self >
itk::CommandIterationUpdatev4::CommandIterationUpdatev4
CommandIterationUpdatev4()
Definition: itkCommandIterationUpdatev4.h:146
itk::CommandIterationUpdatev4
Implementation of the Command Pattern to be invoked every iteration.
Definition: itkCommandIterationUpdatev4.h:33
itk::CommandIterationUpdatev4::Execute
void Execute(const itk::Object *, const itk::EventObject &event) override
Definition: itkCommandIterationUpdatev4.h:69
itk::Command
Superclass for callback/observer methods.
Definition: itkCommand.h:45
itk::CommandIterationUpdatev4::SetOptimizer
void SetOptimizer(OptimizerType *optimizer)
Definition: itkCommandIterationUpdatev4.h:126
itk::Command
class ITK_FORWARD_EXPORT Command
Definition: itkObject.h:43
itk::CommandIterationUpdatev4::m_PrintParameters
bool m_PrintParameters
Definition: itkCommandIterationUpdatev4.h:154
itk::CommandIterationUpdatev4::m_Optimizer
WeakPointer< OptimizerType > m_Optimizer
Definition: itkCommandIterationUpdatev4.h:146
itk::WeakPointer< OptimizerType >
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::EventObject
Abstraction of the Events used to communicating among filters and with GUIs.
Definition: itkEventObject.h:57
itkCommand.h
itk::CommandIterationUpdatev4::Execute
void Execute(itk::Object *caller, const itk::EventObject &event) override
Definition: itkCommandIterationUpdatev4.h:63