ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkCommandIterationUpdate.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 itkCommandIterationUpdate_h
19 #define itkCommandIterationUpdate_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  virtual void Execute(itk::Object *caller, const itk::EventObject & event) ITK_OVERRIDE
62  {
63  Execute( (const itk::Object *)caller, event);
64  }
65 
66  virtual void Execute(const itk::Object *, const itk::EventObject & event) ITK_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( typeid( event ) == typeid( itk::IterationEvent ) )
74  {
75  std::cout << m_Optimizer->GetCurrentIteration() << " = ";
76  std::cout << m_Optimizer->GetValue() << " : ";
77  std::cout << m_Optimizer->GetCurrentPosition() << std::endl;
78  }
79  else if( typeid( event ) == typeid( itk::EndEvent ) )
80  {
81  std::cout << std::endl << std::endl;
82  std::cout << "After " << m_Optimizer->GetCurrentIteration();
83  std::cout << " iterations " << std::endl;
84  std::cout << "Solution is = " << m_Optimizer->GetCurrentPosition();
85  std::cout << std::endl;
86  std::cout << "With value = " << m_Optimizer->GetValue();
87  std::cout << std::endl;
88  std::cout << "Stop condition = " << m_Optimizer->GetStopCondition();
89  std::cout << std::endl;
90  }
91 
92  }
93 
94 
98  itkTypeMacro( CommandIterationUpdate, ::itk::Command );
99 
100 
104  itkNewMacro( Self );
105 
106 
110  typedef TOptimizer OptimizerType;
111 
112 
116  void SetOptimizer( OptimizerType * optimizer )
117  {
118  m_Optimizer = optimizer;
119  m_Optimizer->AddObserver( itk::IterationEvent(), this );
120  }
122 
123 protected:
124 
129 
130 private:
131 
136 };
137 
138 } // end namespace itk
139 
140 #endif
WeakPointer< OptimizerType > m_Optimizer
void SetOptimizer(OptimizerType *optimizer)
itk::SmartPointer< const Self > ConstPointer
virtual void Execute(itk::Object *caller, const itk::EventObject &event) override
virtual void Execute(const itk::Object *, const itk::EventObject &event) override
Abstraction of the Events used to communicating among filters and with GUIs.
Base class for most ITK classes.
Definition: itkObject.h:57
itk::SmartPointer< Self > Pointer
Superclass for callback/observer methods.
Definition: itkCommand.h:44