ITK  4.4.0
Insight Segmentation and Registration Toolkit
itkConvergenceMonitoringFunction.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 __itkConvergenceMonitoringFunction_h
19 #define __itkConvergenceMonitoringFunction_h
20 
21 #include "itkObject.h"
22 #include "itkObjectFactory.h"
23 
24 #include "itkNumericTraits.h"
25 
26 #include <deque>
27 
28 namespace itk
29 {
30 namespace Function
31 {
42 template<class TScalar, class TEnergyValue>
44 : public Object
45 {
46 public:
47 
49  typedef Object Superclass;
52 
55 
56  typedef TScalar ScalarType;
58 
59  typedef TEnergyValue EnergyValueType;
60  typedef std::deque<EnergyValueType> EnergyValueContainerType;
61  typedef typename EnergyValueContainerType::size_type EnergyValueContainerSizeType;
62  typedef typename EnergyValueContainerType::iterator EnergyValueIterator;
63  typedef typename EnergyValueContainerType::const_iterator EnergyValueConstIterator;
64 
65  /* Add energy value to the end of the profile. */
66  virtual void AddEnergyValue( const EnergyValueType value )
67  {
68  itkDebugMacro( "Adding energy value " << value );
69  this->m_EnergyValues.push_back( value );
70  this->Modified();
71  }
72 
73  /* Get the current number of energy values. */
74  EnergyValueContainerSizeType GetNumberOfEnergyValues() const
75  {
76  return this->m_EnergyValues.size();
77  }
78 
80  virtual void ClearEnergyValues()
81  {
82  if( this->GetNumberOfEnergyValues() > 0 )
83  {
84  itkDebugMacro( "Clearing energy values." );
85  this->m_EnergyValues.clear();
86  this->Modified();
87  }
88  }
90 
92  virtual RealType GetConvergenceValue() const = 0;
93 
94 protected:
96  {
97  this->m_EnergyValues.clear();
98  }
99 
101 
102  void PrintSelf( std::ostream & os, Indent indent ) const
103  {
104  Superclass::PrintSelf( os, indent );
105 
106  os << std::endl << "Energy values: " << std::flush;
107 
108  EnergyValueConstIterator it = this->m_EnergyValues.begin();
109  while( it != this->m_EnergyValues.end() )
110  {
111  os << "(" << it - this->m_EnergyValues.begin() << "): " << *it << " ";
112  ++it;
113  }
114  os << std::endl;
115  }
116 
118 
119 private:
120  ConvergenceMonitoringFunction(const Self &); //purposely not implemented
121  void operator=(const Self &); //purposely not implemented
122 
123 };
124 } // end namespace function
125 } // end namespace itk
126 
127 #endif
128