Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkSingleValuedVnlCostFunctionAdaptor.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkSingleValuedVnlCostFunctionAdaptor.h,v $
00005   Language:  C++
00006   Date:      $Date: 2005/03/30 22:26:05 $
00007   Version:   $Revision: 1.10 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkSingleValuedVnlCostFunctionAdaptor_h
00018 #define __itkSingleValuedVnlCostFunctionAdaptor_h
00019 
00020 #include "itkSingleValuedCostFunction.h"
00021 #include "vnl/vnl_cost_function.h"
00022 
00023 
00024 namespace itk
00025 {
00026   
00036 class SingleValuedVnlCostFunctionAdaptor : 
00037     public vnl_cost_function
00038 {
00039 public:
00040 
00042   typedef   vnl_vector<double>     InternalParametersType;
00043 
00045   typedef   double                 InternalMeasureType;
00046 
00048   typedef   vnl_vector<double>     InternalDerivativeType;
00049 
00051   typedef SingleValuedCostFunction::ParametersType ParametersType;
00052 
00054   typedef SingleValuedCostFunction::DerivativeType DerivativeType;
00055 
00057   typedef SingleValuedCostFunction::MeasureType MeasureType;
00058 
00060   typedef Array<double>             ScalesType;
00061 
00063   SingleValuedVnlCostFunctionAdaptor(unsigned int spaceDimension);
00064 
00065 
00067   void SetCostFunction( SingleValuedCostFunction * costFunction )
00068   { m_CostFunction = costFunction; }
00069 
00071   const SingleValuedCostFunction * GetCostFunction( void ) const
00072   { return m_CostFunction; }
00073 
00074 
00076   virtual InternalMeasureType f( const InternalParametersType & inparameters );
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 ) const;
00091 
00093   void SetScales(const ScalesType & scales);
00094 
00103    void SetNegateCostFunction( bool value );
00104    bool GetNegateCostFunction() const;
00105    void NegateCostFunctionOn() { m_NegateCostFunction = true; }
00106    void NegateCostFunctionOff() { m_NegateCostFunction = false; }
00108 
00113   unsigned long AddObserver(const EventObject & event, Command *) const;
00114 
00119   const MeasureType & GetCachedValue() const;
00120   const DerivativeType & GetCachedDerivative() const;
00121   const ParametersType & GetCachedCurrentParameters() const;
00123 
00124 protected:
00125 
00128   void ReportIteration( const EventObject & event ) const;
00129 
00130 private:
00131 
00132   SingleValuedCostFunction::Pointer   m_CostFunction;
00133   bool                                m_ScalesInitialized;
00134   ScalesType                          m_Scales;
00135   bool                                m_NegateCostFunction;
00136   Object::Pointer                     m_Reporter;
00137   
00138   mutable MeasureType                 m_CachedValue;
00139   mutable DerivativeType              m_CachedDerivative;
00140   mutable ParametersType              m_CachedCurrentParameters;
00141 
00142 };  // end of Class CostFunction
00143 
00144     
00145 } // end namespace itk
00146 
00147 
00148 #endif
00149 
00150 
00151 
00152 

Generated at Mon Mar 12 03:04:33 2007 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000