ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkCommandVnlIterationUpdate.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 
31 template < typename TOptimizer >
33 {
34 public:
35 
40 
41 
46 
47 
52 
57 
61  void Execute(itk::Object *caller, const itk::EventObject & event) override
62  {
63  Execute( (const itk::Object *)caller, event);
64  }
65 
66  void Execute(const itk::Object * itkNotUsed(caller), const itk::EventObject & event) override
67  {
68  if( typeid( event ) == typeid( itk::StartEvent ) )
69  {
70  std::cout << std::endl << "Position Value";
71  std::cout << std::endl << std::endl;
72  }
73  else if( itk::IterationEvent().CheckEvent( &event ) )
74  {
75  std::cout << m_Optimizer->GetCurrentIteration() << " = ";
76  std::cout << m_Optimizer->GetCurrentPosition() << std::endl;
77  }
78  else if( typeid( event ) == typeid( itk::EndEvent ) )
79  {
80  std::cout << std::endl << std::endl;
81  std::cout << "After " << m_Optimizer->GetCurrentIteration();
82  std::cout << " iterations " << std::endl;
83  std::cout << "Solution is = " << m_Optimizer->GetCurrentPosition();
84  std::cout << std::endl;
85  std::cout << "vnl report = " << std::endl;
86  m_Optimizer->GetOptimizer()->diagnose_outcome( std::cout );
87  }
88 
89  }
90 
91 
95  itkTypeMacro( CommandVnlIterationUpdate, ::itk::Command );
96 
97 
101  itkNewMacro( Self );
102 
103 
107  using OptimizerType = TOptimizer;
108 
109 
113  void SetOptimizer( OptimizerType * optimizer )
114  {
115  m_Optimizer = optimizer;
116  m_Optimizer->AddObserver( itk::IterationEvent(), this );
117  }
119 
120 protected:
121 
125  CommandVnlIterationUpdate() = default;
126 
127 private:
128 
133 };
134 
135 
136 } // end namespace itk
137 
138 
139 #endif
void Execute(const itk::Object *, const itk::EventObject &event) override
void SetOptimizer(OptimizerType *optimizer)
Abstraction of the Events used to communicating among filters and with GUIs.
class ITK_FORWARD_EXPORT Command
Definition: itkObject.h:41
void Execute(itk::Object *caller, const itk::EventObject &event) override
Base class for most ITK classes.
Definition: itkObject.h:60
Superclass for callback/observer methods.
Definition: itkCommand.h:44
WeakPointer< OptimizerType > m_Optimizer