ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkMultipleValuedVnlCostFunctionAdaptor.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 itkMultipleValuedVnlCostFunctionAdaptor_h
19 #define itkMultipleValuedVnlCostFunctionAdaptor_h
20 
22 #include "vnl/vnl_least_squares_function.h"
23 #include "ITKOptimizersExport.h"
24 
25 namespace itk
26 {
37 class ITKOptimizers_EXPORT MultipleValuedVnlCostFunctionAdaptor:
38  public vnl_least_squares_function
39 {
40 public:
41 
43  typedef vnl_vector< double > InternalParametersType;
44 
46  typedef vnl_vector< double > InternalMeasureType;
47 
49  typedef vnl_matrix< double > InternalDerivativeType;
50 
53 
56 
59 
62 
64  MultipleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension,
65  unsigned int numberOfValues);
66 
69  { m_CostFunction = costFunction; }
70 
73  { return m_CostFunction; }
74 
76  virtual void f(const InternalParametersType & inparameters,
77  InternalMeasureType & measures) ITK_OVERRIDE;
78 
80  virtual void gradf(const InternalParametersType & inparameters,
81  InternalDerivativeType & gradient) ITK_OVERRIDE;
82 
84  virtual void compute(const InternalParametersType & x,
85  InternalMeasureType *f,
86  InternalDerivativeType *g);
87 
89  void ConvertExternalToInternalGradient(
90  const DerivativeType & input,
91  InternalDerivativeType & output);
92 
94  void ConvertExternalToInternalMeasures(
95  const MeasureType & input,
96  InternalMeasureType & output);
97 
101  void SetUseGradient(bool);
102 
103  void UseGradientOn() { this->SetUseGradient(true); }
104  void UseGradientOff() { this->SetUseGradient(false); }
105  bool GetUseGradient() const;
106 
108  void SetScales(const ScalesType & scales);
109 
114  unsigned long AddObserver(const EventObject & event, Command *) const;
115 
120  const MeasureType & GetCachedValue() const;
121 
122  const DerivativeType & GetCachedDerivative() const;
123 
124  const ParametersType & GetCachedCurrentParameters() const;
125 
126 protected:
127 
130  void ReportIteration(const EventObject & event) const;
131 
132 private:
133 
135  itkGetConstReferenceMacro(InverseScales, ScalesType);
136 
138 
142 
146 }; // end of Class CostFunction
147 } // end namespace itk
148 
149 #endif
This class is a base for the CostFunctions returning a multiple values.
void SetCostFunction(MultipleValuedCostFunction *costFunction)
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:45
MultipleValuedCostFunction::ParametersType ParametersType
Abstraction of the Events used to communicating among filters and with GUIs.
const MultipleValuedCostFunction * GetCostFunction(void) const
This class is an Adaptor that allows to pass itk::MultipleValuedCostFunctions to vnl_optimizers expec...
MultipleValuedCostFunction::DerivativeType DerivativeType
Superclass for callback/observer methods.
Definition: itkCommand.h:44