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 __itkConvergenceMonitoringFunction_h 00019 #define __itkConvergenceMonitoringFunction_h 00020 00021 #include "itkObject.h" 00022 #include "itkObjectFactory.h" 00023 00024 #include "itkNumericTraits.h" 00025 00026 #include <deque> 00027 00028 namespace itk 00029 { 00030 namespace Function 00031 { 00042 template<class TScalar, class TEnergyValue> 00043 class ITK_EXPORT ConvergenceMonitoringFunction 00044 : public Object 00045 { 00046 public: 00047 00048 typedef ConvergenceMonitoringFunction Self; 00049 typedef Object Superclass; 00050 typedef SmartPointer<Self> Pointer; 00051 typedef SmartPointer<const Self> ConstPointer; 00052 00054 itkTypeMacro( ConvergenceMonitoringFunction, Object ); 00055 00056 typedef TScalar ScalarType; 00057 typedef typename NumericTraits<ScalarType>::RealType RealType; 00058 00059 typedef TEnergyValue EnergyValueType; 00060 typedef std::deque<EnergyValueType> EnergyValueContainerType; 00061 typedef typename EnergyValueContainerType::size_type EnergyValueContainerSizeType; 00062 typedef typename EnergyValueContainerType::iterator EnergyValueIterator; 00063 typedef typename EnergyValueContainerType::const_iterator EnergyValueConstIterator; 00064 00065 /* Add energy value to the end of the profile. */ 00066 virtual void AddEnergyValue( const EnergyValueType value ) 00067 { 00068 itkDebugMacro( "Adding energy value " << value ); 00069 this->m_EnergyValues.push_back( value ); 00070 this->Modified(); 00071 } 00072 00073 /* Get the current number of energy values. */ 00074 EnergyValueContainerSizeType GetNumberOfEnergyValues() const 00075 { 00076 return this->m_EnergyValues.size(); 00077 } 00078 00080 virtual void ClearEnergyValues() 00081 { 00082 if( this->GetNumberOfEnergyValues() > 0 ) 00083 { 00084 itkDebugMacro( "Clearing energy values." ); 00085 this->m_EnergyValues.clear(); 00086 this->Modified(); 00087 } 00088 } 00090 00092 virtual RealType GetConvergenceValue() const = 0; 00093 00094 protected: 00095 ConvergenceMonitoringFunction() 00096 { 00097 this->m_EnergyValues.clear(); 00098 } 00099 00100 ~ConvergenceMonitoringFunction() {} 00101 00102 void PrintSelf( std::ostream & os, Indent indent ) const 00103 { 00104 Superclass::PrintSelf( os, indent ); 00105 00106 os << std::endl << "Energy values: " << std::flush; 00107 00108 EnergyValueConstIterator it = this->m_EnergyValues.begin(); 00109 while( it != this->m_EnergyValues.end() ) 00110 { 00111 os << "(" << it - this->m_EnergyValues.begin() << "): " << *it << " "; 00112 ++it; 00113 } 00114 os << std::endl; 00115 } 00116 00117 EnergyValueContainerType m_EnergyValues; 00118 00119 private: 00120 ConvergenceMonitoringFunction(const Self &); //purposely not implemented 00121 void operator=(const Self &); //purposely not implemented 00122 00123 }; 00124 } // end namespace function 00125 } // end namespace itk 00126 00127 #endif 00128