ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkSingleValuedVnlCostFunctionAdaptor.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 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:
38  public vnl_cost_function
39 {
40 public:
41 
43  typedef vnl_vector< double > InternalParametersType;
44 
46  typedef double InternalMeasureType;
47 
49  typedef vnl_vector< double > InternalDerivativeType;
50 
53 
56 
59 
62 
64  SingleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension);
65 
68  { m_CostFunction = costFunction; }
69 
72  { return m_CostFunction; }
73 
75  virtual InternalMeasureType f(const InternalParametersType & inparameters) ITK_OVERRIDE;
76 
78  virtual void gradf(const InternalParametersType & inparameters,
79  InternalDerivativeType & gradient) ITK_OVERRIDE;
80 
82  virtual void compute(const InternalParametersType & x,
83  InternalMeasureType *f,
84  InternalDerivativeType *g) ITK_OVERRIDE;
85 
87  void ConvertExternalToInternalGradient(
88  const DerivativeType & input,
89  InternalDerivativeType & output) const;
90 
92  void SetScales(const ScalesType & scales);
93 
102  void SetNegateCostFunction(bool value);
103 
104  bool GetNegateCostFunction() const;
105 
106  void NegateCostFunctionOn() { m_NegateCostFunction = true; }
107  void NegateCostFunctionOff() { m_NegateCostFunction = false; }
108 
113  unsigned long AddObserver(const EventObject & event, Command *) const;
114 
119  const MeasureType & GetCachedValue() const;
120 
121  const DerivativeType & GetCachedDerivative() const;
122 
123  const ParametersType & GetCachedCurrentParameters() const;
124 
125 protected:
126 
129  void ReportIteration(const EventObject & event) const;
130 
131 private:
132 
134  itkGetConstReferenceMacro(InverseScales, ScalesType);
135 
141 
145 }; // end of Class CostFunction
146 } // end namespace itk
147 
148 #endif
Array class with size defined at construction time.
Definition: itkArray.h:50
SingleValuedCostFunction::DerivativeType DerivativeType
This class is a base for the CostFunctions returning a single value.
This class is an Adaptor that allows to pass itk::SingleValuedCostFunctions to vnl_optimizers expecti...
SingleValuedCostFunction::ParametersType ParametersType
void SetCostFunction(SingleValuedCostFunction *costFunction)
Abstraction of the Events used to communicating among filters and with GUIs.
Superclass::ParametersType ParametersType
const SingleValuedCostFunction * GetCostFunction(void) const
Superclass for callback/observer methods.
Definition: itkCommand.h:44