00001 /*========================================================================= 00002 00003 Program: Insight Segmentation & Registration Toolkit 00004 Module: $RCSfile: itkMultipleValuedVnlCostFunctionAdaptor.h,v $ 00005 Language: C++ 00006 Date: $Date: 2004/03/14 17:43:02 $ 00007 Version: $Revision: 1.5 $ 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 __itkMultipleValuedVnlCostFunctionAdaptor_h 00018 #define __itkMultipleValuedVnlCostFunctionAdaptor_h 00019 00020 #include "itkMultipleValuedCostFunction.h" 00021 #include "vnl/vnl_least_squares_function.h" 00022 00023 00024 namespace itk 00025 { 00026 00036 class 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 void UseGradientOn() { this->SetUseGradient( true ); }; 00102 void UseGradientOff() { this->SetUseGradient( false ); }; 00103 bool GetUseGradient() const; 00104 00106 void SetScales(const ScalesType & scales); 00107 00108 private: 00109 00110 MultipleValuedCostFunction::Pointer m_CostFunction; 00111 bool m_ScalesInitialized; 00112 ScalesType m_Scales; 00113 00114 00115 }; // end of Class CostFunction 00116 00117 00118 } // end namespace itk 00119 00120 00121 #endif 00122 00123 00124