ITK  5.0.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<typename TScalar, typename TEnergyValue>
44 : public Object
45 {
46 public:
47  ITK_DISALLOW_COPY_AND_ASSIGN(ConvergenceMonitoringFunction);
48 
50  using Superclass = Object;
53 
55  itkTypeMacro( ConvergenceMonitoringFunction, Object );
56 
57  using ScalarType = TScalar;
59 
60  using EnergyValueType = TEnergyValue;
61  using EnergyValueContainerType = std::deque<EnergyValueType>;
62  using EnergyValueContainerSizeType = typename EnergyValueContainerType::size_type;
63  using EnergyValueIterator = typename EnergyValueContainerType::iterator;
64  using EnergyValueConstIterator = typename EnergyValueContainerType::const_iterator;
65 
66  /* Add energy value to the end of the profile. */
67  virtual void AddEnergyValue( const EnergyValueType value )
68  {
69  itkDebugMacro( "Adding energy value " << value );
70  this->m_EnergyValues.push_back( value );
71  this->Modified();
72  }
73 
74  /* Get the current number of energy values. */
76  {
77  return this->m_EnergyValues.size();
78  }
79 
81  virtual void ClearEnergyValues()
82  {
83  if( this->GetNumberOfEnergyValues() > 0 )
84  {
85  itkDebugMacro( "Clearing energy values." );
86  this->m_EnergyValues.clear();
87  this->Modified();
88  }
89  }
91 
93  virtual RealType GetConvergenceValue() const = 0;
94 
95 protected:
97  {
98  this->m_EnergyValues.clear();
99  }
100 
101  ~ConvergenceMonitoringFunction() override = default;
102 
103  void PrintSelf( std::ostream & os, Indent indent ) const override
104  {
105  Superclass::PrintSelf( os, indent );
106 
107  os << std::endl << "Energy values: " << std::flush;
108 
109  auto it = this->m_EnergyValues.begin();
110  while( it != this->m_EnergyValues.end() )
111  {
112  os << "(" << it - this->m_EnergyValues.begin() << "): " << *it << " ";
113  ++it;
114  }
115  os << std::endl;
116  }
117 
119 };
120 } // end namespace Function
121 } // end namespace itk
122 
123 #endif
Light weight base class for most itk classes.
virtual RealType GetConvergenceValue() const =0
typename EnergyValueContainerType::const_iterator EnergyValueConstIterator
Define numeric traits for std::vector.
Abstract base class which monitors convergence during the course of optimization. ...
EnergyValueContainerSizeType GetNumberOfEnergyValues() const
void PrintSelf(std::ostream &os, Indent indent) const override
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void Modified() const
Control indentation during Print() invocation.
Definition: itkIndent.h:49
Base class for most ITK classes.
Definition: itkObject.h:60
virtual void AddEnergyValue(const EnergyValueType value)