ITK  5.2.0
Insight Toolkit
itkConvergenceMonitoringFunction.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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 {
45 public:
46  ITK_DISALLOW_COPY_AND_MOVE(ConvergenceMonitoringFunction);
47 
49  using Superclass = Object;
52 
55 
56  using ScalarType = TScalar;
58 
59  using EnergyValueType = TEnergyValue;
60  using EnergyValueContainerType = std::deque<EnergyValueType>;
61  using EnergyValueContainerSizeType = typename EnergyValueContainerType::size_type;
62  using EnergyValueIterator = typename EnergyValueContainerType::iterator;
63  using EnergyValueConstIterator = typename EnergyValueContainerType::const_iterator;
64 
65  /* Add energy value to the end of the profile. */
66  virtual void
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. */
77  {
78  return this->m_EnergyValues.size();
79  }
80 
82  virtual void
84  {
85  if (this->GetNumberOfEnergyValues() > 0)
86  {
87  itkDebugMacro("Clearing energy values.");
88  this->m_EnergyValues.clear();
89  this->Modified();
90  }
91  }
93 
95  virtual RealType
96  GetConvergenceValue() const = 0;
97 
98 protected:
100 
101  ~ConvergenceMonitoringFunction() override = default;
102 
103  void
104  PrintSelf(std::ostream & os, Indent indent) const override
105  {
106  Superclass::PrintSelf(os, indent);
107 
108  os << std::endl << "Energy values: " << std::flush;
109 
110  auto it = this->m_EnergyValues.begin();
111  while (it != this->m_EnergyValues.end())
112  {
113  os << "(" << it - this->m_EnergyValues.begin() << "): " << *it << " ";
114  ++it;
115  }
116  os << std::endl;
117  }
118 
120 };
121 } // end namespace Function
122 } // end namespace itk
123 
124 #endif
itk::Function::ConvergenceMonitoringFunction< TScalar, TScalar >::EnergyValueContainerSizeType
typename EnergyValueContainerType::size_type EnergyValueContainerSizeType
Definition: itkConvergenceMonitoringFunction.h:61
itkObjectFactory.h
itk::Function::ConvergenceMonitoringFunction< TScalar, TScalar >::EnergyValueType
TScalar EnergyValueType
Definition: itkConvergenceMonitoringFunction.h:59
itk::Function::ConvergenceMonitoringFunction::ClearEnergyValues
virtual void ClearEnergyValues()
Definition: itkConvergenceMonitoringFunction.h:83
itk::Function::ConvergenceMonitoringFunction< TScalar, TScalar >::ScalarType
TScalar ScalarType
Definition: itkConvergenceMonitoringFunction.h:56
itk::Function::ConvergenceMonitoringFunction::m_EnergyValues
EnergyValueContainerType m_EnergyValues
Definition: itkConvergenceMonitoringFunction.h:119
itk::Function::ConvergenceMonitoringFunction< TScalar, TScalar >::EnergyValueIterator
typename EnergyValueContainerType::iterator EnergyValueIterator
Definition: itkConvergenceMonitoringFunction.h:62
itk::Function::ConvergenceMonitoringFunction::GetNumberOfEnergyValues
EnergyValueContainerSizeType GetNumberOfEnergyValues() const
Definition: itkConvergenceMonitoringFunction.h:76
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::Function::ConvergenceMonitoringFunction::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
Definition: itkConvergenceMonitoringFunction.h:104
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:59
itk::Function::ConvergenceMonitoringFunction::ConvergenceMonitoringFunction
ConvergenceMonitoringFunction()
Definition: itkConvergenceMonitoringFunction.h:99
itk::Function::ConvergenceMonitoringFunction::AddEnergyValue
virtual void AddEnergyValue(const EnergyValueType value)
Definition: itkConvergenceMonitoringFunction.h:67
itk::Function::ConvergenceMonitoringFunction< TScalar, TScalar >::EnergyValueConstIterator
typename EnergyValueContainerType::const_iterator EnergyValueConstIterator
Definition: itkConvergenceMonitoringFunction.h:63
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:58
itk::Function::ConvergenceMonitoringFunction::~ConvergenceMonitoringFunction
~ConvergenceMonitoringFunction() override=default
itkObject.h
itk::Function::ConvergenceMonitoringFunction< TScalar, TScalar >::RealType
typename NumericTraits< ScalarType >::RealType RealType
Definition: itkConvergenceMonitoringFunction.h:57
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Function::ConvergenceMonitoringFunction< TScalar, TScalar >::EnergyValueContainerType
std::deque< EnergyValueType > EnergyValueContainerType
Definition: itkConvergenceMonitoringFunction.h:60
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itkNumericTraits.h
itk::Function::ConvergenceMonitoringFunction::GetConvergenceValue
virtual RealType GetConvergenceValue() const =0
itk::Function::ConvergenceMonitoringFunction
Abstract base class which monitors convergence during the course of optimization.
Definition: itkConvergenceMonitoringFunction.h:43
itk::Object::Object
Object()
itk::Object::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::Object::Modified
virtual void Modified() const