00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 ITK_EXPORT 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
00075 virtual InternalMeasureType f( const InternalParametersType & inparameters );
00076
00078 virtual void gradf(const InternalParametersType & inparameters,
00079 InternalDerivativeType & gradient );
00080
00082 virtual void compute(const InternalParametersType & x,
00083 InternalMeasureType * f,
00084 InternalDerivativeType * g );
00085
00087 void ConvertExternalToInternalGradient(
00088 const DerivativeType & input,
00089 InternalDerivativeType & output ) const;
00090
00092 void SetScales(const ScalesType & scales);
00093
00102 void SetNegateCostFunction( bool value );
00103 bool GetNegateCostFunction() const;
00104 void NegateCostFunctionOn() { m_NegateCostFunction = true; }
00105 void NegateCostFunctionOff() { m_NegateCostFunction = false; }
00107
00112 unsigned long AddObserver(const EventObject & event, Command *) const;
00113
00118 const MeasureType & GetCachedValue() const;
00119 const DerivativeType & GetCachedDerivative() const;
00120 const ParametersType & GetCachedCurrentParameters() const;
00122
00123 protected:
00124
00127 void ReportIteration( const EventObject & event ) const;
00128
00129 private:
00130
00131 SingleValuedCostFunction::Pointer m_CostFunction;
00132 bool m_ScalesInitialized;
00133 ScalesType m_Scales;
00134 bool m_NegateCostFunction;
00135 Object::Pointer m_Reporter;
00136
00137 mutable MeasureType m_CachedValue;
00138 mutable DerivativeType m_CachedDerivative;
00139 mutable ParametersType m_CachedCurrentParameters;
00140
00141 };
00142
00143
00144 }
00145
00146
00147 #endif
00148