ITK  6.0.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 * https://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
28namespace itk
29{
30namespace Function
31{
42template <typename TScalar, typename TEnergyValue>
44{
45public:
46 ITK_DISALLOW_COPY_AND_MOVE(ConvergenceMonitoringFunction);
47
52
54 itkOverrideGetNameOfClassMacro(ConvergenceMonitoringFunction);
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 }
95 virtual RealType
97
98protected:
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
Abstract base class which monitors convergence during the course of optimization.
typename EnergyValueContainerType::iterator EnergyValueIterator
virtual RealType GetConvergenceValue() const =0
void PrintSelf(std::ostream &os, Indent indent) const override
typename NumericTraits< ScalarType >::RealType RealType
virtual void AddEnergyValue(const EnergyValueType value)
EnergyValueContainerSizeType GetNumberOfEnergyValues() const
typename EnergyValueContainerType::const_iterator EnergyValueConstIterator
typename EnergyValueContainerType::size_type EnergyValueContainerSizeType
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Light weight base class for most itk classes.
Define additional traits for native types such as int or float.
Base class for most ITK classes.
Definition: itkObject.h:62
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void Modified() const
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....