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 
25 namespace itk
26 {
37 class ITKOptimizers_EXPORT SingleValuedVnlCostFunctionAdaptor : public vnl_cost_function
38 {
39 public:
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
88  compute(const InternalParametersType & x, InternalMeasureType * fun, InternalDerivativeType * g) override;
89 
91  void
92  ConvertExternalToInternalGradient(const DerivativeType & input, InternalDerivativeType & output) const;
93 
95  void
96  SetScales(const ScalesType & scales);
97 
106  void
107  SetNegateCostFunction(bool flag);
108 
109  bool
110  GetNegateCostFunction() const;
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 &
135  GetCachedValue() const;
136 
137  const DerivativeType &
138  GetCachedDerivative() const;
139 
140  const ParametersType &
141  GetCachedCurrentParameters() const;
142 
143 protected:
146  void
147  ReportIteration(const EventObject & event) const;
148 
149 private:
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
itk::SingleValuedCostFunction::MeasureType
double MeasureType
Definition: itkSingleValuedCostFunction.h:50
itk::SingleValuedVnlCostFunctionAdaptor::MeasureType
SingleValuedCostFunction::MeasureType MeasureType
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:56
itk::SingleValuedVnlCostFunctionAdaptor::ParametersType
SingleValuedCostFunction::ParametersType ParametersType
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:50
itk::SingleValuedVnlCostFunctionAdaptor::InternalParametersType
vnl_vector< double > InternalParametersType
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:41
itk::SmartPointer< Self >
itk::SingleValuedVnlCostFunctionAdaptor
This class is an Adaptor that allows to pass itk::SingleValuedCostFunctions to vnl_optimizers expecti...
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:37
itk::Command
Superclass for callback/observer methods.
Definition: itkCommand.h:45
itk::SingleValuedVnlCostFunctionAdaptor::NegateCostFunctionOff
void NegateCostFunctionOff()
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:118
itk::SingleValuedVnlCostFunctionAdaptor::NegateCostFunctionOn
void NegateCostFunctionOn()
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:113
itk::SingleValuedVnlCostFunctionAdaptor::InternalMeasureType
double InternalMeasureType
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:44
itk::SingleValuedVnlCostFunctionAdaptor::GetCostFunction
const SingleValuedCostFunction * GetCostFunction() const
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:73
itk::SingleValuedCostFunction
This class is a base for the CostFunctions returning a single value.
Definition: itkSingleValuedCostFunction.h:34
itk::SingleValuedVnlCostFunctionAdaptor::SetCostFunction
void SetCostFunction(SingleValuedCostFunction *costFunction)
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:66
itk::SingleValuedCostFunction::ParametersType
Superclass::ParametersType ParametersType
Definition: itkSingleValuedCostFunction.h:54
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::Array
Array class with size defined at construction time.
Definition: itkArray.h:47
itk::EventObject
Abstraction of the Events used to communicating among filters and with GUIs.
Definition: itkEventObject.h:58
itkSingleValuedCostFunction.h
itk::SingleValuedCostFunction::DerivativeType
Array< ParametersValueType > DerivativeType
Definition: itkSingleValuedCostFunction.h:59
itk::SingleValuedVnlCostFunctionAdaptor::InternalDerivativeType
vnl_vector< double > InternalDerivativeType
Definition: itkSingleValuedVnlCostFunctionAdaptor.h:47