ITK  5.2.0
Insight Toolkit
itkCommandVnlIterationUpdate.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 itkCommandVnlIterationUpdate_h
19 #define itkCommandVnlIterationUpdate_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 * itkNotUsed(caller), 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 (itk::IterationEvent().CheckEvent(&event))
77  {
78  std::cout << m_Optimizer->GetCurrentIteration() << " = ";
79  std::cout << m_Optimizer->GetCurrentPosition() << std::endl;
80  }
81  else if (typeid(event) == typeid(itk::EndEvent))
82  {
83  std::cout << std::endl << std::endl;
84  std::cout << "After " << m_Optimizer->GetCurrentIteration();
85  std::cout << " iterations " << std::endl;
86  std::cout << "Solution is = " << m_Optimizer->GetCurrentPosition();
87  std::cout << std::endl;
88  std::cout << "vnl report = " << std::endl;
89  m_Optimizer->GetOptimizer()->diagnose_outcome(std::cout);
90  }
91  }
92 
93 
97  itkTypeMacro(CommandVnlIterationUpdate, ::itk::Command);
98 
99 
103  itkNewMacro(Self);
104 
105 
109  using OptimizerType = TOptimizer;
110 
111 
115  void
117  {
118  m_Optimizer = optimizer;
119  m_Optimizer->AddObserver(itk::IterationEvent(), this);
120  }
122 
123 protected:
127  CommandVnlIterationUpdate() = default;
128 
129 private:
134 };
135 
136 
137 } // end namespace itk
138 
139 
140 #endif
itkWeakPointer.h
itk::CommandVnlIterationUpdate::Execute
void Execute(const itk::Object *, const itk::EventObject &event) override
Definition: itkCommandVnlIterationUpdate.h:69
itk::CommandVnlIterationUpdate::OptimizerType
TOptimizer OptimizerType
Definition: itkCommandVnlIterationUpdate.h:109
itk::SmartPointer< Self >
itk::CommandVnlIterationUpdate::SetOptimizer
void SetOptimizer(OptimizerType *optimizer)
Definition: itkCommandVnlIterationUpdate.h:116
itk::Command
Superclass for callback/observer methods.
Definition: itkCommand.h:45
itk::Command
class ITK_FORWARD_EXPORT Command
Definition: itkObject.h:43
itk::CommandVnlIterationUpdate::CommandVnlIterationUpdate
CommandVnlIterationUpdate()=default
itk::CommandVnlIterationUpdate::m_Optimizer
WeakPointer< OptimizerType > m_Optimizer
Definition: itkCommandVnlIterationUpdate.h:133
itk::CommandVnlIterationUpdate
Definition: itkCommandVnlIterationUpdate.h:33
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::CommandVnlIterationUpdate::Execute
void Execute(itk::Object *caller, const itk::EventObject &event) override
Definition: itkCommandVnlIterationUpdate.h:63
itk::EventObject
Abstraction of the Events used to communicating among filters and with GUIs.
Definition: itkEventObject.h:57
itkCommand.h
itk::CommandVnlIterationUpdate::Self
CommandVnlIterationUpdate Self
Definition: itkCommandVnlIterationUpdate.h:40