ITK  6.0.0
Insight Toolkit
itkSingleValuedVnlCostFunctionAdaptor.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 itkSingleValuedVnlCostFunctionAdaptor_h
19#define itkSingleValuedVnlCostFunctionAdaptor_h
20
22#include "vnl/vnl_cost_function.h"
23#include "ITKOptimizersExport.h"
24
25namespace itk
26{
37class ITKOptimizers_EXPORT SingleValuedVnlCostFunctionAdaptor : public vnl_cost_function
38{
39public:
41 using InternalParametersType = vnl_vector<double>;
42
44 using InternalMeasureType = double;
45
47 using InternalDerivativeType = vnl_vector<double>;
48
51
54
57
60
62 SingleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension);
63
65 void
67 {
68 m_CostFunction = costFunction;
69 }
70
74 {
75 return m_CostFunction;
76 }
77
79 InternalMeasureType
80 f(const InternalParametersType & inparameters) override;
81
83 void
84 gradf(const InternalParametersType & inparameters, InternalDerivativeType & gradient) override;
85
87 void
89
91 void
93
95 void
96 SetScales(const ScalesType & scales);
97
106 void
108
109 bool
111
112 void
114 {
115 m_NegateCostFunction = true;
116 }
117 void
119 {
120 m_NegateCostFunction = false;
121 }
122
127 unsigned long
128 AddObserver(const EventObject & event, Command *) const;
129
134 const MeasureType &
136
137 const DerivativeType &
139
140 const ParametersType &
142
143protected:
146 void
147 ReportIteration(const EventObject & event) const;
148
149private:
151 itkGetConstReferenceMacro(InverseScales, ScalesType);
152
154 bool m_ScalesInitialized{};
155 ScalesType m_InverseScales{};
156 bool m_NegateCostFunction{};
157 Object::Pointer m_Reporter{};
158
159 mutable MeasureType m_CachedValue{};
160 mutable DerivativeType m_CachedDerivative{};
161 mutable ParametersType m_CachedCurrentParameters{};
162}; // end of Class CostFunction
163} // end namespace itk
164
165#endif
Array class with size defined at construction time.
Definition: itkArray.h:48
Superclass for callback/observer methods.
Definition: itkCommand.h:46
Abstraction of the Events used to communicating among filters and with GUIs.
This class is a base for the CostFunctions returning a single value.
Array< ParametersValueType > DerivativeType
Superclass::ParametersType ParametersType
This class is an Adaptor that allows to pass itk::SingleValuedCostFunctions to vnl_optimizers expecti...
const MeasureType & GetCachedValue() const
const ParametersType & GetCachedCurrentParameters() const
void compute(const InternalParametersType &x, InternalMeasureType *fun, InternalDerivativeType *g) override
InternalMeasureType f(const InternalParametersType &inparameters) override
SingleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension)
void ReportIteration(const EventObject &event) const
unsigned long AddObserver(const EventObject &event, Command *) const
SingleValuedCostFunction::ParametersType ParametersType
void SetCostFunction(SingleValuedCostFunction *costFunction)
void ConvertExternalToInternalGradient(const DerivativeType &input, InternalDerivativeType &output) const
void gradf(const InternalParametersType &inparameters, InternalDerivativeType &gradient) override
void SetScales(const ScalesType &scales)
const DerivativeType & GetCachedDerivative() const
const SingleValuedCostFunction * GetCostFunction() const
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....