ITK  4.6.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 
24 namespace itk
25 {
37  public vnl_least_squares_function
38 {
39 public:
40 
42  typedef vnl_vector< double > InternalParametersType;
43 
45  typedef vnl_vector< double > InternalMeasureType;
46 
48  typedef vnl_matrix< double > InternalDerivativeType;
49 
52 
55 
58 
61 
63  MultipleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension,
64  unsigned int numberOfValues);
65 
68  { m_CostFunction = costFunction; }
69 
72  { return m_CostFunction; }
73 
75  virtual void f(const InternalParametersType & inparameters,
76  InternalMeasureType & measures) ITK_OVERRIDE;
77 
79  virtual void gradf(const InternalParametersType & inparameters,
80  InternalDerivativeType & gradient) ITK_OVERRIDE;
81 
83  virtual void compute(const InternalParametersType & x,
86 
89  const DerivativeType & input,
90  InternalDerivativeType & output);
91 
94  const MeasureType & input,
95  InternalMeasureType & output);
96 
100  void SetUseGradient(bool);
101 
102  void UseGradientOn() { this->SetUseGradient(true); }
103  void UseGradientOff() { this->SetUseGradient(false); }
104  bool GetUseGradient() const;
105 
107  void SetScales(const ScalesType & scales);
108 
113  unsigned long AddObserver(const EventObject & event, Command *) const;
114 
119  const MeasureType & GetCachedValue() const;
120 
121  const DerivativeType & GetCachedDerivative() const;
122 
124 
125 protected:
126 
129  void ReportIteration(const EventObject & event) const;
130 
131 private:
132 
134  itkGetConstReferenceMacro(InverseScales, ScalesType);
135 
137 
141 
145 }; // end of Class CostFunction
146 } // end namespace itk
147 
148 #endif
This class is a base for the CostFunctions returning a multiple values.
void SetCostFunction(MultipleValuedCostFunction *costFunction)
const MeasureType & GetCachedValue() const
void ConvertExternalToInternalMeasures(const MeasureType &input, InternalMeasureType &output)
virtual void f(const InternalParametersType &inparameters, InternalMeasureType &measures) ITK_OVERRIDE
void ReportIteration(const EventObject &event) const
const DerivativeType & GetCachedDerivative() const
virtual void compute(const InternalParametersType &x, InternalMeasureType *f, InternalDerivativeType *g)
Array2D class representing a 2D array with size defined at construction time.
Definition: itkArray2D.h:44
unsigned long AddObserver(const EventObject &event, Command *) const
MultipleValuedCostFunction::ParametersType ParametersType
const ParametersType & GetCachedCurrentParameters() const
Abstraction of the Events used to communicating among filters and with GUIs.
void ConvertExternalToInternalGradient(const DerivativeType &input, InternalDerivativeType &output)
virtual void gradf(const InternalParametersType &inparameters, InternalDerivativeType &gradient) ITK_OVERRIDE
void SetScales(const ScalesType &scales)
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
MultipleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension, unsigned int numberOfValues)