ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkMultipleValuedVnlCostFunctionAdaptor.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkMultipleValuedVnlCostFunctionAdaptor_h
00019 #define __itkMultipleValuedVnlCostFunctionAdaptor_h
00020 
00021 #include "itkMultipleValuedCostFunction.h"
00022 #include "vnl/vnl_least_squares_function.h"
00023 
00024 namespace itk
00025 {
00036 class ITK_EXPORT MultipleValuedVnlCostFunctionAdaptor:
00037   public vnl_least_squares_function
00038 {
00039 public:
00040 
00042   typedef   vnl_vector< double > InternalParametersType;
00043 
00045   typedef   vnl_vector< double > InternalMeasureType;
00046 
00048   typedef   vnl_matrix< double > InternalDerivativeType;
00049 
00051   typedef MultipleValuedCostFunction::MeasureType MeasureType;
00052 
00054   typedef MultipleValuedCostFunction::ParametersType ParametersType;
00055 
00057   typedef MultipleValuedCostFunction::DerivativeType DerivativeType;
00058 
00060   typedef Array< double > ScalesType;
00061 
00063   MultipleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension,
00064                                        unsigned int numberOfValues);
00065 
00067   void SetCostFunction(MultipleValuedCostFunction *costFunction)
00068   { m_CostFunction = costFunction; }
00069 
00071   const MultipleValuedCostFunction * GetCostFunction(void) const
00072   { return m_CostFunction; }
00073 
00075   virtual void f(const InternalParametersType & inparameters,
00076                  InternalMeasureType    & measures);
00077 
00079   virtual void gradf(const InternalParametersType   & inparameters,
00080                      InternalDerivativeType   & gradient);
00081 
00083   virtual void compute(const InternalParametersType   & x,
00084                        InternalMeasureType      *f,
00085                        InternalDerivativeType   *g);
00086 
00088   void ConvertExternalToInternalGradient(
00089     const DerivativeType         & input,
00090     InternalDerivativeType & output);
00091 
00093   void ConvertExternalToInternalMeasures(
00094     const MeasureType         & input,
00095     InternalMeasureType & output);
00096 
00100   void SetUseGradient(bool);
00101 
00102   void UseGradientOn()  { this->SetUseGradient(true); }
00103   void UseGradientOff() { this->SetUseGradient(false); }
00104   bool GetUseGradient() const;
00105 
00107   void SetScales(const ScalesType & scales);
00108 
00113   unsigned long AddObserver(const EventObject & event, Command *) const;
00114 
00119   const MeasureType & GetCachedValue() const;
00120 
00121   const DerivativeType & GetCachedDerivative() const;
00122 
00123   const ParametersType & GetCachedCurrentParameters() const;
00124 
00125 protected:
00126 
00129   void ReportIteration(const EventObject & event) const;
00130 
00131 private:
00132 
00133   MultipleValuedCostFunction::Pointer m_CostFunction;
00134 
00135   bool            m_ScalesInitialized;
00136   ScalesType      m_Scales;
00137   Object::Pointer m_Reporter;
00138 
00139   mutable MeasureType    m_CachedValue;
00140   mutable DerivativeType m_CachedDerivative;
00141   mutable ParametersType m_CachedCurrentParameters;
00142 };  // end of Class CostFunction
00143 } // end namespace itk
00144 
00145 #endif
00146