freSetupOptimizationMetric.cxx

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   F.R.E.E. - flexible registration evaluation engine
00004   Version:   v.1.0.0
00005   Date:      $Date: 2006/09/01 12:00:00 $
00006   Module:    $RCSfile: freSetupOptimizationMetric.cxx,v $
00007   Language:  C++
00008 
00009 
00010 
00011   Copyright (c) 2007 Ralf o Floca (Department of Medical Informatics,
00012   Institute for Medical Biometry and Informatics, University of Heidelberg,
00013   Germany). All rights reserved.
00014   See FREECopyright.txt or http://www.mi.med.uni-hd.de/free/copyright.htm
00015   for details.
00016 
00017      This software is distributed WITHOUT ANY WARRANTY; without even 
00018      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00019      PURPOSE.  See the above copyright notices for more information.
00020 
00021 =========================================================================*/
00022 #include "freSetupOptimizationMetric.h"
00023 
00024 namespace FREE
00025 {
00026   
00027         SetupOptimizationMetric::SetupOptimizationMetric()
00028         {
00029                 m_Transform = NULL;
00030                 m_smpAdaptations = NULL;
00031                 m_Delta = 0.05;
00032                 m_CachedValues.fill(0.0);
00033                 m_CachedDerivative.fill(0.0);
00034                 m_CachedParameters.fill(0.0);
00035                 m_MetricScales.fill(1.0);
00036 
00037     this->fnOnEvaluationProgress = 0;
00038     this->fnOnEvaluationDone = 0;
00039     this->fnOnNextAdaptation = 0;
00040     this->fnOnEvaluationFailed = 0;
00041         };
00042 
00043         SetupOptimizationMetric::~SetupOptimizationMetric()
00044         {
00045         };
00046 
00047   void
00048   SetupOptimizationMetric::
00049   Initialize()
00050   {
00051                 if (this->m_smpAdaptations.IsNull()) throwExceptionMacro("Error. Cannot calculate metric value, adaptiation list is null.");
00052                 if (this->m_Transform.IsNull()) throwExceptionMacro("Error. Cannot calculate metric value, no setup transform set.");
00053 
00054     //redefine if you need initialization in derived classes
00055   };
00056 
00057   Adaptation::AdaptationList*
00058   SetupOptimizationMetric::
00059   GetAdaptationList() const
00060   {
00061     return m_smpAdaptations.GetPointer();
00062   };
00063 
00064   void
00065   SetupOptimizationMetric::
00066   SetAdaptationList(Adaptation::AdaptationList* pAdaptations)
00067   {
00068     if (m_smpAdaptations.GetPointer()!=pAdaptations)
00069     {
00070       m_smpAdaptations=pAdaptations;
00071       this->Modified();
00072     }
00073   };
00074 
00075   unsigned int
00076   SetupOptimizationMetric::
00077 	GetNumberOfParameters(void) const
00078         {
00079                 if (m_Transform.IsNull()) return 0;
00080                 
00081                 return m_Transform->GetNumberOfParameters();
00082         };
00083 
00084 SetupOptimizationMetric::MeasureType
00085 SetupOptimizationMetric::
00086 GetValue( const ParametersType & parameters ) const
00087 {
00088   m_MetricStatistic.GetData().Reset();
00089 
00090   this->m_CachedValues = ComputeDecomposedValue(parameters);
00091         this->m_CachedParameters = parameters;
00092 
00093         return ComposeValue(m_CachedValues);
00094 };
00095 
00096 SetupOptimizationMetric::DecomposedMeasureType
00097 SetupOptimizationMetric::
00098 GetDecomposedValue( const ParametersType & parameters ) const
00099 {
00100   m_MetricStatistic.GetData().Reset();
00101 
00102   this->m_CachedValues = ComputeDecomposedValue(parameters);
00103         this->m_CachedParameters = parameters;
00104         
00105         return this->m_CachedValues;
00106 };
00107 
00108 SetupOptimizationMetric::DecomposedMeasureType
00109 SetupOptimizationMetric::
00110 GetCurrentDecomposedValue() const
00111 {
00112         return this->m_CachedValues;
00113 };
00114 
00115 SetupOptimizationMetric::MeasureType
00116 SetupOptimizationMetric::
00117 GetCurrentValue() const
00118 {
00119         return ComposeValue(m_CachedValues);
00120 };
00121 
00122 SetupOptimizationMetric::ParametersType
00123 SetupOptimizationMetric::
00124 GetCurrentParameters() const
00125 {
00126         return this->m_CachedParameters;
00127 };
00128 
00129 void
00130 SetupOptimizationMetric::
00131 GetDerivative( const ParametersType & parameters, 
00132                  DerivativeType & derivative           ) const
00133 {
00134   m_MetricStatistic.GetData().Reset();
00135 
00136   ComputeDecomposedValueAndDerivative(parameters, m_CachedValues, derivative);
00137         this->m_CachedDerivative = derivative;
00138         this->m_CachedParameters = parameters;
00139 }
00140 
00141 void
00142 SetupOptimizationMetric::
00143 GetValueAndDerivative(const ParametersType & parameters, 
00144                         MeasureType & value, DerivativeType  & derivative) const
00145 {
00146         DecomposedMeasureType values;
00147   
00148   m_MetricStatistic.GetData().Reset();
00149 
00150   ComputeDecomposedValueAndDerivative(parameters, values, derivative);
00151 
00152         this->m_CachedValues = values;
00153         this->m_CachedDerivative = derivative;
00154         this->m_CachedParameters = parameters;
00155         value = ComposeValue(m_CachedValues);
00156 }
00157 
00158 void
00159 SetupOptimizationMetric::
00160 ComputeDecomposedValueAndDerivative( const ParametersType & parametersconst,
00161                                                                                                                                                  DecomposedMeasureType& value,
00162                                                                                                                                                  DerivativeType& derivative) const
00163 {
00164         throwExceptionMacro("Error: Registration Metrics, cannot calculate gradients by default");
00165 };
00166 
00167 SetupOptimizationMetric::MeasureType
00168 SetupOptimizationMetric::
00169 ComposeValue(const DecomposedMeasureType& values) const
00170 {
00171         MeasureType result = 0.0;
00172 
00173         for(unsigned int i=0; i<values.GetSize(); i++)
00174   { 
00175                 if (i < m_MetricScales.GetSize())       result += values[i]*this->m_MetricScales[i];
00176                 else result += values[i];
00177   }
00178 
00179         return result;
00180 };
00181 
00182 } // end namespace FREE

Generated at Sat Oct 13 17:27:29 2007 for f.r.e.e. - Flexible Registration and Evaluation Engine by doxygen 1.5.3 written by Dimitri van Heesch, © 1997-2000