ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
00001 /*========================================================================= 00002 * 00003 * Copyright Insight Software Consortium 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); 00006 * you may not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0.txt 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 * 00017 *=========================================================================*/ 00018 #ifndef __itkCommandIterationUpdate_h 00019 #define __itkCommandIterationUpdate_h 00020 00021 #include "itkCommand.h" 00022 #include "itkWeakPointer.h" 00023 00024 namespace itk { 00025 00031 template < class TOptimizer > 00032 class ITK_EXPORT CommandIterationUpdate : public Command 00033 { 00034 public: 00035 00039 typedef CommandIterationUpdate Self; 00040 00041 00045 typedef itk::Command Superclass; 00046 00047 00051 typedef itk::SmartPointer<Self> Pointer; 00052 00056 typedef itk::SmartPointer<const Self> ConstPointer; 00057 00061 void Execute(itk::Object *caller, const itk::EventObject & event) 00062 { 00063 Execute( (const itk::Object *)caller, event); 00064 } 00065 00066 void Execute(const itk::Object *, const itk::EventObject & event) 00067 { 00068 if( typeid( event ) == typeid( itk::StartEvent ) ) 00069 { 00070 std::cout << std::endl << "Position Value"; 00071 std::cout << std::endl << std::endl; 00072 } 00073 else if( typeid( event ) == typeid( itk::IterationEvent ) ) 00074 { 00075 std::cout << m_Optimizer->GetCurrentIteration() << " = "; 00076 std::cout << m_Optimizer->GetValue() << " : "; 00077 std::cout << m_Optimizer->GetCurrentPosition() << std::endl; 00078 } 00079 else if( typeid( event ) == typeid( itk::EndEvent ) ) 00080 { 00081 std::cout << std::endl << std::endl; 00082 std::cout << "After " << m_Optimizer->GetCurrentIteration(); 00083 std::cout << " iterations " << std::endl; 00084 std::cout << "Solution is = " << m_Optimizer->GetCurrentPosition(); 00085 std::cout << std::endl; 00086 std::cout << "With value = " << m_Optimizer->GetValue(); 00087 std::cout << std::endl; 00088 std::cout << "Stop condition = " << m_Optimizer->GetStopCondition(); 00089 std::cout << std::endl; 00090 } 00091 00092 } 00093 00094 00098 itkTypeMacro( CommandIterationUpdate, ::itk::Command ); 00099 00100 00104 itkNewMacro( Self ); 00105 00106 00110 typedef TOptimizer OptimizerType; 00111 00112 00116 void SetOptimizer( OptimizerType * optimizer ) 00117 { 00118 m_Optimizer = optimizer; 00119 m_Optimizer->AddObserver( itk::IterationEvent(), this ); 00120 } 00122 00123 protected: 00124 00128 CommandIterationUpdate() {}; 00129 00130 private: 00131 00135 WeakPointer<OptimizerType> m_Optimizer; 00136 }; 00137 00138 } // end namespace itk 00139 00140 #endif 00141