ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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::Function
29{
40template <typename TScalar, typename TEnergyValue>
42{
43public:
44 ITK_DISALLOW_COPY_AND_MOVE(ConvergenceMonitoringFunction);
45
50
52 itkOverrideGetNameOfClassMacro(ConvergenceMonitoringFunction);
53
54 using ScalarType = TScalar;
56
57 using EnergyValueType = TEnergyValue;
58 using EnergyValueContainerType = std::deque<EnergyValueType>;
59 using EnergyValueContainerSizeType = typename EnergyValueContainerType::size_type;
60 using EnergyValueIterator = typename EnergyValueContainerType::iterator;
61 using EnergyValueConstIterator = typename EnergyValueContainerType::const_iterator;
62
63 /* Add energy value to the end of the profile. */
64 virtual void
66 {
67 itkDebugMacro("Adding energy value " << value);
68 this->m_EnergyValues.push_back(value);
69 this->Modified();
70 }
71
72 /* Get the current number of energy values. */
75 {
76 return this->m_EnergyValues.size();
77 }
78
80 virtual void
82 {
83 if (this->GetNumberOfEnergyValues() > 0)
84 {
85 itkDebugMacro("Clearing energy values.");
86 this->m_EnergyValues.clear();
87 this->Modified();
88 }
89 }
90
92 virtual RealType
94
95protected:
97
98 ~ConvergenceMonitoringFunction() override = default;
99
100 void
101 PrintSelf(std::ostream & os, Indent indent) const override
102 {
103 Superclass::PrintSelf(os, indent);
104
105 os << std::endl << "Energy values: " << std::flush;
106
107 auto it = this->m_EnergyValues.begin();
108 while (it != this->m_EnergyValues.end())
109 {
110 os << '(' << it - this->m_EnergyValues.begin() << "): " << *it << ' ';
111 ++it;
112 }
113 os << std::endl;
114 }
115
117};
118} // namespace itk::Function
119
120#endif
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
void PrintSelf(std::ostream &os, Indent indent) const override
virtual void Modified() const
Implements transparent reference counting.