cmtkOptimizer.h

Go to the documentation of this file.
00001 /*
00002 //
00003 //  Copyright 1997-2009 Torsten Rohlfing
00004 //
00005 //  Copyright 2004-2010 SRI International
00006 //
00007 //  This file is part of the Computational Morphometry Toolkit.
00008 //
00009 //  http://www.nitrc.org/projects/cmtk/
00010 //
00011 //  The Computational Morphometry Toolkit is free software: you can
00012 //  redistribute it and/or modify it under the terms of the GNU General Public
00013 //  License as published by the Free Software Foundation, either version 3 of
00014 //  the License, or (at your option) any later version.
00015 //
00016 //  The Computational Morphometry Toolkit is distributed in the hope that it
00017 //  will be useful, but WITHOUT ANY WARRANTY; without even the implied
00018 //  warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 //  GNU General Public License for more details.
00020 //
00021 //  You should have received a copy of the GNU General Public License along
00022 //  with the Computational Morphometry Toolkit.  If not, see
00023 //  <http://www.gnu.org/licenses/>.
00024 //
00025 //  $Revision: 2398 $
00026 //
00027 //  $LastChangedDate: 2010-10-05 14:54:37 -0700 (Tue, 05 Oct 2010) $
00028 //
00029 //  $LastChangedBy: torstenrohlfing $
00030 //
00031 */
00032 
00033 #ifndef __cmtkOptimizer_h_included_
00034 #define __cmtkOptimizer_h_included_
00035 
00036 #include <cmtkconfig.h>
00037 
00038 #include <Registration/cmtkOptimizerBase.h>
00039 #include <Registration/cmtkRegistrationCallback.h>
00040 
00041 #include <Base/cmtkMacros.h>
00042 #include <Base/cmtkFunctional.h>
00043 #include <Base/cmtkVector.h>
00044 
00045 #include <System/cmtkSmartPtr.h>
00046 
00047 #include <vector>
00048 
00049 namespace
00050 cmtk
00051 {
00052 
00055 
00057 class Optimizer : 
00059   public OptimizerBase
00060 {
00061 public:
00063   typedef Optimizer Self;
00064 
00066   typedef OptimizerBase Superclass;
00067 
00069   typedef SmartPointer<Self> SmartPtr;
00070 
00078   cmtkGetSetMacro(bool,UpdateStepScaleVector);
00079 
00084   cmtkGetSetMacro(RegistrationCallback::SmartPtr,Callback);
00085 
00088   cmtkGetSetMacro(Functional::SmartPtr,Functional);
00089 
00091   virtual void SetDeltaFThreshold( const Self::ReturnType value )
00092   {
00093     this->m_DeltaFThreshold = value;
00094   }
00095 
00097   virtual CallbackResult CallbackExecuteWithData( const CoordinateVector &v, const Self::ReturnType metric ) 
00098   {
00099     if ( m_Callback )
00100       return m_Callback->ExecuteWithData( v, metric );
00101     return CALLBACK_OK;
00102   }
00103 
00105   virtual CallbackResult CallbackExecute()
00106   {
00107     if ( m_Callback ) 
00108       m_Callback->Execute();
00109     return CALLBACK_OK;
00110   }
00111 
00113   virtual void CallbackComment ( const char* comment = NULL ) 
00114   {
00115     if ( m_Callback ) 
00116       m_Callback->Comment( comment );
00117   }
00118 
00120   virtual unsigned int GetSearchSpaceDimension() const 
00121   {
00122     return this->m_Functional->VariableParamVectorDim();
00123   }
00124 
00126   virtual Self::ParameterType GetParamStep( unsigned int idx, const Self::ParameterType mmStep = 1.0 ) const 
00127   {
00128     return this->m_Functional->GetParamStep( idx, mmStep );
00129   }
00130 
00132   virtual Self::ReturnType Evaluate ( CoordinateVector& v ) 
00133   {
00134     return this->m_Functional->EvaluateAt( v );
00135   }
00136 
00138   virtual Self::ReturnType EvaluateWithGradient( CoordinateVector& v, CoordinateVector& directionVector, const Self::ParameterType step = 1 ) 
00139   {
00140     return this->m_Functional->EvaluateWithGradient( v, directionVector, step );
00141   }
00142 
00144   Optimizer()
00145     : m_Callback( NULL ),
00146       m_Functional( NULL ),
00147       m_DeltaFThreshold( 0.0 )
00148   {
00149     this->m_UpdateStepScaleVector = false;
00150   }
00151 
00153   virtual ~Optimizer () {}
00154 
00156   virtual CallbackResult Optimize( CoordinateVector&, const Self::ParameterType = 1, const Self::ParameterType = 0 ) = 0;
00157 
00159   bool GetLastOptimizeChangedParameters() const
00160   {
00161     return this->m_LastOptimizeChangedParameters;
00162   }
00163 
00164 protected:
00166   bool m_LastOptimizeChangedParameters;
00167 
00172   Self::ReturnType m_DeltaFThreshold;
00173 };
00174 
00176 
00177 } // namespace cmtk
00178 
00179 #endif // #ifdef __cmtkOptimizer_h_included_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines