ITK
4.1.0
Insight Segmentation and Registration Toolkit
|
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 __itkSingleValuedVnlCostFunctionAdaptor_h 00019 #define __itkSingleValuedVnlCostFunctionAdaptor_h 00020 00021 #include "itkSingleValuedCostFunction.h" 00022 #include "vnl/vnl_cost_function.h" 00023 00024 namespace itk 00025 { 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 00066 void SetCostFunction(SingleValuedCostFunction *costFunction) 00067 { m_CostFunction = costFunction; } 00068 00070 const SingleValuedCostFunction * GetCostFunction(void) const 00071 { return m_CostFunction; } 00072 00074 virtual InternalMeasureType f(const InternalParametersType & inparameters); 00075 00077 virtual void gradf(const InternalParametersType & inparameters, 00078 InternalDerivativeType & gradient); 00079 00081 virtual void compute(const InternalParametersType & x, 00082 InternalMeasureType *f, 00083 InternalDerivativeType *g); 00084 00086 void ConvertExternalToInternalGradient( 00087 const DerivativeType & input, 00088 InternalDerivativeType & output) const; 00089 00091 void SetScales(const ScalesType & scales); 00092 00101 void SetNegateCostFunction(bool value); 00102 00103 bool GetNegateCostFunction() const; 00104 00105 void NegateCostFunctionOn() { m_NegateCostFunction = true; } 00106 void NegateCostFunctionOff() { m_NegateCostFunction = false; } 00107 00112 unsigned long AddObserver(const EventObject & event, Command *) const; 00113 00118 const MeasureType & GetCachedValue() const; 00119 00120 const DerivativeType & GetCachedDerivative() const; 00121 00122 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 }; // end of Class CostFunction 00142 } // end namespace itk 00143 00144 #endif 00145